i915: Validate API and version in i915CreateContext
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 7 Aug 2012 19:30:14 +0000 (12:30 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 14 Aug 2012 00:36:50 +0000 (17:36 -0700)
v2: Use base-10 for versions like gl_context::Version.  Suggested by Ken.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i915/i915_context.c
src/mesa/drivers/dri/i915/i915_context.h
src/mesa/drivers/dri/intel/intel_screen.c

index dc322929fbdeb6b27e9e30085780fd1ed5ea52bb..1a0baa2965c66a9c0bff0e6f383225d8777d8bdd 100644 (file)
@@ -146,6 +146,9 @@ bool
 i915CreateContext(int api,
                  const struct gl_config * mesaVis,
                   __DRIcontext * driContextPriv,
+                  unsigned major_version,
+                  unsigned minor_version,
+                  unsigned *error,
                   void *sharedContextPrivate)
 {
    struct dd_function_table functions;
@@ -153,8 +156,10 @@ i915CreateContext(int api,
    struct intel_context *intel = &i915->intel;
    struct gl_context *ctx = &intel->ctx;
 
-   if (!i915)
+   if (!i915) {
+      *error = __DRI_CTX_ERROR_NO_MEMORY;
       return false;
+   }
 
    i915InitVtbl(i915);
 
@@ -163,6 +168,33 @@ i915CreateContext(int api,
    if (!intelInitContext(intel, api, mesaVis, driContextPriv,
                          sharedContextPrivate, &functions)) {
       FREE(i915);
+      *error = __DRI_CTX_ERROR_NO_MEMORY;
+      return false;
+   }
+
+   /* Now that the extension bits are known, filter against the requested 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;
+         FREE(i915);
+         return false;
+      }
+      break;
+   }
+   case API_OPENGLES:
+   case API_OPENGLES2:
+      break;
+   default:
+      *error = __DRI_CTX_ERROR_BAD_API;
+      FREE(i915);
       return false;
    }
 
index 70374658ec89a330e993bb61b327f6726ebc78e3..f5c15960dd0b664a45ab09e8398f99c7de945ed2 100644 (file)
@@ -322,6 +322,9 @@ do {                                                                        \
 extern bool i915CreateContext(int api,
                              const struct gl_config * mesaVis,
                              __DRIcontext * driContextPriv,
+                              unsigned major_version,
+                              unsigned minor_version,
+                              unsigned *error,
                              void *sharedContextPrivate);
 
 
index 877d11b709e23c33590f998355e977a548f24557..737cc49b16bcc056048989572187324302695ce6 100644 (file)
@@ -693,6 +693,9 @@ extern bool
 i915CreateContext(int api,
                  const struct gl_config *mesaVis,
                  __DRIcontext *driContextPriv,
+                  unsigned major_version,
+                  unsigned minor_version,
+                  unsigned *error,
                  void *sharedContextPrivate);
 extern bool
 brwCreateContext(int api,
@@ -734,6 +737,7 @@ intelCreateContext(gl_api api,
 #ifdef I915
    if (IS_9XX(intelScreen->deviceID)) {
       success = i915CreateContext(api, mesaVis, driContextPriv,
+                                  major_version, minor_version, error,
                                   sharedContextPrivate);
    } else {
       switch (api) {