#endif
#include <sys/types.h>
#include <sys/stat.h>
+#include "util/debug.h"
#include "util/macros.h"
#include "egl_dri2.h"
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;
xcb_free_gc(dri2_dpy->conn, dri2_surf->swapgc);
}
-static void
-swrastGetDrawableInfo(__DRIdrawable * draw,
+static bool
+x11_get_drawable_info(__DRIdrawable * draw,
int *x, int *y, int *w, int *h,
void *loaderPrivate)
{
xcb_get_geometry_cookie_t cookie;
xcb_get_geometry_reply_t *reply;
xcb_generic_error_t *error;
+ bool ret;
- *w = *h = 0;
cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable);
reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error);
if (reply == NULL)
- return;
+ return false;
if (error != NULL) {
+ ret = false;
_eglLog(_EGL_WARNING, "error in xcb_get_geometry");
free(error);
} else {
+ *x = reply->x;
+ *y = reply->y;
*w = reply->width;
*h = reply->height;
+ ret = true;
}
free(reply);
+ return ret;
+}
+
+static void
+swrastGetDrawableInfo(__DRIdrawable * draw,
+ int *x, int *y, int *w, int *h,
+ void *loaderPrivate)
+{
+ *x = *y = *w = *h = 0;
+ x11_get_drawable_info(draw, x, y, w, h, loaderPrivate);
}
static void
xcb_get_geometry_cookie_t cookie;
xcb_get_geometry_reply_t *reply;
xcb_generic_error_t *error;
- xcb_drawable_t drawable;
const __DRIconfig *config;
- STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
- drawable = (uintptr_t) native_surface;
-
(void) drv;
dri2_surf = malloc(sizeof *dri2_surf);
return NULL;
}
- if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list))
+ if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, false))
goto cleanup_surf;
dri2_surf->region = XCB_NONE;
dri2_surf->drawable, dri2_dpy->screen->root,
dri2_surf->base.Width, dri2_surf->base.Height);
} else {
- if (!drawable) {
- if (type == EGL_WINDOW_BIT)
- _eglError(EGL_BAD_NATIVE_WINDOW, "dri2_create_surface");
- else
- _eglError(EGL_BAD_NATIVE_PIXMAP, "dri2_create_surface");
- goto cleanup_surf;
- }
- dri2_surf->drawable = drawable;
+ STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
+ dri2_surf->drawable = (uintptr_t) native_surface;
}
config = dri2_get_dri_config(dri2_conf, type,
_EGLConfig *conf, const EGLint *attrib_list)
{
return dri2_x11_create_surface(drv, disp, EGL_PBUFFER_BIT, conf,
- XCB_WINDOW_NONE, attrib_list);
+ NULL, attrib_list);
}
static EGLBoolean
if (surf->Type == EGL_PBUFFER_BIT)
xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable);
+ dri2_fini_surface(surf);
free(surf);
return EGL_TRUE;
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
- int x, y, w = -1, h = -1;
+ int x, y, w, h;
__DRIdrawable *drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
switch (attribute) {
case EGL_WIDTH:
case EGL_HEIGHT:
- swrastGetDrawableInfo(drawable, &x, &y, &w, &h, dri2_surf);
- if (w != -1 && h != -1) {
+ if (x11_get_drawable_info(drawable, &x, &y, &w, &h, dri2_surf)) {
surf->Width = w;
surf->Height = h;
}
struct dri2_egl_display *dri2_dpy =
dri2_egl_display(dri2_surf->base.Resource.Display);
xcb_rectangle_t rectangle;
- unsigned i;
- dri2_surf->buffer_count = count;
- dri2_surf->have_fake_front = 0;
+ dri2_surf->have_fake_front = false;
/* This assumes the DRI2 buffer attachment tokens matches the
* __DRIbuffer tokens. */
- for (i = 0; i < count; i++) {
+ for (unsigned i = 0; i < count; i++) {
dri2_surf->buffers[i].attachment = buffers[i].attachment;
dri2_surf->buffers[i].name = buffers[i].name;
dri2_surf->buffers[i].pitch = buffers[i].pitch;
* Note that EGL doesn't require that several clients rendering
* to the same window must see the same aux buffers. */
if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
- dri2_surf->have_fake_front = 1;
+ dri2_surf->have_fake_front = true;
}
if (dri2_surf->region != XCB_NONE)
error != NULL || xfixes_query->major_version < 2) {
_eglLog(_EGL_WARNING, "DRI2: failed to query xfixes version");
free(error);
+ free(xfixes_query);
return EGL_FALSE;
}
free(xfixes_query);
if (dri2_dpy->driver_name == NULL) {
close(dri2_dpy->fd);
- free(dri2_dpy->driver_name);
free(connect);
return EGL_FALSE;
}
{
xcb_depth_iterator_t d;
xcb_visualtype_t *visuals;
- int i, j, count;
- unsigned int rgba_masks[4];
+ int config_count = 0;
EGLint surface_type;
- EGLint config_attrs[] = {
- EGL_NATIVE_VISUAL_ID, 0,
- EGL_NATIVE_VISUAL_TYPE, 0,
- EGL_NONE
- };
d = xcb_screen_allowed_depths_iterator(dri2_dpy->screen);
- count = 0;
surface_type =
EGL_WINDOW_BIT |
EGLBoolean class_added[6] = { 0, };
visuals = xcb_depth_visuals(d.data);
- for (i = 0; i < xcb_depth_visuals_length(d.data); i++) {
+
+ for (int i = 0; i < xcb_depth_visuals_length(d.data); i++) {
if (class_added[visuals[i]._class])
continue;
class_added[visuals[i]._class] = EGL_TRUE;
- for (j = 0; dri2_dpy->driver_configs[j]; j++) {
+
+ for (int j = 0; dri2_dpy->driver_configs[j]; j++) {
struct dri2_egl_config *dri2_conf;
const __DRIconfig *config = dri2_dpy->driver_configs[j];
- config_attrs[1] = visuals[i].visual_id;
- config_attrs[3] = visuals[i]._class;
-
- rgba_masks[0] = visuals[i].red_mask;
- rgba_masks[1] = visuals[i].green_mask;
- rgba_masks[2] = visuals[i].blue_mask;
- rgba_masks[3] = 0;
- dri2_conf = dri2_add_config(disp, config, count + 1, surface_type,
- config_attrs, rgba_masks);
+ const EGLint config_attrs[] = {
+ EGL_NATIVE_VISUAL_ID, visuals[i].visual_id,
+ EGL_NATIVE_VISUAL_TYPE, visuals[i]._class,
+ EGL_NONE
+ };
+
+ unsigned int rgba_masks[4] = {
+ visuals[i].red_mask,
+ visuals[i].green_mask,
+ visuals[i].blue_mask,
+ 0,
+ };
+
+ dri2_conf = dri2_add_config(disp, config, config_count + 1,
+ surface_type, config_attrs,
+ rgba_masks);
if (dri2_conf)
- count++;
+ if (dri2_conf->base.ConfigID == config_count + 1)
+ 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, count + 1, surface_type,
- config_attrs, rgba_masks);
+ dri2_conf = dri2_add_config(disp, config, config_count + 1,
+ surface_type, config_attrs,
+ rgba_masks);
if (dri2_conf)
- count++;
+ if (dri2_conf->base.ConfigID == config_count + 1)
+ config_count++;
}
}
}
xcb_depth_next(&d);
}
- if (!count) {
+ if (!config_count) {
_eglLog(_EGL_WARNING, "DRI2: failed to create any config");
return EGL_FALSE;
}
if (draw->Type == EGL_PIXMAP_BIT || draw->Type == EGL_PBUFFER_BIT)
return EGL_TRUE;
- if (dri2_dpy->flush)
- dri2_dpy->flush->flush(dri2_surf->dri_drawable);
+ dri2_dpy->flush->flush(dri2_surf->dri_drawable);
if (dri2_surf->have_fake_front)
render_attachment = XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT;
* happened. The driver should still be using the viewport hack to catch
* window resizes.
*/
- if (dri2_dpy->flush &&
- dri2_dpy->flush->base.version >= 3 && dri2_dpy->flush->invalidate)
+ if (dri2_dpy->flush->base.version >= 3 && dri2_dpy->flush->invalidate)
dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);
return swap_count;
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
- if (dri2_dpy->dri2) {
- if (dri2_x11_swap_buffers_msc(drv, disp, draw, 0, 0, 0) != -1) {
- return EGL_TRUE;
- }
- /* Swap failed with a window drawable. */
- _eglError(EGL_BAD_NATIVE_WINDOW, __func__);
- return EGL_FALSE;
- } else {
- assert(dri2_dpy->swrast);
-
+ if (!dri2_dpy->flush) {
dri2_dpy->core->swapBuffers(dri2_surf->dri_drawable);
return EGL_TRUE;
}
+
+ if (dri2_x11_swap_buffers_msc(drv, disp, draw, 0, 0, 0) == -1) {
+ /* Swap failed with a window drawable. */
+ return _eglError(EGL_BAD_NATIVE_WINDOW, __func__);
+ }
+ return EGL_TRUE;
}
static EGLBoolean
EGLBoolean ret;
xcb_xfixes_region_t region;
xcb_rectangle_t rectangles[16];
- int i;
if (numRects > (int)ARRAY_SIZE(rectangles))
return dri2_copy_region(drv, disp, draw, dri2_surf->region);
- for (i = 0; i < numRects; i++) {
+ for (int i = 0; i < numRects; i++) {
rectangles[i].x = rects[i * 4];
rectangles[i].y = dri2_surf->base.Height - rects[i * 4 + 1] - rects[i * 4 + 3];
rectangles[i].width = rects[i * 4 + 2];
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
- if (interval > surf->Config->MaxSwapInterval)
- interval = surf->Config->MaxSwapInterval;
- else if (interval < surf->Config->MinSwapInterval)
- interval = surf->Config->MinSwapInterval;
-
- if (interval != surf->SwapInterval && dri2_dpy->swap_available)
+ if (dri2_dpy->swap_available)
xcb_dri2_swap_interval(dri2_dpy->conn, dri2_surf->drawable, interval);
- surf->SwapInterval = interval;
-
return EGL_TRUE;
}
case 24:
format = __DRI_IMAGE_FORMAT_XRGB8888;
break;
+ case 30:
+ format = __DRI_IMAGE_FORMAT_XRGB2101010;
+ break;
case 32:
format = __DRI_IMAGE_FORMAT_ARGB8888;
break;
return EGL_NO_IMAGE_KHR;
}
- if (!_eglInitImage(&dri2_img->base, disp)) {
- free(buffers_reply);
- free(geometry_reply);
- free(dri2_img);
- return EGL_NO_IMAGE_KHR;
- }
+ _eglInitImage(&dri2_img->base, disp);
stride = buffers[0].pitch / buffers[0].cpp;
dri2_img->dri_image =
cookie = xcb_dri2_get_msc(dri2_dpy->conn, dri2_surf->drawable);
reply = xcb_dri2_get_msc_reply(dri2_dpy->conn, cookie, NULL);
- if (!reply) {
- _eglError(EGL_BAD_ACCESS, __func__);
- return EGL_FALSE;
- }
+ if (!reply)
+ return _eglError(EGL_BAD_ACCESS, __func__);
*ust = ((EGLuint64KHR) reply->ust_hi << 32) | reply->ust_lo;
*msc = ((EGLuint64KHR) reply->msc_hi << 32) | reply->msc_lo;
return EGL_TRUE;
}
-static struct dri2_egl_display_vtbl dri2_x11_swrast_display_vtbl = {
+static const struct dri2_egl_display_vtbl dri2_x11_swrast_display_vtbl = {
.authenticate = NULL,
.create_window_surface = dri2_x11_create_window_surface,
.create_pixmap_surface = dri2_x11_create_pixmap_surface,
.create_pbuffer_surface = dri2_x11_create_pbuffer_surface,
.destroy_surface = dri2_x11_destroy_surface,
- .create_image = dri2_fallback_create_image_khr,
- .swap_interval = dri2_fallback_swap_interval,
+ .create_image = dri2_create_image_khr,
.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,
.get_dri_drawable = dri2_surface_get_dri_drawable,
};
-static struct dri2_egl_display_vtbl dri2_x11_display_vtbl = {
+static const struct dri2_egl_display_vtbl dri2_x11_display_vtbl = {
.authenticate = dri2_x11_authenticate,
.create_window_surface = dri2_x11_create_window_surface,
.create_pixmap_surface = dri2_x11_create_pixmap_surface,
.swap_buffers = dri2_x11_swap_buffers,
.swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage,
.swap_buffers_region = dri2_x11_swap_buffers_region,
+ .set_damage_region = dri2_fallback_set_damage_region,
.post_sub_buffer = dri2_x11_post_sub_buffer,
.copy_buffers = dri2_x11_copy_buffers,
.query_buffer_age = dri2_fallback_query_buffer_age,
static const __DRIextension *swrast_loader_extensions[] = {
&swrast_loader_extension.base,
+ &image_lookup_extension.base,
NULL,
};
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;
}
static void
-dri2_x11_setup_swap_interval(struct dri2_egl_display *dri2_dpy)
+dri2_x11_setup_swap_interval(_EGLDisplay *disp)
{
- GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
int arbitrary_max_interval = 1000;
/* default behavior for no SwapBuffers support: no vblank syncing
*/
dri2_dpy->min_swap_interval = 0;
dri2_dpy->max_swap_interval = 0;
+ dri2_dpy->default_swap_interval = 0;
if (!dri2_dpy->swap_available)
return;
/* If we do have swapbuffers, then we can support pretty much any swap
- * interval, but we allow driconf to override applications.
+ * interval.
*/
- if (dri2_dpy->config)
- dri2_dpy->config->configQueryi(dri2_dpy->dri_screen,
- "vblank_mode", &vblank_mode);
- switch (vblank_mode) {
- case DRI_CONF_VBLANK_NEVER:
- dri2_dpy->min_swap_interval = 0;
- dri2_dpy->max_swap_interval = 0;
- dri2_dpy->default_swap_interval = 0;
- break;
- case DRI_CONF_VBLANK_ALWAYS_SYNC:
- dri2_dpy->min_swap_interval = 1;
- dri2_dpy->max_swap_interval = arbitrary_max_interval;
- dri2_dpy->default_swap_interval = 1;
- break;
- case DRI_CONF_VBLANK_DEF_INTERVAL_0:
- dri2_dpy->min_swap_interval = 0;
- dri2_dpy->max_swap_interval = arbitrary_max_interval;
- dri2_dpy->default_swap_interval = 0;
- break;
- default:
- case DRI_CONF_VBLANK_DEF_INTERVAL_1:
- dri2_dpy->min_swap_interval = 0;
- dri2_dpy->max_swap_interval = arbitrary_max_interval;
- dri2_dpy->default_swap_interval = 1;
- break;
- }
+ dri2_setup_swap_interval(disp, arbitrary_max_interval);
}
#ifdef HAVE_DRI3
&dri3_image_loader_extension.base,
&image_lookup_extension.base,
&use_invalidate.base,
+ &background_callable_extension.base,
NULL,
};
if (!dri2_create_screen(disp))
goto cleanup;
- dri2_x11_setup_swap_interval(dri2_dpy);
+ if (!dri2_setup_extensions(disp))
+ goto cleanup;
+
+ dri2_setup_screen(disp);
+
+ dri2_x11_setup_swap_interval(disp);
if (!dri2_dpy->is_different_gpu)
disp->Extensions.KHR_image_pixmap = EGL_TRUE;
static const __DRIextension *dri2_loader_extensions[] = {
&dri2_loader_extension.base,
&image_lookup_extension.base,
+ &use_invalidate.base,
&background_callable_extension.base,
NULL,
};
if (!dri2_create_screen(disp))
goto cleanup;
- dri2_x11_setup_swap_interval(dri2_dpy);
+ 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;
{
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);
+}