Mesa (master): egl: improve attribute checking for eglCreateContext

Emil Velikov evelikov at kemper.freedesktop.org
Thu Aug 13 16:32:03 UTC 2015


Module: Mesa
Branch: master
Commit: d9603be038b6d30f17ca7c05e60cc78100a625ac
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d9603be038b6d30f17ca7c05e60cc78100a625ac

Author: Frank Binns <frank.binns at imgtec.com>
Date:   Wed Aug 12 16:36:00 2015 +0100

egl: improve attribute checking for eglCreateContext

The EGL 1.4 spec states for eglCreateContext:

	"attribute EGL_CONTEXT_CLIENT_VERSION is only valid when the current
	 rendering API is EGL_OPENGL_ES_API"

Additionally, if the EGL_KHR_create_context EGL extension is supported
(this is mandatory in EGL 1.5) then the EGL_CONTEXT_MAJOR_VERSION_KHR,
which is an alias for EGL_CONTEXT_CLIENT_VERSION, and
EGL_CONTEXT_MINOR_VERSION_KHR attributes are also accepted by
eglCreateContext with the extension spec stating:

	"The values for attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
	 EGL_CONTEXT_MINOR_VERSION_KHR specify the requested client API
	 version. They are only meaningful for OpenGL and OpenGL ES
	 contexts, and specifying them for other types of contexts will
	 generate an error."

Add the necessary checks against the extension and rendering APIs when
validating these attributes as part of eglCreateContext.

Signed-off-by: Frank Binns <frank.binns at imgtec.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
[Emil Velikov: Add newline before the spec quote (Matt)]
Reviewed-by: Emil Velikov <emil.l.velikov at gmail.com>

---

 src/egl/main/eglcontext.c |   33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index e767f4b..588f489 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -101,11 +101,42 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *dpy,
 
       switch (attr) {
       case EGL_CONTEXT_CLIENT_VERSION:
+         /* The EGL 1.4 spec says:
+          *
+          *     "attribute EGL_CONTEXT_CLIENT_VERSION is only valid when the
+          *      current rendering API is EGL_OPENGL_ES_API"
+          *
+          * The EGL_KHR_create_context spec says:
+          *
+          *     "EGL_CONTEXT_MAJOR_VERSION_KHR           0x3098
+          *      (this token is an alias for EGL_CONTEXT_CLIENT_VERSION)"
+          *
+          *     "The values for attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
+          *      EGL_CONTEXT_MINOR_VERSION_KHR specify the requested client API
+          *      version. They are only meaningful for OpenGL and OpenGL ES
+          *      contexts, and specifying them for other types of contexts will
+          *      generate an error."
+          */
+         if ((api != EGL_OPENGL_ES_API &&
+             (!dpy->Extensions.KHR_create_context || api != EGL_OPENGL_API))) {
+               err = EGL_BAD_ATTRIBUTE;
+               break;
+         }
+
          ctx->ClientMajorVersion = val;
          break;
 
       case EGL_CONTEXT_MINOR_VERSION_KHR:
-         if (!dpy->Extensions.KHR_create_context) {
+         /* The EGL_KHR_create_context spec says:
+          *
+          *     "The values for attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
+          *      EGL_CONTEXT_MINOR_VERSION_KHR specify the requested client API
+          *      version. They are only meaningful for OpenGL and OpenGL ES
+          *      contexts, and specifying them for other types of contexts will
+          *      generate an error."
+          */
+         if (!dpy->Extensions.KHR_create_context ||
+             (api != EGL_OPENGL_ES_API && api != EGL_OPENGL_API)) {
             err = EGL_BAD_ATTRIBUTE;
             break;
          }




More information about the mesa-commit mailing list