Skip to content

Commit

Permalink
egl: negotiate reference counting (fixes #25531)
Browse files Browse the repository at this point in the history
According to the specification, EGL displays are not reference-counted
by default. As such, `eglTerminate()` will terminate a display even if
there are other users for it in the same process.

This becomes a fatal problem if platform display is shared by multiple
components, and the EGL display parameters are identical or deemed
compatible by the EGL driver. Typically, this will occur with the
window provider and the display.

To fix this, the Khronos group defined an EGL extension to negotiate
reference counting explicitly.

* On Android, this patch makes no differences as the EGL enables
  reference counting by default, regardless of the baseline
  specifications.
* On X11, this patch makes no differences because the module will
  create its own private Xlib `Display` as the platform display,
  such that the EGL display is not shareable.
* This patch matters on Wayland where the `wl_display` pointer must be
  shared between the window provider and display. Without this patch,
  Either the window provider or the display cannot use EGL.
* On Windows, the situation ought to be similar to Wayland, though this
  is much less of an issue, as EGL is not typically used.

This patch does **not** require reference counting if not available as
this would needlessly break on Android and X11, as well as with the
non-embedded XDG-shell window provider on Wayland.
  • Loading branch information
Rémi Denis-Courmont committed Oct 17, 2021
1 parent 06a7da1 commit 64f2e3b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/video_output/opengl/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
EGLSurface (*createSurface)(EGLDisplay, EGLConfig, void *, const EGLint *)
= CreateWindowSurface;
void *window;
EGLAttrib refs_name = EGL_NONE;
EGLAttrib refs_value = EGL_FALSE;

#ifdef EGL_KHR_display_reference
if (CheckClientExt("EGL_KHR_display_reference"))
{
refs_name = EGL_TRACK_REFERENCES_KHR;
refs_value = EGL_TRUE;
}
#endif

#ifdef USE_PLATFORM_X11
sys->x11 = NULL;
Expand Down Expand Up @@ -340,6 +350,7 @@ static int Open(vlc_gl_t *gl, const struct gl_api *api,
EGL_GREEN_SIZE, 5,
EGL_BLUE_SIZE, 5,
EGL_RENDERABLE_TYPE, api->render_bit,
refs_name, refs_value,
EGL_NONE
};
EGLConfig cfgv[1];
Expand Down

0 comments on commit 64f2e3b

Please sign in to comment.