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