diff options
author | Chad Versace <[email protected]> | 2012-11-09 14:06:40 -0800 |
---|---|---|
committer | Chad Versace <[email protected]> | 2012-11-19 08:17:32 -0800 |
commit | 243cf7a924eaef78ce0d5150747fae6c3c4e6974 (patch) | |
tree | dc399fb5deed8146580785c7cfb00fc6b9d35dfe /src/mesa | |
parent | ddb901fbf4489ffcd85d3320f23913eb1d4fbdfe (diff) |
i965: Validate requested GLES context version in brwCreateContext
For GLES1 and GLES2, brwCreateContext 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.
Before this fix, the switch statement that validated the requested GL
context flavor was an ugly #ifdef copy-paste mess. Instead of reproducing
the copy-past-mess for GLES1 and GLES2, I first refactored it. Now the
switch statement is readable.
Reviewed-by: Kenneth Graunke <[email protected]>
Signed-off-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_context.c | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index 144896534a1..f439cf20abc 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -84,53 +84,45 @@ brwCreateContext(int api, __DRIscreen *sPriv = driContextPriv->driScreenPriv; struct intel_screen *screen = sPriv->driverPrivate; struct dd_function_table functions; + const unsigned req_version = major_version * 10 + minor_version; + unsigned max_supported_version = 0; unsigned i; - /* Filter against the requested API and version. - */ - switch (api) { - case API_OPENGL: { #ifdef TEXTURE_FLOAT_ENABLED - const unsigned max_version = - (screen->gen == 6 || - (screen->gen == 7 && screen->kernel_has_gen7_sol_reset)) - ? 30 : 21; + bool has_texture_float = true; #else - const unsigned max_version = 21; + bool has_texture_float = false; #endif - const unsigned req_version = major_version * 10 + minor_version; - if (req_version > max_version) { - *error = __DRI_CTX_ERROR_BAD_VERSION; - return false; - } + bool supports_gl30 = has_texture_float && + (screen->gen == 6 || + (screen->gen == 7 && + screen->kernel_has_gen7_sol_reset)); + + /* Determine max_supported_version. */ + switch (api) { + case API_OPENGL: + max_supported_version = supports_gl30 ? 30 : 21; break; - } case API_OPENGLES: + max_supported_version = 11; + break; case API_OPENGLES2: + max_supported_version = 20; break; - case API_OPENGL_CORE: { -#ifdef TEXTURE_FLOAT_ENABLED - const unsigned max_version = - (screen->gen == 6 || - (screen->gen == 7 && screen->kernel_has_gen7_sol_reset)) - ? 31 : 0; - const unsigned req_version = major_version * 10 + minor_version; - - if (req_version > max_version) { - *error = (max_version == 0) - ? __DRI_CTX_ERROR_BAD_API : __DRI_CTX_ERROR_BAD_VERSION; - return false; - } + case API_OPENGL_CORE: + max_supported_version = supports_gl30 ? 31 : 0; break; -#else - *error = __DRI_CTX_ERROR_BAD_API; - return false; -#endif - } 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; } struct brw_context *brw = rzalloc(NULL, struct brw_context); |