egl/x11: split out dri2 init entirely

this will enable simplifying the remaining codepaths with the expectation
that dri2 will be ripped out entirely after the next release

Acked-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33891>
This commit is contained in:
Mike Blumenkrantz 2024-08-27 13:43:17 -04:00 committed by Marge Bot
parent 5466ff3a43
commit 323bad6b18
3 changed files with 34 additions and 15 deletions

View file

@ -880,6 +880,7 @@ dri2_initialize(_EGLDisplay *disp)
loader_set_logger(_eglLog);
bool allow_dri2 = false;
switch (disp->Platform) {
case _EGL_PLATFORM_SURFACELESS:
ret = dri2_initialize_surfaceless(disp);
@ -889,7 +890,17 @@ dri2_initialize(_EGLDisplay *disp)
break;
case _EGL_PLATFORM_X11:
case _EGL_PLATFORM_XCB:
ret = dri2_initialize_x11(disp);
ret = dri2_initialize_x11(disp, &allow_dri2);
/* platform_x11 detects dri2 availability */
if (!ret && allow_dri2) {
/* this is a fallthrough using the same dri2_dpy from dri3,
* so the existing one must be destroyed and a new one created
* the caller will switch to the new display automatically
*/
dri2_display_destroy(disp);
dri2_display_create(disp);
ret = dri2_initialize_x11_dri2(disp);
}
break;
case _EGL_PLATFORM_DRM:
ret = dri2_initialize_drm(disp);

View file

@ -503,14 +503,21 @@ dri2_create_image_from_dri(_EGLDisplay *disp, struct dri_image *dri_image);
#ifdef HAVE_X11_PLATFORM
EGLBoolean
dri2_initialize_x11(_EGLDisplay *disp);
dri2_initialize_x11_dri2(_EGLDisplay *disp);
EGLBoolean
dri2_initialize_x11(_EGLDisplay *disp, bool *allow_dri2);
void
dri2_teardown_x11(struct dri2_egl_display *dri2_dpy);
unsigned int
dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth);
#else
static inline EGLBoolean
dri2_initialize_x11(_EGLDisplay *disp)
dri2_initialize_x11_dri2(_EGLDisplay *disp)
{
return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
}
static inline EGLBoolean
dri2_initialize_x11(_EGLDisplay *disp, bool *allow_dri2)
{
return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
}

View file

@ -1948,7 +1948,8 @@ static const __DRIextension *dri2_loader_extensions[] = {
NULL,
};
static EGLBoolean
/* don't consolidate any of this, it's a separate codepath */
EGLBoolean
dri2_initialize_x11_dri2(_EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
@ -2005,10 +2006,16 @@ dri2_initialize_x11_dri2(_EGLDisplay *disp)
cleanup:
return EGL_FALSE;
}
#else
EGLBoolean
dri2_initialize_x11_dri2(_EGLDisplay *disp)
{
return _eglError(EGL_NOT_INITIALIZED, "legacy-x11 dri2 not built");
}
#endif
EGLBoolean
dri2_initialize_x11(_EGLDisplay *disp)
dri2_initialize_x11(_EGLDisplay *disp, bool *allow_dri2)
{
enum dri2_egl_driver_fail status = DRI2_EGL_DRIVER_FAILED;
if (disp->Options.ForceSoftware ||
@ -2024,16 +2031,10 @@ dri2_initialize_x11(_EGLDisplay *disp)
#endif
#ifdef HAVE_X11_DRI2
if (!debug_get_bool_option("LIBGL_DRI2_DISABLE", false) &&
status != DRI2_EGL_DRIVER_PREFER_ZINK)
/* this is a fallthrough using the same dri2_dpy from dri3,
* so the existing one must be destroyed and a new one created
* the caller will switch to the new display automatically
*/
dri2_display_destroy(disp);
dri2_display_create(disp);
if (dri2_initialize_x11_dri2(disp))
return EGL_TRUE;
*allow_dri2 = !debug_get_bool_option("LIBGL_DRI2_DISABLE", false) &&
status != DRI2_EGL_DRIVER_PREFER_ZINK;
#else
*allow_dri2 = false;
#endif
return EGL_FALSE;