xcb_dri2_get_buffers_reply_t *reply;
xcb_dri2_dri2_buffer_t *buffers, *back_left;
+ unsigned depth = ((xcb_screen_t *)(vscreen->xcb_screen))->root_depth;
unsigned i;
assert(scrn);
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_TEXTURE_2D;
- templ.format = PIPE_FORMAT_B8G8R8X8_UNORM;
+ templ.format = vl_dri2_format_for_depth(vscreen, depth);
templ.last_level = 0;
templ.width0 = reply->width;
templ.height0 = reply->height;
return NULL;
}
+static xcb_visualtype_t *
+get_xcb_visualtype_for_depth(struct vl_screen *vscreen, int depth)
+{
+ xcb_visualtype_iterator_t visual_iter;
+ xcb_screen_t *screen = vscreen->xcb_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;
+}
+
+static uint32_t
+get_red_mask_for_depth(struct vl_screen *vscreen, int depth)
+{
+ xcb_visualtype_t *visual = get_xcb_visualtype_for_depth(vscreen, depth);
+
+ if (visual) {
+ return visual->red_mask;
+ }
+
+ return 0;
+}
+
+uint32_t
+vl_dri2_format_for_depth(struct vl_screen *vscreen, int depth)
+{
+ switch (depth) {
+ case 24:
+ return PIPE_FORMAT_B8G8R8X8_UNORM;
+ case 30:
+ /* Different preferred formats for different hw */
+ if (get_red_mask_for_depth(vscreen, 30) == 0x3ff)
+ return PIPE_FORMAT_R10G10B10X2_UNORM;
+ else
+ return PIPE_FORMAT_B10G10R10X2_UNORM;
+ default:
+ return PIPE_FORMAT_NONE;
+ }
+}
+
struct vl_screen *
vl_dri2_screen_create(Display *display, int screen)
{
xcb_dri2_authenticate_cookie_t authenticate_cookie;
xcb_dri2_authenticate_reply_t *authenticate = NULL;
xcb_screen_iterator_t s;
- xcb_screen_t *xcb_screen;
xcb_generic_error_t *error = NULL;
char *device_name;
int fd, device_name_length;
goto free_query;
s = xcb_setup_roots_iterator(xcb_get_setup(scrn->conn));
- xcb_screen = get_xcb_screen(s, screen);
- if (!xcb_screen)
+ scrn->base.xcb_screen = get_xcb_screen(s, screen);
+ if (!scrn->base.xcb_screen)
goto free_query;
driverType = XCB_DRI2_DRIVER_TYPE_DRI;
}
}
- connect_cookie = xcb_dri2_connect_unchecked(scrn->conn,
- xcb_screen->root,
- driverType);
+ connect_cookie = xcb_dri2_connect_unchecked(
+ scrn->conn, ((xcb_screen_t *)(scrn->base.xcb_screen))->root, driverType);
connect = xcb_dri2_connect_reply(scrn->conn, connect_cookie, NULL);
if (connect == NULL ||
connect->driver_name_length + connect->device_name_length == 0)
if (drmGetMagic(fd, &magic))
goto close_fd;
- authenticate_cookie = xcb_dri2_authenticate_unchecked(scrn->conn,
- xcb_screen->root,
- magic);
+ authenticate_cookie = xcb_dri2_authenticate_unchecked(
+ scrn->conn, ((xcb_screen_t *)(scrn->base.xcb_screen))->root, magic);
authenticate = xcb_dri2_authenticate_reply(scrn->conn, authenticate_cookie, NULL);
if (authenticate == NULL || !authenticate->authenticated)