From 0d65f229c5c3a0eb2cc7da742ee0aca1e5c72fc7 Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Mon, 3 Jan 2022 19:57:14 +0100 Subject: [PATCH] egl/dri2: short-circuit dri2_make_current when possible If an application calls eglMakeCurrent with the same context and the same draw and read surfaces as the current ones, there is no need to go through all the work of unbinding/flushing the old context and binding the new one. While the EGL spec is a bit ambiguous here, it seems that the implicit flush of the outgoing context only needs to be done when the context is actually changed. Signed-off-by: Lucas Stach Reviewed-by: Adam Jackson Part-of: --- src/egl/drivers/dri2/egl_dri2.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 93030ad..93e3af6 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1783,6 +1783,13 @@ dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) return EGL_FALSE; + if (old_ctx == ctx && old_dsurf == dsurf && old_rsurf == rsurf) { + _eglPutSurface(old_dsurf); + _eglPutSurface(old_rsurf); + _eglPutContext(old_ctx); + return EGL_TRUE; + } + if (old_ctx) { __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; old_disp = old_ctx->Resource.Display; -- 2.7.4