From 07ee01365a8bddf6f50821ecd585784498a25ff0 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 3 Aug 2009 11:34:37 -0600 Subject: [PATCH] egl: Replace IsBound by a pointer to the binding. IsBound tells if a context or surface is current. What it does not tell is, to which thread a context is current, or to which context a surface is current. This commit replaces IsBound by a pointer to the binding thread or context. Signed-off-by: Chia-I Wu --- src/egl/drivers/demo/demo.c | 4 ++-- src/egl/drivers/dri/egldri.c | 4 ++-- src/egl/drivers/glx/egl_glx.c | 2 +- src/egl/drivers/xdri/egl_xdri.c | 2 +- src/egl/main/eglcontext.c | 14 +++++++------- src/egl/main/eglcontext.h | 17 ++++++++++++++--- src/egl/main/eglsurface.c | 2 +- src/egl/main/eglsurface.h | 19 +++++++++++++++---- src/gallium/state_trackers/egl/egl_context.c | 2 +- src/gallium/state_trackers/egl/egl_surface.c | 2 +- src/gallium/winsys/egl_xlib/egl_xlib.c | 4 ++-- src/mesa/drivers/dri/fb/fb_egl.c | 4 ++-- 12 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/egl/drivers/demo/demo.c b/src/egl/drivers/demo/demo.c index f316974d836..e8c0c1df5ee 100644 --- a/src/egl/drivers/demo/demo.c +++ b/src/egl/drivers/demo/demo.c @@ -236,7 +236,7 @@ demoDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) { DemoSurface *fs = LookupDemoSurface(surface); _eglUnlinkSurface(&fs->Base); - if (!fs->Base.IsBound) + if (!_eglIsSurfaceBound(&fs->Base)) free(fs); return EGL_TRUE; } @@ -247,7 +247,7 @@ demoDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) { DemoContext *fc = LookupDemoContext(context); _eglUnlinkContext(&fc->Base); - if (!fc->Base.IsBound) + if (!_eglIsContextBound(&fc->Base)) free(fc); return EGL_TRUE; } diff --git a/src/egl/drivers/dri/egldri.c b/src/egl/drivers/dri/egldri.c index 3f9617a8f98..9e400be6248 100644 --- a/src/egl/drivers/dri/egldri.c +++ b/src/egl/drivers/dri/egldri.c @@ -296,7 +296,7 @@ _eglDRIDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) fs->drawable.destroyDrawable(disp, fs->drawable.private); - if (!fs->Base.IsBound) + if (!_eglIsSurfaceBound(&fs->Base)) free(fs); return EGL_TRUE; } @@ -312,7 +312,7 @@ _eglDRIDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) fc->driContext.destroyContext(disp, 0, fc->driContext.private); - if (!fc->Base.IsBound) + if (!_eglIsContextBound(&fc->Base)) free(fc); return EGL_TRUE; } diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 207b1ea7793..5ed4b6883f8 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -739,7 +739,7 @@ GLX_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) return EGL_TRUE; if (surf) { _eglUnlinkSurface(surf); - if (!surf->IsBound) + if (!_eglIsSurfaceBound(surf)) free(surf); return EGL_TRUE; diff --git a/src/egl/drivers/xdri/egl_xdri.c b/src/egl/drivers/xdri/egl_xdri.c index e040efdd438..d8d29fcef49 100644 --- a/src/egl/drivers/xdri/egl_xdri.c +++ b/src/egl/drivers/xdri/egl_xdri.c @@ -958,7 +958,7 @@ xdri_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) struct xdri_egl_surface *xdri_surf = lookup_surface(surface); if (xdri_surf) { _eglUnlinkSurface(&xdri_surf->Base); - if (!xdri_surf->Base.IsBound) { + if (!_eglIsSurfaceBound(&xdri_surf->Base)) { /* st_unreference_framebuffer(surf->Framebuffer); */ diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 9ab4286d3a8..f8d5687f87c 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -96,7 +96,7 @@ _eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) _EGLContext *context = _eglLookupContext(ctx); if (context) { _eglUnlinkContext(context); - if (!context->IsBound) + if (!_eglIsContextBound(context)) free(context); return EGL_TRUE; } @@ -207,7 +207,7 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, * check if the old context or surfaces need to be deleted */ if (oldDrawSurface != NULL) { - oldDrawSurface->IsBound = EGL_FALSE; + oldDrawSurface->Binding = NULL; if (!_eglIsSurfaceLinked(oldDrawSurface)) { /* make sure we don't try to rebind a deleted surface */ if (draw == oldDrawSurface || draw == oldReadSurface) { @@ -218,7 +218,7 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, } } if (oldReadSurface != NULL && oldReadSurface != oldDrawSurface) { - oldReadSurface->IsBound = EGL_FALSE; + oldReadSurface->Binding = NULL; if (!_eglIsSurfaceLinked(oldReadSurface)) { /* make sure we don't try to rebind a deleted surface */ if (read == oldDrawSurface || read == oldReadSurface) { @@ -229,7 +229,7 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, } } if (oldContext != NULL) { - oldContext->IsBound = EGL_FALSE; + oldContext->Binding = NULL; if (!_eglIsContextLinked(oldContext)) { /* make sure we don't try to rebind a deleted context */ if (ctx == oldContext) { @@ -248,9 +248,9 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface d, } ctx->DrawSurface = draw; ctx->ReadSurface = read; - ctx->IsBound = EGL_TRUE; - draw->IsBound = EGL_TRUE; - read->IsBound = EGL_TRUE; + ctx->Binding = t; + draw->Binding = ctx; + read->Binding = ctx; t->CurrentContexts[apiIndex] = ctx; } else { diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index 2fb28d38b91..4276c0980e2 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -15,12 +15,12 @@ struct _egl_context _EGLDisplay *Display; _EGLContext *Next; - _EGLConfig *Config; - + /* The bound status of the context */ + _EGLThreadInfo *Binding; _EGLSurface *DrawSurface; _EGLSurface *ReadSurface; - EGLBoolean IsBound; + _EGLConfig *Config; EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */ EGLint ClientVersion; /**< 1 = OpenGLES 1.x, 2 = OpenGLES 2.x */ @@ -51,4 +51,15 @@ _eglMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface rea extern EGLBoolean _eglCopyContextMESA(_EGLDriver *drv, EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); + +/** + * Return true if the context is bound to a thread. + */ +static INLINE EGLBoolean +_eglIsContextBound(_EGLContext *ctx) +{ + return (ctx->Binding != NULL); +} + + #endif /* EGLCONTEXT_INCLUDED */ diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index 9821e636287..bd263fe2650 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -413,7 +413,7 @@ _eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) _EGLSurface *surf = _eglLookupSurface(surface); if (surf) { _eglUnlinkSurface(surf); - if (!surf->IsBound) + if (!_eglIsSurfaceBound(surf)) free(surf); return EGL_TRUE; } diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index f9413eb9d75..88641768449 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -15,12 +15,12 @@ struct _egl_surface _EGLSurface *Next; EGLSurface Handle; - _EGLConfig *Config; - - /* May need reference counting here */ - EGLBoolean IsBound; + /* The bound status of the surface */ + _EGLContext *Binding; EGLBoolean BoundToTexture; + _EGLConfig *Config; + EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ EGLint Width, Height; EGLint TextureFormat, TextureTarget; @@ -100,5 +100,16 @@ _eglCreatePbufferFromClientBuffer(_EGLDriver *drv, EGLDisplay dpy, #endif /* EGL_VERSION_1_2 */ +/** + * Return true if the surface is bound to a thread. + * A surface bound to a texutre is not considered bound by + * this function. + */ +static INLINE EGLBoolean +_eglIsSurfaceBound(_EGLSurface *surf) +{ + return (surf->Binding != NULL); +} + #endif /* EGLSURFACE_INCLUDED */ diff --git a/src/gallium/state_trackers/egl/egl_context.c b/src/gallium/state_trackers/egl/egl_context.c index e2da2180f71..2c8f51cf388 100644 --- a/src/gallium/state_trackers/egl/egl_context.c +++ b/src/gallium/state_trackers/egl/egl_context.c @@ -148,7 +148,7 @@ drm_destroy_context(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) { struct drm_context *c = lookup_drm_context(context); _eglUnlinkContext(&c->base); - if (!c->base.IsBound) { + if (!_eglIsContextBound(&c->base)) { st_destroy_context(c->st); c->pipe->destroy(c->pipe); free(c); diff --git a/src/gallium/state_trackers/egl/egl_surface.c b/src/gallium/state_trackers/egl/egl_surface.c index 86f2ea97e54..7413c9b73b8 100644 --- a/src/gallium/state_trackers/egl/egl_surface.c +++ b/src/gallium/state_trackers/egl/egl_surface.c @@ -366,7 +366,7 @@ drm_destroy_surface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) struct drm_surface *surf = lookup_drm_surface(surface); _eglUnlinkSurface(&surf->base); - if (!surf->base.IsBound) { + if (!_eglIsSurfaceBound(&surf->base)) { if (surf->screen) drm_takedown_shown_screen(drv, surf->screen); st_unreference_framebuffer(surf->stfb); diff --git a/src/gallium/winsys/egl_xlib/egl_xlib.c b/src/gallium/winsys/egl_xlib/egl_xlib.c index e1ddcae97ba..1a1dad65f0b 100644 --- a/src/gallium/winsys/egl_xlib/egl_xlib.c +++ b/src/gallium/winsys/egl_xlib/egl_xlib.c @@ -382,7 +382,7 @@ xlib_eglDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext ctx) struct xlib_egl_context *context = lookup_context(ctx); if (context) { _eglUnlinkContext(&context->Base); - if (!context->Base.IsBound) { + if (!_eglIsContextBound(&context->Base)) { /* API-dependent clean-up */ switch (context->Base.ClientAPI) { case EGL_OPENGL_ES_API: @@ -533,7 +533,7 @@ xlib_eglDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) struct xlib_egl_surface *surf = lookup_surface(surface); if (surf) { _eglUnlinkSurface(&surf->Base); - if (!surf->Base.IsBound) { + if (!_eglIsSurfaceBound(&surf->Base)) { XFreeGC(surf->Dpy, surf->Gc); st_unreference_framebuffer(surf->Framebuffer); free(surf); diff --git a/src/mesa/drivers/dri/fb/fb_egl.c b/src/mesa/drivers/dri/fb/fb_egl.c index dee67feb5ac..4e41860d8c8 100644 --- a/src/mesa/drivers/dri/fb/fb_egl.c +++ b/src/mesa/drivers/dri/fb/fb_egl.c @@ -605,7 +605,7 @@ fbDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface) { fbSurface *fs = Lookup_fbSurface(surface); _eglUnlinkSurface(&fs->Base); - if (!fs->Base.IsBound) + if (!_eglIsSurfaceBound(&fs->Base)) free(fs); return EGL_TRUE; } @@ -616,7 +616,7 @@ fbDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context) { fbContext *fc = Lookup_fbContext(context); _eglUnlinkContext(&fc->Base); - if (!fc->Base.IsBound) + if (!_eglIsContextBound(&fc->Base)) free(fc); return EGL_TRUE; } -- 2.30.2