diff options
Diffstat (limited to 'opengl/libs/EGL/egl.cpp')
-rw-r--r-- | opengl/libs/EGL/egl.cpp | 376 |
1 files changed, 229 insertions, 147 deletions
diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index e13af1c..a53b375 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -45,6 +45,7 @@ #include "hooks.h" #include "egl_impl.h" #include "Loader.h" +#include "glesv2dbg.h" #define setError(_e, _r) setErrorEtc(__FUNCTION__, __LINE__, _e, _r) @@ -71,25 +72,78 @@ static char const * const gExtensionString = // ---------------------------------------------------------------------------- -class egl_object_t { - static SortedVector<egl_object_t*> sObjects; - static Mutex sLock; +class egl_object_t; +struct egl_display_t; +static egl_display_t* get_display(EGLDisplay dpy); + +struct egl_config_t { + egl_config_t() {} + egl_config_t(int impl, EGLConfig config) + : impl(impl), config(config), configId(0), implConfigId(0) { } + int impl; // the implementation this config is for + EGLConfig config; // the implementation's EGLConfig + EGLint configId; // our CONFIG_ID + EGLint implConfigId; // the implementation's CONFIG_ID + inline bool operator < (const egl_config_t& rhs) const { + if (impl < rhs.impl) return true; + if (impl > rhs.impl) return false; + return config < rhs.config; + } +}; + +struct egl_display_t { + enum { NOT_INITIALIZED, INITIALIZED, TERMINATED }; + + struct strings_t { + char const * vendor; + char const * version; + char const * clientApi; + char const * extensions; + }; + + struct DisplayImpl { + DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), + state(NOT_INITIALIZED), numConfigs(0) { } + EGLDisplay dpy; + EGLConfig* config; + EGLint state; + EGLint numConfigs; + strings_t queryString; + }; + uint32_t magic; + DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS]; + EGLint numTotalConfigs; + egl_config_t* configs; + uint32_t refs; + Mutex lock; + + SortedVector<egl_object_t*> objects; + + egl_display_t() : magic('_dpy'), numTotalConfigs(0), configs(0) { } + ~egl_display_t() { magic = 0; } + inline bool isReady() const { return (refs > 0); } + inline bool isValid() const { return magic == '_dpy'; } + inline bool isAlive() const { return isValid(); } +}; + +class egl_object_t { + egl_display_t *display; volatile int32_t terminated; mutable volatile int32_t count; public: - egl_object_t() : terminated(0), count(1) { - Mutex::Autolock _l(sLock); - sObjects.add(this); + egl_object_t(EGLDisplay dpy) : display(get_display(dpy)), terminated(0), count(1) { + Mutex::Autolock _l(display->lock); + display->objects.add(this); } inline bool isAlive() const { return !terminated; } private: bool get() { - Mutex::Autolock _l(sLock); - if (egl_object_t::sObjects.indexOf(this) >= 0) { + Mutex::Autolock _l(display->lock); + if (display->objects.indexOf(this) >= 0) { android_atomic_inc(&count); return true; } @@ -97,9 +151,9 @@ private: } bool put() { - Mutex::Autolock _l(sLock); + Mutex::Autolock _l(display->lock); if (android_atomic_dec(&count) == 1) { - sObjects.remove(this); + display->objects.remove(this); return true; } return false; @@ -146,65 +200,13 @@ public: }; }; -SortedVector<egl_object_t*> egl_object_t::sObjects; -Mutex egl_object_t::sLock; - - -struct egl_config_t { - egl_config_t() {} - egl_config_t(int impl, EGLConfig config) - : impl(impl), config(config), configId(0), implConfigId(0) { } - int impl; // the implementation this config is for - EGLConfig config; // the implementation's EGLConfig - EGLint configId; // our CONFIG_ID - EGLint implConfigId; // the implementation's CONFIG_ID - inline bool operator < (const egl_config_t& rhs) const { - if (impl < rhs.impl) return true; - if (impl > rhs.impl) return false; - return config < rhs.config; - } -}; - -struct egl_display_t { - enum { NOT_INITIALIZED, INITIALIZED, TERMINATED }; - - struct strings_t { - char const * vendor; - char const * version; - char const * clientApi; - char const * extensions; - }; - - struct DisplayImpl { - DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), - state(NOT_INITIALIZED), numConfigs(0) { } - EGLDisplay dpy; - EGLConfig* config; - EGLint state; - EGLint numConfigs; - strings_t queryString; - }; - - uint32_t magic; - DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS]; - EGLint numTotalConfigs; - egl_config_t* configs; - uint32_t refs; - Mutex lock; - - egl_display_t() : magic('_dpy'), numTotalConfigs(0), configs(0) { } - ~egl_display_t() { magic = 0; } - inline bool isValid() const { return magic == '_dpy'; } - inline bool isAlive() const { return isValid(); } -}; - struct egl_surface_t : public egl_object_t { typedef egl_object_t::LocalRef<egl_surface_t, EGLSurface> Ref; egl_surface_t(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, EGLSurface surface, int impl, egl_connection_t const* cnx) - : dpy(dpy), surface(surface), config(config), win(win), impl(impl), cnx(cnx) { + : egl_object_t(dpy), dpy(dpy), surface(surface), config(config), win(win), impl(impl), cnx(cnx) { } ~egl_surface_t() { } @@ -222,10 +224,16 @@ struct egl_context_t : public egl_object_t egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, int impl, egl_connection_t const* cnx, int version) - : dpy(dpy), context(context), config(config), read(0), draw(0), impl(impl), - cnx(cnx), version(version) + : egl_object_t(dpy), dpy(dpy), context(context), config(config), read(0), draw(0), + impl(impl), cnx(cnx), version(version), dbg(NULL) { } + ~egl_context_t() + { + if (dbg) + DestroyDbgContext(dbg); + dbg = NULL; + } EGLDisplay dpy; EGLContext context; EGLConfig config; @@ -234,6 +242,7 @@ struct egl_context_t : public egl_object_t int impl; egl_connection_t const* cnx; int version; + DbgContext * dbg; }; struct egl_image_t : public egl_object_t @@ -241,7 +250,7 @@ struct egl_image_t : public egl_object_t typedef egl_object_t::LocalRef<egl_image_t, EGLImageKHR> Ref; egl_image_t(EGLDisplay dpy, EGLContext context) - : dpy(dpy), context(context) + : egl_object_t(dpy), dpy(dpy), context(context) { memset(images, 0, sizeof(images)); } @@ -255,7 +264,7 @@ struct egl_sync_t : public egl_object_t typedef egl_object_t::LocalRef<egl_sync_t, EGLSyncKHR> Ref; egl_sync_t(EGLDisplay dpy, EGLContext context, EGLSyncKHR sync) - : dpy(dpy), context(context), sync(sync) + : egl_object_t(dpy), dpy(dpy), context(context), sync(sync) { } EGLDisplay dpy; @@ -296,9 +305,9 @@ EGLAPI pthread_key_t gGLTraceKey = -1; // ---------------------------------------------------------------------------- -static int gEGLTraceLevel; +static int gEGLTraceLevel, gEGLDebugLevel; static int gEGLApplicationTraceLevel; -extern EGLAPI gl_hooks_t gHooksTrace; +extern EGLAPI gl_hooks_t gHooksTrace, gHooksDebug; static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { pthread_setspecific(gGLTraceKey, value); @@ -314,12 +323,37 @@ static void initEglTraceLevel() { int propertyLevel = atoi(value); int applicationLevel = gEGLApplicationTraceLevel; gEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; + + property_get("debug.egl.debug_proc", value, ""); + long pid = getpid(); + char procPath[128] = {}; + sprintf(procPath, "/proc/%ld/cmdline", pid); + FILE * file = fopen(procPath, "r"); + if (file) + { + char cmdline[256] = {}; + if (fgets(cmdline, sizeof(cmdline) - 1, file)) + { + if (!strcmp(value, cmdline)) + gEGLDebugLevel = 1; + } + fclose(file); + } + + if (gEGLDebugLevel > 0) + { + property_get("debug.egl.debug_port", value, "5039"); + StartDebugServer(atoi(value)); + } } static void setGLHooksThreadSpecific(gl_hooks_t const *value) { if (gEGLTraceLevel > 0) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksTrace); + } else if (gEGLDebugLevel > 0 && value != &gHooksNoContext) { + setGlTraceThreadSpecific(value); + setGlThreadSpecific(&gHooksDebug); } else { setGlThreadSpecific(value); } @@ -561,6 +595,11 @@ egl_context_t* get_context(EGLContext context) { return egl_to_native_cast<egl_context_t>(context); } +DbgContext * getDbgContextThreadSpecific() +{ + return get_context(getContext())->dbg; +} + static inline egl_image_t* get_image(EGLImageKHR image) { return egl_to_native_cast<egl_image_t>(image); @@ -571,12 +610,22 @@ egl_sync_t* get_sync(EGLSyncKHR sync) { return egl_to_native_cast<egl_sync_t>(sync); } +static inline +egl_display_t* validate_display(EGLDisplay dpy) +{ + egl_display_t * const dp = get_display(dpy); + if (!dp) return setError(EGL_BAD_DISPLAY, (egl_display_t*)NULL); + if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (egl_display_t*)NULL); + + return dp; +} + static egl_connection_t* validate_display_config( EGLDisplay dpy, EGLConfig config, egl_display_t const*& dp) { - dp = get_display(dpy); - if (!dp) return setError(EGL_BAD_DISPLAY, (egl_connection_t*)NULL); + dp = validate_display(dpy); + if (!dp) return (egl_connection_t*) NULL; if (intptr_t(config) >= dp->numTotalConfigs) { return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL); @@ -590,9 +639,9 @@ static egl_connection_t* validate_display_config( static EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx) { - if ((uintptr_t(dpy)-1U) >= NUM_DISPLAYS) - return setError(EGL_BAD_DISPLAY, EGL_FALSE); - if (!get_display(dpy)->isAlive()) + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + if (!dp->isAlive()) return setError(EGL_BAD_DISPLAY, EGL_FALSE); if (!get_context(ctx)->isAlive()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); @@ -601,9 +650,9 @@ static EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx) static EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface) { - if ((uintptr_t(dpy)-1U) >= NUM_DISPLAYS) - return setError(EGL_BAD_DISPLAY, EGL_FALSE); - if (!get_display(dpy)->isAlive()) + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + if (!dp->isAlive()) return setError(EGL_BAD_DISPLAY, EGL_FALSE); if (!get_surface(surface)->isAlive()) return setError(EGL_BAD_SURFACE, EGL_FALSE); @@ -923,8 +972,8 @@ EGLBoolean eglGetConfigs( EGLDisplay dpy, { clearError(); - egl_display_t const * const dp = get_display(dpy); - if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; GLint numConfigs = dp->numTotalConfigs; if (!configs) { @@ -949,8 +998,8 @@ EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, { clearError(); - egl_display_t const * const dp = get_display(dpy); - if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; if (num_config==0) { return setError(EGL_BAD_PARAMETER, EGL_FALSE); @@ -1168,12 +1217,14 @@ EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t * const s = get_surface(surface); EGLBoolean result = s->cnx->egl.eglDestroySurface( @@ -1192,12 +1243,14 @@ EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); EGLBoolean result(EGL_TRUE); @@ -1260,12 +1313,14 @@ EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + ContextRef _c(ctx); if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); if (!validate_display_context(dpy, ctx)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_context_t * const c = get_context(ctx); EGLBoolean result = c->cnx->egl.eglDestroyContext( dp->disp[c->impl].dpy, c->context); @@ -1301,14 +1356,23 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, { clearError(); + egl_display_t const * const dp = get_display(dpy); + if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + + /* If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not + EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is + a valid but uninitialized display. */ + if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || + (draw != EGL_NO_SURFACE) ) { + if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); + } + // get a reference to the object passed in ContextRef _c(ctx); SurfaceRef _d(draw); SurfaceRef _r(read); - // validate the display and the context (if not EGL_NO_CONTEXT) - egl_display_t const * const dp = get_display(dpy); - if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + // validate the context (if not EGL_NO_CONTEXT) if ((ctx != EGL_NO_CONTEXT) && (!validate_display_context(dpy, ctx))) { // EGL_NO_CONTEXT is valid return EGL_FALSE; @@ -1378,6 +1442,8 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, loseCurrent(cur_c); if (ctx != EGL_NO_CONTEXT) { + if (!c->dbg && gEGLDebugLevel > 0) + c->dbg = CreateDbgContext(c->version, c->cnx->hooks[c->version]); setGLHooksThreadSpecific(c->cnx->hooks[c->version]); setContext(ctx); _c.acquire(); @@ -1399,13 +1465,15 @@ EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + ContextRef _c(ctx); if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); if (!validate_display_context(dpy, ctx)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_context_t * const c = get_context(ctx); EGLBoolean result(EGL_TRUE); @@ -1607,7 +1675,7 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) cnx->hooks[GLESv1_INDEX]->ext.extensions[slot] = cnx->hooks[GLESv2_INDEX]->ext.extensions[slot] = #if EGL_TRACE - gHooksTrace.ext.extensions[slot] = + gHooksDebug.ext.extensions[slot] = gHooksTrace.ext.extensions[slot] = #endif cnx->egl.eglGetProcAddress(procname); } @@ -1635,14 +1703,20 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) { + EGLBoolean Debug_eglSwapBuffers(EGLDisplay dpy, EGLSurface draw); + if (gEGLDebugLevel > 0) + Debug_eglSwapBuffers(dpy, draw); + clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(draw); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, draw)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(draw); return s->cnx->egl.eglSwapBuffers(dp->disp[s->impl].dpy, s->surface); } @@ -1652,12 +1726,14 @@ EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); return s->cnx->egl.eglCopyBuffers( dp->disp[s->impl].dpy, s->surface, target); @@ -1667,7 +1743,9 @@ const char* eglQueryString(EGLDisplay dpy, EGLint name) { clearError(); - egl_display_t const * const dp = get_display(dpy); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return (const char *) NULL; + switch (name) { case EGL_VENDOR: return gVendorString; @@ -1691,12 +1769,14 @@ EGLBoolean eglSurfaceAttrib( { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglSurfaceAttrib) { return s->cnx->egl.eglSurfaceAttrib( @@ -1710,12 +1790,14 @@ EGLBoolean eglBindTexImage( { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglBindTexImage) { return s->cnx->egl.eglBindTexImage( @@ -1729,12 +1811,14 @@ EGLBoolean eglReleaseTexImage( { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglReleaseTexImage) { return s->cnx->egl.eglReleaseTexImage( @@ -1747,8 +1831,8 @@ EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) { clearError(); - egl_display_t * const dp = get_display(dpy); - if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; EGLBoolean res = EGL_TRUE; for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { @@ -1886,13 +1970,15 @@ EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglLockSurfaceKHR) { @@ -1906,13 +1992,15 @@ EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, surface)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglUnlockSurfaceKHR) { @@ -1927,12 +2015,14 @@ EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_NO_IMAGE_KHR; + if (ctx != EGL_NO_CONTEXT) { ContextRef _c(ctx); if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); if (!validate_display_context(dpy, ctx)) return EGL_NO_IMAGE_KHR; - egl_display_t const * const dp = get_display(dpy); egl_context_t * const c = get_context(ctx); // since we have an EGLContext, we know which implementation to use EGLImageKHR image = c->cnx->egl.eglCreateImageKHR( @@ -1945,10 +2035,6 @@ EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, return (EGLImageKHR)result; } else { // EGL_NO_CONTEXT is a valid parameter - egl_display_t const * const dp = get_display(dpy); - if (dp == 0) { - return setError(EGL_BAD_DISPLAY, EGL_NO_IMAGE_KHR); - } /* Since we don't have a way to know which implementation to call, * we're calling all of them. If at least one of the implementation @@ -2000,35 +2086,33 @@ EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) { clearError(); - egl_display_t const * const dp = get_display(dpy); - if (dp == 0) { - return setError(EGL_BAD_DISPLAY, EGL_FALSE); - } - - ImageRef _i(img); - if (!_i.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); - - egl_image_t* image = get_image(img); - bool success = false; - for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { - egl_connection_t* const cnx = &gEGLImpl[i]; - if (image->images[i] != EGL_NO_IMAGE_KHR) { - if (cnx->dso) { - if (cnx->egl.eglDestroyImageKHR) { - if (cnx->egl.eglDestroyImageKHR( - dp->disp[i].dpy, image->images[i])) { - success = true; - } - } - } - } - } - if (!success) - return EGL_FALSE; - - _i.terminate(); - - return EGL_TRUE; + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + + ImageRef _i(img); + if (!_i.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); + + egl_image_t* image = get_image(img); + bool success = false; + for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { + egl_connection_t* const cnx = &gEGLImpl[i]; + if (image->images[i] != EGL_NO_IMAGE_KHR) { + if (cnx->dso) { + if (cnx->egl.eglDestroyImageKHR) { + if (cnx->egl.eglDestroyImageKHR( + dp->disp[i].dpy, image->images[i])) { + success = true; + } + } + } + } + } + if (!success) + return EGL_FALSE; + + _i.terminate(); + + return EGL_TRUE; } // ---------------------------------------------------------------------------- @@ -2040,12 +2124,14 @@ EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_l { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_NO_SYNC_KHR; + EGLContext ctx = eglGetCurrentContext(); ContextRef _c(ctx); if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_NO_SYNC_KHR); if (!validate_display_context(dpy, ctx)) return EGL_NO_SYNC_KHR; - egl_display_t const * const dp = get_display(dpy); egl_context_t * const c = get_context(ctx); EGLSyncKHR result = EGL_NO_SYNC_KHR; if (c->cnx->egl.eglCreateSyncKHR) { @@ -2062,10 +2148,8 @@ EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) { clearError(); - egl_display_t const * const dp = get_display(dpy); - if (dp == 0) { - return setError(EGL_BAD_DISPLAY, EGL_FALSE); - } + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; SyncRef _s(sync); if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); @@ -2092,10 +2176,8 @@ EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTi { clearError(); - egl_display_t const * const dp = get_display(dpy); - if (dp == 0) { - return setError(EGL_BAD_DISPLAY, EGL_FALSE); - } + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; SyncRef _s(sync); if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); @@ -2121,10 +2203,8 @@ EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute { clearError(); - egl_display_t const * const dp = get_display(dpy); - if (dp == 0) { - return setError(EGL_BAD_DISPLAY, EGL_FALSE); - } + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; SyncRef _s(sync); if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); @@ -2155,12 +2235,14 @@ EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, { clearError(); + egl_display_t const * const dp = validate_display(dpy); + if (!dp) return EGL_FALSE; + SurfaceRef _s(draw); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); if (!validate_display_surface(dpy, draw)) return EGL_FALSE; - egl_display_t const * const dp = get_display(dpy); egl_surface_t const * const s = get_surface(draw); if (s->cnx->egl.eglSetSwapRectangleANDROID) { return s->cnx->egl.eglSetSwapRectangleANDROID( |