egl/dri2: only take a dri2_dpy reference when binding a new context/surfaces
authorFrank Binns <frank.binns@imgtec.com>
Tue, 28 Jul 2020 14:50:30 +0000 (15:50 +0100)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Jul 2020 20:01:14 +0000 (20:01 +0000)
commitd0e32e5f8105eccd075ebbf42594100ed663fd6e
tree8262c3edff965a1d77440783671713b166b1a90c
parentb9391c1d50b1ed5b5c89814399e99700e46677cc
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@imgtec.com>
Reviewed-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Nicolas Cortes <nicolas.g.cortes@intel.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3328
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6105>
src/egl/drivers/dri2/egl_dri2.c