diff options
author | Emil Velikov <emil.velikov@collabora.com> | 2016-11-21 13:46:50 +0000 |
---|---|---|
committer | Emil Velikov <emil.l.velikov@gmail.com> | 2016-11-22 15:13:41 +0000 |
commit | b9880d2e93a260c348b9413cb2c633365ba13b6e (patch) | |
tree | 18795e84d697ed69cd200e0baefa7062d07da416 /src/egl | |
parent | a56a505db72b0a5ff973a489a094186d7dfcd9e7 (diff) |
egl/x11: factor out dri2_get_xcb_connection()
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.
v2: Call xcb_disconnect() on error (Eric)
Note: use xcb_disconnect() even in the xcb_connection_has_error() case
as per the manual:
... memory will not be freed until xcb_disconnect...
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> (v1)
Diffstat (limited to 'src/egl')
-rw-r--r-- | src/egl/drivers/dri2/platform_x11.c | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 92c4eade195..00613d909d5 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -1180,13 +1180,10 @@ 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"); + const char *msg; disp->DriverData = (void *) dri2_dpy; if (disp->PlatformDisplay == NULL) { @@ -1200,10 +1197,30 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp) } if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) { - _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); - goto cleanup_dpy; + msg = "xcb_connect failed"; + goto disconnect; } + return EGL_TRUE; +disconnect: + if (disp->PlatformDisplay == NULL) + xcb_disconnect(dri2_dpy->conn); + + return _eglError(EGL_BAD_ALLOC, msg); +} + +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 * here will allow is to simply free the memory at dri2_terminate(). @@ -1308,21 +1325,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 +1425,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; |