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