summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-I Wu <olvaffe@gmail.com>2010-01-28 16:57:49 +0800
committerChia-I Wu <olvaffe@gmail.com>2010-01-28 17:28:48 +0800
commit6baa2c8d022e5dd1e305e7da2925c1e6f9370f35 (patch)
treec354b4fb532e992c42563bec2b63b668bf453e85
parent45ba53324341234144ca02122bf2c0b5ef58c361 (diff)
egl: Migrate drivers to use _eglBindContext.
_eglMakeCurrent is a big hammer that is not easy to use. Migrate drivers to use _eglBindContext and un-export _eglMakeCurrent.
-rw-r--r--src/egl/drivers/glx/egl_glx.c20
-rw-r--r--src/egl/drivers/xdri/egl_xdri.c21
-rw-r--r--src/egl/main/eglcontext.c23
-rw-r--r--src/egl/main/eglcontext.h2
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.c21
5 files changed, 42 insertions, 45 deletions
diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c
index 5efb72e8754..1c38db64915 100644
--- a/src/egl/drivers/glx/egl_glx.c
+++ b/src/egl/drivers/glx/egl_glx.c
@@ -660,8 +660,10 @@ GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx);
GLXDrawable ddraw, rdraw;
GLXContext cctx;
+ EGLBoolean ret = EGL_FALSE;
- if (!_eglMakeCurrent(drv, disp, dsurf, rsurf, ctx))
+ /* bind the new context and return the "orphaned" one */
+ if (!_eglBindContext(&ctx, &dsurf, &rsurf))
return EGL_FALSE;
ddraw = (GLX_dsurf) ? GLX_dsurf->glx_drawable : None;
@@ -669,11 +671,21 @@ GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
cctx = (GLX_ctx) ? GLX_ctx->context : NULL;
if (GLX_dpy->have_make_current_read)
- return glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx);
+ ret = glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx);
else if (ddraw == rdraw)
- return glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx);
+ ret = glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx);
- return EGL_FALSE;
+ if (ret) {
+ if (dsurf && !_eglIsSurfaceLinked(dsurf))
+ destroy_surface(disp, dsurf);
+ if (rsurf && rsurf != dsurf && !_eglIsSurfaceLinked(rsurf))
+ destroy_surface(disp, rsurf);
+ }
+ else {
+ _eglBindContext(&ctx, &dsurf, &rsurf);
+ }
+
+ return ret;
}
/** Get size of given window */
diff --git a/src/egl/drivers/xdri/egl_xdri.c b/src/egl/drivers/xdri/egl_xdri.c
index 26fe95b0431..2ca9ea8a5b0 100644
--- a/src/egl/drivers/xdri/egl_xdri.c
+++ b/src/egl/drivers/xdri/egl_xdri.c
@@ -475,17 +475,13 @@ xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d,
struct xdri_egl_context *xdri_ctx = lookup_context(context);
struct xdri_egl_surface *draw = lookup_surface(d);
struct xdri_egl_surface *read = lookup_surface(r);
- _EGLContext *old = _eglGetCurrentContext();
- /* an unlinked context will be invalid after context switch */
- if (!_eglIsContextLinked(old))
- old = NULL;
-
- if (!_eglMakeCurrent(drv, dpy, d, r, context))
+ /* bind the new context and return the "orphaned" one */
+ if (!_eglBindContext(&context, &d, &r))
return EGL_FALSE;
/* flush before context switch */
- if (old && old != context && xdri_driver->FlushCurrentContext)
+ if (context && xdri_driver->FlushCurrentContext)
xdri_driver->FlushCurrentContext();
/* the symbol is defined in libGL.so */
@@ -498,11 +494,18 @@ xdri_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *d,
return EGL_FALSE;
}
}
- else if (old) {
- xdri_ctx = lookup_context(old);
+ else if (context) {
+ xdri_ctx = lookup_context(context);
xdri_ctx->driContext->unbindContext(xdri_ctx->driContext);
}
+ if (context && !_eglIsContextLinked(context))
+ destroy_context(dpy, context);
+ if (d && !_eglIsSurfaceLinked(d))
+ destroy_surface(dpy, d);
+ if (r && r != d && !_eglIsSurfaceLinked(r))
+ destroy_surface(dpy, r);
+
return EGL_TRUE;
}
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 60d2efd44b9..4496f76eceb 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -310,32 +310,13 @@ _eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read)
/**
- * Drivers will typically call this to do the error checking and
- * update the various flags.
- * Then, the driver will do its device-dependent Make-Current stuff.
+ * Just a placeholder/demo function. Drivers should override this.
*/
EGLBoolean
_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw,
_EGLSurface *read, _EGLContext *ctx)
{
- if (!_eglBindContext(&ctx, &draw, &read))
- return EGL_FALSE;
-
- /* nothing we can do if the display is uninitialized */
- if (dpy->Initialized) {
- /* avoid double destroy */
- if (read && read == draw)
- read = NULL;
-
- if (ctx && !_eglIsContextLinked(ctx))
- drv->API.DestroyContext(drv, dpy, ctx);
- if (draw && !_eglIsSurfaceLinked(draw))
- drv->API.DestroySurface(drv, dpy, draw);
- if (read && !_eglIsSurfaceLinked(read))
- drv->API.DestroySurface(drv, dpy, read);
- }
-
- return EGL_TRUE;
+ return EGL_FALSE;
}
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index 84d8deed51c..4811e3bb7ad 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -51,7 +51,7 @@ PUBLIC EGLBoolean
_eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read);
-PUBLIC EGLBoolean
+extern EGLBoolean
_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx);
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index 657c771a6b1..f8334217c47 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -856,18 +856,14 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
_EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx)
{
struct egl_g3d_context *gctx = egl_g3d_context(ctx);
+ struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
struct egl_g3d_context *old_gctx;
- EGLint api;
EGLBoolean ok = EGL_TRUE;
- /* find the old context */
- api = (gctx) ? gctx->base.ClientAPI : eglQueryAPI();
- old_gctx = egl_g3d_get_current_context(api);
- if (old_gctx && !_eglIsContextLinked(&old_gctx->base))
- old_gctx = NULL;
-
- if (!_eglMakeCurrent(drv, dpy, draw, read, ctx))
+ /* bind the new context and return the "orphaned" one */
+ if (!_eglBindContext(&ctx, &draw, &read))
return EGL_FALSE;
+ old_gctx = egl_g3d_context(ctx);
if (old_gctx) {
/* flush old context */
@@ -883,8 +879,6 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
}
if (gctx) {
- struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
-
ok = egl_g3d_realloc_context(dpy, &gctx->base);
if (ok) {
ok = gctx->stapi->st_make_current(gctx->st_ctx,
@@ -904,6 +898,13 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
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);
+
return ok;
}