Add encoder support for Dirac using the Schroedinger library.
[vlc/asuraparaju-public.git] / modules / video_output / xcb / xvideo.c
blobf0105f36a2f224ccb3587dc5c9f9fc0bb26525f8
1 /**
2 * @file xvideo.c
3 * @brief X C Bindings video output module for VLC media player
4 */
5 /*****************************************************************************
6 * Copyright © 2009 Rémi Denis-Courmont
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include <stdlib.h>
28 #include <assert.h>
30 #include <xcb/xcb.h>
31 #include <xcb/shm.h>
32 #include <xcb/xv.h>
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_vout_display.h>
37 #include <vlc_picture_pool.h>
38 #include <vlc_dialog.h>
40 #include "xcb_vlc.h"
42 #define ADAPTOR_TEXT N_("XVideo adaptor number")
43 #define ADAPTOR_LONGTEXT N_( \
44 "XVideo hardware adaptor to use. By default, VLC will " \
45 "use the first functional adaptor.")
47 #define FORMAT_TEXT N_("XVideo format id")
48 #define FORMAT_LONGTEXT N_( \
49 "XVideo image format id to use. By default, VLC will " \
50 "try to use the best match for the video being played.")
52 #define SHM_TEXT N_("Use shared memory")
53 #define SHM_LONGTEXT N_( \
54 "Use shared memory to communicate between VLC and the X server.")
56 static int Open (vlc_object_t *);
57 static void Close (vlc_object_t *);
60 * Module descriptor
62 vlc_module_begin ()
63 set_shortname (N_("XVideo"))
64 set_description (N_("XVideo output (XCB)"))
65 set_category (CAT_VIDEO)
66 set_subcategory (SUBCAT_VIDEO_VOUT)
67 set_capability ("vout display", 155)
68 set_callbacks (Open, Close)
70 add_integer ("xvideo-adaptor", -1,
71 ADAPTOR_TEXT, ADAPTOR_LONGTEXT, true)
72 add_integer ("xvideo-format-id", 0,
73 FORMAT_TEXT, FORMAT_LONGTEXT, true)
74 add_bool ("x11-shm", true, SHM_TEXT, SHM_LONGTEXT, true)
75 add_deprecated_alias ("xvideo-shm")
76 add_shortcut ("xcb-xv", "xv", "xvideo", "xid")
77 vlc_module_end ()
79 #define MAX_PICTURES (128)
81 struct vout_display_sys_t
83 xcb_connection_t *conn;
84 vout_window_t *embed;/* VLC window */
86 xcb_cursor_t cursor; /* blank cursor */
87 xcb_window_t window; /* drawable X window */
88 xcb_gcontext_t gc; /* context to put images */
89 xcb_xv_port_t port; /* XVideo port */
90 uint32_t id; /* XVideo format */
91 uint16_t width; /* display width */
92 uint16_t height; /* display height */
93 uint32_t data_size; /* picture byte size (for non-SHM) */
94 bool swap_uv; /* U/V pointer must be swapped in a picture */
95 bool shm; /* whether to use MIT-SHM */
96 bool visible; /* whether it makes sense to draw at all */
98 xcb_xv_query_image_attributes_reply_t *att;
99 picture_pool_t *pool; /* picture pool */
100 picture_resource_t resource[MAX_PICTURES];
103 static picture_pool_t *Pool (vout_display_t *, unsigned);
104 static void Display (vout_display_t *, picture_t *);
105 static int Control (vout_display_t *, int, va_list);
106 static void Manage (vout_display_t *);
109 * Check that the X server supports the XVideo extension.
111 static bool CheckXVideo (vout_display_t *vd, xcb_connection_t *conn)
113 xcb_xv_query_extension_reply_t *r;
114 xcb_xv_query_extension_cookie_t ck = xcb_xv_query_extension (conn);
115 bool ok = false;
117 /* We need XVideo 2.2 for PutImage */
118 r = xcb_xv_query_extension_reply (conn, ck, NULL);
119 if (r == NULL)
120 msg_Dbg (vd, "XVideo extension not available");
121 else
122 if (r->major != 2)
123 msg_Dbg (vd, "XVideo extension v%"PRIu8".%"PRIu8" unknown",
124 r->major, r->minor);
125 else
126 if (r->minor < 2)
127 msg_Dbg (vd, "XVideo extension v%"PRIu8".%"PRIu8" too old",
128 r->major, r->minor);
129 else
131 msg_Dbg (vd, "using XVideo extension v%"PRIu8".%"PRIu8,
132 r->major, r->minor);
133 ok = true;
135 free (r);
136 return ok;
139 static vlc_fourcc_t ParseFormat (vout_display_t *vd,
140 const xcb_xv_image_format_info_t *restrict f)
142 if (f->byte_order != ORDER && f->bpp != 8)
143 return 0; /* Argh! */
145 switch (f->type)
147 case XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB:
148 switch (f->num_planes)
150 case 1:
151 switch (f->bpp)
153 case 32:
154 if (f->depth == 24)
155 return VLC_CODEC_RGB32;
156 if (f->depth == 32)
157 return 0; /* ARGB -> VLC cannot do that currently */
158 break;
159 case 24:
160 if (f->depth == 24)
161 return VLC_CODEC_RGB24;
162 break;
163 case 16:
164 if (f->depth == 16)
165 return VLC_CODEC_RGB16;
166 if (f->depth == 15)
167 return VLC_CODEC_RGB15;
168 break;
169 case 8:
170 if (f->depth == 8)
171 return VLC_CODEC_RGB8;
172 break;
174 break;
176 msg_Err (vd, "unknown XVideo RGB format %"PRIx32" (%.4s)",
177 f->id, f->guid);
178 msg_Dbg (vd, " %"PRIu8" planes, %"PRIu8" bits/pixel, "
179 "depth %"PRIu8, f->num_planes, f->bpp, f->depth);
180 break;
182 case XCB_XV_IMAGE_FORMAT_INFO_TYPE_YUV:
183 if (f->u_sample_bits != f->v_sample_bits
184 || f->vhorz_u_period != f->vhorz_v_period
185 || f->vvert_u_period != f->vvert_v_period
186 || f->y_sample_bits != 8 || f->u_sample_bits != 8
187 || f->vhorz_y_period != 1 || f->vvert_y_period != 1)
188 goto bad;
189 switch (f->num_planes)
191 case 1:
192 switch (f->bpp)
194 /*untested: case 24:
195 if (f->vhorz_u_period == 1 && f->vvert_u_period == 1)
196 return VLC_CODEC_I444;
197 break;*/
198 case 16:
199 if (f->vhorz_u_period == 2 && f->vvert_u_period == 1)
201 if (!strcmp ((const char *)f->vcomp_order, "YUYV"))
202 return VLC_CODEC_YUYV;
203 if (!strcmp ((const char *)f->vcomp_order, "UYVY"))
204 return VLC_CODEC_UYVY;
206 break;
208 break;
209 case 3:
210 switch (f->bpp)
212 case 12:
213 if (f->vhorz_u_period == 2 && f->vvert_u_period == 2)
215 if (!strcmp ((const char *)f->vcomp_order, "YVU"))
216 return VLC_CODEC_YV12;
217 if (!strcmp ((const char *)f->vcomp_order, "YUV"))
218 return VLC_CODEC_I420;
221 break;
223 bad:
224 msg_Err (vd, "unknown XVideo YUV format %"PRIx32" (%.4s)", f->id,
225 f->guid);
226 msg_Dbg (vd, " %"PRIu8" planes, %"PRIu32" bits/pixel, "
227 "%"PRIu32"/%"PRIu32"/%"PRIu32" bits/sample", f->num_planes,
228 f->bpp, f->y_sample_bits, f->u_sample_bits, f->v_sample_bits);
229 msg_Dbg (vd, " period: %"PRIu32"/%"PRIu32"/%"PRIu32"x"
230 "%"PRIu32"/%"PRIu32"/%"PRIu32,
231 f->vhorz_y_period, f->vhorz_u_period, f->vhorz_v_period,
232 f->vvert_y_period, f->vvert_u_period, f->vvert_v_period);
233 msg_Warn (vd, " order: %.32s", f->vcomp_order);
234 break;
236 return 0;
240 static const xcb_xv_image_format_info_t *
241 FindFormat (vout_display_t *vd,
242 vlc_fourcc_t chroma, const video_format_t *fmt,
243 xcb_xv_port_t port,
244 const xcb_xv_list_image_formats_reply_t *list,
245 xcb_xv_query_image_attributes_reply_t **restrict pa)
247 xcb_connection_t *conn = vd->sys->conn;
248 const xcb_xv_image_format_info_t *f, *end;
250 #ifndef XCB_XV_OLD
251 f = xcb_xv_list_image_formats_format (list);
252 #else
253 f = (xcb_xv_image_format_info_t *) (list + 1);
254 #endif
255 end = f + xcb_xv_list_image_formats_format_length (list);
256 for (; f < end; f++)
258 if (chroma != ParseFormat (vd, f))
259 continue;
261 /* VLC pads scanline to 16 pixels internally */
262 unsigned width = fmt->i_width;
263 unsigned height = fmt->i_height;
264 xcb_xv_query_image_attributes_reply_t *i;
265 i = xcb_xv_query_image_attributes_reply (conn,
266 xcb_xv_query_image_attributes (conn, port, f->id,
267 width, height), NULL);
268 if (i == NULL)
269 continue;
271 if (i->width != width || i->height != height)
273 msg_Warn (vd, "incompatible size %ux%u -> %"PRIu32"x%"PRIu32,
274 fmt->i_width, fmt->i_height,
275 i->width, i->height);
276 var_Create (vd->p_libvlc, "xvideo-resolution-error", VLC_VAR_BOOL);
277 if (!var_GetBool (vd->p_libvlc, "xvideo-resolution-error"))
279 dialog_FatalWait (vd, _("Video acceleration not available"),
280 _("Your video output acceleration driver does not support "
281 "the required resolution: %ux%u pixels. The maximum "
282 "supported resolution is %"PRIu32"x%"PRIu32".\n"
283 "Video output acceleration will be disabled. However, "
284 "rendering videos with overly large resolution "
285 "may cause severe performance degration."),
286 width, height, i->width, i->height);
287 var_SetBool (vd->p_libvlc, "xvideo-resolution-error", true);
289 free (i);
290 continue;
292 *pa = i;
293 return f;
295 return NULL;
300 * Probe the X server.
302 static int Open (vlc_object_t *obj)
304 vout_display_t *vd = (vout_display_t *)obj;
305 vout_display_sys_t *p_sys = malloc (sizeof (*p_sys));
307 if (!var_InheritBool (obj, "overlay"))
308 return VLC_EGENERIC;
309 if (p_sys == NULL)
310 return VLC_ENOMEM;
312 vd->sys = p_sys;
314 /* Connect to X */
315 xcb_connection_t *conn;
316 const xcb_screen_t *screen;
317 uint8_t depth;
318 p_sys->embed = GetWindow (vd, &conn, &screen, &depth);
319 if (p_sys->embed == NULL)
321 free (p_sys);
322 return VLC_EGENERIC;
325 p_sys->conn = conn;
326 p_sys->att = NULL;
327 p_sys->pool = NULL;
328 p_sys->swap_uv = false;
330 if (!CheckXVideo (vd, conn))
332 msg_Warn (vd, "Please enable XVideo 2.2 for faster video display");
333 goto error;
336 p_sys->window = xcb_generate_id (conn);
337 xcb_pixmap_t pixmap = xcb_generate_id (conn);
339 /* Cache adaptors infos */
340 xcb_xv_query_adaptors_reply_t *adaptors =
341 xcb_xv_query_adaptors_reply (conn,
342 xcb_xv_query_adaptors (conn, p_sys->embed->handle.xid), NULL);
343 if (adaptors == NULL)
344 goto error;
346 int forced_adaptor = var_InheritInteger (obj, "xvideo-adaptor");
348 /* */
349 video_format_t fmt = vd->fmt;
350 p_sys->port = 0;
352 xcb_xv_adaptor_info_iterator_t it;
353 for (it = xcb_xv_query_adaptors_info_iterator (adaptors);
354 it.rem > 0;
355 xcb_xv_adaptor_info_next (&it))
357 const xcb_xv_adaptor_info_t *a = it.data;
358 char *name;
360 if (forced_adaptor != -1 && forced_adaptor != 0)
362 forced_adaptor--;
363 continue;
366 if (!(a->type & XCB_XV_TYPE_IMAGE_MASK))
367 continue;
369 xcb_xv_list_image_formats_reply_t *r =
370 xcb_xv_list_image_formats_reply (conn,
371 xcb_xv_list_image_formats (conn, a->base_id), NULL);
372 if (r == NULL)
373 continue;
375 /* Look for an image format */
376 const xcb_xv_image_format_info_t *xfmt = NULL;
377 const vlc_fourcc_t *chromas, chromas_default[] = {
378 fmt.i_chroma,
379 VLC_CODEC_RGB32,
380 VLC_CODEC_RGB24,
381 VLC_CODEC_RGB16,
382 VLC_CODEC_RGB15,
383 VLC_CODEC_YUYV,
386 if (vlc_fourcc_IsYUV (fmt.i_chroma))
387 chromas = vlc_fourcc_GetYUVFallback (fmt.i_chroma);
388 else
389 chromas = chromas_default;
391 int forced_format_id = var_CreateGetInteger (obj, "xvideo-format-id");
392 vlc_fourcc_t chroma = forced_format_id;
393 xfmt = FindFormat (vd, chroma, &fmt, a->base_id, r, &p_sys->att);
394 for (size_t i = 0; !xfmt && chromas[i]; i++)
396 chroma = chromas[i];
398 /* Oink oink! */
399 if ((chroma == VLC_CODEC_I420 || chroma == VLC_CODEC_YV12)
400 && a->name_size >= 4
401 && !memcmp ("OMAP", xcb_xv_adaptor_info_name (a), 4))
403 msg_Dbg (vd, "skipping slow I420 format");
404 continue; /* OMAP framebuffer sucks at YUV 4:2:0 */
407 xfmt = FindFormat (vd, chroma, &fmt, a->base_id, r, &p_sys->att);
408 if (xfmt != NULL) break;
410 free (r);
411 if (xfmt == NULL) /* No acceptable image formats */
412 continue;
414 p_sys->id = xfmt->id;
415 p_sys->swap_uv = vlc_fourcc_AreUVPlanesSwapped (fmt.i_chroma, chroma);
416 if (!p_sys->swap_uv)
417 fmt.i_chroma = chroma;
418 if (xfmt->type == XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB)
420 fmt.i_rmask = xfmt->red_mask;
421 fmt.i_gmask = xfmt->green_mask;
422 fmt.i_bmask = xfmt->blue_mask;
425 /* Grab a port */
426 for (unsigned i = 0; i < a->num_ports; i++)
428 xcb_xv_port_t port = a->base_id + i;
429 xcb_xv_grab_port_reply_t *gr =
430 xcb_xv_grab_port_reply (conn,
431 xcb_xv_grab_port (conn, port, XCB_CURRENT_TIME), NULL);
432 uint8_t result = gr ? gr->result : 0xff;
434 free (gr);
435 if (result == 0)
437 p_sys->port = port;
438 goto grabbed_port;
440 msg_Dbg (vd, "cannot grab port %"PRIu32": Xv error %"PRIu8, port,
441 result);
443 continue; /* No usable port */
445 grabbed_port:
446 /* Found port - initialize selected format */
447 name = strndup (xcb_xv_adaptor_info_name (a), a->name_size);
448 if (name != NULL)
450 msg_Dbg (vd, "using adaptor %s", name);
451 free (name);
453 msg_Dbg (vd, "using port %"PRIu32, p_sys->port);
454 msg_Dbg (vd, "using image format 0x%"PRIx32, p_sys->id);
456 /* Look for an X11 visual, create a window */
457 xcb_xv_format_t *f = xcb_xv_adaptor_info_formats (a);
458 for (uint_fast16_t i = a->num_formats; i > 0; i--, f++)
460 if (f->depth != screen->root_depth)
461 continue; /* this would fail anyway */
463 uint32_t mask =
464 XCB_CW_BACK_PIXMAP |
465 XCB_CW_BACK_PIXEL |
466 XCB_CW_BORDER_PIXMAP |
467 XCB_CW_BORDER_PIXEL |
468 XCB_CW_EVENT_MASK |
469 XCB_CW_COLORMAP;
470 const uint32_t list[] = {
471 /* XCB_CW_BACK_PIXMAP */
472 pixmap,
473 /* XCB_CW_BACK_PIXEL */
474 screen->black_pixel,
475 /* XCB_CW_BORDER_PIXMAP */
476 pixmap,
477 /* XCB_CW_BORDER_PIXEL */
478 screen->black_pixel,
479 /* XCB_CW_EVENT_MASK */
480 XCB_EVENT_MASK_VISIBILITY_CHANGE,
481 /* XCB_CW_COLORMAP */
482 screen->default_colormap,
485 xcb_void_cookie_t c;
487 xcb_create_pixmap (conn, f->depth, pixmap, screen->root, 1, 1);
488 c = xcb_create_window_checked (conn, f->depth, p_sys->window,
489 p_sys->embed->handle.xid, 0, 0, 1, 1, 0,
490 XCB_WINDOW_CLASS_INPUT_OUTPUT, f->visual, mask, list);
492 if (!CheckError (vd, conn, "cannot create X11 window", c))
494 msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32
495 " (depth: %"PRIu8")", f->visual, f->depth);
496 msg_Dbg (vd, "using X11 window 0x%08"PRIx32, p_sys->window);
497 goto created_window;
500 xcb_xv_ungrab_port (conn, p_sys->port, XCB_CURRENT_TIME);
501 p_sys->port = 0;
502 msg_Dbg (vd, "no usable X11 visual");
503 continue; /* No workable XVideo format (visual/depth) */
505 created_window:
506 break;
508 free (adaptors);
509 if (!p_sys->port)
511 msg_Err (vd, "no available XVideo adaptor");
512 goto error;
514 else
516 xcb_map_window (conn, p_sys->window);
518 vout_display_place_t place;
520 vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
521 p_sys->width = place.width;
522 p_sys->height = place.height;
524 /* */
525 const uint32_t values[] = {
526 place.x, place.y, place.width, place.height };
527 xcb_configure_window (conn, p_sys->window,
528 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
529 XCB_CONFIG_WINDOW_WIDTH |
530 XCB_CONFIG_WINDOW_HEIGHT,
531 values);
533 p_sys->visible = false;
535 /* Create graphic context */
536 p_sys->gc = xcb_generate_id (conn);
537 xcb_create_gc (conn, p_sys->gc, p_sys->window, 0, NULL);
538 msg_Dbg (vd, "using X11 graphic context 0x%08"PRIx32, p_sys->gc);
540 /* Create cursor */
541 p_sys->cursor = CreateBlankCursor (conn, screen);
543 CheckSHM (obj, conn, &p_sys->shm);
545 /* */
546 vout_display_info_t info = vd->info;
547 info.has_pictures_invalid = false;
548 info.has_event_thread = true;
550 /* Setup vout_display_t once everything is fine */
551 vd->fmt = fmt;
552 vd->info = info;
554 vd->pool = Pool;
555 vd->prepare = NULL;
556 vd->display = Display;
557 vd->control = Control;
558 vd->manage = Manage;
560 /* */
561 bool is_fullscreen = vd->cfg->is_fullscreen;
562 if (is_fullscreen && vout_window_SetFullScreen (p_sys->embed, true))
563 is_fullscreen = false;
564 vout_display_SendEventFullscreen (vd, is_fullscreen);
565 unsigned width, height;
566 if (!GetWindowSize (p_sys->embed, conn, &width, &height))
567 vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen);
569 return VLC_SUCCESS;
571 error:
572 Close (obj);
573 return VLC_EGENERIC;
578 * Disconnect from the X server.
580 static void Close (vlc_object_t *obj)
582 vout_display_t *vd = (vout_display_t *)obj;
583 vout_display_sys_t *p_sys = vd->sys;
585 if (p_sys->pool)
587 for (unsigned i = 0; i < MAX_PICTURES; i++)
589 picture_resource_t *res = &p_sys->resource[i];
591 if (!res->p->p_pixels)
592 break;
593 PictureResourceFree (res, NULL);
595 picture_pool_Delete (p_sys->pool);
598 /* show the default cursor */
599 xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid, XCB_CW_CURSOR,
600 &(uint32_t) { XCB_CURSOR_NONE });
601 xcb_flush (p_sys->conn);
603 free (p_sys->att);
604 xcb_disconnect (p_sys->conn);
605 vout_display_DeleteWindow (vd, p_sys->embed);
606 free (p_sys);
609 static void PoolAlloc (vout_display_t *vd, unsigned requested_count)
611 vout_display_sys_t *p_sys = vd->sys;
613 memset (p_sys->resource, 0, sizeof(p_sys->resource));
615 const uint32_t *pitches= xcb_xv_query_image_attributes_pitches (p_sys->att);
616 const uint32_t *offsets= xcb_xv_query_image_attributes_offsets (p_sys->att);
617 const unsigned num_planes= __MIN(p_sys->att->num_planes, PICTURE_PLANE_MAX);
618 p_sys->data_size = p_sys->att->data_size;
620 picture_t *pic_array[MAX_PICTURES];
621 requested_count = __MIN(requested_count, MAX_PICTURES);
623 unsigned count;
624 for (count = 0; count < requested_count; count++)
626 picture_resource_t *res = &p_sys->resource[count];
628 for (unsigned i = 0; i < num_planes; i++)
630 uint32_t data_size;
631 data_size = (i < num_planes - 1) ? offsets[i+1] : p_sys->data_size;
633 res->p[i].i_lines = (data_size - offsets[i]) / pitches[i];
634 res->p[i].i_pitch = pitches[i];
637 if (PictureResourceAlloc (vd, res, p_sys->att->data_size,
638 p_sys->conn, p_sys->shm))
639 break;
641 /* Allocate further planes as specified by XVideo */
642 /* We assume that offsets[0] is zero */
643 for (unsigned i = 1; i < num_planes; i++)
644 res->p[i].p_pixels = res->p[0].p_pixels + offsets[i];
646 if (p_sys->swap_uv)
647 { /* YVU: swap U and V planes */
648 uint8_t *buf = res->p[2].p_pixels;
649 res->p[2].p_pixels = res->p[1].p_pixels;
650 res->p[1].p_pixels = buf;
653 pic_array[count] = picture_NewFromResource (&vd->fmt, res);
654 if (!pic_array[count])
656 PictureResourceFree (res, p_sys->conn);
657 memset (res, 0, sizeof(*res));
658 break;
662 if (count == 0)
663 return;
665 p_sys->pool = picture_pool_New (count, pic_array);
666 /* TODO release picture resources if NULL */
667 xcb_flush (p_sys->conn);
671 * Return a direct buffer
673 static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
675 vout_display_sys_t *p_sys = vd->sys;
677 if (!p_sys->pool)
678 PoolAlloc (vd, requested_count);
680 return p_sys->pool;
684 * Sends an image to the X server.
686 static void Display (vout_display_t *vd, picture_t *pic)
688 vout_display_sys_t *p_sys = vd->sys;
689 xcb_shm_seg_t segment = pic->p_sys->segment;
690 xcb_void_cookie_t ck;
692 if (!p_sys->visible)
693 goto out;
694 if (segment)
695 ck = xcb_xv_shm_put_image_checked (p_sys->conn, p_sys->port,
696 p_sys->window, p_sys->gc, segment, p_sys->id, 0,
697 /* Src: */ vd->source.i_x_offset,
698 vd->source.i_y_offset,
699 vd->source.i_visible_width,
700 vd->source.i_visible_height,
701 /* Dst: */ 0, 0, p_sys->width, p_sys->height,
702 /* Memory: */ pic->p->i_pitch / pic->p->i_pixel_pitch,
703 pic->p->i_lines, false);
704 else
705 ck = xcb_xv_put_image_checked (p_sys->conn, p_sys->port, p_sys->window,
706 p_sys->gc, p_sys->id,
707 vd->source.i_x_offset,
708 vd->source.i_y_offset,
709 vd->source.i_visible_width,
710 vd->source.i_visible_height,
711 0, 0, p_sys->width, p_sys->height,
712 pic->p->i_pitch / pic->p->i_pixel_pitch,
713 pic->p->i_lines,
714 p_sys->data_size, pic->p->p_pixels);
716 /* Wait for reply. See x11.c for rationale. */
717 xcb_generic_error_t *e = xcb_request_check (p_sys->conn, ck);
718 if (e != NULL)
720 msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code);
721 free (e);
723 out:
724 picture_Release (pic);
727 static int Control (vout_display_t *vd, int query, va_list ap)
729 vout_display_sys_t *p_sys = vd->sys;
731 switch (query)
733 case VOUT_DISPLAY_CHANGE_FULLSCREEN:
735 const vout_display_cfg_t *c = va_arg (ap, const vout_display_cfg_t *);
736 return vout_window_SetFullScreen (p_sys->embed, c->is_fullscreen);
739 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
740 case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
741 case VOUT_DISPLAY_CHANGE_ZOOM:
742 case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
743 case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
745 const vout_display_cfg_t *cfg;
746 const video_format_t *source;
747 bool is_forced = false;
749 if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT
750 || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
752 source = (const video_format_t *)va_arg (ap, const video_format_t *);
753 cfg = vd->cfg;
755 else
757 source = &vd->source;
758 cfg = (const vout_display_cfg_t*)va_arg (ap, const vout_display_cfg_t *);
759 if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
760 is_forced = (bool)va_arg (ap, int);
763 /* */
764 if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
765 && is_forced
766 && (cfg->display.width != vd->cfg->display.width
767 ||cfg->display.height != vd->cfg->display.height)
768 && vout_window_SetSize (p_sys->embed,
769 cfg->display.width,
770 cfg->display.height))
771 return VLC_EGENERIC;
773 vout_display_place_t place;
774 vout_display_PlacePicture (&place, source, cfg, false);
775 p_sys->width = place.width;
776 p_sys->height = place.height;
778 /* Move the picture within the window */
779 const uint32_t values[] = { place.x, place.y,
780 place.width, place.height, };
781 xcb_configure_window (p_sys->conn, p_sys->window,
782 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
783 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
784 values);
785 xcb_flush (p_sys->conn);
786 return VLC_SUCCESS;
788 case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
790 unsigned state = va_arg (ap, unsigned);
791 return vout_window_SetState (p_sys->embed, state);
794 /* Hide the mouse. It will be send when
795 * vout_display_t::info.b_hide_mouse is false */
796 case VOUT_DISPLAY_HIDE_MOUSE:
797 xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid,
798 XCB_CW_CURSOR, &(uint32_t){ p_sys->cursor });
799 return VLC_SUCCESS;
800 case VOUT_DISPLAY_RESET_PICTURES:
801 assert(0);
802 default:
803 msg_Err (vd, "Unknown request in XCB vout display");
804 return VLC_EGENERIC;
808 static void Manage (vout_display_t *vd)
810 vout_display_sys_t *p_sys = vd->sys;
812 ManageEvent (vd, p_sys->conn, &p_sys->visible);