struct native_display * x11_create_dri2_display(Display *dpy, const struct native_event_handler *event_handler) { struct dri2_display *dri2dpy; dri2dpy = CALLOC_STRUCT(dri2_display); if (!dri2dpy) return NULL; dri2dpy->event_handler = event_handler; dri2dpy->dpy = dpy; if (!dri2dpy->dpy) { dri2dpy->dpy = XOpenDisplay(NULL); if (!dri2dpy->dpy) { dri2_display_destroy(&dri2dpy->base); return NULL; } dri2dpy->own_dpy = TRUE; } dri2dpy->xscr_number = DefaultScreen(dri2dpy->dpy); dri2dpy->xscr = x11_screen_create(dri2dpy->dpy, dri2dpy->xscr_number); if (!dri2dpy->xscr) { dri2_display_destroy(&dri2dpy->base); return NULL; } dri2dpy->surfaces = util_hash_table_create(dri2_display_hash_table_hash, dri2_display_hash_table_compare); if (!dri2dpy->surfaces) { dri2_display_destroy(&dri2dpy->base); return NULL; } dri2dpy->base.init_screen = dri2_display_init_screen; dri2dpy->base.destroy = dri2_display_destroy; dri2dpy->base.get_param = dri2_display_get_param; dri2dpy->base.get_configs = dri2_display_get_configs; dri2dpy->base.get_pixmap_format = dri2_display_get_pixmap_format; dri2dpy->base.copy_to_pixmap = native_display_copy_to_pixmap; dri2dpy->base.create_window_surface = dri2_display_create_window_surface; dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface; #ifdef HAVE_WAYLAND_BACKEND dri2dpy->base.wayland_bufmgr = &dri2_display_wayland_bufmgr; #endif return &dri2dpy->base; }
static EGLBoolean dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp) { _EGLDevice *dev; struct dri2_egl_display *dri2_dpy; dri2_dpy = calloc(1, sizeof *dri2_dpy); if (!dri2_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); dri2_dpy->fd = -1; if (!dri2_get_xcb_connection(drv, disp, dri2_dpy)) goto cleanup; dev = _eglAddDevice(dri2_dpy->fd, true); if (!dev) { _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice"); goto cleanup; } disp->Device = dev; /* * Every hardware driver_name is set using strdup. Doing the same in * here will allow is to simply free the memory at dri2_terminate(). */ dri2_dpy->driver_name = strdup("swrast"); if (!dri2_load_driver_swrast(disp)) goto cleanup; dri2_dpy->loader_extensions = swrast_loader_extensions; if (!dri2_create_screen(disp)) goto cleanup; if (!dri2_setup_extensions(disp)) goto cleanup; dri2_setup_screen(disp); if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, true)) goto cleanup; /* Fill vtbl last to prevent accidentally calling virtual function during * initialization. */ dri2_dpy->vtbl = &dri2_x11_swrast_display_vtbl; return EGL_TRUE; cleanup: dri2_display_destroy(disp); return EGL_FALSE; }
static EGLBoolean dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp) { _EGLDevice *dev; struct dri2_egl_display *dri2_dpy; dri2_dpy = calloc(1, sizeof *dri2_dpy); if (!dri2_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); dri2_dpy->fd = -1; if (!dri2_get_xcb_connection(drv, disp, dri2_dpy)) goto cleanup; if (!dri2_x11_connect(dri2_dpy)) goto cleanup; dev = _eglAddDevice(dri2_dpy->fd, false); if (!dev) { _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice"); goto cleanup; } disp->Device = dev; if (!dri2_load_driver(disp)) goto cleanup; if (dri2_dpy->dri2_minor >= 1) dri2_dpy->loader_extensions = dri2_loader_extensions; else dri2_dpy->loader_extensions = dri2_loader_extensions_old; dri2_dpy->swap_available = (dri2_dpy->dri2_minor >= 2); dri2_dpy->invalidate_available = (dri2_dpy->dri2_minor >= 3); if (!dri2_create_screen(disp)) goto cleanup; if (!dri2_setup_extensions(disp)) goto cleanup; dri2_setup_screen(disp); dri2_x11_setup_swap_interval(disp); disp->Extensions.KHR_image_pixmap = EGL_TRUE; disp->Extensions.NOK_swap_region = EGL_TRUE; disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE; disp->Extensions.NV_post_sub_buffer = EGL_TRUE; disp->Extensions.CHROMIUM_sync_control = EGL_TRUE; dri2_set_WL_bind_wayland_display(drv, disp); if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, true)) goto cleanup; /* Fill vtbl last to prevent accidentally calling virtual function during * initialization. */ dri2_dpy->vtbl = &dri2_x11_display_vtbl; _eglLog(_EGL_INFO, "Using DRI2"); return EGL_TRUE; cleanup: dri2_display_destroy(disp); return EGL_FALSE; }