Fail to create GrContext when we get a NULL for a GL/GLSL version string

BUG=368107
R=jvanverth@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/254083002

git-svn-id: http://skia.googlecode.com/svn/trunk@14452 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGLAssembleInterface.cpp b/src/gpu/gl/GrGLAssembleInterface.cpp
index 11355b8..aed11e5 100644
--- a/src/gpu/gl/GrGLAssembleInterface.cpp
+++ b/src/gpu/gl/GrGLAssembleInterface.cpp
@@ -27,7 +27,7 @@
     const char* versionString = (const char*) GetString(GR_GL_VERSION);
     GrGLVersion glVer = GrGLGetVersionFromString(versionString);
 
-    if (glVer < GR_GL_VER(1,5)) {
+    if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) {
         // We must have array and element_array buffer objects.
         return NULL;
     }
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 6fe804f..501411c 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -90,11 +90,11 @@
     return *this;
 }
 
-void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
+bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
 
     this->reset();
     if (!ctxInfo.isInitialized()) {
-        return;
+        return false;
     }
 
     GrGLStandard standard = ctxInfo.standard();
@@ -353,6 +353,8 @@
     }
 
     this->initConfigRenderableTable(ctxInfo);
+
+    return true;
 }
 
 void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 2269cae..48925d4 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -105,7 +105,7 @@
      * Initializes the GrGLCaps to the set of features supported in the current
      * OpenGL context accessible via ctxInfo.
      */
-    void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
+    bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
 
     /**
      * Call to note that a color config has been verified as a valid color
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp
index 54deb32..5bc5b6f 100644
--- a/src/gpu/gl/GrGLContext.cpp
+++ b/src/gpu/gl/GrGLContext.cpp
@@ -37,8 +37,13 @@
         if (interface->validate()) {
 
             fGLVersion = GrGLGetVersionFromString(ver);
+            if (GR_GL_INVALID_VER == fGLVersion) {
+                return false;
+            }
 
-            fGLSLGeneration = GrGetGLSLGeneration(interface);
+            if (!GrGetGLSLGeneration(interface, &fGLSLGeneration)) {
+                return false;
+            }
 
             fVendor = GrGLGetVendor(interface);
 
@@ -51,9 +56,7 @@
             // This must occur before caps init.
             fInterface.reset(SkRef(interface));
 
-            fGLCaps->init(*this, interface);
-
-            return true;
+            return fGLCaps->init(*this, interface);
         }
     }
     return false;
diff --git a/src/gpu/gl/GrGLExtensions.cpp b/src/gpu/gl/GrGLExtensions.cpp
index 6d1b04d..53013df 100644
--- a/src/gpu/gl/GrGLExtensions.cpp
+++ b/src/gpu/gl/GrGLExtensions.cpp
@@ -54,10 +54,11 @@
 
     // glGetStringi and indexed extensions were added in version 3.0 of desktop GL and ES.
     const GrGLubyte* verString = getString(GR_GL_VERSION);
-    if (NULL == verString) {
+    GrGLVersion version = GrGLGetVersionFromString((const char*) verString);
+    if (GR_GL_INVALID_VER == version) {
         return false;
     }
-    GrGLVersion version = GrGLGetVersionFromString((const char*) verString);
+
     bool indexed = version >= GR_GL_VER(3, 0);
 
     if (indexed) {
diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp
index b5da4d3..7efa067 100644
--- a/src/gpu/gl/GrGLInterface.cpp
+++ b/src/gpu/gl/GrGLInterface.cpp
@@ -227,6 +227,9 @@
     }
 
     GrGLVersion glVer = GrGLGetVersion(this);
+    if (GR_GL_INVALID_VER == glVer) {
+        RETURN_FALSE_INTERFACE
+    }
 
     // Now check that baseline ES/Desktop fns not covered above are present
     // and that we have fn pointers for any advertised fExtensions that we will
diff --git a/src/gpu/gl/GrGLSL.cpp b/src/gpu/gl/GrGLSL.cpp
index 1ff0850..7587fe8 100644
--- a/src/gpu/gl/GrGLSL.cpp
+++ b/src/gpu/gl/GrGLSL.cpp
@@ -9,27 +9,33 @@
 #include "GrGLShaderVar.h"
 #include "SkString.h"
 
-GrGLSLGeneration GrGetGLSLGeneration(const GrGLInterface* gl) {
+bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation) {
+    SkASSERT(NULL != generation);
     GrGLSLVersion ver = GrGLGetGLSLVersion(gl);
+    if (GR_GLSL_INVALID_VER == ver) {
+        return false;
+    }
     switch (gl->fStandard) {
         case kGL_GrGLStandard:
             SkASSERT(ver >= GR_GLSL_VER(1,10));
             if (ver >= GR_GLSL_VER(1,50)) {
-                return k150_GrGLSLGeneration;
+                *generation = k150_GrGLSLGeneration;
             } else if (ver >= GR_GLSL_VER(1,40)) {
-                return k140_GrGLSLGeneration;
+                *generation = k140_GrGLSLGeneration;
             } else if (ver >= GR_GLSL_VER(1,30)) {
-                return k130_GrGLSLGeneration;
+                *generation = k130_GrGLSLGeneration;
             } else {
-                return k110_GrGLSLGeneration;
+                *generation = k110_GrGLSLGeneration;
             }
+            return true;
         case kGLES_GrGLStandard:
             // version 1.00 of ES GLSL based on ver 1.20 of desktop GLSL
             SkASSERT(ver >= GR_GL_VER(1,00));
-            return k110_GrGLSLGeneration;
+            *generation = k110_GrGLSLGeneration;
+            return true;
         default:
             GrCrash("Unknown GL Standard");
-            return k110_GrGLSLGeneration; // suppress warning
+            return false;
     }
 }
 
diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h
index 5c0a170..8234be9 100644
--- a/src/gpu/gl/GrGLSL.h
+++ b/src/gpu/gl/GrGLSL.h
@@ -40,7 +40,7 @@
 /**
  * Gets the most recent GLSL Generation compatible with the OpenGL context.
  */
