summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-10-23 12:52:26 +0800
committerChia-I Wu <[email protected]>2010-10-23 15:26:28 +0800
commitd19afc57fe49816f3f3290410e0124d326577be2 (patch)
tree8d90c500c91f8c2e703a05259c85406d4261c3ed /src/gallium/state_trackers
parentdc4f845c37a8446de19036e24fd397a0aa864c02 (diff)
egl: Use reference counting to replace IsLinked or IsBound.
Remove all _egl<Res>IsLinked and _egl<Res>IsBound. Update _eglBindContext and drivers to do reference counting.
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_api.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c
index 3bde39737ba..c10245bb067 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c
@@ -160,7 +160,7 @@ destroy_context(_EGLDisplay *dpy, _EGLContext *ctx)
static EGLBoolean
egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
{
- if (!_eglIsContextBound(ctx))
+ if (_eglPutContext(ctx))
destroy_context(dpy, ctx);
return EGL_TRUE;
}
@@ -433,7 +433,7 @@ destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf)
static EGLBoolean
egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
{
- if (!_eglIsSurfaceBound(surf))
+ if (_eglPutSurface(surf))
destroy_surface(dpy, surf);
return EGL_TRUE;
}
@@ -446,13 +446,15 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
struct egl_g3d_surface *gread = egl_g3d_surface(read);
struct egl_g3d_context *old_gctx;
+ _EGLContext *old_ctx;
+ _EGLSurface *old_draw, *old_read;
EGLBoolean ok = EGL_TRUE;
- /* bind the new context and return the "orphaned" one */
- if (!_eglBindContext(&ctx, &draw, &read))
+ /* make new bindings */
+ if (!_eglBindContext(ctx, draw, read, &old_ctx, &old_draw, &old_read))
return EGL_FALSE;
- old_gctx = egl_g3d_context(ctx);
+ old_gctx = egl_g3d_context(old_ctx);
if (old_gctx) {
/* flush old context */
old_gctx->stctxi->flush(old_gctx->stctxi,
@@ -481,15 +483,33 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
}
else if (old_gctx) {
ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL);
- old_gctx->base.WindowRenderBuffer = EGL_NONE;
+ if (ok)
+ old_gctx->base.WindowRenderBuffer = EGL_NONE;
}
- if (ctx && !_eglIsContextLinked(ctx))
- destroy_context(dpy, ctx);
- if (draw && !_eglIsSurfaceLinked(draw))
- destroy_surface(dpy, draw);
- if (read && read != draw && !_eglIsSurfaceLinked(read))
- destroy_surface(dpy, read);
+ if (ok) {
+ if (_eglPutContext(old_ctx))
+ destroy_context(dpy, old_ctx);
+ if (_eglPutSurface(old_draw))
+ destroy_surface(dpy, old_draw);
+ if (_eglPutSurface(old_read))
+ destroy_surface(dpy, old_read);
+ }
+ else {
+ /* undo the previous _eglBindContext */
+ _eglBindContext(old_ctx, old_draw, old_read, &ctx, &draw, &read);
+ assert(&gctx->base == ctx &&
+ &gdraw->base == draw &&
+ &gread->base == read);
+
+ _eglPutSurface(draw);
+ _eglPutSurface(read);
+ _eglPutContext(ctx);
+
+ _eglPutSurface(old_draw);
+ _eglPutSurface(old_read);
+ _eglPutContext(old_ctx);
+ }
return ok;
}