summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2012-08-07 12:30:14 -0700
committerIan Romanick <[email protected]>2012-08-13 17:36:50 -0700
commitdb273724c9484d513f5caa34729475d2873d9f7b (patch)
tree1045c40489f5d323dfc023d64a3d4ca794293156 /src/mesa/drivers/dri
parenta81e4b3e9272f70ab9074f1c133dda94c58daeff (diff)
i915: Validate API and version in i915CreateContext
v2: Use base-10 for versions like gl_context::Version. Suggested by Ken. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri')
-rw-r--r--src/mesa/drivers/dri/i915/i915_context.c34
-rw-r--r--src/mesa/drivers/dri/i915/i915_context.h3
-rw-r--r--src/mesa/drivers/dri/intel/intel_screen.c4
3 files changed, 40 insertions, 1 deletions
diff --git a/src/mesa/drivers/dri/i915/i915_context.c b/src/mesa/drivers/dri/i915/i915_context.c
index dc322929fbd..1a0baa2965c 100644
--- a/src/mesa/drivers/dri/i915/i915_context.c
+++ b/src/mesa/drivers/dri/i915/i915_context.c
@@ -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;
}
diff --git a/src/mesa/drivers/dri/i915/i915_context.h b/src/mesa/drivers/dri/i915/i915_context.h
index 70374658ec8..f5c15960dd0 100644
--- a/src/mesa/drivers/dri/i915/i915_context.h
+++ b/src/mesa/drivers/dri/i915/i915_context.h
@@ -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);
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 877d11b709e..737cc49b16b 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -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) {