]> git.sesse.net Git - vlc/blob - modules/video_output/omapfb.c
OMAPFB: config -> var
[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 #include <X11/keysym.h>
44
45 #ifdef HAVE_OSSO
46 #include <libosso.h>
47 #endif
48
49 #include <vlc_common.h>
50 #include <vlc_plugin.h>
51 #include <vlc_keys.h>
52 #include <vlc_vout.h>
53 #include <vlc_vout_window.h>
54 #include <vlc_playlist.h>
55
56 /*****************************************************************************
57 * Local prototypes
58 *****************************************************************************/
59 static int  Create           ( vlc_object_t * );
60 static void Destroy          ( vlc_object_t * );
61
62 static int  Init             ( vout_thread_t * );
63 static void End              ( vout_thread_t * );
64 static int  Manage           ( vout_thread_t * );
65 static void DisplayVideo     ( vout_thread_t *, picture_t * );
66 static int  Control          ( vout_thread_t *, int, va_list );
67
68 static void FreePicture      ( vout_thread_t *, picture_t * );
69
70 static int  OpenDisplay      ( vout_thread_t * );
71 static void CloseDisplay     ( vout_thread_t * );
72 static void UpdateScreen     ( vout_thread_t *,
73                                int, int, int, int, int, int, int );
74
75 static int  InitWindow       ( vout_thread_t * );
76 static void CreateWindow     ( vout_sys_t * );
77 static void ToggleFullScreen ( vout_thread_t * );
78
79 #ifdef HAVE_OSSO
80 static const int i_backlight_on_interval = 300;
81 #endif
82
83 /*****************************************************************************
84  * Module descriptor
85  *****************************************************************************/
86 #define FB_DEV_VAR "omapfbdev"
87
88 #define DEVICE_TEXT N_("OMAP Framebuffer device")
89 #define DEVICE_LONGTEXT N_( \
90     "OMAP Framebuffer device to use for rendering (usually /dev/fb0).")
91
92 #define CHROMA_TEXT N_("Chroma used.")
93 #define CHROMA_LONGTEXT N_( \
94     "Force use of a specific chroma for output. Default is Y420 (specific to N770/N8xx hardware)." )
95
96 #define OVERLAY_TEXT N_("Embed the overlay")
97 #define OVERLAY_LONGTEXT N_( \
98     "Embed the framebuffer overlay into a X11 window" )
99
100 vlc_module_begin();
101     set_shortname( "OMAP framebuffer" );
102     set_category( CAT_VIDEO );
103     set_subcategory( SUBCAT_VIDEO_VOUT );
104     add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
105               false )
106     add_string( "omap-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
107                 true )
108     add_bool( "omap-embedded", true, NULL, OVERLAY_TEXT, OVERLAY_LONGTEXT,
109                  true )
110     set_description( N_("OMAP framebuffer video output") );
111     set_capability( "video output", 200 );
112     set_callbacks( Create, Destroy );
113 vlc_module_end();
114
115 /*****************************************************************************
116  * omap_window_t: simple structure with the geometry of a window
117  *****************************************************************************/
118 struct omap_window_t
119 {
120     uint32_t i_x;
121     uint32_t i_y;
122     uint32_t i_width;
123     uint32_t i_height;
124 };
125
126 /*****************************************************************************
127 * vout_sys_t: video output omap framebuffer method descriptor
128  *****************************************************************************
129  * This structure is part of the video output thread descriptor.
130  * It describes the FB specific properties of an output thread.
131  *****************************************************************************/
132 struct vout_sys_t
133 {
134     /* Framebuffer information */
135     int                         i_fd;                       /* device handle */
136     struct fb_var_screeninfo    fb_vinfo;        /* current mode information */
137     struct fb_fix_screeninfo    fb_finfo;
138     struct omapfb_caps          caps;
139     bool                        b_tearsync;
140
141     /* Window information */
142     struct omap_window_t output_window;    /* Size of the real output window */
143     struct omap_window_t main_window;  /* Size of the area we got to display */
144     struct omap_window_t embedded_window;     /* Size of the embedded window */
145
146     /* Video information */
147     uint32_t             i_video_width;                       /* video width */
148     uint32_t             i_video_height;                     /* video height */
149     vlc_fourcc_t         i_chroma;
150     int                  i_color_format;                   /* OMAPFB_COLOR_* */
151     bool                 b_embed;
152     bool                 b_video_enabled;        /* Video must be displayed? */
153     picture_t           *p_output_picture;
154
155     /* Video memory */
156     uint8_t    *p_video;                                      /* base adress */
157     uint8_t    *p_center;                                   /* output adress */
158     size_t      i_page_size;                                    /* page size */
159     int         i_bytes_per_pixel;                /* Bytes used by one pixel */
160     int         i_line_len;                   /* Length of one line in bytes */
161
162     /* X11 */
163     Display   *p_display;
164     vout_window_t *owner_window;
165     Window     window;
166     mtime_t    i_time_button_last_pressed;         /* To detect double click */
167
168     /* Dummy memory */
169     int        i_null_fd;
170     uint8_t   *p_null;
171
172 #ifdef HAVE_OSSO
173     osso_context_t      *p_octx;
174     int                 i_backlight_on_counter;
175 #endif
176 };
177
178 /*****************************************************************************
179  * Create: allocates omapfb video thread output method
180  *****************************************************************************
181  * This function allocates and initializes a FB vout method.
182  *****************************************************************************/
183 static int Create( vlc_object_t *p_this )
184 {
185     vout_thread_t *p_vout = (vout_thread_t *)p_this;
186     vout_sys_t    *p_sys;
187
188     if( p_vout->fmt_in.i_chroma != VLC_CODEC_I420 &&
189         p_vout->fmt_in.i_chroma != VLC_CODEC_YV12 )
190         return VLC_EGENERIC;
191
192     /* Allocate instance and initialize some members */
193     p_vout->p_sys = p_sys = calloc( 1, sizeof( vout_sys_t ) );
194     if( p_vout->p_sys == NULL )
195         return VLC_ENOMEM;
196
197     p_vout->pf_init = Init;
198     p_vout->pf_end = End;
199     p_vout->pf_manage = Manage;
200     p_vout->pf_render = NULL;
201     p_vout->pf_display = DisplayVideo;
202     p_vout->pf_control = Control;
203
204     p_sys->b_embed = var_CreateGetInteger( p_vout, "omap-embedded" );
205     p_sys->b_video_enabled = true;
206
207     if( OpenDisplay( p_vout ) )
208     {
209         free( p_vout->p_sys );
210         return VLC_EGENERIC;
211     }
212
213     if( InitWindow( p_vout ) )
214     {
215         free( p_vout->p_sys );
216         return VLC_EGENERIC;
217     }
218
219 #ifdef HAVE_OSSO
220     p_vout->p_sys->i_backlight_on_counter = i_backlight_on_interval;
221     p_vout->p_sys->p_octx = osso_initialize( "vlc", VERSION, 0, NULL );
222     if ( p_vout->p_sys->p_octx == NULL ) {
223         msg_Err( p_vout, "Could not get osso context" );
224     } else {
225         msg_Dbg( p_vout, "Initialized osso context" );
226     }
227 #endif
228
229     return VLC_SUCCESS;
230 }
231
232 /*****************************************************************************
233  * Destroy: destroy omapfb video thread output method
234  *****************************************************************************
235  * Terminate an output method created by Create
236  *****************************************************************************/
237 static void Destroy( vlc_object_t *p_this )
238 {
239     vout_thread_t *p_vout = (vout_thread_t *)p_this;
240
241     CloseDisplay( p_vout );
242
243     if( p_vout->p_sys->b_embed )
244     {
245         vout_window_Delete( p_vout->p_sys->owner_window );
246         XCloseDisplay( p_vout->p_sys->p_display );
247     }
248
249 #ifdef HAVE_OSSO
250     if ( p_vout->p_sys->p_octx != NULL ) {
251         msg_Dbg( p_vout, "Deinitializing osso context" );
252         osso_deinitialize( p_vout->p_sys->p_octx );
253     }
254 #endif
255
256     /* Destroy structure */
257     free( p_vout->p_sys );
258 }
259
260
261 /*****************************************************************************
262  * Init: initialize omap framebuffer video thread output method
263  *****************************************************************************/
264 static int Init( vout_thread_t *p_vout )
265 {
266     vout_sys_t *p_sys = (vout_sys_t *)p_vout->p_sys;
267
268     // We want to keep the same aspect
269     p_vout->fmt_out.i_aspect = p_vout->output.i_aspect = p_vout->render.i_aspect;
270     // We ask where the video should be displayed in the video area
271     vout_PlacePicture( p_vout, p_sys->main_window.i_width,
272                        p_sys->main_window.i_height,
273                        &p_sys->output_window.i_x,
274                        &p_sys->output_window.i_y,
275                        &p_sys->output_window.i_width,
276                        &p_sys->output_window.i_height );
277     p_sys->output_window.i_x = ( p_sys->output_window.i_x +
278                                  p_sys->main_window.i_x ) & ~1;
279     p_sys->output_window.i_y = ( p_sys->output_window.i_y +
280                                  p_sys->main_window.i_y ) & ~1;
281
282     // Hardware upscaling better than software
283     if( p_vout->fmt_render.i_width <= p_sys->main_window.i_width &&
284         p_vout->fmt_render.i_height <= p_sys->main_window.i_height )
285     {
286         p_sys->i_video_width =
287         p_vout->output.i_width =
288         p_vout->fmt_out.i_width =
289         p_vout->fmt_out.i_visible_width = p_vout->fmt_render.i_width;
290         p_sys->i_video_height =
291         p_vout->output.i_height =
292         p_vout->fmt_out.i_height =
293         p_vout->fmt_out.i_visible_height = p_vout->fmt_render.i_height;
294     }
295     else
296     {
297         p_sys->i_video_width =
298         p_vout->output.i_width =
299         p_vout->fmt_out.i_width =
300         p_vout->fmt_out.i_visible_width = p_sys->output_window.i_width;
301         p_sys->i_video_height =
302         p_vout->output.i_height =
303         p_vout->fmt_out.i_height =
304         p_vout->fmt_out.i_visible_height = p_sys->output_window.i_height;
305     }
306
307     p_vout->output.i_chroma =
308     p_vout->fmt_out.i_chroma = VLC_CODEC_I420;
309     p_sys->i_color_format = OMAPFB_COLOR_YUV420;
310
311     // place in the framebuffer where we have to write
312     p_sys->p_center = p_sys->p_video + p_sys->output_window.i_x*p_sys->i_bytes_per_pixel
313                       + p_sys->output_window.i_y*p_sys->i_line_len;
314
315     // We get and set a direct render vlc picture
316     I_OUTPUTPICTURES = 0;
317     picture_t *p_pic = NULL;
318     int i_index;
319
320     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
321     {
322         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
323         {
324             p_pic = p_vout->p_picture + i_index;
325             break;
326         }
327     }
328
329     /* Allocate the picture */
330     if( p_pic == NULL )
331     {
332         return VLC_EGENERIC;
333     }
334
335     p_sys->p_output_picture = p_pic;
336     p_pic->p->p_pixels = p_vout->p_sys->p_center;
337     p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
338     p_pic->p->i_lines = p_sys->i_video_height;
339     p_pic->p->i_visible_lines = p_sys->i_video_height;
340     p_pic->p->i_pitch = p_sys->i_line_len;
341     p_pic->p->i_visible_pitch = p_sys->i_line_len;
342     p_pic->i_planes = 1;
343     p_pic->i_status = DESTROYED_PICTURE;
344     p_pic->i_type   = DIRECT_PICTURE;
345
346     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
347
348     I_OUTPUTPICTURES++;
349
350     return VLC_SUCCESS;
351 }
352
353 /*****************************************************************************
354  * End: terminate omap framebuffer video thread output method
355  *****************************************************************************/
356 static void End( vout_thread_t *p_vout )
357 {
358     /* Clear the screen */
359     UpdateScreen( p_vout, 0, 0,
360                   p_vout->p_sys->fb_vinfo.xres,
361                   p_vout->p_sys->fb_vinfo.yres,
362                   p_vout->p_sys->fb_vinfo.xres,
363                   p_vout->p_sys->fb_vinfo.yres,
364                   OMAPFB_COLOR_RGB565 );
365 }
366
367 /*****************************************************************************
368  * Control: control facility for the vout
369  *****************************************************************************/
370 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
371 {
372     return VLC_EGENERIC;
373 }
374
375 /*****************************************************************************
376 * FreePicture: Destroy the picture and make it free again
377 ******************************************************************************/
378 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
379 {
380     p_pic->p->p_pixels = NULL;
381     p_pic->i_status = FREE_PICTURE;
382 }
383
384 /*****************************************************************************
385  * Manage: handle omapfb events
386  *****************************************************************************
387  * This function should be called regularly by video output thread.
388  *****************************************************************************/
389 static int Manage( vout_thread_t *p_vout )
390 {
391     XEvent xevent;
392
393     while( XPending( p_vout->p_sys->p_display ) )
394     {
395         XNextEvent( p_vout->p_sys->p_display, &xevent );
396
397         if( xevent.type == ButtonPress &&
398             ((XButtonEvent *)&xevent)->button == Button1 )
399         {
400             /* detect double-clicks */
401             if( ( ((XButtonEvent *)&xevent)->time -
402                     p_vout->p_sys->i_time_button_last_pressed ) < 300 )
403             {
404                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
405             }
406
407             p_vout->p_sys->i_time_button_last_pressed =
408                         ((XButtonEvent *)&xevent)->time;
409         }
410         else if( xevent.type == KeyPress )
411         {
412             KeySym x_key_symbol;
413             vlc_value_t val;
414
415             x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
416                                              xevent.xkey.keycode, 0 );
417
418             switch( x_key_symbol )
419             {
420             case XK_Return:
421                 val.i_int = ACTIONID_PLAY_PAUSE; break;
422             case XK_Escape:
423                 val.i_int = ACTIONID_QUIT; break;
424             case XK_Down:
425                 val.i_int = ACTIONID_JUMP_BACKWARD_MEDIUM; break;
426             case XK_Up:
427                 val.i_int = ACTIONID_JUMP_FORWARD_MEDIUM; break;
428             case XK_Right:
429                 val.i_int = ACTIONID_JUMP_FORWARD_SHORT; break;
430             case XK_Left:
431                 val.i_int = ACTIONID_JUMP_BACKWARD_SHORT; break;
432             case XK_F6:
433                 val.i_int = ACTIONID_TOGGLE_FULLSCREEN; break;
434             case XK_F7:
435                 val.i_int = ACTIONID_VOL_UP; break;
436             case XK_F8:
437                 val.i_int = ACTIONID_VOL_DOWN; break;
438             }
439             var_SetInteger( p_vout->p_libvlc, "key-action", val.i_int );
440         }
441         else if( ( xevent.type == VisibilityNotify &&
442                  xevent.xvisibility.state == VisibilityUnobscured ) ||
443                  xevent.type == FocusIn )
444         {
445             p_vout->p_sys->b_video_enabled = true;
446             p_vout->p_sys->p_output_picture->p->p_pixels =
447                 p_vout->p_sys->p_center;
448             XSetInputFocus( p_vout->p_sys->p_display, p_vout->p_sys->window,
449                             RevertToParent, CurrentTime );
450         }
451         else if( ( xevent.type == VisibilityNotify &&
452                  xevent.xvisibility.state != VisibilityUnobscured ) ||
453                  xevent.type == FocusOut || xevent.type == UnmapNotify )
454         {
455             UpdateScreen( p_vout, 0, 0,
456                           p_vout->p_sys->fb_vinfo.xres,
457                           p_vout->p_sys->fb_vinfo.yres,
458                           p_vout->p_sys->fb_vinfo.xres,
459                           p_vout->p_sys->fb_vinfo.yres,
460                           OMAPFB_COLOR_RGB565 );
461             p_vout->p_sys->b_video_enabled = false;
462             p_vout->p_sys->p_output_picture->p->p_pixels =
463                 p_vout->p_sys->p_null;
464          }
465     }
466
467     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
468     {
469         /* Update the object variable and trigger callback */
470         var_SetBool( p_vout, "fullscreen", !p_vout->b_fullscreen );
471
472         if( p_vout->p_sys->b_embed )
473             ToggleFullScreen( p_vout );
474         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
475     }
476
477     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
478     {
479         FreePicture( p_vout, p_vout->p_sys->p_output_picture );
480         if( Init( p_vout ) )
481         {
482             msg_Err( p_vout, "cannot reinit framebuffer screen" );
483             return VLC_EGENERIC;
484         }
485     }
486
487
488 #ifdef HAVE_OSSO
489     if ( p_vout->p_sys->p_octx != NULL ) {
490         if ( p_vout->p_sys->i_backlight_on_counter == i_backlight_on_interval ) {
491             if ( osso_display_blanking_pause( p_vout->p_sys->p_octx ) != OSSO_OK ) {
492                 msg_Err( p_vout, "Could not disable backlight blanking" );
493         } else {
494                 msg_Dbg( p_vout, "Backlight blanking disabled" );
495             }
496             p_vout->p_sys->i_backlight_on_counter = 0;
497         } else {
498             p_vout->p_sys->i_backlight_on_counter ++;
499         }
500     }
501 #endif
502
503     return VLC_SUCCESS;
504 }
505
506 /*****************************************************************************
507  * DisplayVideo: displays previously rendered output
508  *****************************************************************************
509  * This function update the screen resulting in the display of the last
510  * rendered picture.
511  *****************************************************************************/
512 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
513 {
514     VLC_UNUSED( p_pic );
515
516     if( !p_vout->p_sys->b_video_enabled )
517         return;
518
519     UpdateScreen( p_vout,
520                   p_vout->p_sys->output_window.i_x,
521                   p_vout->p_sys->output_window.i_y,
522                   p_vout->p_sys->i_video_width,
523                   p_vout->p_sys->i_video_height,
524                   p_vout->p_sys->output_window.i_width,
525                   p_vout->p_sys->output_window.i_height,
526                   p_vout->p_sys->i_color_format );
527
528     // Wait for the window to be fully displayed
529     ioctl( p_vout->p_sys->i_fd, OMAPFB_SYNC_GFX);
530 }
531
532 /*****************************************************************************
533  * OpenDisplay: initialize framebuffer
534  *****************************************************************************/
535 static int OpenDisplay( vout_thread_t *p_vout )
536 {
537     vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
538     char *psz_device;                             /* framebuffer device path */
539
540     /* Open framebuffer device */
541     if( !(psz_device = var_CreateGetNonEmptyString( p_vout, FB_DEV_VAR )) )
542     {
543         msg_Err( p_vout, "don't know which fb device to open" );
544         return VLC_EGENERIC;
545     }
546
547     p_sys->i_fd = open( psz_device, O_RDWR );
548     if( p_sys->i_fd == -1 )
549     {
550         msg_Err( p_vout, "cannot open %s (%m)", psz_device );
551         free( psz_device );
552         return VLC_EGENERIC;
553     }
554     free( psz_device );
555
556     // Get caps, try older interface if needed
557     if( ioctl( p_sys->i_fd, OMAPFB_GET_CAPS, &p_sys->caps ) != 0 )
558     {
559         if( ioctl( p_sys->i_fd, OMAP_IOR( 42, unsigned long ), &p_sys->caps ) != 0 )
560         {
561             msg_Err( p_vout, "OMAPFB_GET_CAPS ioctl failed" );
562             close( p_sys->i_fd );
563             return VLC_EGENERIC;
564         }
565     }
566
567     if( ( p_sys->caps.ctrl & OMAPFB_CAPS_TEARSYNC ) != 0 )
568         p_sys->b_tearsync = true;
569
570     if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->fb_vinfo ) )
571     {
572         msg_Err( p_vout, "Can't get VSCREENINFO: %s", strerror(errno) );
573         close( p_sys->i_fd );
574         return VLC_EGENERIC;
575     }
576     if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &p_sys->fb_finfo ) )
577     {
578         msg_Err( p_vout, "Can't get FSCREENINFO: %s", strerror(errno) );
579         close( p_sys->i_fd );
580         return VLC_EGENERIC;
581     }
582
583     p_sys->i_bytes_per_pixel = 2;
584     p_sys->i_page_size = p_sys->fb_finfo.smem_len;
585     p_sys->i_line_len = p_sys->fb_finfo.line_length;
586
587     if( (p_sys->p_video = (uint8_t *)mmap( 0, p_sys->i_page_size, PROT_READ | PROT_WRITE, MAP_SHARED,
588                                             p_sys->i_fd, 0 )) == MAP_FAILED )
589     {
590         msg_Err( p_vout, "Can't mmap: %s", strerror(errno) );
591         close( p_sys->i_fd );
592         return VLC_EGENERIC;
593     }
594
595     p_sys->p_display = XOpenDisplay( NULL );
596
597     /* Open /dev/null and map it */
598     p_sys->i_null_fd = open( "/dev/zero", O_RDWR );
599     if( p_sys->i_null_fd == -1 )
600     {
601         msg_Err( p_vout, "cannot open /dev/zero (%m)" );
602         munmap( p_sys->p_video, p_sys->i_page_size );
603         close( p_sys->i_fd );
604         return VLC_EGENERIC;
605     }
606
607     if( (p_sys->p_null = (uint8_t *)mmap( 0, p_sys->i_page_size, PROT_READ | PROT_WRITE,
608                                           MAP_PRIVATE, p_sys->i_null_fd, 0 )) == MAP_FAILED )
609     {
610         msg_Err( p_vout, "Can't mmap 2: %s", strerror(errno) );
611         munmap( p_sys->p_video, p_sys->i_page_size );
612         close( p_sys->i_null_fd );
613         close( p_sys->i_fd );
614         return VLC_EGENERIC;
615     }
616
617     return VLC_SUCCESS;
618 }
619
620 /*****************************************************************************
621  * CloseDisplay: terminate FB video thread output method
622  *****************************************************************************/
623 static void CloseDisplay( vout_thread_t *p_vout )
624 {
625     munmap( p_vout->p_sys->p_video, p_vout->p_sys->i_page_size );
626     munmap( p_vout->p_sys->p_null,  p_vout->p_sys->i_page_size );
627
628     close( p_vout->p_sys->i_fd );
629     close( p_vout->p_sys->i_null_fd );
630 }
631
632 /*****************************************************************************
633  * UpdateScreen: update the screen of the omapfb
634  *****************************************************************************/
635 static void UpdateScreen( vout_thread_t *p_vout, int i_x, int i_y,
636                           int i_width, int i_height,
637                           int i_out_width, int i_out_height, int i_format )
638 {
639     struct omapfb_update_window update;
640     update.x = i_x;
641     update.y = i_y;
642     update.width = i_width;
643     update.height = i_height;
644     update.out_x = i_x;
645     update.out_y = i_y;
646     update.out_width = i_out_width;
647     update.out_height = i_out_height;
648     update.format = i_format;
649     if( p_vout->p_sys->b_tearsync )
650         update.format |= OMAPFB_FORMAT_FLAG_TEARSYNC;
651     ioctl( p_vout->p_sys->i_fd, OMAPFB_UPDATE_WINDOW, &update );
652 }
653
654 /*****************************************************************************
655  * InitWindow: get embedded window and init X11
656  *****************************************************************************/
657 static int InitWindow( vout_thread_t *p_vout )
658 {
659     vout_sys_t *p_sys = (vout_sys_t *)p_vout->p_sys;
660
661     if( p_sys->b_embed )
662     {
663         p_sys->p_display = XOpenDisplay( NULL );
664
665         // Request window from interface
666         vout_window_cfg_t wnd_cfg;
667
668         memset( &wnd_cfg, 0, sizeof(wnd_cfg) );
669         wnd_cfg.type   = VOUT_WINDOW_TYPE_XID;
670         wnd_cfg.x      = p_sys->embedded_window.i_x;
671         wnd_cfg.y      = p_sys->embedded_window.i_y;
672         wnd_cfg.width  = p_sys->embedded_window.i_width;
673         wnd_cfg.height = p_sys->embedded_window.i_height;
674
675         p_sys->owner_window = vout_window_New( VLC_OBJECT(p_vout), NULL, &wnd_cfg );
676         p_sys->main_window = p_sys->embedded_window;
677
678         // We have to create a new window to get some events
679         // (ButtonPress for example)
680         CreateWindow( p_sys );
681     }
682     else
683     {
684         // No embedding, fullscreen framebuffer overlay with no events handling
685         p_sys->main_window.i_x = p_sys->main_window.i_y = 0;
686         p_sys->main_window.i_width = p_sys->fb_vinfo.xres;
687         p_sys->main_window.i_height = p_sys->fb_vinfo.yres;
688         p_vout->b_fullscreen = true;
689         var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen );
690     }
691
692     return VLC_SUCCESS;
693 }
694
695 static void CreateWindow( vout_sys_t *p_sys )
696 {
697     XSetWindowAttributes    xwindow_attributes;
698     xwindow_attributes.backing_store = Always;
699     xwindow_attributes.background_pixel =
700         BlackPixel( p_sys->p_display, DefaultScreen(p_sys->p_display) );
701     xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
702     p_sys->window = XCreateWindow( p_sys->p_display,
703                                    p_sys->owner_window->handle.xid,
704                                    0, 0,
705                                    p_sys->main_window.i_width,
706                                    p_sys->main_window.i_height,
707                                    0,
708                                    0, InputOutput, 0,
709                                    CWBackingStore | CWBackPixel | CWEventMask,
710                                    &xwindow_attributes );
711
712     XMapWindow( p_sys->p_display, p_sys->window );
713     XSelectInput( p_sys->p_display, p_sys->window,
714                   KeyPressMask | ButtonPressMask | StructureNotifyMask |
715                   VisibilityChangeMask | FocusChangeMask );
716     XSelectInput( p_sys->p_display, p_sys->owner_window->handle.xid,
717                   StructureNotifyMask );
718     XSetInputFocus( p_sys->p_display, p_sys->window, RevertToParent, CurrentTime );
719 }
720
721 static void ToggleFullScreen ( vout_thread_t * p_vout )
722 {
723     p_vout->b_fullscreen = !p_vout->b_fullscreen;
724
725     if( p_vout->b_fullscreen )
726     {
727         msg_Dbg( p_vout, "Entering fullscreen mode" );
728         XReparentWindow( p_vout->p_sys->p_display,
729                          p_vout->p_sys->window,
730                          DefaultRootWindow( p_vout->p_sys->p_display ),
731                          0, 0 );
732
733         XEvent xev;
734
735         /* init X event structure for _NET_WM_FULLSCREEN client msg */
736         xev.xclient.type = ClientMessage;
737         xev.xclient.serial = 0;
738         xev.xclient.send_event = True;
739         xev.xclient.message_type = XInternAtom( p_vout->p_sys->p_display,
740                                                 "_NET_WM_STATE", False );
741         xev.xclient.window = p_vout->p_sys->window;
742         xev.xclient.format = 32;
743         if( p_vout->b_fullscreen )
744             xev.xclient.data.l[0] = 1;
745         else
746             xev.xclient.data.l[0] = 0;
747         xev.xclient.data.l[1] = XInternAtom( p_vout->p_sys->p_display,
748                                             "_NET_WM_STATE_FULLSCREEN", False );
749         xev.xclient.data.l[2] = 0;
750         xev.xclient.data.l[3] = 0;
751         xev.xclient.data.l[4] = 0;
752
753         XSendEvent( p_vout->p_sys->p_display,
754                     DefaultRootWindow( p_vout->p_sys->p_display ), False,
755                     SubstructureRedirectMask | SubstructureNotifyMask, &xev);
756
757         p_vout->p_sys->main_window.i_x = p_vout->p_sys->main_window.i_y = 0;
758         p_vout->p_sys->main_window.i_width = p_vout->p_sys->fb_vinfo.xres;
759         p_vout->p_sys->main_window.i_height = p_vout->p_sys->fb_vinfo.yres;
760     }
761     else
762     {
763         msg_Dbg( p_vout, "Leaving fullscreen mode" );
764
765         XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
766
767         p_vout->p_sys->main_window = p_vout->p_sys->embedded_window;
768         CreateWindow( p_vout->p_sys );
769     }
770
771     XSync( p_vout->p_sys->p_display, False);
772
773     /* signal that the size needs to be updated */
774     p_vout->i_changes |= VOUT_SIZE_CHANGE;
775 }