-GrGLSLGeneration GrGetGLSLGeneration(const GrGLInterface* gl);
+bool GrGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation);
 
 /**
  * Returns a string to include at the beginning of a shader to declare the GLSL
diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp
index a479523..ddfcfbf 100644
--- a/src/gpu/gl/GrGLUtil.cpp
+++ b/src/gpu/gl/GrGLUtil.cpp
@@ -140,7 +140,7 @@
 GrGLVersion GrGLGetVersionFromString(const char* versionString) {
     if (NULL == versionString) {
         SkDEBUGFAIL("NULL GL version string.");
-        return 0;
+        return GR_GL_INVALID_VER;
     }
 
     int major, minor;
@@ -152,7 +152,7 @@
         if (get_gl_version_for_mesa(mesaMajor, &major, &minor)) {
             return GR_GL_VER(major, minor);
         } else {
-            return 0;
+            return GR_GL_INVALID_VER;
         }
     }
 
@@ -173,13 +173,13 @@
         return GR_GL_VER(major, minor);
     }
 
-    return 0;
+    return GR_GL_INVALID_VER;
 }
 
 GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) {
     if (NULL == versionString) {
         SkDEBUGFAIL("NULL GLSL version string.");
-        return 0;
+        return GR_GLSL_INVALID_VER;
     }
 
     int major, minor;
@@ -202,7 +202,7 @@
     }
 #endif
 
-    return 0;
+    return GR_GLSL_INVALID_VER;
 }
 
 GrGLVendor GrGLGetVendorFromString(const char* vendorString) {
diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h
index b99487a..73fcec1 100644
--- a/src/gpu/gl/GrGLUtil.h
+++ b/src/gpu/gl/GrGLUtil.h
@@ -18,6 +18,14 @@
 typedef uint32_t GrGLVersion;
 typedef uint32_t GrGLSLVersion;
 
+#define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \
+                                 static_cast<int>(minor))
+#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
+                                   static_cast<int>(minor))
+
+#define GR_GL_INVALID_VER GR_GL_VER(0, 0)
+#define GR_GLSL_INVALID_VER GR_GL_VER(0, 0)
+
 /**
  * The Vendor and Renderer enum values are lazily updated as required.
  */
@@ -37,11 +45,6 @@
     kOther_GrGLRenderer
 };
 
-#define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \
-                                 static_cast<int>(minor))
-#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
-                                   static_cast<int>(minor))
-
 ////////////////////////////////////////////////////////////////////////////////
 
 /**