]> git.sesse.net Git - vlc/blob - modules/hw/vdpau/display.c
vdpau: use custom picture destroy callback
[vlc] / modules / hw / vdpau / display.c
1 /**
2  * @file display.c
3  * @brief VDPAU video display module for VLC media player
4  */
5 /*****************************************************************************
6  * Copyright © 2009-2013 Rémi Denis-Courmont
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program 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 Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, 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
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_vout_display.h>
35 #include <vlc_picture_pool.h>
36 #include <vlc_xlib.h>
37
38 #include "vlc_vdpau.h"
39 #include "events.h"
40
41 static int Open(vlc_object_t *);
42 static void Close(vlc_object_t *);
43
44 vlc_module_begin()
45     set_shortname(N_("VDPAU"))
46     set_description(N_("VDPAU output"))
47     set_category(CAT_VIDEO)
48     set_subcategory(SUBCAT_VIDEO_VOUT)
49     set_capability("vout display", 300)
50     set_callbacks(Open, Close)
51
52     add_shortcut("vdpau", "xid")
53 vlc_module_end()
54
55 struct vout_display_sys_t
56 {
57     xcb_connection_t *conn; /**< XCB connection */
58     vout_window_t *embed; /**< parent window */
59     vdp_t *vdp; /**< VDPAU back-end */
60     picture_t *current; /**< Currently visible picture */
61
62     xcb_window_t window; /**< target window (owned by VDPAU back-end) */
63     xcb_cursor_t cursor; /**< blank cursor */
64     VdpDevice device; /**< VDPAU device handle */
65     VdpPresentationQueueTarget target; /**< VDPAU presentation queue target */
66     VdpPresentationQueue queue; /**< VDPAU presentation queue */
67     VdpRGBAFormat rgb_fmt; /**< Output surface format */
68
69     picture_pool_t *pool; /**< pictures pool */
70 };
71
72 static void pictureSys_DestroyVDPAU(picture_sys_t *psys)
73 {
74     vdp_output_surface_destroy(psys->vdp, psys->surface);
75     vdp_release_x11(psys->vdp);
76     free(psys);
77 }
78
79 static void PictureDestroyVDPAU(picture_t *pic)
80 {
81     pictureSys_DestroyVDPAU(pic->p_sys);
82     free(pic);
83 }
84
85 static VdpStatus picture_NewVDPAU(vdp_t *vdp, VdpRGBAFormat rgb_fmt,
86                                   const video_format_t *restrict fmt,
87                                   picture_t **restrict picp)
88 {
89     picture_sys_t *psys = malloc(sizeof (*psys));
90     if (unlikely(psys == NULL))
91         return VDP_STATUS_RESOURCES;
92
93     psys->vdp = vdp_hold_x11(vdp, &psys->device);
94
95     VdpStatus err = vdp_output_surface_create(psys->vdp, psys->device,
96                           rgb_fmt, fmt->i_visible_width, fmt->i_visible_height,
97                                               &psys->surface);
98     if (err != VDP_STATUS_OK)
99     {
100         vdp_release_x11(psys->vdp);
101         free(psys);
102         return err;
103     }
104
105     picture_resource_t res = {
106         .p_sys = psys,
107         .pf_destroy = PictureDestroyVDPAU,
108     };
109
110     picture_t *pic = picture_NewFromResource(fmt, &res);
111     if (unlikely(pic == NULL))
112     {
113         pictureSys_DestroyVDPAU(psys);
114         return VDP_STATUS_RESOURCES;
115     }
116     *picp = pic;
117     return VDP_STATUS_OK;
118 }
119
120 static picture_pool_t *PoolAlloc(vout_display_t *vd, unsigned requested_count)
121 {
122     vout_display_sys_t *sys = vd->sys;
123     picture_t *pics[requested_count];
124
125     unsigned count = 0;
126     while (count < requested_count)
127     {
128         VdpStatus err = picture_NewVDPAU(sys->vdp, sys->rgb_fmt, &vd->fmt,
129                                          pics + count);
130         if (err != VDP_STATUS_OK)
131         {
132             msg_Err(vd, "%s creation failure: %s", "output surface",
133                     vdp_get_error_string(sys->vdp, err));
134             break;
135         }
136         count++;
137     }
138     sys->current = NULL;
139     return count ? picture_pool_New(count, pics) : NULL;
140 }
141
142 static void PoolFree(vout_display_t *vd, picture_pool_t *pool)
143 {
144     vout_display_sys_t *sys = vd->sys;
145
146     if (sys->current != NULL)
147         picture_Release(sys->current);
148     picture_pool_Delete(pool);
149 }
150
151 static picture_pool_t *Pool(vout_display_t *vd, unsigned requested_count)
152 {
153     vout_display_sys_t *sys = vd->sys;
154
155     if (sys->pool == NULL)
156         sys->pool = PoolAlloc(vd, requested_count);
157     return sys->pool;
158 }
159
160 static void RenderRegion(vout_display_t *vd, VdpOutputSurface target,
161                          const subpicture_region_t *reg, int alpha)
162 {
163     vout_display_sys_t *sys = vd->sys;
164     VdpBitmapSurface surface;
165     VdpRGBAFormat fmt = VDP_RGBA_FORMAT_R8G8B8A8; /* TODO? YUVA */
166     VdpStatus err;
167
168     /* Create GPU surface for sub-picture */
169     err = vdp_bitmap_surface_create(sys->vdp, sys->device, fmt,
170         reg->fmt.i_visible_width, reg->fmt.i_visible_height, VDP_FALSE,
171                                     &surface);
172     if (err != VDP_STATUS_OK)
173     {
174         msg_Err(vd, "%s creation failure: %s", "bitmap surface",
175                 vdp_get_error_string(sys->vdp, err));
176         return;
177     }
178
179     /* Upload sub-picture to GPU surface */
180     picture_t *subpic = reg->p_picture;
181     const void *data = subpic->p[0].p_pixels;
182     uint32_t pitch = subpic->p[0].i_pitch;
183
184     err = vdp_bitmap_surface_put_bits_native(sys->vdp, surface, &data, &pitch,
185                                              NULL);
186     if (err != VDP_STATUS_OK)
187     {
188         msg_Err(vd, "subpicture upload failure: %s",
189                 vdp_get_error_string(sys->vdp, err));
190         goto out;
191     }
192
193     /* Render onto main surface */
194     VdpRect area = {
195         reg->i_x,
196         reg->i_y,
197         reg->i_x + reg->fmt.i_visible_width,
198         reg->i_y + reg->fmt.i_visible_height,
199     };
200     VdpColor color = { 1.f, 1.f, 1.f, reg->i_alpha * alpha / 65535.f };
201     VdpOutputSurfaceRenderBlendState state = {
202         .struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION,
203         .blend_factor_source_color =
204             VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA,
205         .blend_factor_destination_color =
206             VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
207         .blend_factor_source_alpha =
208             VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ZERO,
209         .blend_factor_destination_alpha =
210             VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
211         .blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
212         .blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
213         .blend_constant = { 0.f, 0.f, 0.f, 0.f },
214     };
215
216     err = vdp_output_surface_render_bitmap_surface(sys->vdp, target, &area,
217                                              surface, NULL, &color, &state, 0);
218     if (err != VDP_STATUS_OK)
219         msg_Err(vd, "blending failure: %s",
220                 vdp_get_error_string(sys->vdp, err));
221
222 out:/* Destroy GPU surface */
223     vdp_bitmap_surface_destroy(sys->vdp, surface);
224 }
225
226 static void Queue(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)
227 {
228     vout_display_sys_t *sys = vd->sys;
229     VdpOutputSurface surface = pic->p_sys->surface;
230     VdpStatus err;
231
232     VdpPresentationQueueStatus status;
233     VdpTime ts;
234     err = vdp_presentation_queue_query_surface_status(sys->vdp, sys->queue,
235                                                       surface, &status, &ts);
236     if (err == VDP_STATUS_OK && status != VDP_PRESENTATION_QUEUE_STATUS_IDLE)
237         msg_Dbg(vd, "surface status: %u", status);
238
239     if (subpic != NULL)
240         for (subpicture_region_t *r = subpic->p_region; r != NULL;
241              r = r->p_next)
242             RenderRegion(vd, surface, r, subpic->i_alpha);
243
244     /* Compute picture presentation time */
245     mtime_t now = mdate();
246     VdpTime pts;
247
248     err = vdp_presentation_queue_get_time(sys->vdp, sys->queue, &pts);
249     if (err != VDP_STATUS_OK)
250     {
251         msg_Err(vd, "presentation queue time failure: %s",
252                 vdp_get_error_string(sys->vdp, err));
253         if (err == VDP_STATUS_DISPLAY_PREEMPTED)
254             vout_display_SendEventPicturesInvalid(vd);
255         return;
256     }
257
258     mtime_t delay = pic->date - now;
259     if (delay < 0)
260         delay = 0; /* core bug: date is not updated during pause */
261     if (unlikely(delay > CLOCK_FREQ))
262     {   /* We would get stuck if the delay was too long. */
263         msg_Dbg(vd, "picture date corrupt: delay of %"PRId64" us", delay);
264         delay = CLOCK_FREQ / 50;
265     }
266     pts += delay * 1000;
267
268     /* Queue picture */
269     err = vdp_presentation_queue_display(sys->vdp, sys->queue, surface, 0, 0,
270                                          pts);
271     if (err != VDP_STATUS_OK)
272         msg_Err(vd, "presentation queue display failure: %s",
273                 vdp_get_error_string(sys->vdp, err));
274 }
275
276 static void Wait(vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
277 {
278     vout_display_sys_t *sys = vd->sys;
279
280     picture_t *current = sys->current;
281     if (current != NULL)
282     {
283         picture_sys_t *psys = current->p_sys;
284         VdpTime pts;
285         VdpStatus err;
286
287         err = vdp_presentation_queue_block_until_surface_idle(sys->vdp,
288                                               sys->queue, psys->surface, &pts);
289         if (err != VDP_STATUS_OK)
290         {
291             msg_Err(vd, "presentation queue blocking error: %s",
292                     vdp_get_error_string(sys->vdp, err));
293             picture_Release(pic);
294             return;
295         }
296         picture_Release(current);
297     }
298
299     sys->current = pic;
300     (void) subpicture;
301 }
302
303 static int Control(vout_display_t *vd, int query, va_list ap)
304 {
305     vout_display_sys_t *sys = vd->sys;
306
307     switch (query)
308     {
309     case VOUT_DISPLAY_HIDE_MOUSE:
310         xcb_change_window_attributes(sys->conn, sys->embed->handle.xid,
311                                     XCB_CW_CURSOR, &(uint32_t){ sys->cursor });
312         break;
313     case VOUT_DISPLAY_RESET_PICTURES:
314     {
315         msg_Dbg(vd, "resetting pictures");
316         if (sys->pool != NULL)
317         {
318             PoolFree(vd, sys->pool);
319             sys->pool = NULL;
320         }
321
322         const video_format_t *src= &vd->source;
323         video_format_t *fmt = &vd->fmt;
324         vout_display_place_t place;
325
326         vout_display_PlacePicture(&place, src, vd->cfg, false);
327
328         fmt->i_width = src->i_width * place.width / src->i_visible_width;
329         fmt->i_height = src->i_height * place.height / src->i_visible_height;
330         fmt->i_visible_width  = place.width;
331         fmt->i_visible_height = place.height;
332         fmt->i_x_offset = src->i_x_offset * place.width / src->i_visible_width;
333         fmt->i_y_offset = src->i_y_offset * place.height / src->i_visible_height;
334
335         const uint32_t values[] = { place.x, place.y,
336                                     place.width, place.height, };
337         xcb_configure_window(sys->conn, sys->window,
338                              XCB_CONFIG_WINDOW_X|XCB_CONFIG_WINDOW_Y|
339                              XCB_CONFIG_WINDOW_WIDTH|XCB_CONFIG_WINDOW_HEIGHT,
340                              values);
341         break;
342     }
343     case VOUT_DISPLAY_CHANGE_FULLSCREEN:
344     {
345         const vout_display_cfg_t *c = va_arg(ap, const vout_display_cfg_t *);
346         return vout_window_SetFullScreen(sys->embed, c->is_fullscreen);
347     }
348     case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
349     {
350         unsigned state = va_arg(ap, unsigned);
351         return vout_window_SetState(sys->embed, state);
352     }
353     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
354     {
355         const vout_display_cfg_t *cfg = va_arg(ap, const vout_display_cfg_t *);
356         bool forced = va_arg(ap, int);
357         if (forced)
358         {
359             vout_window_SetSize(sys->embed,
360                                 cfg->display.width, cfg->display.height);
361             return VLC_EGENERIC; /* Always fail. See x11.c for rationale. */
362         }
363
364         vout_display_place_t place;
365         vout_display_PlacePicture(&place, &vd->source, cfg, false);
366         if (place.width  != vd->fmt.i_visible_width
367          || place.height != vd->fmt.i_visible_height)
368         {
369             vout_display_SendEventPicturesInvalid(vd);
370             return VLC_SUCCESS;
371         }
372
373         const uint32_t values[] = { place.x, place.y,
374                                     place.width, place.height, };
375         xcb_configure_window(sys->conn, sys->window,
376                              XCB_CONFIG_WINDOW_X|XCB_CONFIG_WINDOW_Y|
377                              XCB_CONFIG_WINDOW_WIDTH|XCB_CONFIG_WINDOW_HEIGHT,
378                              values);
379         break;
380     }
381     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
382     case VOUT_DISPLAY_CHANGE_ZOOM:
383     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
384     case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
385         vout_display_SendEventPicturesInvalid (vd);
386         return VLC_SUCCESS;
387     default:
388         msg_Err(vd, "unknown control request %d", query);
389         return VLC_EGENERIC;
390     }
391     xcb_flush (sys->conn);
392     return VLC_SUCCESS;
393 }
394
395 static void Manage(vout_display_t *vd)
396 {
397     vout_display_sys_t *sys = vd->sys;
398     bool visible;
399
400     XCB_Manage(vd, sys->conn, &visible);
401 }
402
403 static int xcb_screen_num(xcb_connection_t *conn, const xcb_screen_t *screen)
404 {
405     const xcb_setup_t *setup = xcb_get_setup(conn);
406     unsigned snum = 0;
407
408     for (xcb_screen_iterator_t i = xcb_setup_roots_iterator(setup);
409          i.rem > 0; xcb_screen_next(&i))
410     {
411         if (i.data->root == screen->root)
412             return snum;
413         snum++;
414     }
415     return -1;
416 }
417
418 static int Open(vlc_object_t *obj)
419 {
420     if (!vlc_xlib_init(obj))
421         return VLC_EGENERIC;
422
423     vout_display_t *vd = (vout_display_t *)obj;
424     vout_display_sys_t *sys = malloc(sizeof (*sys));
425     if (unlikely(sys == NULL))
426         return VLC_ENOMEM;
427
428     const xcb_screen_t *screen;
429     uint16_t width, height;
430     sys->embed = XCB_parent_Create(vd, &sys->conn, &screen, &width, &height);
431     if (sys->embed == NULL)
432     {
433         free(sys);
434         return VLC_EGENERIC;
435     }
436
437     /* Load the VDPAU back-end and create a device instance */
438     VdpStatus err = vdp_get_x11(sys->embed->display.x11,
439                                 xcb_screen_num(sys->conn, screen),
440                                 &sys->vdp, &sys->device);
441     if (err != VDP_STATUS_OK)
442     {
443         msg_Dbg(obj, "device creation failure: error %d", (int)err);
444         xcb_disconnect(sys->conn);
445         vout_display_DeleteWindow(vd, sys->embed);
446         free(sys);
447         return VLC_EGENERIC;
448     }
449
450     const char *info;
451     if (vdp_get_information_string(sys->vdp, &info) == VDP_STATUS_OK)
452         msg_Dbg(vd, "using back-end %s", info);
453
454     /* Check source format */
455     VdpChromaType chroma;
456     VdpYCbCrFormat format;
457     if (vd->fmt.i_chroma == VLC_CODEC_VDPAU_VIDEO_420
458      || vd->fmt.i_chroma == VLC_CODEC_VDPAU_VIDEO_422)
459         ;
460     else
461     if (vlc_fourcc_to_vdp_ycc(vd->fmt.i_chroma, &chroma, &format))
462     {
463         uint32_t w, h;
464         VdpBool ok;
465
466         err = vdp_video_surface_query_capabilities(sys->vdp, sys->device,
467                                                    chroma, &ok, &w, &h);
468         if (err != VDP_STATUS_OK)
469         {
470             msg_Err(vd, "%s capabilities query failure: %s", "video surface",
471                     vdp_get_error_string(sys->vdp, err));
472             goto error;
473         }
474         if (!ok || w < vd->fmt.i_width || h < vd->fmt.i_height)
475         {
476             msg_Err(vd, "source video %s not supported", "chroma type");
477             goto error;
478         }
479
480         err = vdp_video_surface_query_get_put_bits_y_cb_cr_capabilities(
481                                    sys->vdp, sys->device, chroma, format, &ok);
482         if (err != VDP_STATUS_OK)
483         {
484             msg_Err(vd, "%s capabilities query failure: %s", "video surface",
485                     vdp_get_error_string(sys->vdp, err));
486             goto error;
487         }
488         if (!ok)
489         {
490             msg_Err(vd, "source video %s not supported", "YCbCr format");
491             goto error;
492         }
493     }
494     else
495         goto error;
496
497     /* Check video mixer capabilities */
498     {
499         uint32_t min, max;
500
501         err = vdp_video_mixer_query_parameter_value_range(sys->vdp,
502                     sys->device, VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
503                                                           &min, &max);
504         if (err != VDP_STATUS_OK)
505         {
506             msg_Err(vd, "%s capabilities query failure: %s",
507                     "video mixer surface width",
508                     vdp_get_error_string(sys->vdp, err));
509             goto error;
510         }
511         if (min > vd->fmt.i_width || vd->fmt.i_width > max)
512         {
513             msg_Err(vd, "source video %s not supported", "width");
514             goto error;
515         }
516
517         err = vdp_video_mixer_query_parameter_value_range(sys->vdp,
518                    sys->device, VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
519                                                           &min, &max);
520         if (err != VDP_STATUS_OK)
521         {
522             msg_Err(vd, "%s capabilities query failure: %s",
523                     "video mixer surface width",
524                     vdp_get_error_string(sys->vdp, err));
525             goto error;
526         }
527         if (min > vd->fmt.i_height || vd->fmt.i_height > max)
528         {
529             msg_Err(vd, "source video %s not supported", "height");
530             goto error;
531         }
532     }
533
534     /* Select surface format */
535     static const VdpRGBAFormat rgb_fmts[] = {
536         VDP_RGBA_FORMAT_R10G10B10A2, VDP_RGBA_FORMAT_B10G10R10A2,
537         VDP_RGBA_FORMAT_B8G8R8A8, VDP_RGBA_FORMAT_R8G8B8A8,
538     };
539     unsigned i;
540
541     for (i = 0; i < sizeof (rgb_fmts) / sizeof (rgb_fmts[0]); i++)
542     {
543         uint32_t w, h;
544         VdpBool ok;
545
546         err = vdp_output_surface_query_capabilities(sys->vdp, sys->device,
547                                                     rgb_fmts[i], &ok, &w, &h);
548         if (err != VDP_STATUS_OK)
549         {
550             msg_Err(vd, "%s capabilities query failure: %s", "output surface",
551                     vdp_get_error_string(sys->vdp, err));
552             continue;
553         }
554         /* NOTE: Wrong! No warranties that zoom <= 100%! */
555         if (!ok || w < vd->fmt.i_width || h < vd->fmt.i_height)
556             continue;
557
558         sys->rgb_fmt = rgb_fmts[i];
559         msg_Dbg(vd, "using RGBA format %u", sys->rgb_fmt);
560         break;
561     }
562     if (i == sizeof (rgb_fmts) / sizeof (rgb_fmts[0]))
563     {
564         msg_Err(vd, "no supported output surface format");
565         goto error;
566     }
567
568     /* VDPAU-X11 requires a window dedicated to the back-end */
569     {
570         xcb_pixmap_t pix = xcb_generate_id(sys->conn);
571         xcb_create_pixmap(sys->conn, screen->root_depth, pix,
572                           screen->root, 1, 1);
573
574         uint32_t mask =
575             XCB_CW_BACK_PIXMAP | XCB_CW_BACK_PIXEL |
576             XCB_CW_BORDER_PIXMAP | XCB_CW_BORDER_PIXEL |
577             XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
578         const uint32_t values[] = {
579             pix, screen->black_pixel, pix, screen->black_pixel,
580             XCB_EVENT_MASK_VISIBILITY_CHANGE, screen->default_colormap
581         };
582         vout_display_place_t place;
583
584         vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
585         sys->window = xcb_generate_id(sys->conn);
586
587         xcb_void_cookie_t c =
588             xcb_create_window_checked(sys->conn, screen->root_depth,
589                 sys->window, sys->embed->handle.xid, place.x, place.y,
590                 place.width, place.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
591                 screen->root_visual, mask, values);
592         if (XCB_error_Check(vd, sys->conn, "window creation failure", c))
593             goto error;
594         msg_Dbg(vd, "using X11 window 0x%08"PRIx32, sys->window);
595         xcb_map_window(sys->conn, sys->window);
596     }
597
598     /* Check bitmap capabilities (for SPU) */
599     const vlc_fourcc_t *spu_chromas = NULL;
600     {
601         static const vlc_fourcc_t subpicture_chromas[] = { VLC_CODEC_RGBA, 0 };
602         uint32_t w, h;
603         VdpBool ok;
604
605         err = vdp_bitmap_surface_query_capabilities(sys->vdp, sys->device,
606                                         VDP_RGBA_FORMAT_R8G8B8A8, &ok, &w, &h);
607         if (err != VDP_STATUS_OK)
608         {
609             msg_Err(vd, "%s capabilities query failure: %s", "output surface",
610                     vdp_get_error_string(sys->vdp, err));
611             ok = VDP_FALSE;
612         }
613         if (ok)
614             spu_chromas = subpicture_chromas;
615     }
616
617     /* Initialize VDPAU queue */
618     err = vdp_presentation_queue_target_create_x11(sys->vdp, sys->device,
619                                                    sys->window, &sys->target);
620     if (err != VDP_STATUS_OK)
621     {
622         msg_Err(vd, "%s creation failure: %s", "presentation queue target",
623                 vdp_get_error_string(sys->vdp, err));
624         goto error;
625     }
626
627     err = vdp_presentation_queue_create(sys->vdp, sys->device, sys->target,
628                                         &sys->queue);
629     if (err != VDP_STATUS_OK)
630     {
631         msg_Err(vd, "%s creation failure: %s", "presentation queue",
632                 vdp_get_error_string(sys->vdp, err));
633         vdp_presentation_queue_target_destroy(sys->vdp, sys->target);
634         goto error;
635     }
636
637     VdpColor black = { 0.f, 0.f, 0.f, 1.f };
638     vdp_presentation_queue_set_background_color(sys->vdp, sys->queue, &black);
639
640     sys->cursor = XCB_cursor_Create(sys->conn, screen);
641     sys->pool = NULL;
642
643     /* */
644     vd->sys = sys;
645     vd->info.has_pictures_invalid = true;
646     vd->info.has_event_thread = true;
647     vd->info.subpicture_chromas = spu_chromas;
648     vd->fmt.i_chroma = VLC_CODEC_VDPAU_OUTPUT;
649
650     vd->pool = Pool;
651     vd->prepare = Queue;
652     vd->display = Wait;
653     vd->control = Control;
654     vd->manage = Manage;
655
656     /* */
657     bool is_fullscreen = vd->cfg->is_fullscreen;
658     if (is_fullscreen && vout_window_SetFullScreen(sys->embed, true))
659         is_fullscreen = false;
660     vout_display_SendEventFullscreen(vd, is_fullscreen);
661     vout_display_SendEventDisplaySize(vd, width, height, is_fullscreen);
662
663     return VLC_SUCCESS;
664
665 error:
666     vdp_release_x11(sys->vdp);
667     xcb_disconnect(sys->conn);
668     vout_display_DeleteWindow(vd, sys->embed);
669     free(sys);
670     return VLC_EGENERIC;
671 }
672
673 static void Close(vlc_object_t *obj)
674 {
675     vout_display_t *vd = (vout_display_t *)obj;
676     vout_display_sys_t *sys = vd->sys;
677
678     /* Restore cursor explicitly (parent window connection will survive) */
679     xcb_change_window_attributes(sys->conn, sys->embed->handle.xid,
680                                XCB_CW_CURSOR, &(uint32_t) { XCB_CURSOR_NONE });
681     xcb_flush(sys->conn);
682
683     vdp_presentation_queue_destroy(sys->vdp, sys->queue);
684     vdp_presentation_queue_target_destroy(sys->vdp, sys->target);
685
686     if (sys->pool != NULL)
687         PoolFree(vd, sys->pool);
688
689     vdp_release_x11(sys->vdp);
690     xcb_disconnect(sys->conn);
691     vout_display_DeleteWindow(vd, sys->embed);
692     free(sys);
693 }