+
+ /* Byte sex is a non-issue for 8-bits. It can be worked around with
+ * RGB masks for 24-bits. Too bad for 15-bits and 16-bits. */
+#ifdef WORDS_BIGENDIAN
+# define ORDER XCB_IMAGE_ORDER_MSB_FIRST
+#else
+# define ORDER XCB_IMAGE_ORDER_LSB_FIRST
+#endif
+ if (fmt->bits_per_pixel == 16 && setup->image_byte_order != ORDER)
+ continue;
+
+ /* Check that the selected screen supports this depth */
+ xcb_depth_iterator_t it = xcb_screen_allowed_depths_iterator (scr);
+ while (it.rem > 0 && it.data->depth != fmt->depth)
+ xcb_depth_next (&it);
+ if (!it.rem)
+ continue; /* Depth not supported on this screen */
+
+ /* Find a visual type for the selected depth */
+ const xcb_visualtype_t *vt = xcb_depth_visuals (it.data);
+ xcb_visualid_t vid = 0;
+ for (int i = xcb_depth_visuals_length (it.data); (i > 0) && !vid; i--)
+ {
+ if (vt->_class == XCB_VISUAL_CLASS_TRUE_COLOR)
+ {
+ msg_Dbg (vout,
+ "using TrueColor %"PRIu8"-bits visual ID 0x%0"PRIx32,
+ fmt->depth, vt->visual_id);
+ vid = vt->visual_id;
+ gray = false;
+ break;
+ }
+ if (fmt->depth == 8 && vt->_class == XCB_VISUAL_CLASS_STATIC_GRAY)
+ {
+ if (!gray)
+ continue; /* Prefer color over gray scale */
+ vid = vt->visual_id;
+ chroma = VLC_FOURCC ('G', 'R', 'E', 'Y');
+ msg_Dbg (vout,
+ "using static gray 8-bits visual ID 0x%x"PRIx32,
+ vt->visual_id);
+ break;
+ }
+ }
+
+ if (!vid)
+ continue; /* The screen does not *really* support this depth */
+
+ vout->fmt_out.i_chroma = vout->output.i_chroma = chroma;
+ if (!gray)
+ {
+ vout->output.i_rmask = vt->red_mask;
+ vout->output.i_gmask = vt->green_mask;
+ vout->output.i_bmask = vt->blue_mask;
+ }
+ p_sys->vid = vid;