Mesa (staging/20.1): egl/dri2: only take a dri2_dpy reference when binding a new context/surfaces

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jul 30 20:07:37 UTC 2020


Module: Mesa
Branch: staging/20.1
Commit: a6cb316fcdf0b87ef7d4355ac046f20b8a7d621c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a6cb316fcdf0b87ef7d4355ac046f20b8a7d621c

Author: Frank Binns <frank.binns at imgtec.com>
Date:   Tue Jul 28 15:50:30 2020 +0100

egl/dri2: only take a dri2_dpy reference when binding a new context/surfaces

This effectively reverts part of 2907faee, which changed dri2_make_current() to
always take a dri2_dpy reference regardless of whether or not a new context or
surface(s) were being bound. This led to a reference count imbalance as there
was no corresponding code added to drop a reference on the dri2_dpy. As a
consequence, any application that called eglInitialize() on a default/native
display after having called eglTerminate() would always get back the old
dri2_dpy, inheriting its previous state.

As the reference count is there to prevent the dri2_dpy from being destroyed
between eglTerminate() and eglInitialize() calls when a context is still bound,
a reference should only be taken when a successful call to
dri2_dpy->core->bindContext() has been made. Fix the issue by restoring the old
reference counting behaviour.

Fixes: 4e8f95f64d004 ("egl_dri2: Always unbind old contexts")
Fixes: 2907faee7a397 ("egl/dri2: try to bind old context if bindContext failed")
Signed-off-by: Frank Binns <frank.binns at imgtec.com>
Reviewed-by: Luigi Santivetti <luigi.santivetti at imgtec.com>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
Tested-by: Nicolas Cortes <nicolas.g.cortes at intel.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3328
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6105>
(cherry picked from commit d0e32e5f8105eccd075ebbf42594100ed663fd6e)

---

 .pick_status.json               | 2 +-
 src/egl/drivers/dri2/egl_dri2.c | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 2feca2eceaa..518ac3b9302 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -301,7 +301,7 @@
         "description": "egl/dri2: only take a dri2_dpy reference when binding a new context/surfaces",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "4e8f95f64d004aa1278609c5bbac9a53c0c6e4c9"
     },
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a3c800b04aa..00d11b292e4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1851,6 +1851,13 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
                 tmp_rsurf == old_rsurf);
 
          _eglLog(_EGL_WARNING, "DRI2: failed to rebind the previous context");
+      } else {
+         /* dri2_dpy->core->bindContext succeeded, so take a reference on the
+          * dri2_dpy. This prevents dri2_dpy from being reinitialized when a
+          * EGLDisplay is terminated and then initialized again while a
+          * context is still bound. See dri2_intitialize() for a more in depth
+          * explanation. */
+         dri2_dpy->ref_count++;
       }
    }
 
@@ -1865,8 +1872,6 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
    if (egl_error != EGL_SUCCESS)
       return _eglError(egl_error, "eglMakeCurrent");
 
-   dri2_dpy->ref_count++;
-
    if (dsurf && _eglSurfaceHasMutableRenderBuffer(dsurf) &&
        dri2_dpy->vtbl->set_shared_buffer_mode) {
       /* Always update the shared buffer mode. This is obviously needed when



More information about the mesa-commit mailing list