#include "xcb_vlc.h"
-#define DISPLAY_TEXT N_("X11 display")
-#define DISPLAY_LONGTEXT N_( \
- "X11 hardware display to use. By default VLC will " \
- "use the value of the DISPLAY environment variable.")
-
#define SHM_TEXT N_("Use shared memory")
#define SHM_LONGTEXT N_( \
"Use shared memory to communicate between VLC and the X server.")
set_subcategory (SUBCAT_VIDEO_VOUT)
set_capability ("vout display", 75)
set_callbacks (Open, Close)
+ add_shortcut ("xcb-x11", "x11", "xid")
- add_string ("x11-display", NULL, NULL,
- DISPLAY_TEXT, DISPLAY_LONGTEXT, true)
add_bool ("x11-shm", true, NULL, SHM_TEXT, SHM_LONGTEXT, true)
vlc_module_end ()
picture_resource_t resource[MAX_PICTURES];
};
-static picture_t *Get (vout_display_t *);
+static picture_pool_t *Pool (vout_display_t *, unsigned);
static void Display (vout_display_t *, picture_t *);
static int Control (vout_display_t *, int, va_list);
static void Manage (vout_display_t *);
static void ResetPictures (vout_display_t *);
+static const xcb_depth_t *FindDepth (const xcb_screen_t *scr,
+ uint_fast8_t depth)
+{
+ xcb_depth_t *d = NULL;
+ for (xcb_depth_iterator_t it = xcb_screen_allowed_depths_iterator (scr);
+ it.rem > 0 && d == NULL;
+ xcb_depth_next (&it))
+ {
+ if (it.data->depth == depth)
+ d = it.data;
+ }
+
+ return d;
+}
+
+
/**
* Probe the X server.
*/
vd->sys = p_sys;
p_sys->pool = NULL;
- /* Connect to X */
- p_sys->conn = Connect (obj);
- if (p_sys->conn == NULL)
- {
- free (p_sys);
- return VLC_EGENERIC;
- }
-
- /* Get window */
+ /* Get window, connect to X server */
const xcb_screen_t *scr;
- p_sys->embed = GetWindow (vd, p_sys->conn, &scr, &p_sys->shm);
+ p_sys->embed = GetWindow (vd, &p_sys->conn, &scr, &(uint8_t){ 0 });
if (p_sys->embed == NULL)
{
- xcb_disconnect (p_sys->conn);
free (p_sys);
return VLC_EGENERIC;
}
const xcb_setup_t *setup = xcb_get_setup (p_sys->conn);
p_sys->byte_order = setup->image_byte_order;
- /* */
- video_format_t fmt_pic = vd->fmt;
-
- /* Determine our video format. */
+ /* Determine our pixel format */
xcb_visualid_t vid = 0;
- uint8_t depth = 0;
- bool gray = true;
+ p_sys->depth = 0;
+
for (const xcb_format_t *fmt = xcb_setup_pixmap_formats (setup),
*end = fmt + xcb_setup_pixmap_formats_length (setup);
- fmt < end; fmt++)
+ fmt < end;
+ fmt++)
{
- vlc_fourcc_t chroma = 0;
+ if (fmt->depth <= p_sys->depth)
+ continue; /* no better than earlier format */
- if (fmt->depth < depth)
- continue; /* We already found a better format! */
+ video_format_t fmt_pic = vd->fmt;
/* Check that the pixmap format is supported by VLC. */
switch (fmt->depth)
{
+ case 32:
+ if (fmt->bits_per_pixel != 32)
+ continue;
+#ifdef FIXED_VLC_RGBA_MASK
+ fmt_pic.i_chroma = VLC_CODEC_RGBA;
+ break;
+#else
+ msg_Dbg (vd, "X11 visual with alpha-channel not supported");
+ continue;
+#endif
case 24:
if (fmt->bits_per_pixel == 32)
- chroma = VLC_CODEC_RGB32;
+ fmt_pic.i_chroma = VLC_CODEC_RGB32;
else if (fmt->bits_per_pixel == 24)
- chroma = VLC_CODEC_RGB24;
+ fmt_pic.i_chroma = VLC_CODEC_RGB24;
else
continue;
break;
case 16:
if (fmt->bits_per_pixel != 16)
continue;
- chroma = VLC_CODEC_RGB16;
+ fmt_pic.i_chroma = VLC_CODEC_RGB16;
break;
case 15:
if (fmt->bits_per_pixel != 16)
continue;
- chroma = VLC_CODEC_RGB15;
+ fmt_pic.i_chroma = VLC_CODEC_RGB15;
break;
case 8:
if (fmt->bits_per_pixel != 8)
continue;
- chroma = VLC_CODEC_RGB8;
+ fmt_pic.i_chroma = VLC_CODEC_RGB8;
break;
default:
continue;
}
+
+ /* VLC pads lines to 16 pixels internally */
if ((fmt->bits_per_pixel << 4) % fmt->scanline_pad)
- continue; /* VLC pads lines to 16 pixels internally */
+ continue;
/* 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. */
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 */
+ const xcb_depth_t *d = FindDepth (scr, fmt->depth);
+ if (d == NULL)
+ continue;
/* Find a visual type for the selected depth */
- const xcb_visualtype_t *vt = xcb_depth_visuals (it.data);
- for (int i = xcb_depth_visuals_length (it.data); i > 0; i--)
+ const xcb_visualtype_t *vt = xcb_depth_visuals (d);
+
+ /* First try True Color class */
+ for (int i = xcb_depth_visuals_length (d); i > 0; i--)
{
if (vt->_class == XCB_VISUAL_CLASS_TRUE_COLOR)
{
- gray = false;
- goto found_vt;
+ fmt_pic.i_rmask = vt->red_mask;
+ fmt_pic.i_gmask = vt->green_mask;
+ fmt_pic.i_bmask = vt->blue_mask;
+ goto found_visual;
}
- if (fmt->depth == 8 && vt->_class == XCB_VISUAL_CLASS_STATIC_GRAY)
+ vt++;
+ }
+ /* Then try Static Gray class */
+ if (fmt->depth == 8)
+ for (int i = xcb_depth_visuals_length (d); i > 0 && !vid; i--)
{
- if (!gray)
- continue; /* Prefer color over gray scale */
- chroma = VLC_CODEC_GREY;
- goto found_vt;
+ if (vt->_class == XCB_VISUAL_CLASS_STATIC_GRAY)
+ goto found_grey;
+ vt++;
}
- }
- continue; /* The screen does not *really* support this depth */
- found_vt:
- fmt_pic.i_chroma = chroma;
- vid = vt->visual_id;
- if (!gray)
- {
- fmt_pic.i_rmask = vt->red_mask;
- fmt_pic.i_gmask = vt->green_mask;
- fmt_pic.i_bmask = vt->blue_mask;
- }
+ continue; /* Fail: unusable pixel format */
+
+ found_grey:
+ fmt_pic.i_chroma = VLC_CODEC_GREY;
+ found_visual:
p_sys->bpp = fmt->bits_per_pixel;
p_sys->pad = fmt->scanline_pad;
- p_sys->depth = depth = fmt->depth;
+ p_sys->depth = fmt->depth;
+ vd->fmt = fmt_pic;
+ vid = vt->visual_id;
}
- if (depth == 0)
+ if (!vid)
{
- msg_Err (vd, "no supported pixmap formats or visual types");
+ msg_Err (obj, "no supported pixel format & visual");
goto error;
}
- msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32" (depth: %"PRIu8")", vid,
- p_sys->depth);
- msg_Dbg (vd, " %"PRIu8" bits per pixels, %"PRIu8" bits line pad",
- p_sys->bpp, p_sys->pad);
+ msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32, vid);
+ msg_Dbg (vd, " %"PRIu8" bits depth", p_sys->depth);
+ msg_Dbg (vd, " %"PRIu8" bits per pixel", p_sys->bpp);
+ msg_Dbg (vd, " %"PRIu8" bits line pad", p_sys->pad);
/* Create colormap (needed to select non-default visual) */
xcb_colormap_t cmap;
p_sys->window = xcb_generate_id (p_sys->conn);
p_sys->gc = xcb_generate_id (p_sys->conn);
+ xcb_pixmap_t pixmap = xcb_generate_id (p_sys->conn);
{
- const uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
+ const uint32_t mask =
+ XCB_CW_BACK_PIXMAP |
+ XCB_CW_BACK_PIXEL |
+ XCB_CW_BORDER_PIXMAP |
+ XCB_CW_BORDER_PIXEL |
+ XCB_CW_EVENT_MASK |
+ XCB_CW_COLORMAP;
const uint32_t values[] = {
+ /* XCB_CW_BACK_PIXMAP */
+ pixmap,
+ /* XCB_CW_BACK_PIXEL */
+ scr->black_pixel,
+ /* XCB_CW_BORDER_PIXMAP */
+ pixmap,
+ /* XCB_CW_BORDER_PIXEL */
+ scr->black_pixel,
/* XCB_CW_EVENT_MASK */
XCB_EVENT_MASK_VISIBILITY_CHANGE,
/* XCB_CW_COLORMAP */
};
xcb_void_cookie_t c;
- c = xcb_create_window_checked (p_sys->conn, depth, p_sys->window,
+ xcb_create_pixmap (p_sys->conn, p_sys->depth, pixmap, scr->root, 1, 1);
+ c = xcb_create_window_checked (p_sys->conn, p_sys->depth,
+ p_sys->window,
p_sys->embed->handle.xid, 0, 0,
width, height, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
p_sys->visible = false;
+ CheckSHM (obj, p_sys->conn, &p_sys->shm);
+
/* */
vout_display_info_t info = vd->info;
info.has_pictures_invalid = true;
+ info.has_event_thread = true;
/* Setup vout_display_t once everything is fine */
- vd->fmt = fmt_pic;
vd->info = info;
- vd->get = Get;
+ vd->pool = Pool;
vd->prepare = NULL;
vd->display = Display;
vd->control = Control;
vd->manage = Manage;
/* */
- vout_display_SendEventFullscreen (vd, false);
- vout_display_SendEventDisplaySize (vd, width, height, false);
+ bool is_fullscreen = vd->cfg->is_fullscreen;
+ if (is_fullscreen && vout_window_SetFullScreen (p_sys->embed, true))
+ is_fullscreen = false;
+ vout_display_SendEventFullscreen (vd, is_fullscreen);
+ vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen);
return VLC_SUCCESS;
vout_display_sys_t *p_sys = vd->sys;
ResetPictures (vd);
- vout_display_DeleteWindow (vd, p_sys->embed);
+
+ /* show the default cursor */
+ xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid, XCB_CW_CURSOR,
+ &(uint32_t) { XCB_CURSOR_NONE });
+ xcb_flush (p_sys->conn);
+
/* colormap, window and context are garbage-collected by X */
xcb_disconnect (p_sys->conn);
+ vout_display_DeleteWindow (vd, p_sys->embed);
free (p_sys);
}
/**
* Return a direct buffer
*/
-static picture_t *Get (vout_display_t *vd)
+static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
{
vout_display_sys_t *p_sys = vd->sys;
+ (void)requested_count;
if (!p_sys->pool)
{
return NULL;
p_sys->pool = picture_pool_New (count, pic_array);
- if (!p_sys->pool)
- {
- /* TODO release picture resources */
- return NULL;
- }
- /* FIXME should also do it in case of error ? */
+ /* TODO release picture resources if NULL */
xcb_flush (p_sys->conn);
}
- return picture_pool_Get (p_sys->pool);
+ return p_sys->pool;
}
/**
if (!p_sys->visible)
goto out;
+ xcb_force_screen_saver (p_sys->conn, XCB_SCREEN_SAVER_RESET);
+
if (segment != 0)
ck = xcb_shm_put_image_checked (p_sys->conn, p_sys->window, p_sys->gc,
/* real width */ pic->p->i_pitch / pic->p->i_pixel_pitch,
values);
return VLC_SUCCESS;
}
- case VOUT_DISPLAY_CHANGE_ON_TOP:
+ case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
{
- int b_on_top = (int)va_arg (ap, int);
- return vout_window_SetOnTop (p_sys->embed, b_on_top);
+ unsigned state = va_arg (ap, unsigned);
+ return vout_window_SetState (p_sys->embed, state);
}
case VOUT_DISPLAY_CHANGE_ZOOM: