]> git.sesse.net Git - vlc/blob - modules/video_output/omapfb.c
OMAP framebuffer: let the window manage key presses instead
[vlc] / modules / video_output / omapfb.c
1 /*****************************************************************************
2 * omapfb.c : omap framebuffer plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2008-2009 the VideoLAN team
5 * $Id$
6 *
7 * Authors: Antoine Lejeune <phytos @ videolan.org>
8 *          Based on fb.c and work of Siarhei Siamashka on mplayer for Maemo
9 *          Needs a recent omapfb.h to compile
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <errno.h>                                                 /* ENOMEM */
31 #include <fcntl.h>                                                 /* open() */
32 #include <unistd.h>                                               /* close() */
33
34 #include <sys/ioctl.h>
35 #include <sys/mman.h>                                              /* mmap() */
36
37 #include <linux/fb.h>
38 #include <asm/arch-omap/omapfb.h>
39
40 /* Embedded window handling */
41 #include <X11/Xlib.h>
42 #include <X11/Xutil.h>
43
44 #ifdef HAVE_OSSO
45 #include <libosso.h>
46 #endif
47
48 #include <vlc_common.h>
49 #include <vlc_plugin.h>
50 #include <vlc_vout.h>
51 #include <vlc_vout_window.h>
52 #include <vlc_playlist.h>
53
54 /*****************************************************************************
55 * Local prototypes
56 *****************************************************************************/
57 static int  Create           ( vlc_object_t * );
58 static void Destroy          ( vlc_object_t * );
59
60 static int  Init             ( vout_thread_t * );
61 static void End              ( vout_thread_t * );
62 static int  Manage           ( vout_thread_t * );
63 static void DisplayVideo     ( vout_thread_t *, picture_t * );
64 static int  Control          ( vout_thread_t *, int, va_list );
65
66 static void FreePicture      ( vout_thread_t *, picture_t * );
67
68 static int  OpenDisplay      ( vout_thread_t * );
69 static void CloseDisplay     ( vout_thread_t * );
70 static void UpdateScreen     ( vout_thread_t *,
71                                int, int, int, int, int, int, int );
72
73 static int  InitWindow       ( vout_thread_t * );
74 static void CreateWindow     ( vout_sys_t * );
75 static void ToggleFullScreen ( vout_thread_t * );
76
77 #ifdef HAVE_OSSO
78 static const int i_backlight_on_interval = 300;
79 #endif
80
81 /*****************************************************************************
82  * Module descriptor
83  *****************************************************************************/
84 #define FB_DEV_VAR "omapfbdev"
85
86 #define DEVICE_TEXT N_("OMAP Framebuffer device")
87 #define DEVICE_LONGTEXT N_( \
88     "OMAP Framebuffer device to use for rendering (usually /dev/fb0).")
89
90 #define CHROMA_TEXT N_("Chroma used.")
91 #define CHROMA_LONGTEXT N_( \
92     "Force use of a specific chroma for output. Default is Y420 (specific to N770/N8xx hardware)." )
93
94 #define OVERLAY_TEXT N_("Embed the overlay")
95 #define OVERLAY_LONGTEXT N_( \
96     "Embed the framebuffer overlay into a X11 window" )
97
98 vlc_module_begin();
99     set_shortname( "OMAP framebuffer" );
100     set_category( CAT_VIDEO );
101     set_subcategory( SUBCAT_VIDEO_VOUT );
102     add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
103               false )
104     add_string( "omap-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
105                 true )
106     add_bool( "omap-embedded", true, NULL, OVERLAY_TEXT, OVERLAY_LONGTEXT,
107                  true )
108     set_description( N_("OMAP framebuffer video output") );
109     set_capability( "video output", 200 );
110     set_callbacks( Create, Destroy );
111 vlc_module_end();
112
113 /*****************************************************************************
114  * omap_window_t: simple structure with the geometry of a window
115  *****************************************************************************/
116 struct omap_window_t
117 {
118     uint32_t i_x;
119     uint32_t i_y;
120     uint32_t i_width;
121     uint32_t i_height;
122 };
123
124 /*****************************************************************************
125 * vout_sys_t: video output omap framebuffer method descriptor
126  *****************************************************************************
127  * This structure is part of the video output thread descriptor.
128  * It describes the FB specific properties of an output thread.
129  *****************************************************************************/
130 struct vout_sys_t
131 {
132     /* Framebuffer information */
133     int                         i_fd;                       /* device handle */
134     struct fb_var_screeninfo    fb_vinfo;        /* current mode information */
135     struct fb_fix_screeninfo    fb_finfo;
136     struct omapfb_caps          caps;
137     bool                        b_tearsync;
138
139     /* Window information */
140     struct omap_window_t output_window;    /* Size of the real output window */
141     struct omap_window_t main_window;  /* Size of the area we got to display */
142     struct omap_window_t embedded_window;     /* Size of the embedded window */
143
144     /* Video information */
145     uint32_t             i_video_width;                       /* video width */
146     uint32_t             i_video_height;                     /* video height */
147     vlc_fourcc_t         i_chroma;
148     int                  i_color_format;                   /* OMAPFB_COLOR_* */
149     bool                 b_video_enabled;        /* Video must be displayed? */
150     picture_t           *p_output_picture;
151
152     /* Video memory */
153     uint8_t    *p_video;                                      /* base adress */
154     uint8_t    *p_center;                                   /* output adress */
155     size_t      i_page_size;                                    /* page size */
156     int         i_bytes_per_pixel;                /* Bytes used by one pixel */
157     int         i_line_len;                   /* Length of one line in bytes */
158
159     /* X11 */
160     Display   *p_display;
161     vout_window_t *owner_window;
162     Window     window;
163     mtime_t    i_time_button_last_pressed;         /* To detect double click */
164
165     /* Dummy memory */
166     int        i_null_fd;
167     uint8_t   *p_null;
168
169 #ifdef HAVE_OSSO
170     osso_context_t      *p_octx;
171     int                 i_backlight_on_counter;
172 #endif
173 };
174
175 /*****************************************************************************
176  * Create: allocates omapfb video thread output method
177  *****************************************************************************
178  * This function allocates and initializes a FB vout method.
179  *****************************************************************************/
180 static int Create( vlc_object_t *p_this )
181 {
182     vout_thread_t *p_vout = (vout_thread_t *)p_this;
183     vout_sys_t    *p_sys;
184
185     if( p_vout->fmt_in.i_chroma != VLC_CODEC_I420 &&
186         p_vout->fmt_in.i_chroma != VLC_CODEC_YV12 )
187         return VLC_EGENERIC;
188
189     /* Allocate instance and initialize some members */
190     p_vout->p_sys = p_sys = calloc( 1, sizeof( vout_sys_t ) );
191     if( p_vout->p_sys == NULL )
192         return VLC_ENOMEM;
193
194     p_vout->pf_init = Init;
195     p_vout->pf_end = End;
196     p_vout->pf_manage = Manage;
197     p_vout->pf_render = NULL;
198     p_vout->pf_display = DisplayVideo;
199     p_vout->pf_control = Control;
200     p_sys->b_video_enabled = true;
201
202     if( OpenDisplay( p_vout ) )
203     {
204         free( p_vout->p_sys );
205         return VLC_EGENERIC;
206     }
207
208     if( InitWindow( p_vout ) )
209     {
210         free( p_vout->p_sys );
211         return VLC_EGENERIC;
212     }
213
214 #ifdef HAVE_OSSO
215     p_vout->p_sys->i_backlight_on_counter = i_backlight_on_interval;
216     p_vout->p_sys->p_octx = osso_initialize( "vlc", VERSION, 0, NULL );
217     if ( p_vout->p_sys->p_octx == NULL ) {
218         msg_Err( p_vout, "Could not get osso context" );
219     } else {
220         msg_Dbg( p_vout, "Initialized osso context" );
221     }
222 #endif
223
224     return VLC_SUCCESS;
225 }
226
227 /*****************************************************************************
228  * Destroy: destroy omapfb video thread output method
229  *****************************************************************************
230  * Terminate an output method created by Create
231  *****************************************************************************/
232 static void Destroy( vlc_object_t *p_this )
233 {
234     vout_thread_t *p_vout = (vout_thread_t *)p_this;
235
236     CloseDisplay( p_vout );
237
238     if( p_vout->p_sys->owner_window )
239     {
240         vout_window_Delete( p_vout->p_sys->owner_window );
241         XCloseDisplay( p_vout->p_sys->p_display );
242     }
243
244 #ifdef HAVE_OSSO
245     if ( p_vout->p_sys->p_octx != NULL ) {
246         msg_Dbg( p_vout, "Deinitializing osso context" );
247         osso_deinitialize( p_vout->p_sys->p_octx );
248     }
249 #endif
250
251     /* Destroy structure */
252     free( p_vout->p_sys );
253 }
254
255
256 /*****************************************************************************
257  * Init: initialize omap framebuffer video thread output method
258  *****************************************************************************/
259 static int Init( vout_thread_t *p_vout )
260 {
261     vout_sys_t *p_sys = (vout_sys_t *)p_vout->p_sys;
262
263     // We want to keep the same aspect
264     p_vout->fmt_out.i_aspect = p_vout->output.i_aspect = p_vout->render.i_aspect;
265     // We ask where the video should be displayed in the video area
266     vout_PlacePicture( p_vout, p_sys->main_window.i_width,
267                        p_sys->main_window.i_height,
268                        &p_sys->output_window.i_x,
269                        &p_sys->output_window.i_y,
270                        &p_sys->output_window.i_width,
271                        &p_sys->output_window.i_height );
272     p_sys->output_window.i_x = ( p_sys->output_window.i_x +
273                                  p_sys->main_window.i_x ) & ~1;
274     p_sys->output_window.i_y = ( p_sys->output_window.i_y +
275                                  p_sys->main_window.i_y ) & ~1;
276
277     // Hardware upscaling better than software
278     if( p_vout->fmt_render.i_width <= p_sys->main_window.i_width &&
279         p_vout->fmt_render.i_height <= p_sys->main_window.i_height )
280     {
281         p_sys->i_video_width =
282         p_vout->output.i_width =
283         p_vout->fmt_out.i_width =
284         p_vout->fmt_out.i_visible_width = p_vout->fmt_render.i_width;
285         p_sys->i_video_height =
286         p_vout->output.i_height =
287         p_vout->fmt_out.i_height =
288         p_vout->fmt_out.i_visible_height = p_vout->fmt_render.i_height;
289     }
290     else
291     {
292         p_sys->i_video_width =
293         p_vout->output.i_width =
294         p_vout->fmt_out.i_width =
295         p_vout->fmt_out.i_visible_width = p_sys->output_window.i_width;
296         p_sys->i_video_height =
297         p_vout->output.i_height =
298         p_vout->fmt_out.i_height =
299         p_vout->fmt_out.i_visible_height = p_sys->output_window.i_height;
300     }
301
302     p_vout->output.i_chroma =
303     p_vout->fmt_out.i_chroma = VLC_CODEC_I420;
304     p_sys->i_color_format = OMAPFB_COLOR_YUV420;
305
306     // place in the framebuffer where we have to write
307     p_sys->p_center = p_sys->p_video + p_sys->output_window.i_x*p_sys->i_bytes_per_pixel
308                       + p_sys->output_window.i_y*p_sys->i_line_len;
309
310     // We get and set a direct render vlc picture
311     I_OUTPUTPICTURES = 0;
312     picture_t *p_pic = NULL;
313     int i_index;
314
315     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
316     {
317         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
318         {
319             p_pic = p_vout->p_picture + i_index;
320             break;
321         }
322     }
323
324     /* Allocate the picture */
325     if( p_pic == NULL )
326     {
327         return VLC_EGENERIC;
328     }
329
330     p_sys->p_output_picture = p_pic;
331     p_pic->p->p_pixels = p_vout->p_sys->p_center;
332     p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
333     p_pic->p->i_lines = p_sys->i_video_height;
334     p_pic->p->i_visible_lines = p_sys->i_video_height;
335     p_pic->p->i_pitch = p_sys->i_line_len;
336     p_pic->p->i_visible_pitch = p_sys->i_line_len;
337     p_pic->i_planes = 1;
338     p_pic->i_status = DESTROYED_PICTURE;
339     p_pic->i_type   = DIRECT_PICTURE;
340
341     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
342
343     I_OUTPUTPICTURES++;
344
345     return VLC_SUCCESS;
346 }
347
348 /*****************************************************************************
349  * End: terminate omap framebuffer video thread output method
350  *****************************************************************************/
351 static void End( vout_thread_t *p_vout )
352 {
353     /* Clear the screen */
354     UpdateScreen( p_vout, 0, 0,
355                   p_vout->p_sys->fb_vinfo.xres,
356                   p_vout->p_sys->fb_vinfo.yres,
357                   p_vout->p_sys->fb_vinfo.xres,
358                   p_vout->p_sys->fb_vinfo.yres,
359                   OMAPFB_COLOR_RGB565 );
360 }
361
362 /*****************************************************************************
363  * Control: control facility for the vout
364  *****************************************************************************/
365 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
366 {
367     return VLC_EGENERIC;
368 }
369
370 /*****************************************************************************
371 * FreePicture: Destroy the picture and make it free again
372 ******************************************************************************/
373 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
374 {
375     p_pic->p->p_pixels = NULL;
376     p_pic->i_status = FREE_PICTURE;
377 }
378
379 /*****************************************************************************
380  * Manage: handle omapfb events
381  *****************************************************************************
382  * This function should be called regularly by video output thread.
383  *****************************************************************************/
384 static int Manage( vout_thread_t *p_vout )
385 {
386     XEvent xevent;
387
388     while( XPending( p_vout->p_sys->p_display ) )
389     {
390         XNextEvent( p_vout->p_sys->p_display, &xevent );
391
392         if( xevent.type == ButtonPress &&
393             ((XButtonEvent *)&xevent)->button == Button1 )
394         {
395             /* detect double-clicks */
396             if( ( ((XButtonEvent *)&xevent)->time -
397                     p_vout->p_sys->i_time_button_last_pressed ) < 300 )
398             {
399                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
400             }
401
402             p_vout->p_sys->i_time_button_last_pressed =
403                         ((XButtonEvent *)&xevent)->time;
404         }
405         else if( ( xevent.type == VisibilityNotify &&
406                  xevent.xvisibility.state != VisibilityUnobscured ) ||
407                  xevent.type == UnmapNotify )
408         {
409             UpdateScreen( p_vout, 0, 0,
410                           p_vout->p_sys->fb_vinfo.xres,
411                           p_vout->p_sys->fb_vinfo.yres,
412                           p_vout->p_sys->fb_vinfo.xres,
413                           p_vout->p_sys->fb_vinfo.yres,
414                           OMAPFB_COLOR_RGB565 );
415             p_vout->p_sys->b_video_enabled = false;
416             p_vout->p_sys->p_output_picture->p->p_pixels =
417                 p_vout->p_sys->p_null;
418          }
419     }
420
421     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
422     {
423         /* Update the object variable and trigger callback */
424         p_vout->b_fullscreen = !p_vout->b_fullscreen;
425         var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen );
426
427         if( p_vout->p_sys->owner_window )
428             vout_window_SetFullscreen( p_vout->p_sys->owner_window,
429                                        p_vout->b_fullscreen );
430         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
431     }
432
433     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
434     {
435         FreePicture( p_vout, p_vout->p_sys->p_output_picture );
436         if( Init( p_vout ) )
437         {
438             msg_Err( p_vout, "cannot reinit framebuffer screen" );
439             return VLC_EGENERIC;
440         }
441     }
442
443
444 #ifdef HAVE_OSSO
445     if ( p_vout->p_sys->p_octx != NULL ) {
446         if ( p_vout->p_sys->i_backlight_on_counter == i_backlight_on_interval ) {
447             if ( osso_display_blanking_pause( p_vout->p_sys->p_octx ) != OSSO_OK ) {
448                 msg_Err( p_vout, "Could not disable backlight blanking" );
449         } else {
450                 msg_Dbg( p_vout, "Backlight blanking disabled" );
451             }
452             p_vout->p_sys->i_backlight_on_counter = 0;
453         } else {
454             p_vout->p_sys->i_backlight_on_counter ++;
455         }
456     }
457 #endif
458
459     return VLC_SUCCESS;
460 }
461
462 /*****************************************************************************
463  * DisplayVideo: displays previously rendered output
464  *****************************************************************************
465  * This function update the screen resulting in the display of the last
466  * rendered picture.
467  *****************************************************************************/
468 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
469 {
470     VLC_UNUSED( p_pic );
471
472     if( !p_vout->p_sys->b_video_enabled )
473         return;
474
475     UpdateScreen( p_vout,
476                   p_vout->p_sys->output_window.i_x,
477                   p_vout->p_sys->output_window.i_y,
478                   p_vout->p_sys->i_video_width,
479                   p_vout->p_sys->i_video_height,
480                   p_vout->p_sys->output_window.i_width,
481                   p_vout->p_sys->output_window.i_height,
482                   p_vout->p_sys->i_color_format );
483
484     // Wait for the window to be fully displayed
485     ioctl( p_vout->p_sys->i_fd, OMAPFB_SYNC_GFX);
486 }
487
488 /*****************************************************************************
489  * OpenDisplay: initialize framebuffer
490  *****************************************************************************/
491 static int OpenDisplay( vout_thread_t *p_vout )
492 {
493     vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
494     char *psz_device;                             /* framebuffer device path */
495
496     /* Open framebuffer device */
497     if( !(psz_device = var_CreateGetNonEmptyString( p_vout, FB_DEV_VAR )) )
498     {
499         msg_Err( p_vout, "don't know which fb device to open" );
500         return VLC_EGENERIC;
501     }
502
503     p_sys->i_fd = open( psz_device, O_RDWR );
504     if( p_sys->i_fd == -1 )
505     {
506         msg_Err( p_vout, "cannot open %s (%m)", psz_device );
507         free( psz_device );
508         return VLC_EGENERIC;
509     }
510     free( psz_device );
511
512     // Get caps, try older interface if needed
513     if( ioctl( p_sys->i_fd, OMAPFB_GET_CAPS, &p_sys->caps ) != 0 )
514     {
515         if( ioctl( p_sys->i_fd, OMAP_IOR( 42, unsigned long ), &p_sys->caps ) != 0 )
516         {
517             msg_Err( p_vout, "OMAPFB_GET_CAPS ioctl failed" );
518             close( p_sys->i_fd );
519             return VLC_EGENERIC;
520         }
521     }
522
523     if( ( p_sys->caps.ctrl & OMAPFB_CAPS_TEARSYNC ) != 0 )
524         p_sys->b_tearsync = true;
525
526     if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->fb_vinfo ) )
527     {
528         msg_Err( p_vout, "Can't get VSCREENINFO: %s", strerror(errno) );
529         close( p_sys->i_fd );
530         return VLC_EGENERIC;
531     }
532     if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &p_sys->fb_finfo ) )
533     {
534         msg_Err( p_vout, "Can't get FSCREENINFO: %s", strerror(errno) );
535         close( p_sys->i_fd );
536         return VLC_EGENERIC;
537     }
538
539     p_sys->i_bytes_per_pixel = 2;
540     p_sys->i_page_size = p_sys->fb_finfo.smem_len;
541     p_sys->i_line_len = p_sys->fb_finfo.line_length;
542
543     if( (p_sys->p_video = (uint8_t *)mmap( 0, p_sys->i_page_size, PROT_READ | PROT_WRITE, MAP_SHARED,
544                                             p_sys->i_fd, 0 )) == MAP_FAILED )
545     {
546         msg_Err( p_vout, "Can't mmap: %s", strerror(errno) );
547         close( p_sys->i_fd );
548         return VLC_EGENERIC;
549     }
550
551     p_sys->p_display = XOpenDisplay( NULL );
552
553     /* Open /dev/null and map it */
554     p_sys->i_null_fd = open( "/dev/zero", O_RDWR );
555     if( p_sys->i_null_fd == -1 )
556     {
557         msg_Err( p_vout, "cannot open /dev/zero (%m)" );
558         munmap( p_sys->p_video, p_sys->i_page_size );
559         close( p_sys->i_fd );
560         return VLC_EGENERIC;
561     }
562
563     if( (p_sys->p_null = (uint8_t *)mmap( 0, p_sys->i_page_size, PROT_READ | PROT_WRITE,
564                                           MAP_PRIVATE, p_sys->i_null_fd, 0 )) == MAP_FAILED )
565     {
566         msg_Err( p_vout, "Can't mmap 2: %s", strerror(errno) );
567         munmap( p_sys->p_video, p_sys->i_page_size );
568         close( p_sys->i_null_fd );
569         close( p_sys->i_fd );
570         return VLC_EGENERIC;
571     }
572
573     return VLC_SUCCESS;
574 }
575
576 /*****************************************************************************
577  * CloseDisplay: terminate FB video thread output method
578  *****************************************************************************/
579 static void CloseDisplay( vout_thread_t *p_vout )
580 {
581     munmap( p_vout->p_sys->p_video, p_vout->p_sys->i_page_size );
582     munmap( p_vout->p_sys->p_null,  p_vout->p_sys->i_page_size );
583
584     close( p_vout->p_sys->i_fd );
585     close( p_vout->p_sys->i_null_fd );
586 }
587
588 /*****************************************************************************
589  * UpdateScreen: update the screen of the omapfb
590  *****************************************************************************/
591 static void UpdateScreen( vout_thread_t *p_vout, int i_x, int i_y,
592                           int i_width, int i_height,
593                           int i_out_width, int i_out_height, int i_format )
594 {
595     struct omapfb_update_window update;
596     update.x = i_x;
597     update.y = i_y;
598     update.width = i_width;
599     update.height = i_height;
600     update.out_x = i_x;
601     update.out_y = i_y;
602     update.out_width = i_out_width;
603     update.out_height = i_out_height;
604     update.format = i_format;
605     if( p_vout->p_sys->b_tearsync )
606         update.format |= OMAPFB_FORMAT_FLAG_TEARSYNC;
607     ioctl( p_vout->p_sys->i_fd, OMAPFB_UPDATE_WINDOW, &update );
608 }
609
610 /*****************************************************************************
611  * InitWindow: get embedded window and init X11
612  *****************************************************************************/
613 static int InitWindow( vout_thread_t *p_vout )
614 {
615     vout_sys_t *p_sys = (vout_sys_t *)p_vout->p_sys;
616
617     if( var_CreateGetBool( p_vout, "omap-embedded" ) )
618     {
619         p_sys->p_display = XOpenDisplay( NULL );
620
621         // Request window from interface
622         vout_window_cfg_t wnd_cfg;
623
624         memset( &wnd_cfg, 0, sizeof(wnd_cfg) );
625         wnd_cfg.type   = VOUT_WINDOW_TYPE_XID;
626         wnd_cfg.x      = p_sys->embedded_window.i_x;
627         wnd_cfg.y      = p_sys->embedded_window.i_y;
628         wnd_cfg.width  = p_sys->embedded_window.i_width;
629         wnd_cfg.height = p_sys->embedded_window.i_height;
630
631         p_sys->owner_window = vout_window_New( VLC_OBJECT(p_vout), NULL, &wnd_cfg );
632         p_sys->main_window = p_sys->embedded_window;
633
634         // We have to create a new window to get some events
635         CreateWindow( p_sys );
636     }
637     else
638     {
639         // No embedding, fullscreen framebuffer overlay with no events handling
640         p_sys->main_window.i_x = p_sys->main_window.i_y = 0;
641         p_sys->main_window.i_width = p_sys->fb_vinfo.xres;
642         p_sys->main_window.i_height = p_sys->fb_vinfo.yres;
643         p_vout->b_fullscreen = true;
644         var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen );
645     }
646
647     return VLC_SUCCESS;
648 }
649
650 static void CreateWindow( vout_sys_t *p_sys )
651 {
652     XSetWindowAttributes    xwindow_attributes;
653     xwindow_attributes.backing_store = Always;
654     xwindow_attributes.background_pixel =
655         BlackPixel( p_sys->p_display, DefaultScreen(p_sys->p_display) );
656     xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask
657                                   | VisibilityChangeMask;
658     p_sys->window = XCreateWindow( p_sys->p_display,
659                                    p_sys->owner_window->handle.xid,
660                                    0, 0,
661                                    p_sys->main_window.i_width,
662                                    p_sys->main_window.i_height,
663                                    0,
664                                    0, InputOutput, 0,
665                                    CWBackingStore | CWBackPixel | CWEventMask,
666                                    &xwindow_attributes );
667
668     XMapWindow( p_sys->p_display, p_sys->window );
669     XSelectInput( p_sys->p_display, p_sys->owner_window->handle.xid,
670                   StructureNotifyMask );
671 }
672