[Mesa-dev] [PATCH] i915: Validate requested GLES context version in i915CreateContext (v2)

Chad Versace chad.versace at linux.intel.com
Tue Nov 20 15:43:33 PST 2012


Commit 243cf7a applied a similar fix to i965.

For GLES1 and GLES2, i915CreateContext neglected to validate the requested
context version received from the DRI layer. If DRI requested an OpenGL
ES2 context with version 3.9, we provided it one.

v2: Allow GLES2 only if GL_ARB_fragment_shader is supported.

Note: This is a candidate for the stable branches.
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/mesa/drivers/dri/i915/i915_context.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_context.c b/src/mesa/drivers/dri/i915/i915_context.c
index 3ef4eca..1f479e3 100644
--- a/src/mesa/drivers/dri/i915/i915_context.c
+++ b/src/mesa/drivers/dri/i915/i915_context.c
@@ -158,6 +158,8 @@ i915CreateContext(int api,
    struct i915_context *i915 = rzalloc(NULL, struct i915_context);
    struct intel_context *intel = &i915->intel;
    struct gl_context *ctx = &intel->ctx;
+   unsigned req_version = major_version * 10 + minor_version;
+   unsigned max_supported_version = 0;
 
    if (!i915) {
       *error = __DRI_CTX_ERROR_NO_MEMORY;
@@ -178,24 +180,32 @@ i915CreateContext(int api,
     * and version.
     */
    switch (api) {
-   case API_OPENGL: {
-      const unsigned max_version =
-         (ctx->Extensions.ARB_fragment_shader &&
-          ctx->Extensions.ARB_occlusion_query) ? 20 : 15;
-      const unsigned req_version = major_version * 10 + minor_version;
-
-      if (req_version > max_version) {
-         *error = __DRI_CTX_ERROR_BAD_VERSION;
-         return false;
-      }
+   case API_OPENGL:
+      if (ctx->Extensions.ARB_fragment_shader &&
+          ctx->Extensions.ARB_occlusion_query)
+         max_supported_version = 20;
+      else
+         max_supported_version = 15;
       break;
-   }
    case API_OPENGLES:
+      max_supported_version = 11;
+      break;
    case API_OPENGLES2:
+      if (ctx->Extensions.ARB_fragment_shader)
+         max_supported_version = 20;
+      else
+         max_supported_version = 0;
       break;
    default:
+      break;
+   }
+
+   if (max_supported_version == 0) {
       *error = __DRI_CTX_ERROR_BAD_API;
       return false;
+   } else if (req_version > max_supported_version) {
+      *error = __DRI_CTX_ERROR_BAD_VERSION;
+      return false;
    }
 
    intel_init_texture_formats(ctx);
-- 
1.7.11.7



More information about the mesa-dev mailing list