Fix a bug where eglMakeCurrent(NULL) did not work

This happened because the VALIDATE macros terminated the function prematurally.
Also clear the surface bindings from the previous context.

Change-Id: I33d587f5e877caa6ec651a04ff887e0c77a9d5f3
This commit is contained in:
Yochai Shefi Simchon
2011-05-22 16:23:28 +03:00
parent 88ec3acc83
commit 889d928f29

View File

@@ -676,13 +676,6 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw
RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH); RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH);
} }
VALIDATE_CONTEXT(context);
VALIDATE_SURFACE(draw,newDrawSrfc);
VALIDATE_SURFACE(read,newReadSrfc);
EglSurface* newDrawPtr = newDrawSrfc.Ptr();
EglSurface* newReadPtr = newReadSrfc.Ptr();
EglContext* newCtx = ctx.Ptr();
ThreadInfo* thread = getThreadInfo(); ThreadInfo* thread = getThreadInfo();
EglContext* prevCtx = static_cast<EglContext*>(thread->eglContext); EglContext* prevCtx = static_cast<EglContext*>(thread->eglContext);
@@ -692,11 +685,17 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw
if(!EglOS::makeCurrent(dpy->nativeType(),NULL,NULL,NULL)) { if(!EglOS::makeCurrent(dpy->nativeType(),NULL,NULL,NULL)) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS);
} }
thread->updateInfo(newCtx,dpy,NULL,newCtx->getShareGroup(),dpy->getManager(newCtx->version())); thread->updateInfo(NULL,dpy,NULL,ShareGroupPtr(NULL),dpy->getManager(prevCtx->version()));
g_eglInfo->getIface(prevCtx->version())->setShareGroup(newCtx->getGlesContext(),ShareGroupPtr(NULL));
ctx->setSurfaces(SurfacePtr(NULL),SurfacePtr(NULL));
} }
} else { //assining new context } else { //assining new context
VALIDATE_CONTEXT(context);
VALIDATE_SURFACE(draw,newDrawSrfc);
VALIDATE_SURFACE(read,newReadSrfc);
EglSurface* newDrawPtr = newDrawSrfc.Ptr();
EglSurface* newReadPtr = newReadSrfc.Ptr();
EglContext* newCtx = ctx.Ptr();
//surfaces compitability check //surfaces compitability check
if(!((*ctx->getConfig()).compitableWith((*newDrawPtr->getConfig()))) || if(!((*ctx->getConfig()).compitableWith((*newDrawPtr->getConfig()))) ||
!((*ctx->getConfig()).compitableWith((*newReadPtr->getConfig())))) { !((*ctx->getConfig()).compitableWith((*newReadPtr->getConfig())))) {
@@ -760,6 +759,8 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw
dpy->removeContext(prevCtxPtr); dpy->removeContext(prevCtxPtr);
} }
} }
prevCtx->setSurfaces(SurfacePtr(NULL),SurfacePtr(NULL));
} }
return EGL_TRUE; return EGL_TRUE;
} }
@@ -816,7 +817,13 @@ EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void) {
EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay);
EglContext* ctx = static_cast<EglContext*>(thread->eglContext); EglContext* ctx = static_cast<EglContext*>(thread->eglContext);
if(dpy && ctx){ if(dpy && ctx){
return dpy->getContext(ctx).Ptr(); // This double check is required because a context might still be current after it is destroyed - in which case
// its handle should be invalid, that is EGL_NO_CONTEXT should be returned even though the context is current
EGLContext c = (EGLContext)ctx->getHndl();
if(dpy->getContext(c).Ptr())
{
return c;
}
} }
return EGL_NO_CONTEXT; return EGL_NO_CONTEXT;
} }
@@ -836,9 +843,12 @@ EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) {
// current after it is destroyed - in which case its handle should // current after it is destroyed - in which case its handle should
// be invalid, that is EGL_NO_SURFACE should be returned even // be invalid, that is EGL_NO_SURFACE should be returned even
// though the surface is current. // though the surface is current.
surface = dpy->getSurface(surface.Ptr()); EGLSurface s = (EGLSurface)surface->getHndl();
surface = dpy->getSurface(s);
if(surface.Ptr()) if(surface.Ptr())
return surface.Ptr(); {
return s;
}
} }
} }
return EGL_NO_SURFACE; return EGL_NO_SURFACE;