From eabf59791e6fc553d1a882341dfca628cd5fc66d Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Sat, 7 Apr 2018 13:01:15 -0700 Subject: [PATCH] egl/dri2: In dri2_make_current, return early on failure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This pulls an 'else' block into the function's main body, making the code easier to follow. Without this change, the upcoming EGL_KHR_mutable_render_buffer patch transforms dri2_make_current() into spaghetti. Reviewed-by: Tapani Pälli --- src/egl/drivers/dri2/egl_dri2.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index e109ad37f55..1208ebb3156 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1493,20 +1493,7 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, unbind = (cctx == NULL && ddraw == NULL && rdraw == NULL); - if (unbind || dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { - dri2_destroy_surface(drv, disp, old_dsurf); - dri2_destroy_surface(drv, disp, old_rsurf); - - if (!unbind) - dri2_dpy->ref_count++; - if (old_ctx) { - EGLDisplay old_disp = _eglGetDisplayHandle(old_ctx->Resource.Display); - dri2_destroy_context(drv, disp, old_ctx); - dri2_display_release(old_disp); - } - - return EGL_TRUE; - } else { + if (!unbind && !dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { /* undo the previous _eglBindContext */ _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf); assert(&dri2_ctx->base == ctx && @@ -1527,6 +1514,20 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, */ return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); } + + dri2_destroy_surface(drv, disp, old_dsurf); + dri2_destroy_surface(drv, disp, old_rsurf); + + if (!unbind) + dri2_dpy->ref_count++; + + if (old_ctx) { + EGLDisplay old_disp = _eglGetDisplayHandle(old_ctx->Resource.Display); + dri2_destroy_context(drv, disp, old_ctx); + dri2_display_release(old_disp); + } + + return EGL_TRUE; } __DRIdrawable * -- 2.30.2