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