]> git.sesse.net Git - vlc/blob - modules/video_output/xcb/xvideo.c
XCB-XV: cosmetic, kill a few gotos
[vlc] / modules / video_output / xcb / xvideo.c
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
7  *
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.
12  *
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.
17  *
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  ****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <stdlib.h>
28 #include <assert.h>
29
30 #include <xcb/xcb.h>
31 #include <xcb/shm.h>
32 #include <xcb/xv.h>
33
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_vout_display.h>
37 #include <vlc_picture_pool.h>
38
39 #include "xcb_vlc.h"
40
41 #define DISPLAY_TEXT N_("X11 display")
42 #define DISPLAY_LONGTEXT N_( \
43     "X11 hardware display to use. By default, VLC will " \
44     "use the value of the DISPLAY environment variable.")
45
46 #define ADAPTOR_TEXT N_("XVideo adaptor number")
47 #define ADAPTOR_LONGTEXT N_( \
48     "XVideo hardware adaptor to use. By default, VLC will " \
49     "use the first functional adaptor.")
50
51 #define SHM_TEXT N_("Use shared memory")
52 #define SHM_LONGTEXT N_( \
53     "Use shared memory to communicate between VLC and the X server.")
54
55 static int  Open (vlc_object_t *);
56 static void Close (vlc_object_t *);
57
58 /*
59  * Module descriptor
60  */
61 vlc_module_begin ()
62     set_shortname (N_("XVideo"))
63     set_description (N_("XVideo output (XCB)"))
64     set_category (CAT_VIDEO)
65     set_subcategory (SUBCAT_VIDEO_VOUT)
66     set_capability ("vout display", 155)
67     set_callbacks (Open, Close)
68
69     add_string ("x11-display", NULL, NULL,
70                 DISPLAY_TEXT, DISPLAY_LONGTEXT, true)
71         add_deprecated_alias ("xvideo-display")
72     add_integer ("xvideo-adaptor", -1, NULL,
73                  ADAPTOR_TEXT, ADAPTOR_LONGTEXT, true)
74     add_bool ("x11-shm", true, NULL, SHM_TEXT, SHM_LONGTEXT, true)
75         add_deprecated_alias ("xvideo-shm")
76     add_shortcut ("xcb-xv")
77     add_shortcut ("xv")
78     add_shortcut ("xvideo")
79 vlc_module_end ()
80
81 #define MAX_PICTURES (VOUT_MAX_PICTURES)
82
83 struct vout_display_sys_t
84 {
85     xcb_connection_t *conn;
86     vout_window_t *embed;/* VLC window */
87
88     xcb_cursor_t cursor; /* blank cursor */
89     xcb_window_t window; /* drawable X window */
90     xcb_gcontext_t gc;   /* context to put images */
91     xcb_xv_port_t port;  /* XVideo port */
92     uint32_t id;         /* XVideo format */
93     uint16_t width;      /* display width */
94     uint16_t height;     /* display height */
95     uint32_t data_size;  /* picture byte size (for non-SHM) */
96     bool shm;            /* whether to use MIT-SHM */
97     bool visible;        /* whether it makes sense to draw at all */
98
99     xcb_xv_query_image_attributes_reply_t *att;
100     picture_pool_t *pool; /* picture pool */
101     picture_resource_t resource[MAX_PICTURES];
102 };
103
104 static picture_t *Get (vout_display_t *);
105 static void Display (vout_display_t *, picture_t *);
106 static int Control (vout_display_t *, int, va_list);
107 static void Manage (vout_display_t *);
108
109 /**
110  * Check that the X server supports the XVideo extension.
111  */
112 static bool CheckXVideo (vout_display_t *vd, xcb_connection_t *conn)
113 {
114     xcb_xv_query_extension_reply_t *r;
115     xcb_xv_query_extension_cookie_t ck = xcb_xv_query_extension (conn);
116     bool ok = false;
117
118     r = xcb_xv_query_extension_reply (conn, ck, NULL);
119     if (r != NULL)
120     {   /* We need XVideo 2.2 for PutImage */
121         if ((r->major > 2) || (r->major == 2 && r->minor >= 2))
122         {
123             msg_Dbg (vd, "using XVideo extension v%"PRIu8".%"PRIu8,
124                      r->major, r->minor);
125             ok = true;
126         }
127         else
128             msg_Dbg (vd, "XVideo extension too old (v%"PRIu8".%"PRIu8,
129                      r->major, r->minor);
130         free (r);
131     }
132     else
133         msg_Dbg (vd, "XVideo extension not available");
134     return ok;
135 }
136
137 static vlc_fourcc_t ParseFormat (vout_display_t *vd,
138                                  const xcb_xv_image_format_info_t *restrict f)
139 {
140     if (f->byte_order != ORDER && f->bpp != 8)
141         return 0; /* Argh! */
142
143     switch (f->type)
144     {
145       case XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB:
146         switch (f->num_planes)
147         {
148           case 1:
149             switch (f->bpp)
150             {
151               case 32:
152                 if (f->depth == 24)
153                     return VLC_CODEC_RGB32;
154                 break;
155               case 24:
156                 if (f->depth == 24)
157                     return VLC_CODEC_RGB24;
158                 break;
159               case 16:
160                 if (f->depth == 16)
161                     return VLC_CODEC_RGB16;
162                 if (f->depth == 15)
163                     return VLC_CODEC_RGB15;
164                 break;
165               case 8:
166                 if (f->depth == 8)
167                     return VLC_CODEC_RGB8;
168                 break;
169             }
170             break;
171         }
172         msg_Err (vd, "unknown XVideo RGB format %"PRIx32" (%.4s)",
173                  f->id, f->guid);
174         msg_Dbg (vd, " %"PRIu8" planes, %"PRIu8" bits/pixel, "
175                  "depth %"PRIu8, f->num_planes, f->bpp, f->depth);
176         break;
177
178       case XCB_XV_IMAGE_FORMAT_INFO_TYPE_YUV:
179         if (f->u_sample_bits != f->v_sample_bits
180          || f->vhorz_u_period != f->vhorz_v_period
181          || f->vvert_u_period != f->vvert_v_period
182          || f->y_sample_bits != 8 || f->u_sample_bits != 8
183          || f->vhorz_y_period != 1 || f->vvert_y_period != 1)
184             goto bad;
185         switch (f->num_planes)
186         {
187           case 1:
188             switch (f->bpp)
189             {
190               /*untested: case 24:
191                 if (f->vhorz_u_period == 1 && f->vvert_u_period == 1)
192                     return VLC_CODEC_I444;
193                 break;*/
194               case 16:
195                 if (f->vhorz_u_period == 2 && f->vvert_u_period == 1)
196                 {
197                     if (!strcmp ((const char *)f->vcomp_order, "YUYV"))
198                         return VLC_CODEC_YUYV;
199                     if (!strcmp ((const char *)f->vcomp_order, "UYVY"))
200                         return VLC_CODEC_UYVY;
201                 }
202                 break;
203             }
204             break;
205           case 3:
206             switch (f->bpp)
207             {
208               case 12:
209                 if (f->vhorz_u_period == 2 && f->vvert_u_period == 2)
210                 {
211                     if (!strcmp ((const char *)f->vcomp_order, "YVU"))
212                         return VLC_CODEC_YV12;
213                     if (!strcmp ((const char *)f->vcomp_order, "YUV"))
214                         return VLC_CODEC_I420;
215                 }
216             }
217             break;
218         }
219     bad:
220         msg_Err (vd, "unknown XVideo YUV format %"PRIx32" (%.4s)", f->id,
221                  f->guid);
222         msg_Dbg (vd, " %"PRIu8" planes, %"PRIu32" bits/pixel, "
223                  "%"PRIu32"/%"PRIu32"/%"PRIu32" bits/sample", f->num_planes,
224                  f->bpp, f->y_sample_bits, f->u_sample_bits, f->v_sample_bits);
225         msg_Dbg (vd, " period: %"PRIu32"/%"PRIu32"/%"PRIu32"x"
226                  "%"PRIu32"/%"PRIu32"/%"PRIu32,
227                  f->vhorz_y_period, f->vhorz_u_period, f->vhorz_v_period,
228                  f->vvert_y_period, f->vvert_u_period, f->vvert_v_period);
229         msg_Warn (vd, " order: %.32s", f->vcomp_order);
230         break;
231     }
232     return 0;
233 }
234
235
236 static const xcb_xv_image_format_info_t *
237 FindFormat (vout_display_t *vd,
238             vlc_fourcc_t chroma, const video_format_t *fmt,
239             xcb_xv_port_t port,
240             const xcb_xv_list_image_formats_reply_t *list,
241             xcb_xv_query_image_attributes_reply_t **restrict pa)
242 {
243     xcb_connection_t *conn = vd->sys->conn;
244     const xcb_xv_image_format_info_t *f, *end;
245
246 #ifndef XCB_XV_OLD
247     f = xcb_xv_list_image_formats_format (list);
248 #else
249     f = (xcb_xv_image_format_info_t *) (list + 1);
250 #endif
251     end = f + xcb_xv_list_image_formats_format_length (list);
252     for (; f < end; f++)
253     {
254         if (chroma != ParseFormat (vd, f))
255             continue;
256
257         /* VLC pads scanline to 16 pixels internally */
258         unsigned width = (fmt->i_width + 15) & ~15;
259         unsigned height = (fmt->i_height + 15) & ~15;
260         xcb_xv_query_image_attributes_reply_t *i;
261         i = xcb_xv_query_image_attributes_reply (conn,
262             xcb_xv_query_image_attributes (conn, port, f->id,
263                                            width, height), NULL);
264         if (i == NULL)
265             continue;
266
267         if (i->width != width || i->height != height)
268         {
269             msg_Warn (vd, "incompatible size %ux%u -> %"PRIu32"x%"PRIu32,
270                       fmt->i_width, fmt->i_height,
271                       i->width, i->height);
272             free (i);
273             continue;
274         }
275         *pa = i;
276         return f;
277     }
278     return NULL;
279 }
280
281
282 /**
283  * Probe the X server.
284  */
285 static int Open (vlc_object_t *obj)
286 {
287     vout_display_t *vd = (vout_display_t *)obj;
288     vout_display_sys_t *p_sys = malloc (sizeof (*p_sys));
289     if (p_sys == NULL)
290         return VLC_ENOMEM;
291
292     vd->sys = p_sys;
293
294     /* Connect to X */
295     xcb_connection_t *conn = Connect (obj);
296     if (conn == NULL)
297     {
298         free (p_sys);
299         return VLC_EGENERIC;
300     }
301     p_sys->conn = conn;
302
303     if (!CheckXVideo (vd, conn))
304     {
305         msg_Warn (vd, "Please enable XVideo 2.2 for faster video display");
306         xcb_disconnect (conn);
307         free (p_sys);
308         return VLC_EGENERIC;
309     }
310
311     const xcb_screen_t *screen;
312     p_sys->embed = GetWindow (vd, conn, &screen, &p_sys->shm);
313     if (p_sys->embed == NULL)
314     {
315         xcb_disconnect (conn);
316         free (p_sys);
317         return VLC_EGENERIC;
318     }
319
320     /* */
321     p_sys->att = NULL;
322     p_sys->pool = NULL;
323
324     /* Cache adaptors infos */
325     xcb_xv_query_adaptors_reply_t *adaptors =
326         xcb_xv_query_adaptors_reply (conn,
327             xcb_xv_query_adaptors (conn, p_sys->embed->handle.xid), NULL);
328     if (adaptors == NULL)
329         goto error;
330
331     int forced_adaptor = var_CreateGetInteger (obj, "xvideo-adaptor");
332
333     /* */
334     video_format_t fmt = vd->fmt;
335     bool found_adaptor = false;
336
337     xcb_xv_adaptor_info_iterator_t it;
338     for (it = xcb_xv_query_adaptors_info_iterator (adaptors);
339          it.rem > 0 && !found_adaptor;
340          xcb_xv_adaptor_info_next (&it))
341     {
342         const xcb_xv_adaptor_info_t *a = it.data;
343         char *name;
344
345         if (forced_adaptor != -1 && forced_adaptor != 0)
346         {
347             forced_adaptor--;
348             continue;
349         }
350
351         if (!(a->type & XCB_XV_TYPE_IMAGE_MASK))
352             continue;
353
354         xcb_xv_list_image_formats_reply_t *r =
355             xcb_xv_list_image_formats_reply (conn,
356                 xcb_xv_list_image_formats (conn, a->base_id), NULL);
357         if (r == NULL)
358             continue;
359
360         /* Look for an image format */
361         const xcb_xv_image_format_info_t *xfmt = NULL;
362         const vlc_fourcc_t *chromas, chromas_default[] = {
363             fmt.i_chroma,
364             VLC_CODEC_RGB32,
365             VLC_CODEC_RGB24,
366             VLC_CODEC_RGB16,
367             VLC_CODEC_RGB15,
368             VLC_CODEC_YUYV,
369             0
370         };
371         if (vlc_fourcc_IsYUV (fmt.i_chroma))
372             chromas = vlc_fourcc_GetYUVFallback (fmt.i_chroma);
373         else
374             chromas = chromas_default;
375
376         vlc_fourcc_t chroma;
377         for (size_t i = 0; chromas[i]; i++)
378         {
379             chroma = chromas[i];
380
381             /* Oink oink! */
382             if ((chroma == VLC_CODEC_I420 || chroma == VLC_CODEC_YV12)
383              && a->name_size >= 4
384              && !memcmp ("OMAP", xcb_xv_adaptor_info_name (a), 4))
385             {
386                 msg_Dbg (vd, "skipping slow I420 format");
387                 continue; /* OMAP framebuffer sucks at YUV 4:2:0 */
388             }
389
390             xfmt = FindFormat (vd, chroma, &fmt, a->base_id, r, &p_sys->att);
391             if (xfmt != NULL)
392             {
393                 p_sys->id = xfmt->id;
394                 fmt.i_chroma = chroma;
395                 if (xfmt->type == XCB_XV_IMAGE_FORMAT_INFO_TYPE_RGB)
396                 {
397                     fmt.i_rmask = xfmt->red_mask;
398                     fmt.i_gmask = xfmt->green_mask;
399                     fmt.i_bmask = xfmt->blue_mask;
400                 }
401                 break;
402             }
403         }
404         free (r);
405         if (xfmt == NULL) /* No acceptable image formats */
406             continue;
407
408         /* Grab a port */
409         for (unsigned i = 0; i < a->num_ports; i++)
410         {
411              xcb_xv_port_t port = a->base_id + i;
412              xcb_xv_grab_port_reply_t *gr =
413                  xcb_xv_grab_port_reply (conn,
414                      xcb_xv_grab_port (conn, port, XCB_CURRENT_TIME), NULL);
415              uint8_t result = gr ? gr->result : 0xff;
416
417              free (gr);
418              if (result == 0)
419              {
420                  p_sys->port = port;
421                  found_adaptor = true;
422                  break;
423              }
424              msg_Dbg (vd, "cannot grab port %"PRIu32, port);
425         }
426         if (!found_adaptor)
427             continue;
428
429         /* Found port - initialize selected format */
430         name = strndup (xcb_xv_adaptor_info_name (a), a->name_size);
431         if (name != NULL)
432         {
433             msg_Dbg (vd, "using adaptor %s", name);
434             free (name);
435         }
436         msg_Dbg (vd, "using port %"PRIu32, p_sys->port);
437         msg_Dbg (vd, "using image format 0x%"PRIx32, p_sys->id);
438     }
439     free (adaptors);
440     if (!found_adaptor)
441     {
442         msg_Err (vd, "no available XVideo adaptor");
443         goto error;
444     }
445
446     /* Create window */
447     {
448         const uint32_t mask =
449             /* XCB_CW_EVENT_MASK */
450             XCB_EVENT_MASK_VISIBILITY_CHANGE;
451         xcb_void_cookie_t c;
452         xcb_window_t window = xcb_generate_id (conn);
453
454         c = xcb_create_window_checked (conn, screen->root_depth, window,
455                                        p_sys->embed->handle.xid, 0, 0, 1, 1, 0,
456                                        XCB_WINDOW_CLASS_INPUT_OUTPUT,
457                                        screen->root_visual,
458                                        XCB_CW_EVENT_MASK, &mask);
459         if (CheckError (vd, conn, "cannot create X11 window", c))
460             goto error;
461         p_sys->window = window;
462         msg_Dbg (vd, "using X11 window 0x%08"PRIx32, window);
463         xcb_map_window (conn, window);
464
465         vout_display_place_t place;
466
467         vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
468         p_sys->width  = place.width;
469         p_sys->height = place.height;
470
471         /* */
472         const uint32_t values[] = { place.x, place.y, place.width, place.height };
473         xcb_configure_window (conn, window,
474                               XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
475                               XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
476                               values);
477     }
478     p_sys->visible = false;
479
480     /* Create graphic context */
481     p_sys->gc = xcb_generate_id (conn);
482     xcb_create_gc (conn, p_sys->gc, p_sys->window, 0, NULL);
483     msg_Dbg (vd, "using X11 graphic context 0x%08"PRIx32, p_sys->gc);
484
485     /* Create cursor */
486     p_sys->cursor = CreateBlankCursor (conn, screen);
487
488     /* */
489     p_sys->pool = NULL;
490
491     /* */
492     vout_display_info_t info = vd->info;
493     info.has_pictures_invalid = false;
494
495     /* Setup vout_display_t once everything is fine */
496     vd->fmt = fmt;
497     vd->info = info;
498
499     vd->get = Get;
500     vd->prepare = NULL;
501     vd->display = Display;
502     vd->control = Control;
503     vd->manage = Manage;
504
505     /* */
506     vout_display_SendEventFullscreen (vd, false);
507     unsigned width, height;
508     if (!GetWindowSize (p_sys->embed, conn, &width, &height))
509         vout_display_SendEventDisplaySize (vd, width, height, false);
510
511     return VLC_SUCCESS;
512
513 error:
514     Close (obj);
515     return VLC_EGENERIC;
516 }
517
518
519 /**
520  * Disconnect from the X server.
521  */
522 static void Close (vlc_object_t *obj)
523 {
524     vout_display_t *vd = (vout_display_t *)obj;
525     vout_display_sys_t *p_sys = vd->sys;
526
527     if (p_sys->pool)
528     {
529         for (unsigned i = 0; i < MAX_PICTURES; i++)
530         {
531             picture_resource_t *res = &p_sys->resource[i];
532
533             if (!res->p->p_pixels)
534                 break;
535             PictureResourceFree (res, NULL);
536         }
537         picture_pool_Delete (p_sys->pool);
538     }
539
540     free (p_sys->att);
541     vout_display_DeleteWindow (vd, p_sys->embed);
542     xcb_disconnect (p_sys->conn);
543     free (p_sys);
544 }
545
546 /**
547  * Return a direct buffer
548  */
549 static picture_t *Get (vout_display_t *vd)
550 {
551     vout_display_sys_t *p_sys = vd->sys;
552
553     if (!p_sys->pool)
554     {
555         picture_t *pic = picture_New (vd->fmt.i_chroma, p_sys->att->width,
556                                       p_sys->att->height, 0);
557         if (!pic)
558             return NULL;
559
560         memset (p_sys->resource, 0, sizeof(p_sys->resource));
561
562         const uint32_t *offsets =
563             xcb_xv_query_image_attributes_offsets (p_sys->att);
564         p_sys->data_size = p_sys->att->data_size;
565
566         unsigned count;
567         picture_t *pic_array[MAX_PICTURES];
568         for (count = 0; count < MAX_PICTURES; count++)
569         {
570             picture_resource_t *res = &p_sys->resource[count];
571
572             for (int i = 0; i < pic->i_planes; i++)
573             {
574                 res->p[i].i_lines = pic->p[i].i_lines; /* FIXME seems wrong*/
575                 res->p[i].i_pitch = pic->p[i].i_pitch;
576             }
577             if (PictureResourceAlloc (vd, res, p_sys->att->data_size,
578                                       p_sys->conn, p_sys->shm))
579                 break;
580
581             /* Allocate further planes as specified by XVideo */
582             /* We assume that offsets[0] is zero */
583             for (int i = 1; i < pic->i_planes; i++)
584                 res->p[i].p_pixels = res->p[0].p_pixels + offsets[i];
585             if (vd->fmt.i_chroma == VLC_CODEC_YV12)
586             {   /* YVU: swap U and V planes */
587                 uint8_t *buf = res->p[2].p_pixels;
588                 res->p[2].p_pixels = res->p[1].p_pixels;
589                 res->p[1].p_pixels = buf;
590             }
591
592             pic_array[count] = picture_NewFromResource (&vd->fmt, res);
593             if (!pic_array[count])
594             {
595                 PictureResourceFree (res, p_sys->conn);
596                 memset (res, 0, sizeof(*res));
597                 break;
598             }
599         }
600         picture_Release (pic);
601
602         if (count == 0)
603             return NULL;
604
605         p_sys->pool = picture_pool_New (count, pic_array);
606         if (!p_sys->pool)
607         {
608             /* TODO release picture resources */
609             return NULL;
610         }
611         /* FIXME should also do it in case of error ? */
612         xcb_flush (p_sys->conn);
613     }
614
615     return picture_pool_Get (p_sys->pool);
616 }
617
618 /**
619  * Sends an image to the X server.
620  */
621 static void Display (vout_display_t *vd, picture_t *pic)
622 {
623     vout_display_sys_t *p_sys = vd->sys;
624     xcb_shm_seg_t segment = pic->p_sys->segment;
625     xcb_void_cookie_t ck;
626
627     if (!p_sys->visible)
628         goto out;
629     if (segment)
630         ck = xcb_xv_shm_put_image_checked (p_sys->conn, p_sys->port,
631                               p_sys->window, p_sys->gc, segment, p_sys->id, 0,
632                    /* Src: */ vd->source.i_x_offset,
633                               vd->source.i_y_offset,
634                               vd->source.i_visible_width,
635                               vd->source.i_visible_height,
636                    /* Dst: */ 0, 0, p_sys->width, p_sys->height,
637                 /* Memory: */ pic->p->i_pitch / pic->p->i_pixel_pitch,
638                               pic->p->i_lines, false);
639     else
640         ck = xcb_xv_put_image_checked (p_sys->conn, p_sys->port, p_sys->window,
641                           p_sys->gc, p_sys->id,
642                           vd->source.i_x_offset,
643                           vd->source.i_y_offset,
644                           vd->source.i_visible_width,
645                           vd->source.i_visible_height,
646                           0, 0, p_sys->width, p_sys->height,
647                           pic->p->i_pitch / pic->p->i_pixel_pitch,
648                           pic->p->i_lines,
649                           p_sys->data_size, pic->p->p_pixels);
650
651     /* Wait for reply. See x11.c for rationale. */
652     xcb_generic_error_t *e = xcb_request_check (p_sys->conn, ck);
653     if (e != NULL)
654     {
655         msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code);
656         free (e);
657     }
658 out:
659     picture_Release (pic);
660 }
661
662 static int Control (vout_display_t *vd, int query, va_list ap)
663 {
664     vout_display_sys_t *p_sys = vd->sys;
665
666     switch (query)
667     {
668     case VOUT_DISPLAY_CHANGE_FULLSCREEN:
669     {
670         const vout_display_cfg_t *c = va_arg (ap, const vout_display_cfg_t *);
671         return vout_window_SetFullScreen (p_sys->embed, c->is_fullscreen);
672     }
673
674     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
675     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
676     case VOUT_DISPLAY_CHANGE_ZOOM:
677     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
678     case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
679     {
680         const vout_display_cfg_t *cfg;
681         const video_format_t *source;
682         bool is_forced;
683
684         if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT
685          || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
686         {
687             source = (const video_format_t *)va_arg (ap, const video_format_t *);
688             cfg = vd->cfg;
689         }
690         else
691         {
692             source = &vd->source;
693             cfg = (const vout_display_cfg_t*)va_arg (ap, const vout_display_cfg_t *);
694             if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
695                 is_forced = (bool)va_arg (ap, int);
696         }
697
698         /* */
699         if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE
700          && is_forced
701          && (cfg->display.width  != vd->cfg->display.width
702            ||cfg->display.height != vd->cfg->display.height)
703          && vout_window_SetSize (p_sys->embed,
704                                   cfg->display.width,
705                                   cfg->display.height))
706             return VLC_EGENERIC;
707
708         vout_display_place_t place;
709         vout_display_PlacePicture (&place, source, cfg, false);
710         p_sys->width  = place.width;
711         p_sys->height = place.height;
712
713         /* Move the picture within the window */
714         const uint32_t values[] = { place.x, place.y,
715                                     place.width, place.height, };
716         xcb_configure_window (p_sys->conn, p_sys->window,
717                               XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
718                             | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
719                               values);
720         xcb_flush (p_sys->conn);
721         return VLC_SUCCESS;
722     }
723     case VOUT_DISPLAY_CHANGE_ON_TOP:
724     {
725         int on_top = (int)va_arg (ap, int);
726         return vout_window_SetOnTop (p_sys->embed, on_top);
727     }
728
729     /* Hide the mouse. It will be send when
730      * vout_display_t::info.b_hide_mouse is false */
731     case VOUT_DISPLAY_HIDE_MOUSE:
732         xcb_change_window_attributes (p_sys->conn, p_sys->embed->handle.xid,
733                                   XCB_CW_CURSOR, &(uint32_t){ p_sys->cursor });
734         return VLC_SUCCESS;
735     case VOUT_DISPLAY_RESET_PICTURES:
736         assert(0);
737     default:
738         msg_Err (vd, "Unknown request in XCB vout display");
739         return VLC_EGENERIC;
740     }
741 }
742
743 static void Manage (vout_display_t *vd)
744 {
745     vout_display_sys_t *p_sys = vd->sys;
746
747     ManageEvent (vd, p_sys->conn, &p_sys->visible);
748 }
749