diff options
Diffstat (limited to 'src/egl/main/eglcontext.c')
-rw-r--r-- | src/egl/main/eglcontext.c | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 374c006dae..461679db09 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -6,12 +6,12 @@ #include "egldisplay.h" #include "egldriver.h" #include "eglglobals.h" -#include "eglhash.h" #include "eglsurface.h" /** - * Initialize the given _EGLContext object to defaults. + * Initialize the given _EGLContext object to defaults and/or the values + * in the attrib_list. */ EGLBoolean _eglInitContext(_EGLDriver *drv, EGLDisplay dpy, _EGLContext *ctx, @@ -20,42 +20,54 @@ _eglInitContext(_EGLDriver *drv, EGLDisplay dpy, _EGLContext *ctx, _EGLConfig *conf; _EGLDisplay *display = _eglLookupDisplay(dpy); EGLint i; + const EGLenum api = eglQueryAPI(); + + if (api == EGL_NONE) { + _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); + return EGL_FALSE; + } conf = _eglLookupConfig(drv, dpy, config); if (!conf) { - _eglError(EGL_BAD_CONFIG, "eglCreateContext"); + _eglError(EGL_BAD_CONFIG, "_eglInitContext"); return EGL_FALSE; } + memset(ctx, 0, sizeof(_EGLContext)); + + ctx->ClientVersion = 1; /* the default, per EGL spec */ + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { switch (attrib_list[i]) { - /* no attribs defined for now */ + case EGL_CONTEXT_CLIENT_VERSION: + i++; + ctx->ClientVersion = attrib_list[i]; + break; default: - _eglError(EGL_BAD_ATTRIBUTE, "eglCreateContext"); - return EGL_NO_CONTEXT; + _eglError(EGL_BAD_ATTRIBUTE, "_eglInitContext"); + return EGL_FALSE; } } - memset(ctx, 0, sizeof(_EGLContext)); ctx->Display = display; ctx->Config = conf; ctx->DrawSurface = EGL_NO_SURFACE; ctx->ReadSurface = EGL_NO_SURFACE; + ctx->ClientAPI = api; return EGL_TRUE; } -/* - * Assign an EGLContext handle to the _EGLContext object then put it into - * the hash table. +/** + * Save a new _EGLContext into the hash table. */ void _eglSaveContext(_EGLContext *ctx) { - assert(ctx); - ctx->Handle = _eglHashGenKey(_eglGlobal.Contexts); - _eglHashInsert(_eglGlobal.Contexts, ctx->Handle, ctx); + /* no-op. + * Public EGLContext handle and private _EGLContext are the same. + */ } @@ -65,19 +77,34 @@ _eglSaveContext(_EGLContext *ctx) void _eglRemoveContext(_EGLContext *ctx) { - _eglHashRemove(_eglGlobal.Contexts, ctx->Handle); + /* no-op. + * Public EGLContext handle and private _EGLContext are the same. + */ +} + + +/** + * Return the public handle for the given private context ptr. + * This is the inverse of _eglLookupContext(). + */ +EGLContext +_eglGetContextHandle(_EGLContext *ctx) +{ + /* just a cast! */ + return (EGLContext) ctx; } /** * Return the _EGLContext object that corresponds to the given * EGLContext handle. + * This is the inverse of _eglGetContextHandle(). */ _EGLContext * _eglLookupContext(EGLContext ctx) { - _EGLContext *c = (_EGLContext *) _eglHashLookup(_eglGlobal.Contexts, ctx); - return c; + /* just a cast since EGLContext is just a void ptr */ + return (_EGLContext *) ctx; } @@ -112,7 +139,7 @@ _eglCreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, } _eglSaveContext(context); - return context->Handle; + return (EGLContext) context; #endif return EGL_NO_CONTEXT; } @@ -126,7 +153,6 @@ _eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) { _EGLContext *context = _eglLookupContext(ctx); if (context) { - _eglHashRemove(_eglGlobal.Contexts, ctx); if (context->IsBound) { context->DeletePending = EGL_TRUE; } @@ -163,8 +189,11 @@ _eglQueryContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx, #ifdef EGL_VERSION_1_2 case EGL_CONTEXT_CLIENT_TYPE: *value = c->ClientAPI; - return EGL_FALSE; + return EGL_TRUE; #endif /* EGL_VERSION_1_2 */ + case EGL_CONTEXT_CLIENT_VERSION: + *value = c->ClientVersion; + return EGL_TRUE; default: _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext"); return EGL_FALSE; @@ -239,7 +268,7 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, ctx = NULL; } /* really delete context now */ - drv->API.DestroyContext(drv, dpy, oldContext->Handle); + drv->API.DestroyContext(drv, dpy, _eglGetContextHandle(oldContext)); } } |