diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 07df3b43456..af867b71b3e 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -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); diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 3f3505d3dd2..41443bdc8e4 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -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"); } diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 5af91888da3..283b0a0b8b3 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -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;