Bug 1427088 - Don't rely on glGetStringi just because it exists. - r=daoshengmu draft
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 08 Jan 2018 12:35:04 -0800
changeset 717385 23116a91a86837d18383306540615473a594a6af
parent 717183 ca379fcca95b1f4a3744242ea8647004b99b3507
child 745237 bc6f17a5b30857a0c939bbc448aebe22fe0008df
push id94656
push userbmo:jgilbert@mozilla.com
push dateMon, 08 Jan 2018 21:23:31 +0000
reviewersdaoshengmu
bugs1427088
milestone59.0a1
Bug 1427088 - Don't rely on glGetStringi just because it exists. - r=daoshengmu MozReview-Commit-ID: Gmf6phqDOTK
gfx/gl/GLContext.cpp
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1651,38 +1651,41 @@ GLContext::DebugCallback(GLenum source,
 
 void
 GLContext::InitExtensions()
 {
     MOZ_ASSERT(IsCurrent());
 
     std::vector<nsCString> driverExtensionList;
 
-    if (mSymbols.fGetStringi) {
-        GLuint count = 0;
-        GetUIntegerv(LOCAL_GL_NUM_EXTENSIONS, &count);
-        for (GLuint i = 0; i < count; i++) {
-            // This is UTF-8.
-            const char* rawExt = (const char*)fGetStringi(LOCAL_GL_EXTENSIONS, i);
-
-            // We CANNOT use nsDependentCString here, because the spec doesn't guarantee
-            // that the pointers returned are different, only that their contents are.
-            // On Flame, each of these index string queries returns the same address.
-            driverExtensionList.push_back(nsCString(rawExt));
+    [&]() {
+        if (mSymbols.fGetStringi) {
+            GLuint count = 0;
+            if (GetPotentialInteger(LOCAL_GL_NUM_EXTENSIONS, (GLint*)&count)) {
+                for (GLuint i = 0; i < count; i++) {
+                    // This is UTF-8.
+                    const char* rawExt = (const char*)fGetStringi(LOCAL_GL_EXTENSIONS, i);
+
+                    // We CANNOT use nsDependentCString here, because the spec doesn't guarantee
+                    // that the pointers returned are different, only that their contents are.
+                    // On Flame, each of these index string queries returns the same address.
+                    driverExtensionList.push_back(nsCString(rawExt));
+                }
+                return;
+            }
         }
-    } else {
-        MOZ_ALWAYS_TRUE(!fGetError());
+
         const char* rawExts = (const char*)fGetString(LOCAL_GL_EXTENSIONS);
-        MOZ_ALWAYS_TRUE(!fGetError());
-
         if (rawExts) {
             nsDependentCString exts(rawExts);
             SplitByChar(exts, ' ', &driverExtensionList);
         }
-    }
+    }();
+    const auto err = fGetError();
+    MOZ_ASSERT(!err);
 
     const bool shouldDumpExts = ShouldDumpExts();
     if (shouldDumpExts) {
         printf_stderr("%i GL driver extensions: (*: recognized)\n",
                       (uint32_t)driverExtensionList.size());
     }
 
     MarkBitfieldByStrings(driverExtensionList, shouldDumpExts, sExtensionNames,