egl/x11: store xcb_screen_t *screen instead of int screen
Just fetch and store it once, rather than doing the xcb_setup_roots_iterator + get_xcb_screen dance five times. v2: Call xcb_disconnect() on error (Eric) Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> (v1)
This commit is contained in:
parent
b9880d2e93
commit
7c6babb22c
|
@ -199,7 +199,7 @@ struct dri2_egl_display
|
||||||
|
|
||||||
#ifdef HAVE_X11_PLATFORM
|
#ifdef HAVE_X11_PLATFORM
|
||||||
xcb_connection_t *conn;
|
xcb_connection_t *conn;
|
||||||
int screen;
|
xcb_screen_t *screen;
|
||||||
int swap_available;
|
int swap_available;
|
||||||
#ifdef HAVE_DRI3
|
#ifdef HAVE_DRI3
|
||||||
struct loader_dri3_extensions loader_dri3_ext;
|
struct loader_dri3_extensions loader_dri3_ext;
|
||||||
|
|
|
@ -206,10 +206,8 @@ dri2_x11_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
|
||||||
struct dri2_egl_surface *dri2_surf;
|
struct dri2_egl_surface *dri2_surf;
|
||||||
xcb_get_geometry_cookie_t cookie;
|
xcb_get_geometry_cookie_t cookie;
|
||||||
xcb_get_geometry_reply_t *reply;
|
xcb_get_geometry_reply_t *reply;
|
||||||
xcb_screen_iterator_t s;
|
|
||||||
xcb_generic_error_t *error;
|
xcb_generic_error_t *error;
|
||||||
xcb_drawable_t drawable;
|
xcb_drawable_t drawable;
|
||||||
xcb_screen_t *screen;
|
|
||||||
const __DRIconfig *config;
|
const __DRIconfig *config;
|
||||||
|
|
||||||
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
|
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
|
||||||
|
@ -228,16 +226,9 @@ dri2_x11_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
|
||||||
|
|
||||||
dri2_surf->region = XCB_NONE;
|
dri2_surf->region = XCB_NONE;
|
||||||
if (type == EGL_PBUFFER_BIT) {
|
if (type == EGL_PBUFFER_BIT) {
|
||||||
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
|
||||||
screen = get_xcb_screen(s, dri2_dpy->screen);
|
|
||||||
if (!screen) {
|
|
||||||
_eglError(EGL_BAD_ALLOC, "failed to get xcb screen");
|
|
||||||
goto cleanup_surf;
|
|
||||||
}
|
|
||||||
|
|
||||||
dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn);
|
dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn);
|
||||||
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize,
|
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize,
|
||||||
dri2_surf->drawable, screen->root,
|
dri2_surf->drawable, dri2_dpy->screen->root,
|
||||||
dri2_surf->base.Width, dri2_surf->base.Height);
|
dri2_surf->base.Width, dri2_surf->base.Height);
|
||||||
} else {
|
} else {
|
||||||
if (!drawable) {
|
if (!drawable) {
|
||||||
|
@ -544,20 +535,10 @@ dri2_x11_do_authenticate(struct dri2_egl_display *dri2_dpy, uint32_t id)
|
||||||
{
|
{
|
||||||
xcb_dri2_authenticate_reply_t *authenticate;
|
xcb_dri2_authenticate_reply_t *authenticate;
|
||||||
xcb_dri2_authenticate_cookie_t authenticate_cookie;
|
xcb_dri2_authenticate_cookie_t authenticate_cookie;
|
||||||
xcb_screen_iterator_t s;
|
|
||||||
xcb_screen_t *screen;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
|
||||||
|
|
||||||
screen = get_xcb_screen(s, dri2_dpy->screen);
|
|
||||||
if (!screen) {
|
|
||||||
_eglLog(_EGL_WARNING, "DRI2: failed to get xcb screen");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
authenticate_cookie =
|
authenticate_cookie =
|
||||||
xcb_dri2_authenticate_unchecked(dri2_dpy->conn, screen->root, id);
|
xcb_dri2_authenticate_unchecked(dri2_dpy->conn, dri2_dpy->screen->root, id);
|
||||||
authenticate =
|
authenticate =
|
||||||
xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL);
|
xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL);
|
||||||
|
|
||||||
|
@ -598,8 +579,6 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
|
||||||
xcb_dri2_connect_reply_t *connect;
|
xcb_dri2_connect_reply_t *connect;
|
||||||
xcb_dri2_connect_cookie_t connect_cookie;
|
xcb_dri2_connect_cookie_t connect_cookie;
|
||||||
xcb_generic_error_t *error;
|
xcb_generic_error_t *error;
|
||||||
xcb_screen_iterator_t s;
|
|
||||||
xcb_screen_t *screen;
|
|
||||||
char *driver_name, *loader_driver_name, *device_name;
|
char *driver_name, *loader_driver_name, *device_name;
|
||||||
const xcb_query_extension_reply_t *extension;
|
const xcb_query_extension_reply_t *extension;
|
||||||
|
|
||||||
|
@ -622,13 +601,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
|
||||||
XCB_DRI2_MAJOR_VERSION,
|
XCB_DRI2_MAJOR_VERSION,
|
||||||
XCB_DRI2_MINOR_VERSION);
|
XCB_DRI2_MINOR_VERSION);
|
||||||
|
|
||||||
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
connect_cookie = xcb_dri2_connect_unchecked(dri2_dpy->conn, dri2_dpy->screen->root,
|
||||||
screen = get_xcb_screen(s, dri2_dpy->screen);
|
|
||||||
if (!screen) {
|
|
||||||
_eglLog(_EGL_WARNING, "DRI2: failed to get xcb screen");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
connect_cookie = xcb_dri2_connect_unchecked(dri2_dpy->conn, screen->root,
|
|
||||||
XCB_DRI2_DRIVER_TYPE_DRI);
|
XCB_DRI2_DRIVER_TYPE_DRI);
|
||||||
|
|
||||||
xfixes_query =
|
xfixes_query =
|
||||||
|
@ -720,7 +693,6 @@ static EGLBoolean
|
||||||
dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
|
dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
|
||||||
_EGLDisplay *disp, bool supports_preserved)
|
_EGLDisplay *disp, bool supports_preserved)
|
||||||
{
|
{
|
||||||
xcb_screen_iterator_t s;
|
|
||||||
xcb_depth_iterator_t d;
|
xcb_depth_iterator_t d;
|
||||||
xcb_visualtype_t *visuals;
|
xcb_visualtype_t *visuals;
|
||||||
int i, j, count;
|
int i, j, count;
|
||||||
|
@ -732,8 +704,7 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
d = xcb_screen_allowed_depths_iterator(dri2_dpy->screen);
|
||||||
d = xcb_screen_allowed_depths_iterator(get_xcb_screen(s, dri2_dpy->screen));
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
surface_type =
|
surface_type =
|
||||||
|
@ -1183,17 +1154,19 @@ static EGLBoolean
|
||||||
dri2_get_xcb_connection(_EGLDriver *drv, _EGLDisplay *disp,
|
dri2_get_xcb_connection(_EGLDriver *drv, _EGLDisplay *disp,
|
||||||
struct dri2_egl_display *dri2_dpy)
|
struct dri2_egl_display *dri2_dpy)
|
||||||
{
|
{
|
||||||
|
xcb_screen_iterator_t s;
|
||||||
|
int screen = 0;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
|
|
||||||
disp->DriverData = (void *) dri2_dpy;
|
disp->DriverData = (void *) dri2_dpy;
|
||||||
if (disp->PlatformDisplay == NULL) {
|
if (disp->PlatformDisplay == NULL) {
|
||||||
dri2_dpy->conn = xcb_connect(0, &dri2_dpy->screen);
|
dri2_dpy->conn = xcb_connect(NULL, &screen);
|
||||||
dri2_dpy->own_device = true;
|
dri2_dpy->own_device = true;
|
||||||
} else {
|
} else {
|
||||||
Display *dpy = disp->PlatformDisplay;
|
Display *dpy = disp->PlatformDisplay;
|
||||||
|
|
||||||
dri2_dpy->conn = XGetXCBConnection(dpy);
|
dri2_dpy->conn = XGetXCBConnection(dpy);
|
||||||
dri2_dpy->screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) {
|
if (!dri2_dpy->conn || xcb_connection_has_error(dri2_dpy->conn)) {
|
||||||
|
@ -1201,6 +1174,13 @@ dri2_get_xcb_connection(_EGLDriver *drv, _EGLDisplay *disp,
|
||||||
goto disconnect;
|
goto disconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
||||||
|
dri2_dpy->screen = get_xcb_screen(s, screen);
|
||||||
|
if (!dri2_dpy->screen) {
|
||||||
|
msg = "failed to get xcb screen";
|
||||||
|
goto disconnect;
|
||||||
|
}
|
||||||
|
|
||||||
return EGL_TRUE;
|
return EGL_TRUE;
|
||||||
disconnect:
|
disconnect:
|
||||||
if (disp->PlatformDisplay == NULL)
|
if (disp->PlatformDisplay == NULL)
|
||||||
|
|
|
@ -160,16 +160,6 @@ dri3_set_swap_interval(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
|
||||||
return EGL_TRUE;
|
return EGL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static xcb_screen_t *
|
|
||||||
get_xcb_screen(xcb_screen_iterator_t iter, int screen)
|
|
||||||
{
|
|
||||||
for (; iter.rem; --screen, xcb_screen_next(&iter))
|
|
||||||
if (screen == 0)
|
|
||||||
return iter.data;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static _EGLSurface *
|
static _EGLSurface *
|
||||||
dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
|
dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
|
||||||
_EGLConfig *conf, void *native_surface,
|
_EGLConfig *conf, void *native_surface,
|
||||||
|
@ -180,8 +170,6 @@ dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
|
||||||
struct dri3_egl_surface *dri3_surf;
|
struct dri3_egl_surface *dri3_surf;
|
||||||
const __DRIconfig *dri_config;
|
const __DRIconfig *dri_config;
|
||||||
xcb_drawable_t drawable;
|
xcb_drawable_t drawable;
|
||||||
xcb_screen_iterator_t s;
|
|
||||||
xcb_screen_t *screen;
|
|
||||||
|
|
||||||
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
|
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
|
||||||
drawable = (uintptr_t) native_surface;
|
drawable = (uintptr_t) native_surface;
|
||||||
|
@ -198,16 +186,9 @@ dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
|
||||||
goto cleanup_surf;
|
goto cleanup_surf;
|
||||||
|
|
||||||
if (type == EGL_PBUFFER_BIT) {
|
if (type == EGL_PBUFFER_BIT) {
|
||||||
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
|
||||||
screen = get_xcb_screen(s, dri2_dpy->screen);
|
|
||||||
if (!screen) {
|
|
||||||
_eglError(EGL_BAD_NATIVE_WINDOW, "dri3_create_surface");
|
|
||||||
goto cleanup_surf;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawable = xcb_generate_id(dri2_dpy->conn);
|
drawable = xcb_generate_id(dri2_dpy->conn);
|
||||||
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize,
|
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize,
|
||||||
drawable, screen->root,
|
drawable, dri2_dpy->screen->root,
|
||||||
dri3_surf->base.Width, dri3_surf->base.Height);
|
dri3_surf->base.Width, dri3_surf->base.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,8 +454,6 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
|
||||||
xcb_present_query_version_reply_t *present_query;
|
xcb_present_query_version_reply_t *present_query;
|
||||||
xcb_present_query_version_cookie_t present_query_cookie;
|
xcb_present_query_version_cookie_t present_query_cookie;
|
||||||
xcb_generic_error_t *error;
|
xcb_generic_error_t *error;
|
||||||
xcb_screen_iterator_t s;
|
|
||||||
xcb_screen_t *screen;
|
|
||||||
const xcb_query_extension_reply_t *extension;
|
const xcb_query_extension_reply_t *extension;
|
||||||
|
|
||||||
xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri3_id);
|
xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri3_id);
|
||||||
|
@ -517,14 +496,7 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
|
||||||
}
|
}
|
||||||
free(present_query);
|
free(present_query);
|
||||||
|
|
||||||
s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn));
|
dri2_dpy->fd = loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0);
|
||||||
screen = get_xcb_screen(s, dri2_dpy->screen);
|
|
||||||
if (!screen) {
|
|
||||||
_eglError(EGL_BAD_NATIVE_WINDOW, "dri3_x11_connect");
|
|
||||||
return EGL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
dri2_dpy->fd = loader_dri3_open(dri2_dpy->conn, screen->root, 0);
|
|
||||||
if (dri2_dpy->fd < 0) {
|
if (dri2_dpy->fd < 0) {
|
||||||
int conn_error = xcb_connection_has_error(dri2_dpy->conn);
|
int conn_error = xcb_connection_has_error(dri2_dpy->conn);
|
||||||
_eglLog(_EGL_WARNING, "DRI3: Screen seems not DRI3 capable");
|
_eglLog(_EGL_WARNING, "DRI3: Screen seems not DRI3 capable");
|
||||||
|
|
Loading…
Reference in New Issue