#endif
#include <sys/types.h>
#include <sys/stat.h>
+#include "util/debug.h"
#include "util/macros.h"
#include "egl_dri2.h"
dri2_x11_swap_interval(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
EGLint interval);
+uint32_t
+dri2_format_for_depth(struct dri2_egl_display *dri2_dpy, uint32_t depth);
+
static void
swrastCreateDrawable(struct dri2_egl_display * dri2_dpy,
struct dri2_egl_surface * dri2_surf)
xcb_create_gc(dri2_dpy->conn, dri2_surf->swapgc, dri2_surf->drawable, mask, valgc);
switch (dri2_surf->depth) {
case 32:
+ case 30:
case 24:
dri2_surf->bytes_per_pixel = 4;
break;
return NULL;
}
+static xcb_visualtype_t *
+get_xcb_visualtype_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
+{
+ xcb_visualtype_iterator_t visual_iter;
+ xcb_screen_t *screen = dri2_dpy->screen;
+ xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(screen);
+
+ for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
+ if (depth_iter.data->depth != depth)
+ continue;
+
+ visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
+ if (visual_iter.rem)
+ return visual_iter.data;
+ }
+
+ return NULL;
+}
+
+/* Get red channel mask for given depth. */
+unsigned int
+dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
+{
+ xcb_visualtype_t *visual = get_xcb_visualtype_for_depth(dri2_dpy, depth);
+
+ if (visual)
+ return visual->red_mask;
+
+ return 0;
+}
/**
* Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
return NULL;
}
- if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, false))
+ if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
+ false, native_surface))
goto cleanup_surf;
dri2_surf->region = XCB_NONE;
config = dri2_get_dri_config(dri2_conf, type,
dri2_surf->base.GLColorspace);
+ if (!config) {
+ _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
+ goto cleanup_pixmap;
+ }
+
if (dri2_dpy->dri2) {
dri2_surf->dri_drawable =
dri2_dpy->dri2->createNewDrawable(dri2_dpy->dri_screen, config,
* have.
*/
static EGLBoolean
-dri2_query_surface(_EGLDriver *drv, _EGLDisplay *dpy,
+dri2_query_surface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLSurface *surf, EGLint attribute,
EGLint *value)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
int x, y, w, h;
default:
break;
}
- return _eglQuerySurface(drv, dpy, surf, attribute, value);
+ return _eglQuerySurface(drv, disp, surf, attribute, value);
}
/**
if (dri2_dpy->driver_name == NULL) {
close(dri2_dpy->fd);
- free(dri2_dpy->driver_name);
free(connect);
return EGL_FALSE;
}
return dri2_x11_do_authenticate(dri2_dpy, id);
}
+static bool
+dri2_x11_config_match_attrib(struct dri2_egl_display *dri2_dpy,
+ const __DRIconfig *config,
+ unsigned int attrib,
+ unsigned int value)
+{
+ uint32_t config_val;
+ if (!dri2_dpy->core->getConfigAttrib(config, attrib, &config_val))
+ return false;
+ return config_val == value;
+}
+
static EGLBoolean
dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
_EGLDisplay *disp, bool supports_preserved)
config_count++;
/* Allow a 24-bit RGB visual to match a 32-bit RGBA EGLConfig.
+ * Ditto for 30-bit RGB visuals to match a 32-bit RGBA EGLConfig.
* Otherwise it will only match a 32-bit RGBA visual. On a
* composited window manager on X11, this will make all of the
* EGLConfigs with destination alpha get blended by the
* compositor. This is probably not what the application
* wants... especially on drivers that only have 32-bit RGBA
* EGLConfigs! */
- if (d.data->depth == 24) {
+ if (d.data->depth == 24 || d.data->depth == 30) {
rgba_masks[3] =
~(rgba_masks[0] | rgba_masks[1] | rgba_masks[2]);
dri2_conf = dri2_add_config(disp, config, config_count + 1,
xcb_depth_next(&d);
}
+ /* Add a 565-no-depth-no-stencil pbuffer-only config. If X11 is depth 24,
+ * we wouldn't have 565 available, which the CTS demands.
+ */
+ for (int j = 0; dri2_dpy->driver_configs[j]; j++) {
+ const __DRIconfig *config = dri2_dpy->driver_configs[j];
+ const EGLint config_attrs[] = {
+ EGL_NATIVE_VISUAL_ID, 0,
+ EGL_NATIVE_VISUAL_TYPE, EGL_NONE,
+ EGL_NONE
+ };
+ EGLint surface_type = EGL_PBUFFER_BIT;
+ unsigned int rgba_masks[4] = {
+ 0x1f << 11,
+ 0x3f << 5,
+ 0x1f << 0,
+ 0,
+ };
+
+ /* Check that we've found single-sample, no depth, no stencil. */
+ if (!dri2_x11_config_match_attrib(dri2_dpy, config,
+ __DRI_ATTRIB_DEPTH_SIZE, 0) ||
+ !dri2_x11_config_match_attrib(dri2_dpy, config,
+ __DRI_ATTRIB_STENCIL_SIZE, 0) ||
+ !dri2_x11_config_match_attrib(dri2_dpy, config,
+ __DRI_ATTRIB_SAMPLES, 0)) {
+ continue;
+ }
+
+ if (dri2_add_config(disp, config, config_count + 1, surface_type,
+ config_attrs, rgba_masks)) {
+ config_count++;
+ break;
+ }
+ }
+
if (!config_count) {
_eglLog(_EGL_WARNING, "DRI2: failed to create any config");
return EGL_FALSE;
xcb_dri2_swap_buffers_reply_t *reply;
int64_t swap_count = -1;
- /* No-op for a pixmap or pbuffer surface */
- if (draw->Type == EGL_PIXMAP_BIT || draw->Type == EGL_PBUFFER_BIT)
- return 0;
-
- if (draw->SwapBehavior == EGL_BUFFER_PRESERVED || !dri2_dpy->swap_available)
- return dri2_copy_region(drv, disp, draw, dri2_surf->region) ? 0 : -1;
-
- dri2_flush_drawable_for_swapbuffers(disp, draw);
+ if (draw->SwapBehavior == EGL_BUFFER_PRESERVED || !dri2_dpy->swap_available) {
+ swap_count = dri2_copy_region(drv, disp, draw, dri2_surf->region) ? 0 : -1;
+ } else {
+ dri2_flush_drawable_for_swapbuffers(disp, draw);
- cookie = xcb_dri2_swap_buffers_unchecked(dri2_dpy->conn, dri2_surf->drawable,
- msc_hi, msc_lo, divisor_hi, divisor_lo, remainder_hi, remainder_lo);
+ cookie = xcb_dri2_swap_buffers_unchecked(dri2_dpy->conn,
+ dri2_surf->drawable, msc_hi,
+ msc_lo, divisor_hi, divisor_lo,
+ remainder_hi, remainder_lo);
- reply = xcb_dri2_swap_buffers_reply(dri2_dpy->conn, cookie, NULL);
+ reply = xcb_dri2_swap_buffers_reply(dri2_dpy->conn, cookie, NULL);
- if (reply) {
- swap_count = (((int64_t)reply->swap_hi) << 32) | reply->swap_lo;
- free(reply);
+ if (reply) {
+ swap_count = combine_u32_into_u64(reply->swap_hi, reply->swap_lo);
+ free(reply);
+ }
}
/* Since we aren't watching for the server's invalidate events like we're
return EGL_TRUE;
}
+uint32_t
+dri2_format_for_depth(struct dri2_egl_display *dri2_dpy, uint32_t depth)
+{
+ switch (depth) {
+ case 16:
+ return __DRI_IMAGE_FORMAT_RGB565;
+ case 24:
+ return __DRI_IMAGE_FORMAT_XRGB8888;
+ case 30:
+ /* Different preferred formats for different hw */
+ if (dri2_x11_get_red_mask_for_depth(dri2_dpy, 30) == 0x3ff)
+ return __DRI_IMAGE_FORMAT_XBGR2101010;
+ else
+ return __DRI_IMAGE_FORMAT_XRGB2101010;
+ case 32:
+ return __DRI_IMAGE_FORMAT_ARGB8888;
+ default:
+ return __DRI_IMAGE_FORMAT_NONE;
+ }
+}
+
static _EGLImage *
dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
EGLClientBuffer buffer, const EGLint *attr_list)
return NULL;
}
- switch (geometry_reply->depth) {
- case 16:
- format = __DRI_IMAGE_FORMAT_RGB565;
- break;
- case 24:
- format = __DRI_IMAGE_FORMAT_XRGB8888;
- break;
- case 32:
- format = __DRI_IMAGE_FORMAT_ARGB8888;
- break;
- default:
+ format = dri2_format_for_depth(dri2_dpy, geometry_reply->depth);
+ if (format == __DRI_IMAGE_FORMAT_NONE) {
_eglError(EGL_BAD_PARAMETER,
"dri2_create_image_khr: unsupported pixmap depth");
free(buffers_reply);
.create_pbuffer_surface = dri2_x11_create_pbuffer_surface,
.destroy_surface = dri2_x11_destroy_surface,
.create_image = dri2_create_image_khr,
- .swap_interval = dri2_fallback_swap_interval,
.swap_buffers = dri2_x11_swap_buffers,
.set_damage_region = dri2_fallback_set_damage_region,
.swap_buffers_region = dri2_fallback_swap_buffers_region,
.post_sub_buffer = dri2_fallback_post_sub_buffer,
- .copy_buffers = dri2_x11_copy_buffers,
+ /* XXX: should really implement this since X11 has pixmaps */
+ .copy_buffers = dri2_fallback_copy_buffers,
.query_buffer_age = dri2_fallback_query_buffer_age,
.query_surface = dri2_query_surface,
.create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image,
NULL,
};
+static int
+dri2_find_screen_for_display(const _EGLDisplay *disp, int fallback_screen)
+{
+ const EGLAttrib *attr;
+
+ for (attr = disp->Options.Attribs; attr; attr += 2) {
+ if (attr[0] == EGL_PLATFORM_X11_SCREEN_EXT)
+ return attr[1];
+ }
+
+ return fallback_screen;
+}
+
static EGLBoolean
dri2_get_xcb_connection(_EGLDriver *drv, _EGLDisplay *disp,
struct dri2_egl_display *dri2_dpy)
{
xcb_screen_iterator_t s;
- int screen = (uintptr_t)disp->Options.Platform;
+ int screen;
const char *msg;
disp->DriverData = (void *) dri2_dpy;
if (disp->PlatformDisplay == NULL) {
dri2_dpy->conn = xcb_connect(NULL, &screen);
dri2_dpy->own_device = true;
+ screen = dri2_find_screen_for_display(disp, screen);
} else {
Display *dpy = disp->PlatformDisplay;
-
dri2_dpy->conn = XGetXCBConnection(dpy);
screen = DefaultScreen(dpy);
}
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_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->min_swap_interval = 0;
dri2_dpy->max_swap_interval = 0;
+ dri2_dpy->default_swap_interval = 0;
if (!dri2_dpy->swap_available)
return;
&dri3_image_loader_extension.base,
&image_lookup_extension.base,
&use_invalidate.base,
+ &background_callable_extension.base,
NULL,
};
static EGLBoolean
dri2_initialize_x11_dri3(_EGLDriver *drv, _EGLDisplay *disp)
{
+ _EGLDevice *dev;
struct dri2_egl_display *dri2_dpy;
dri2_dpy = calloc(1, sizeof *dri2_dpy);
if (!dri3_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_dri3(disp))
goto cleanup;
static const __DRIextension *dri2_loader_extensions[] = {
&dri2_loader_extension.base,
&image_lookup_extension.base,
+ &use_invalidate.base,
&background_callable_extension.base,
NULL,
};
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_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;
{
EGLBoolean initialized = EGL_FALSE;
- if (!getenv("LIBGL_ALWAYS_SOFTWARE")) {
+ if (!disp->Options.ForceSoftware) {
#ifdef HAVE_DRI3
- if (!getenv("LIBGL_DRI3_DISABLE"))
+ if (!env_var_as_boolean("LIBGL_DRI3_DISABLE", false))
initialized = dri2_initialize_x11_dri3(drv, disp);
#endif
return initialized;
}
+void
+dri2_teardown_x11(struct dri2_egl_display *dri2_dpy)
+{
+ if (dri2_dpy->own_device)
+ xcb_disconnect(dri2_dpy->conn);
+}