From: Emil Velikov <emil.veli...@collabora.com> Identical throughout dri2, dri3 and drisw. Next patch will add more common code, so rather than duplicating it factor out the function.
Note: this also sets eglError on failure. Something that's quite inconsistent throughout the codebase. Signed-off-by: Emil Velikov <emil.veli...@collabora.com> --- src/egl/drivers/dri2/platform_x11.c | 58 +++++++++++++------------------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index cf2ce3f..e152868 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -1180,14 +1180,9 @@ static const __DRIextension *swrast_loader_extensions[] = { }; static EGLBoolean -dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp) +dri2_get_xcb_connection(_EGLDriver *drv, _EGLDisplay *disp, + struct dri2_egl_display *dri2_dpy) { - struct dri2_egl_display *dri2_dpy; - - dri2_dpy = calloc(1, sizeof *dri2_dpy); - if (!dri2_dpy) - return _eglError(EGL_BAD_ALLOC, "eglInitialize"); - disp->DriverData = (void *) dri2_dpy; if (disp->PlatformDisplay == NULL) { dri2_dpy->conn = xcb_connect(0, &dri2_dpy->screen); @@ -1199,10 +1194,23 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp) dri2_dpy->screen = DefaultScreen(dpy); } - if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) { - _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); + if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) + return _eglError(EGL_BAD_ALLOC, "xcb_connect failed"); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp) +{ + struct dri2_egl_display *dri2_dpy; + + dri2_dpy = calloc(1, sizeof *dri2_dpy); + if (!dri2_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + + if (!dri2_get_xcb_connection(drv, disp, dri2_dpy)) goto cleanup_dpy; - } /* * Every hardware driver_name is set using strdup. Doing the same in @@ -1308,21 +1316,8 @@ dri2_initialize_x11_dri3(_EGLDriver *drv, _EGLDisplay *disp) if (!dri2_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); - disp->DriverData = (void *) dri2_dpy; - if (disp->PlatformDisplay == NULL) { - dri2_dpy->conn = xcb_connect(0, &dri2_dpy->screen); - dri2_dpy->own_device = true; - } else { - Display *dpy = disp->PlatformDisplay; - - dri2_dpy->conn = XGetXCBConnection(dpy); - dri2_dpy->screen = DefaultScreen(dpy); - } - - if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) { - _eglLog(_EGL_WARNING, "DRI3: xcb_connect failed"); + if (!dri2_get_xcb_connection(drv, disp, dri2_dpy)) goto cleanup_dpy; - } if (!dri3_x11_connect(dri2_dpy)) goto cleanup_conn; @@ -1421,21 +1416,8 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp) if (!dri2_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); - disp->DriverData = (void *) dri2_dpy; - if (disp->PlatformDisplay == NULL) { - dri2_dpy->conn = xcb_connect(0, &dri2_dpy->screen); - dri2_dpy->own_device = true; - } else { - Display *dpy = disp->PlatformDisplay; - - dri2_dpy->conn = XGetXCBConnection(dpy); - dri2_dpy->screen = DefaultScreen(dpy); - } - - if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) { - _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); + if (!dri2_get_xcb_connection(drv, disp, dri2_dpy)) goto cleanup_dpy; - } if (!dri2_x11_connect(dri2_dpy)) goto cleanup_conn; -- 2.10.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev