static struct loader_dri3_buffer *
dri3_find_back_alloc(struct loader_dri3_drawable *draw);
+static xcb_screen_t *
+get_screen_for_root(xcb_connection_t *conn, xcb_window_t root)
+{
+ xcb_screen_iterator_t screen_iter =
+ xcb_setup_roots_iterator(xcb_get_setup(conn));
+
+ for (; screen_iter.rem; xcb_screen_next (&screen_iter)) {
+ if (screen_iter.data->root == root)
+ return screen_iter.data;
+ }
+
+ return NULL;
+}
+
+static xcb_visualtype_t *
+get_xcb_visualtype_for_depth(struct loader_dri3_drawable *draw, int depth)
+{
+ xcb_visualtype_iterator_t visual_iter;
+ xcb_screen_t *screen = draw->screen;
+ xcb_depth_iterator_t depth_iter;
+
+ if (!screen)
+ return NULL;
+
+ 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 drawable at given depth. */
+static unsigned int
+dri3_get_red_mask_for_depth(struct loader_dri3_drawable *draw, int depth)
+{
+ xcb_visualtype_t *visual = get_xcb_visualtype_for_depth(draw, depth);
+
+ if (visual)
+ return visual->red_mask;
+
+ return 0;
+}
+
/**
* Do we have blit functionality in the image blit extension?
*
return 1;
}
+ draw->screen = get_screen_for_root(draw->conn, reply->root);
draw->width = reply->width;
draw->height = reply->height;
draw->depth = reply->depth;
* checking for wrap.
*/
if (ce->kind == XCB_PRESENT_COMPLETE_KIND_PIXMAP) {
- draw->recv_sbc = (draw->send_sbc & 0xffffffff00000000LL) | ce->serial;
- if (draw->recv_sbc > draw->send_sbc)
- draw->recv_sbc -= 0x100000000;
+ uint64_t recv_sbc = (draw->send_sbc & 0xffffffff00000000LL) | ce->serial;
+
+ /* Only assume wraparound if that results in exactly the previous
+ * SBC + 1, otherwise ignore received SBC > sent SBC (those are
+ * probably from a previous loader_dri3_drawable instance) to avoid
+ * calculating bogus target MSC values in loader_dri3_swap_buffers_msc
+ */
+ if (recv_sbc <= draw->send_sbc)
+ draw->recv_sbc = recv_sbc;
+ else if (recv_sbc == (draw->recv_sbc + 0x100000001ULL))
+ draw->recv_sbc = recv_sbc - 0x100000000ULL;
/* When moving from flip to copy, we assume that we can allocate in
* a more optimal way if we don't need to cater for the display
}
}
- /* If the server tells us that our allocation is suboptimal, we
+ /* If the server tells us that our allocation is suboptimal, we
* reallocate once.
*/
#ifdef HAVE_DRI3_MODIFIERS
}
}
+/* Map format of render buffer to corresponding format for the linear_buffer
+ * used for sharing with the display gpu of a Prime setup (== is_different_gpu).
+ * Usually linear_format == format, except for depth >= 30 formats, where
+ * different gpu vendors have different preferences wrt. color channel ordering.
+ */
+static uint32_t
+dri3_linear_format_for_format(struct loader_dri3_drawable *draw, uint32_t format)
+{
+ switch (format) {
+ case __DRI_IMAGE_FORMAT_XRGB2101010:
+ case __DRI_IMAGE_FORMAT_XBGR2101010:
+ /* Different preferred formats for different hw */
+ if (dri3_get_red_mask_for_depth(draw, 30) == 0x3ff)
+ return __DRI_IMAGE_FORMAT_XBGR2101010;
+ else
+ return __DRI_IMAGE_FORMAT_XRGB2101010;
+
+ case __DRI_IMAGE_FORMAT_ARGB2101010:
+ case __DRI_IMAGE_FORMAT_ABGR2101010:
+ /* Different preferred formats for different hw */
+ if (dri3_get_red_mask_for_depth(draw, 30) == 0x3ff)
+ return __DRI_IMAGE_FORMAT_ABGR2101010;
+ else
+ return __DRI_IMAGE_FORMAT_ARGB2101010;
+
+ default:
+ return format;
+ }
+}
+
/* the DRIimage createImage function takes __DRI_IMAGE_FORMAT codes, while
* the createImageFromFds call takes __DRI_IMAGE_FOURCC codes. To avoid
* complete confusion, just deal in __DRI_IMAGE_FORMAT codes for now and
uint32_t count = 0;
mod_cookie = xcb_dri3_get_supported_modifiers(draw->conn,
- draw->drawable,
+ draw->window,
depth, buffer->cpp * 8);
mod_reply = xcb_dri3_get_supported_modifiers_reply(draw->conn,
mod_cookie,
buffer->linear_buffer =
draw->ext->image->createImage(draw->dri_screen,
- width, height, format,
+ width, height,
+ dri3_linear_format_for_format(draw, format),
__DRI_IMAGE_USE_SHARE |
__DRI_IMAGE_USE_LINEAR |
__DRI_IMAGE_USE_BACKBUFFER,
buffer->modifier != DRM_FORMAT_MOD_INVALID) {
xcb_dri3_pixmap_from_buffers(draw->conn,
pixmap,
- draw->drawable,
+ draw->window,
num_planes,
width, height,
buffer->strides[0], buffer->offsets[0],
xcb_generic_error_t *error;
xcb_present_query_capabilities_cookie_t present_capabilities_cookie;
xcb_present_query_capabilities_reply_t *present_capabilities_reply;
+ xcb_window_t root_win;
draw->first_init = false;
mtx_unlock(&draw->mtx);
return false;
}
-
draw->width = geom_reply->width;
draw->height = geom_reply->height;
draw->depth = geom_reply->depth;
draw->vtable->set_drawable_size(draw, draw->width, draw->height);
+ root_win = geom_reply->root;
free(geom_reply);
xcb_unregister_for_special_event(draw->conn, draw->special_event);
draw->special_event = NULL;
}
+
+ if (draw->is_pixmap)
+ draw->window = root_win;
+ else
+ draw->window = draw->drawable;
}
dri3_flush_present_events(draw);
mtx_unlock(&draw->mtx);