From f4e67e3e5e5017284300a61e7bb046723a44b0cf Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Wed, 30 Apr 2014 01:26:04 +0000 Subject: [PATCH] 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 --- src/gpu/gl/GrGLAssembleInterface.cpp | 2 +- src/gpu/gl/GrGLCaps.cpp | 6 ++++-- src/gpu/gl/GrGLCaps.h | 2 +- src/gpu/gl/GrGLContext.cpp | 11 +++++++---- src/gpu/gl/GrGLExtensions.cpp | 5 +++-- src/gpu/gl/GrGLInterface.cpp | 3 +++ src/gpu/gl/GrGLSL.cpp | 20 +++++++++++++------- src/gpu/gl/GrGLSL.h | 2 +- src/gpu/gl/GrGLUtil.cpp | 10 +++++----- src/gpu/gl/GrGLUtil.h | 13 ++++++++----- 10 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/gpu/gl/GrGLAssembleInterface.cpp b/src/gpu/gl/GrGLAssembleInterface.cpp index 11355b8991..aed11e539f 100644 --- a/src/gpu/gl/GrGLAssembleInterface.cpp +++ b/src/gpu/gl/GrGLAssembleInterface.cpp @@ -27,7 +27,7 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { 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 6fe804f2f8..501411c0e9 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -90,11 +90,11 @@ GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) { 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 @@ void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { } 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 2269cae8ff..48925d48b4 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -105,7 +105,7 @@ public: * 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 54deb323c0..5bc5b6f031 100644 --- a/src/gpu/gl/GrGLContext.cpp +++ b/src/gpu/gl/GrGLContext.cpp @@ -37,8 +37,13 @@ bool GrGLContextInfo::initialize(const GrGLInterface* interface) { 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 @@ bool GrGLContextInfo::initialize(const GrGLInterface* interface) { // 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 6d1b04d2cc..53013df64d 100644 --- a/src/gpu/gl/GrGLExtensions.cpp +++ b/src/gpu/gl/GrGLExtensions.cpp @@ -54,10 +54,11 @@ bool GrGLExtensions::init(GrGLStandard standard, // 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 b5da4d3a95..7efa067ddb 100644 --- a/src/gpu/gl/GrGLInterface.cpp +++ b/src/gpu/gl/GrGLInterface.cpp @@ -227,6 +227,9 @@ bool GrGLInterface::validate() const { } 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 1ff0850a1d..7587fe8d64 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 5c0a170e78..8234be9c46 100644 --- a/src/gpu/gl/GrGLSL.h +++ b/src/gpu/gl/GrGLSL.h @@ -40,7 +40,7 @@ enum GrGLSLGeneration { /** * 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 a479523b65..ddfcfbf0a6 100644 --- a/src/gpu/gl/GrGLUtil.cpp +++ b/src/gpu/gl/GrGLUtil.cpp @@ -140,7 +140,7 @@ bool GrGLIsChromiumFromRendererString(const char* rendererString) { 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 @@ GrGLVersion GrGLGetVersionFromString(const char* versionString) { 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 @@ GrGLVersion GrGLGetVersionFromString(const char* versionString) { 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 @@ GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) { } #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 b99487a1af..73fcec1177 100644 --- a/src/gpu/gl/GrGLUtil.h +++ b/src/gpu/gl/GrGLUtil.h @@ -18,6 +18,14 @@ class SkMatrix; typedef uint32_t GrGLVersion; typedef uint32_t GrGLSLVersion; +#define GR_GL_VER(major, minor) ((static_cast(major) << 16) | \ + static_cast(minor)) +#define GR_GLSL_VER(major, minor) ((static_cast(major) << 16) | \ + static_cast(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 @@ enum GrGLRenderer { kOther_GrGLRenderer }; -#define GR_GL_VER(major, minor) ((static_cast(major) << 16) | \ - static_cast(minor)) -#define GR_GLSL_VER(major, minor) ((static_cast(major) << 16) | \ - static_cast(minor)) - //////////////////////////////////////////////////////////////////////////////// /**