Commit 3c34f3b4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

XCB/X11: cosmetic changes

parent eed1ae9d
...@@ -55,16 +55,15 @@ vlc_module_begin () ...@@ -55,16 +55,15 @@ vlc_module_begin ()
add_obsolete_bool ("x11-shm") /* obsoleted since 1.2.0 */ add_obsolete_bool ("x11-shm") /* obsoleted since 1.2.0 */
vlc_module_end () vlc_module_end ()
/* It must be large enough to absorb the server display jitter but it is /* This must be large enough to absorb the server display jitter.
* useless to used a too large value, direct rendering cannot be used with * But excessively large value is useless as direct rendering cannot be used
* xcb x11 * with XCB X11. */
*/
#define MAX_PICTURES (3) #define MAX_PICTURES (3)
struct vout_display_sys_t struct vout_display_sys_t
{ {
xcb_connection_t *conn; xcb_connection_t *conn;
vout_window_t *embed; /* VLC window (when windowed) */ vout_window_t *embed; /* VLC window */
xcb_cursor_t cursor; /* blank cursor */ xcb_cursor_t cursor; /* blank cursor */
xcb_window_t window; /* drawable X window */ xcb_window_t window; /* drawable X window */
...@@ -106,34 +105,36 @@ static const xcb_depth_t *FindDepth (const xcb_screen_t *scr, ...@@ -106,34 +105,36 @@ static const xcb_depth_t *FindDepth (const xcb_screen_t *scr,
static int Open (vlc_object_t *obj) static int Open (vlc_object_t *obj)
{ {
vout_display_t *vd = (vout_display_t *)obj; vout_display_t *vd = (vout_display_t *)obj;
vout_display_sys_t *p_sys = malloc (sizeof (*p_sys)); vout_display_sys_t *sys = malloc (sizeof (*sys));
if (p_sys == NULL) if (unlikely(sys == NULL))
return VLC_ENOMEM; return VLC_ENOMEM;
vd->sys = p_sys; vd->sys = sys;
p_sys->pool = NULL; sys->pool = NULL;
/* Get window, connect to X server */ /* Get window, connect to X server */
xcb_connection_t *conn;
const xcb_screen_t *scr; const xcb_screen_t *scr;
p_sys->embed = GetWindow (vd, &p_sys->conn, &scr, &(uint8_t){ 0 }); sys->embed = GetWindow (vd, &conn, &scr, &(uint8_t){ 0 });
if (p_sys->embed == NULL) if (sys->embed == NULL)
{ {
free (p_sys); free (sys);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
sys->conn = conn;
const xcb_setup_t *setup = xcb_get_setup (p_sys->conn); const xcb_setup_t *setup = xcb_get_setup (conn);
/* Determine our pixel format */ /* Determine our pixel format */
xcb_visualid_t vid = 0; xcb_visualid_t vid;
p_sys->depth = 0; sys->depth = 0;
for (const xcb_format_t *fmt = xcb_setup_pixmap_formats (setup), for (const xcb_format_t *fmt = xcb_setup_pixmap_formats (setup),
*end = fmt + xcb_setup_pixmap_formats_length (setup); *end = fmt + xcb_setup_pixmap_formats_length (setup);
fmt < end; fmt < end;
fmt++) fmt++)
{ {
if (fmt->depth <= p_sys->depth) if (fmt->depth <= sys->depth)
continue; /* no better than earlier format */ continue; /* no better than earlier format */
video_format_t fmt_pic = vd->fmt; video_format_t fmt_pic = vd->fmt;
...@@ -207,8 +208,8 @@ static int Open (vlc_object_t *obj) ...@@ -207,8 +208,8 @@ static int Open (vlc_object_t *obj)
vd->fmt = fmt_pic; vd->fmt = fmt_pic;
vid = vt->visual_id; vid = vt->visual_id;
msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32, vid); msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32, vid);
p_sys->depth = fmt->depth; sys->depth = fmt->depth;
msg_Dbg (vd, " %"PRIu8" bits depth", p_sys->depth); msg_Dbg (vd, " %"PRIu8" bits depth", sys->depth);
msg_Dbg (vd, " %"PRIu8" bits per pixel", fmt->bits_per_pixel); msg_Dbg (vd, " %"PRIu8" bits per pixel", fmt->bits_per_pixel);
msg_Dbg (vd, " %"PRIu8" bits line pad", fmt->scanline_pad); msg_Dbg (vd, " %"PRIu8" bits line pad", fmt->scanline_pad);
goto found_format; goto found_format;
...@@ -239,8 +240,8 @@ found_format:; ...@@ -239,8 +240,8 @@ found_format:;
xcb_colormap_t cmap; xcb_colormap_t cmap;
if (vid != scr->root_visual) if (vid != scr->root_visual)
{ {
cmap = xcb_generate_id (p_sys->conn); cmap = xcb_generate_id (conn);
xcb_create_colormap (p_sys->conn, XCB_COLORMAP_ALLOC_NONE, xcb_create_colormap (conn, XCB_COLORMAP_ALLOC_NONE,
cmap, scr->root, vid); cmap, scr->root, vid);
} }
else else
...@@ -248,12 +249,12 @@ found_format:; ...@@ -248,12 +249,12 @@ found_format:;
/* Create window */ /* Create window */
unsigned width, height; unsigned width, height;
if (GetWindowSize (p_sys->embed, p_sys->conn, &width, &height)) if (GetWindowSize (sys->embed, conn, &width, &height))
goto error; goto error;
p_sys->window = xcb_generate_id (p_sys->conn); sys->window = xcb_generate_id (conn);
p_sys->gc = xcb_generate_id (p_sys->conn); sys->gc = xcb_generate_id (conn);
xcb_pixmap_t pixmap = xcb_generate_id (p_sys->conn); xcb_pixmap_t pixmap = xcb_generate_id (conn);
{ {
const uint32_t mask = const uint32_t mask =
XCB_CW_BACK_PIXMAP | XCB_CW_BACK_PIXMAP |
...@@ -278,35 +279,30 @@ found_format:; ...@@ -278,35 +279,30 @@ found_format:;
}; };
xcb_void_cookie_t c; xcb_void_cookie_t c;
xcb_create_pixmap (p_sys->conn, p_sys->depth, pixmap, scr->root, 1, 1); xcb_create_pixmap (conn, sys->depth, pixmap, scr->root, 1, 1);
c = xcb_create_window_checked (p_sys->conn, p_sys->depth, c = xcb_create_window_checked (conn, sys->depth, sys->window,
p_sys->window, sys->embed->handle.xid, 0, 0,
p_sys->embed->handle.xid, 0, 0,
width, height, 0, width, height, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_WINDOW_CLASS_INPUT_OUTPUT,
vid, mask, values); vid, mask, values);
xcb_map_window (p_sys->conn, p_sys->window); xcb_map_window (conn, sys->window);
/* Create graphic context (I wonder why the heck do we need this) */ /* Create graphic context (I wonder why the heck do we need this) */
xcb_create_gc (p_sys->conn, p_sys->gc, p_sys->window, 0, NULL); xcb_create_gc (conn, sys->gc, sys->window, 0, NULL);
if (CheckError (vd, p_sys->conn, "cannot create X11 window", c)) if (CheckError (vd, conn, "cannot create X11 window", c))
goto error; goto error;
} }
msg_Dbg (vd, "using X11 window %08"PRIx32, p_sys->window); msg_Dbg (vd, "using X11 window %08"PRIx32, sys->window);
msg_Dbg (vd, "using X11 graphic context %08"PRIx32, p_sys->gc); msg_Dbg (vd, "using X11 graphic context %08"PRIx32, sys->gc);
p_sys->cursor = CreateBlankCursor (p_sys->conn, scr);
p_sys->visible = false; sys->cursor = CreateBlankCursor (conn, scr);
sys->visible = false;
sys->shm = CheckSHM (obj, conn);
p_sys->shm = CheckSHM (obj, p_sys->conn);
/* */
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 */ /* Setup vout_display_t once everything is fine */
vd->info = info; vd->info.has_pictures_invalid = true;
vd->info.has_event_thread = true;
vd->pool = Pool; vd->pool = Pool;
vd->prepare = NULL; vd->prepare = NULL;
...@@ -316,7 +312,7 @@ found_format:; ...@@ -316,7 +312,7 @@ found_format:;
/* */ /* */
bool is_fullscreen = vd->cfg->is_fullscreen; bool is_fullscreen = vd->cfg->is_fullscreen;
if (is_fullscreen && vout_window_SetFullScreen (p_sys->embed, true)) if (is_fullscreen && vout_window_SetFullScreen (sys->embed, true))
is_fullscreen = false; is_fullscreen = false;
vout_display_SendEventFullscreen (vd, is_fullscreen); vout_display_SendEventFullscreen (vd, is_fullscreen);
vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen); vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen);
...@@ -335,19 +331,19 @@ error: ...@@ -335,19 +331,19 @@ error:
static void Close (vlc_object_t *obj) static void Close (vlc_object_t *obj)
{ {
vout_display_t *vd = (vout_display_t *)obj; vout_display_t *vd = (vout_display_t *)obj;
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *sys = vd->sys;
ResetPictures (vd); ResetPictures (vd);
/* show the default cursor */ /* show the default cursor */
xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid, XCB_CW_CURSOR, xcb_change_window_attributes (sys->conn, sys->embed->handle.xid, XCB_CW_CURSOR,
&(uint32_t) { XCB_CURSOR_NONE }); &(uint32_t) { XCB_CURSOR_NONE });
xcb_flush (p_sys->conn); xcb_flush (sys->conn);
/* colormap, window and context are garbage-collected by X */ /* colormap, window and context are garbage-collected by X */
xcb_disconnect (p_sys->conn); xcb_disconnect (sys->conn);
vout_display_DeleteWindow (vd, p_sys->embed); vout_display_DeleteWindow (vd, sys->embed);
free (p_sys); free (sys);
} }
/** /**
...@@ -355,59 +351,58 @@ static void Close (vlc_object_t *obj) ...@@ -355,59 +351,58 @@ static void Close (vlc_object_t *obj)
*/ */
static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count) static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *sys = vd->sys;
(void)requested_count; (void)requested_count;
if (!p_sys->pool) if (sys->pool)
{ return sys->pool;
vout_display_place_t place;
vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
/* */ vout_display_place_t place;
const uint32_t values[] = { place.x, place.y, place.width, place.height };
xcb_configure_window (p_sys->conn, p_sys->window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values);
picture_t *pic = picture_NewFromFormat (&vd->fmt); vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
if (!pic)
return NULL;
assert (pic->i_planes == 1); /* */
memset (p_sys->resource, 0, sizeof(p_sys->resource)); const uint32_t values[] = { place.x, place.y, place.width, place.height };
xcb_configure_window (sys->conn, sys->window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values);
picture_t *pic = picture_NewFromFormat (&vd->fmt);
if (!pic)
return NULL;
assert (pic->i_planes == 1);
memset (sys->resource, 0, sizeof(sys->resource));
unsigned count;
picture_t *pic_array[MAX_PICTURES];
for (count = 0; count < MAX_PICTURES; count++)
{
picture_resource_t *res = &sys->resource[count];
unsigned count; res->p->i_lines = pic->p->i_lines;
picture_t *pic_array[MAX_PICTURES]; res->p->i_pitch = pic->p->i_pitch;
for (count = 0; count < MAX_PICTURES; count++) if (PictureResourceAlloc (vd, res, res->p->i_pitch * res->p->i_lines,
sys->conn, sys->shm))
break;
pic_array[count] = picture_NewFromResource (&vd->fmt, res);
if (!pic_array[count])
{ {
picture_resource_t *res = &p_sys->resource[count]; PictureResourceFree (res, sys->conn);
memset (res, 0, sizeof(*res));
res->p->i_lines = pic->p->i_lines; break;
res->p->i_pitch = pic->p->i_pitch;
if (PictureResourceAlloc (vd, res, res->p->i_pitch * res->p->i_lines,
p_sys->conn, p_sys->shm))
break;
pic_array[count] = picture_NewFromResource (&vd->fmt, res);
if (!pic_array[count])
{
PictureResourceFree (res, p_sys->conn);
memset (res, 0, sizeof(*res));
break;
}
} }
picture_Release (pic);
if (count == 0)
return NULL;
p_sys->pool = picture_pool_New (count, pic_array);
/* TODO release picture resources if NULL */
xcb_flush (p_sys->conn);
} }
picture_Release (pic);
if (count == 0)
return NULL;
return p_sys->pool; sys->pool = picture_pool_New (count, pic_array);
/* TODO release picture resources if NULL */
xcb_flush (sys->conn);
return sys->pool;
} }
/** /**
...@@ -415,31 +410,31 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count) ...@@ -415,31 +410,31 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
*/ */
static void Display (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture) static void Display (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *sys = vd->sys;
xcb_shm_seg_t segment = pic->p_sys->segment; xcb_shm_seg_t segment = pic->p_sys->segment;
xcb_void_cookie_t ck; xcb_void_cookie_t ck;
if (!p_sys->visible) if (!sys->visible)
goto out; goto out;
if (segment != 0) if (segment != 0)
ck = xcb_shm_put_image_checked (p_sys->conn, p_sys->window, p_sys->gc, ck = xcb_shm_put_image_checked (sys->conn, sys->window, sys->gc,
/* real width */ pic->p->i_pitch / pic->p->i_pixel_pitch, /* real width */ pic->p->i_pitch / pic->p->i_pixel_pitch,
/* real height */ pic->p->i_lines, /* real height */ pic->p->i_lines,
/* x */ vd->fmt.i_x_offset, /* x */ vd->fmt.i_x_offset,
/* y */ vd->fmt.i_y_offset, /* y */ vd->fmt.i_y_offset,
/* width */ vd->fmt.i_visible_width, /* width */ vd->fmt.i_visible_width,
/* height */ vd->fmt.i_visible_height, /* height */ vd->fmt.i_visible_height,
0, 0, p_sys->depth, XCB_IMAGE_FORMAT_Z_PIXMAP, 0, 0, sys->depth, XCB_IMAGE_FORMAT_Z_PIXMAP,
0, segment, 0); 0, segment, 0);
else else
{ {
const size_t offset = vd->fmt.i_y_offset * pic->p->i_pitch; const size_t offset = vd->fmt.i_y_offset * pic->p->i_pitch;
const unsigned lines = pic->p->i_lines - vd->fmt.i_y_offset; const unsigned lines = pic->p->i_lines - vd->fmt.i_y_offset;
ck = xcb_put_image_checked (p_sys->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, ck = xcb_put_image_checked (sys->conn, XCB_IMAGE_FORMAT_Z_PIXMAP,
p_sys->window, p_sys->gc, sys->window, sys->gc,
pic->p->i_pitch / pic->p->i_pixel_pitch, pic->p->i_pitch / pic->p->i_pixel_pitch,
lines, -vd->fmt.i_x_offset, 0, 0, p_sys->depth, lines, -vd->fmt.i_x_offset, 0, 0, sys->depth,
pic->p->i_pitch * lines, pic->p->p_pixels + offset); pic->p->i_pitch * lines, pic->p->p_pixels + offset);
} }
...@@ -447,7 +442,7 @@ static void Display (vout_display_t *vd, picture_t *pic, subpicture_t *subpictur ...@@ -447,7 +442,7 @@ static void Display (vout_display_t *vd, picture_t *pic, subpicture_t *subpictur
* display the picture. xcb_flush() is *not* sufficient: especially with * display the picture. xcb_flush() is *not* sufficient: especially with
* shared memory the PUT requests are so short that many of them can fit in * shared memory the PUT requests are so short that many of them can fit in
* X11 socket output buffer before the kernel preempts VLC. */ * X11 socket output buffer before the kernel preempts VLC. */
xcb_generic_error_t *e = xcb_request_check (p_sys->conn, ck); xcb_generic_error_t *e = xcb_request_check (sys->conn, ck);
if (e != NULL) if (e != NULL)
{ {
msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code); msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code);
...@@ -464,14 +459,14 @@ out: ...@@ -464,14 +459,14 @@ out:
static int Control (vout_display_t *vd, int query, va_list ap) static int Control (vout_display_t *vd, int query, va_list ap)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *sys = vd->sys;
switch (query) switch (query)
{ {
case VOUT_DISPLAY_CHANGE_FULLSCREEN: case VOUT_DISPLAY_CHANGE_FULLSCREEN:
{ {
const vout_display_cfg_t *c = va_arg (ap, const vout_display_cfg_t *); const vout_display_cfg_t *c = va_arg (ap, const vout_display_cfg_t *);
return vout_window_SetFullScreen (p_sys->embed, c->is_fullscreen); return vout_window_SetFullScreen (sys->embed, c->is_fullscreen);
} }
case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE: case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
...@@ -481,7 +476,7 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -481,7 +476,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
const bool is_forced = (bool)va_arg (ap, int); const bool is_forced = (bool)va_arg (ap, int);
if (is_forced if (is_forced
&& vout_window_SetSize (p_sys->embed, && vout_window_SetSize (sys->embed,
p_cfg->display.width, p_cfg->display.width,
p_cfg->display.height)) p_cfg->display.height))
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -498,7 +493,7 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -498,7 +493,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
/* Move the picture within the window */ /* Move the picture within the window */
const uint32_t values[] = { place.x, place.y }; const uint32_t values[] = { place.x, place.y };
xcb_configure_window (p_sys->conn, p_sys->window, xcb_configure_window (sys->conn, sys->window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
values); values);
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -506,7 +501,7 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -506,7 +501,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
case VOUT_DISPLAY_CHANGE_WINDOW_STATE: case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
{ {
unsigned state = va_arg (ap, unsigned); unsigned state = va_arg (ap, unsigned);
return vout_window_SetState (p_sys->embed, state); return vout_window_SetState (sys->embed, state);
} }
case VOUT_DISPLAY_CHANGE_ZOOM: case VOUT_DISPLAY_CHANGE_ZOOM:
...@@ -537,8 +532,8 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -537,8 +532,8 @@ static int Control (vout_display_t *vd, int query, va_list ap)
/* Hide the mouse. It will be send when /* Hide the mouse. It will be send when
* vout_display_t::info.b_hide_mouse is false */ * vout_display_t::info.b_hide_mouse is false */
case VOUT_DISPLAY_HIDE_MOUSE: case VOUT_DISPLAY_HIDE_MOUSE:
xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid, xcb_change_window_attributes (sys->conn, sys->embed->handle.xid,
XCB_CW_CURSOR, &(uint32_t){ p_sys->cursor }); XCB_CW_CURSOR, &(uint32_t){ sys->cursor });
return VLC_SUCCESS; return VLC_SUCCESS;
default: default:
...@@ -549,26 +544,26 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -549,26 +544,26 @@ static int Control (vout_display_t *vd, int query, va_list ap)
static void Manage (vout_display_t *vd) static void Manage (vout_display_t *vd)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *sys = vd->sys;
ManageEvent (vd, p_sys->conn, &p_sys->visible); ManageEvent (vd, sys->conn, &sys->visible);
} }
static void ResetPictures (vout_display_t *vd) static void ResetPictures (vout_display_t *vd)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *sys = vd->sys;
if (!p_sys->pool) if (!sys->pool)
return; return;
for (unsigned i = 0; i < MAX_PICTURES; i++) for (unsigned i = 0; i < MAX_PICTURES; i++)
{ {
picture_resource_t *res = &p_sys->resource[i]; picture_resource_t *res = &sys->resource[i];
if (!res->p->p_pixels) if (!res->p->p_pixels)
break; break;
PictureResourceFree (res, p_sys->conn); PictureResourceFree (res, sys->conn);
} }
picture_pool_Delete (p_sys->pool); picture_pool_Delete (sys->pool);
p_sys->pool = NULL; sys->pool = NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment