]> git.sesse.net Git - vlc/blob - plugins/sdl/vout_sdl.c
* Added a 'd' keystroke to dump the stream contents (for debugging
[vlc] / plugins / sdl / vout_sdl.c
1 /*****************************************************************************
2  * vout_sdl.c: SDL video output display method
3  *****************************************************************************
4  * Copyright (C) 1998, 1999, 2000 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *          Pierre Baillet <oct@zoy.org>
8  *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #define MODULE_NAME sdl
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <errno.h>                                                 /* ENOMEM */
34 #include <stdlib.h>                                                /* free() */
35 #include <string.h>                                            /* strerror() */
36
37 #include <SDL/SDL.h>
38
39 #include "config.h"
40 #include "common.h"
41 #include "threads.h"
42 #include "mtime.h"
43 #include "tests.h"
44 #include "modules.h"
45
46 #include "video.h"
47 #include "video_output.h"
48
49 #include "intf_msg.h"
50 #include "interface.h"
51 /* FIXME: get rid of this */
52 #include "keystrokes.h"
53 #include "main.h"
54
55 /*****************************************************************************
56  * FIXME: this file is ...                                                   *
57  *                                                                           *
58  *              XXX   XXX     FIXME     XXX     XXX   XXX   XXX              *
59  *              XXX   XXX   XXX   XXX   XXX     XXX   XXX   XXX              *
60  *              XXX   XXX   XXX         XXX       FIXME     XXX              *
61  *              XXX   XXX   XXX  TODO   XXX        XXX      XXX              *
62  *              XXX   XXX   XXX   XXX   XXX        XXX                       *
63  *                FIXME       FIXME       FIXME    XXX      XXX              *
64  *                                                                           *
65  *****************************************************************************/
66
67 /*****************************************************************************
68  * vout_sys_t: video output SDL method descriptor
69  *****************************************************************************
70  * This structure is part of the video output thread descriptor.
71  * It describes the SDL specific properties of an output thread.
72  *****************************************************************************/
73 typedef struct vout_sys_s
74 {
75     int i_width;
76     int i_height;
77     SDL_Surface *   p_display;                             /* display device */
78     SDL_Overlay *   p_overlay;                             /* overlay device */
79     boolean_t   b_fullscreen;
80     boolean_t   b_overlay;
81     boolean_t   b_cursor;
82     boolean_t   b_reopen_display;
83     Uint8   *   p_sdl_buf[2];                          /* Buffer information */
84 } vout_sys_t;
85
86 /*****************************************************************************
87  * Local prototypes.
88  *****************************************************************************/
89 static int  vout_Probe     ( probedata_t *p_data );
90 static int  vout_Create    ( struct vout_thread_s * );
91 static int  vout_Init      ( struct vout_thread_s * );
92 static void vout_End       ( struct vout_thread_s * );
93 static void vout_Destroy   ( struct vout_thread_s * );
94 static int  vout_Manage    ( struct vout_thread_s * );
95 static void vout_Display   ( struct vout_thread_s * );
96 static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
97                              u16 *blue, u16 *transp );
98
99 static int  SDLOpenDisplay      ( vout_thread_t *p_vout );
100 static void SDLCloseDisplay     ( vout_thread_t *p_vout );
101
102 /*****************************************************************************
103  * Functions exported as capabilities. They are declared as static so that
104  * we don't pollute the namespace too much.
105  *****************************************************************************/
106 void _M( vout_getfunctions )( function_list_t * p_function_list )
107 {
108     p_function_list->pf_probe = vout_Probe;
109     p_function_list->functions.vout.pf_create     = vout_Create;
110     p_function_list->functions.vout.pf_init       = vout_Init;
111     p_function_list->functions.vout.pf_end        = vout_End;
112     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
113     p_function_list->functions.vout.pf_manage     = vout_Manage;
114     p_function_list->functions.vout.pf_display    = vout_Display;
115     p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
116 }
117
118 /*****************************************************************************
119  * vout_Probe: probe the video driver and return a score
120  *****************************************************************************
121  * This function tries to initialize SDL and returns a score to the
122  * plugin manager so that it can select the best plugin.
123  *****************************************************************************/
124 static int vout_Probe( probedata_t *p_data )
125 {
126     if( TestMethod( VOUT_METHOD_VAR, "sdl" ) )
127     {
128         return( 999 );
129     }
130
131     return( 100 );
132 }
133
134 /*****************************************************************************
135  * vout_Create: allocate SDL video thread output method
136  *****************************************************************************
137  * This function allocate and initialize a SDL vout method. It uses some of the
138  * vout properties to choose the correct mode, and change them according to the
139  * mode actually used.
140  *****************************************************************************/
141 static int vout_Create( vout_thread_t *p_vout )
142 {
143     /* Allocate structure */
144     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
145     if( p_vout->p_sys == NULL )
146     {
147         intf_ErrMsg( "vout error: can't create p_sys (%s)", strerror(ENOMEM) );
148         return( 1 );
149     }
150
151     /* Initialize library */
152     if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE)
153             < 0 )
154     {
155         intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
156         free( p_vout->p_sys );
157         return( 1 );
158     }
159
160     p_vout->p_sys->b_cursor = 1; /* TODO should be done with a main_GetInt.. */
161     p_vout->p_sys->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
162                                 VOUT_FULLSCREEN_DEFAULT );
163     p_vout->p_sys->b_overlay = main_GetIntVariable( VOUT_OVERLAY_VAR,
164                                 VOUT_OVERLAY_DEFAULT );
165     p_vout->p_sys->i_width = main_GetIntVariable( VOUT_WIDTH_VAR, 
166                                 VOUT_WIDTH_DEFAULT );
167     p_vout->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
168                                 VOUT_HEIGHT_DEFAULT );
169
170     p_vout->p_sys->p_display = NULL;
171     p_vout->p_sys->p_overlay = NULL;
172
173     if( SDLOpenDisplay(p_vout) )
174     {
175         intf_ErrMsg( "vout error: can't set up SDL (%s)", SDL_GetError() );
176         free( p_vout->p_sys );
177         return( 1 );
178     }
179
180     /* FIXME: get rid of this ASAP, it's FUCKING UGLY */
181     { intf_thread_t * p_intf = p_main->p_intf;
182     intf_AssignKey(p_intf, SDLK_q,      INTF_KEY_QUIT, 0);
183     intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
184     /* intf_AssignKey(p_intf,3,'Q'); */
185     intf_AssignKey(p_intf, SDLK_0,      INTF_KEY_SET_CHANNEL,0);
186     intf_AssignKey(p_intf, SDLK_1,      INTF_KEY_SET_CHANNEL,1);
187     intf_AssignKey(p_intf, SDLK_2,      INTF_KEY_SET_CHANNEL,2);
188     intf_AssignKey(p_intf, SDLK_3,      INTF_KEY_SET_CHANNEL,3);
189     intf_AssignKey(p_intf, SDLK_4,      INTF_KEY_SET_CHANNEL,4);
190     intf_AssignKey(p_intf, SDLK_5,      INTF_KEY_SET_CHANNEL,5);
191     intf_AssignKey(p_intf, SDLK_6,      INTF_KEY_SET_CHANNEL,6);
192     intf_AssignKey(p_intf, SDLK_7,      INTF_KEY_SET_CHANNEL,7);
193     intf_AssignKey(p_intf, SDLK_8,      INTF_KEY_SET_CHANNEL,8);
194     intf_AssignKey(p_intf, SDLK_9,      INTF_KEY_SET_CHANNEL,9);
195     intf_AssignKey(p_intf, SDLK_PLUS,   INTF_KEY_INC_VOLUME, 0);
196     intf_AssignKey(p_intf, SDLK_MINUS,  INTF_KEY_DEC_VOLUME, 0);
197     intf_AssignKey(p_intf, SDLK_m,      INTF_KEY_TOGGLE_VOLUME, 0);
198     /* intf_AssignKey(p_intf,'M','M'); */
199     intf_AssignKey(p_intf, SDLK_g,      INTF_KEY_DEC_GAMMA, 0);
200     /* intf_AssignKey(p_intf,'G','G'); */
201     intf_AssignKey(p_intf, SDLK_c,      INTF_KEY_TOGGLE_GRAYSCALE, 0);
202     intf_AssignKey(p_intf, SDLK_SPACE,  INTF_KEY_TOGGLE_INTERFACE, 0);
203     intf_AssignKey(p_intf, SDLK_i,      INTF_KEY_TOGGLE_INFO, 0);
204     intf_AssignKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, 0);
205     intf_AssignKey(p_intf, SDLK_d,      INTF_KEY_DUMP_STREAM, 0); }
206
207     return( 0 );
208 }
209
210 /*****************************************************************************
211  * vout_Init: initialize SDL video thread output method
212  *****************************************************************************
213  * This function initialize the SDL display device.
214  *****************************************************************************/
215 static int vout_Init( vout_thread_t *p_vout )
216 {
217     /* This hack is hugly, but hey, you are, too. */
218
219     SDL_Overlay *   p_overlay;
220
221     p_overlay = SDL_CreateYUVOverlay( VOUT_WIDTH_DEFAULT, VOUT_HEIGHT_DEFAULT,
222                                       SDL_YV12_OVERLAY, 
223                                       p_vout->p_sys->p_display );
224     intf_Msg( "vout: YUV acceleration %s",
225               p_overlay->hw_overlay ? "activated" : "unavailable !" ); 
226     p_vout->b_need_render = !p_overlay->hw_overlay;
227
228     SDL_FreeYUVOverlay( p_overlay );
229
230     return( 0 );
231 }
232
233 /*****************************************************************************
234  * vout_End: terminate Sys video thread output method
235  *****************************************************************************
236  * Terminate an output method created by vout_SDLCreate
237  *****************************************************************************/
238 static void vout_End( vout_thread_t *p_vout )
239 {
240     SDLCloseDisplay( p_vout );
241     SDL_Quit();
242 }
243
244 /*****************************************************************************
245  * vout_Destroy: destroy Sys video thread output method
246  *****************************************************************************
247  * Terminate an output method created by vout_SDLCreate
248  *****************************************************************************/
249 static void vout_Destroy( vout_thread_t *p_vout )
250 {
251     free( p_vout->p_sys );
252 }
253
254 /*****************************************************************************
255  * vout_Manage: handle Sys events
256  *****************************************************************************
257  * This function should be called regularly by video output thread. It returns
258  * a non null value if an error occured.
259  *****************************************************************************/
260 static int vout_Manage( vout_thread_t *p_vout )
261 {
262     SDL_Event event;                                            /* SDL event */
263     Uint8   i_key;
264
265     /* Process events */
266     while( SDL_PollEvent(&event) )
267     {
268         switch( event.type )
269         {
270         case SDL_VIDEORESIZE:                          /* Resizing of window */
271             p_vout->i_width = event.resize.w;
272             p_vout->i_height = event.resize.h;
273             p_vout->i_changes |= VOUT_SIZE_CHANGE;
274             break;
275
276         case SDL_MOUSEBUTTONUP:
277             switch( event.button.button )
278             {
279             case SDL_BUTTON_RIGHT:
280                 p_main->p_intf->b_menu_change = 1;
281                 break;
282             }
283             break;
284
285         case SDL_MOUSEBUTTONDOWN:
286             switch( event.button.button )
287             {
288             case SDL_BUTTON_MIDDLE:
289                 p_vout->i_changes |= VOUT_CURSOR_CHANGE;
290                 break;
291             }
292             break;
293
294         case SDL_QUIT:
295             intf_ProcessKey( p_main->p_intf, SDLK_q );
296             break;
297
298         case SDL_KEYDOWN:                             /* if a key is pressed */
299             i_key = event.key.keysym.sym;
300
301             switch( i_key )
302             {
303             case SDLK_f:                             /* switch to fullscreen */
304                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
305                 break;
306
307             case SDLK_y:                               /* switch to hard YUV */
308                 p_vout->i_changes |= VOUT_YUV_CHANGE;
309                 break;
310
311             case SDLK_c:                                 /* toggle grayscale */
312                 p_vout->b_grayscale = ! p_vout->b_grayscale;
313                 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
314                 break;
315
316             case SDLK_i:                                      /* toggle info */
317                 p_vout->b_info = ! p_vout->b_info;
318                 p_vout->i_changes |= VOUT_INFO_CHANGE;
319                 break;
320
321             case SDLK_s:                                   /* toggle scaling */
322                 p_vout->b_scale = ! p_vout->b_scale;
323                 p_vout->i_changes |= VOUT_SCALE_CHANGE;
324                 break;
325
326             case SDLK_SPACE:                             /* toggle interface */
327                 p_vout->b_interface = ! p_vout->b_interface;
328                 p_vout->i_changes |= VOUT_INTF_CHANGE;
329                 break;
330
331             default:
332                 if( intf_ProcessKey( p_main->p_intf, (char )i_key ) )
333                 {
334                    intf_DbgMsg( "unhandled key '%c' (%i)", (char)i_key, i_key );                }
335                 break;
336             }
337             break;
338
339         default:
340             break;
341         }
342     }
343
344     /*
345      * Size Change 
346      */
347     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
348     {
349         p_vout->p_sys->i_width = p_vout->i_width;
350         p_vout->p_sys->i_height = p_vout->i_height;
351
352         /* Need to reopen display */
353         SDLCloseDisplay( p_vout );
354         if( SDLOpenDisplay( p_vout ) )
355         {
356           intf_ErrMsg( "vout error: can't reopen display after resize" );
357           return( 1 );
358         }
359         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
360     }
361     
362     /*
363      * YUV Change 
364      */
365     if( p_vout->i_changes & VOUT_YUV_CHANGE )
366     {
367         p_vout->b_need_render = ! p_vout->b_need_render;
368         
369         /* Need to reopen display */
370         SDLCloseDisplay( p_vout );
371         if( SDLOpenDisplay( p_vout ) )
372         {
373           intf_ErrMsg( "error: can't reopen display after YUV change" );
374           return( 1 );
375         }
376         p_vout->i_changes &= ~VOUT_YUV_CHANGE;
377     }
378
379     /*
380      * Fullscreen change
381      */
382     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
383     {
384         p_vout->p_sys->b_fullscreen = ! p_vout->p_sys->b_fullscreen;
385
386         if( p_vout->p_sys->b_fullscreen )
387         {
388             p_vout->p_sys->b_fullscreen = 0;
389             p_vout->p_sys->b_cursor = 1;
390             SDL_ShowCursor( 1 );
391         }
392         else
393         {
394             p_vout->p_sys->b_fullscreen = 1;
395             p_vout->p_sys->b_cursor = 0;
396             SDL_ShowCursor( 0 );
397         }
398
399         SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
400
401         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
402     }
403
404     /*
405      * Pointer change
406      */
407     if( p_vout->i_changes & VOUT_CURSOR_CHANGE )
408     {
409         if( p_vout->p_sys->b_cursor )
410         {
411             SDL_ShowCursor( 0 );
412             p_vout->p_sys->b_cursor = 0;
413         }
414         else
415         {
416             SDL_ShowCursor( 1 );
417             p_vout->p_sys->b_cursor = 1;
418         }
419         p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
420     }
421     
422     return( 0 );
423 }
424
425 /*****************************************************************************
426  * vout_SetPalette: sets an 8 bpp palette
427  *****************************************************************************
428  * This function sets the palette given as an argument. It does not return
429  * anything, but could later send information on which colors it was unable
430  * to set.
431  *****************************************************************************/
432 static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
433                          u16 *blue, u16 *transp)
434 {
435      /* Create a display surface with a grayscale palette */
436     SDL_Color colors[256];
437     int i;
438   
439     /* Fill colors with color information */
440     for( i = 0; i < 256; i++ )
441     {
442         colors[ i ].r = red[ i ] >> 8;
443         colors[ i ].g = green[ i ] >> 8;
444         colors[ i ].b = blue[ i ] >> 8;
445     }
446     
447     /* Set palette */
448     if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
449     {
450         intf_ErrMsg( "vout error: failed setting palette" );
451     }
452
453 }
454
455 /*****************************************************************************
456  * vout_Display: displays previously rendered output
457  *****************************************************************************
458  * This function send the currently rendered image to the display, wait until
459  * it is displayed and switch the two rendering buffer, preparing next frame.
460  *****************************************************************************/
461 static void vout_Display( vout_thread_t *p_vout )
462 {
463     SDL_Rect    disp;
464     if((p_vout->p_sys->p_display != NULL) && !p_vout->p_sys->b_reopen_display)
465     {
466         if( p_vout->b_need_render )
467         {  
468             /* Change display frame */
469             SDL_Flip( p_vout->p_sys->p_display );
470         }
471         else
472         {
473         
474             /*
475              * p_vout->p_rendered_pic->p_y/u/v contains the YUV buffers to
476              * render 
477              */
478             /* TODO: support for streams other than 4:2:0 */
479             /* create the overlay if necessary */
480             if( p_vout->p_sys->p_overlay == NULL )
481             {
482                 p_vout->p_sys->p_overlay = SDL_CreateYUVOverlay( 
483                                              p_vout->p_rendered_pic->i_width, 
484                                              p_vout->p_rendered_pic->i_height,
485                                              SDL_YV12_OVERLAY, 
486                                              p_vout->p_sys->p_display
487                                            );
488                 intf_Msg("vout: YUV acceleration %s",
489                             p_vout->p_sys->p_overlay->hw_overlay
490                             ? "activated" : "unavailable !" ); 
491             }
492
493             SDL_LockYUVOverlay(p_vout->p_sys->p_overlay);
494             /* copy the data into video buffers */
495             /* Y first */
496             memcpy(p_vout->p_sys->p_overlay->pixels[0],
497                    p_vout->p_rendered_pic->p_y,
498                    p_vout->p_sys->p_overlay->h *
499                    p_vout->p_sys->p_overlay->pitches[0]);
500             /* then V */
501             memcpy(p_vout->p_sys->p_overlay->pixels[1],
502                    p_vout->p_rendered_pic->p_v,
503                    p_vout->p_sys->p_overlay->h *
504                    p_vout->p_sys->p_overlay->pitches[1] / 2);
505             /* and U */
506             memcpy(p_vout->p_sys->p_overlay->pixels[2],
507                    p_vout->p_rendered_pic->p_u,
508                    p_vout->p_sys->p_overlay->h *
509                    p_vout->p_sys->p_overlay->pitches[2] / 2);
510
511             disp.w = (&p_vout->p_buffer[p_vout->i_buffer_index])->i_pic_width;
512             disp.h = (&p_vout->p_buffer[p_vout->i_buffer_index])->i_pic_height;
513             disp.x = (p_vout->i_width - disp.w)/2;
514             disp.y = (p_vout->i_height - disp.h)/2;
515
516             SDL_DisplayYUVOverlay( p_vout->p_sys->p_overlay , &disp );
517             SDL_UnlockYUVOverlay(p_vout->p_sys->p_overlay);
518         }
519     }
520 }
521
522 /* following functions are local */
523
524 /*****************************************************************************
525  * SDLOpenDisplay: open and initialize SDL device
526  *****************************************************************************
527  * Open and initialize display according to preferences specified in the vout
528  * thread fields.
529  *****************************************************************************/
530 static int SDLOpenDisplay( vout_thread_t *p_vout )
531 {
532     SDL_Rect    clipping_rect;
533     Uint32      flags;
534     int bpp;
535     /* Open display 
536      * TODO: Check that we can request for a DOUBLEBUF HWSURFACE display
537      */
538
539     /* init flags and cursor */
540     flags = SDL_ANYFORMAT | SDL_HWPALETTE;
541
542     if( p_vout->p_sys->b_fullscreen )
543         flags |= SDL_FULLSCREEN;
544     else
545         flags |= SDL_RESIZABLE;
546
547     if( p_vout->b_need_render )
548         flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
549     else
550         flags |= SDL_SWSURFACE; /* save video memory */
551
552     bpp = SDL_VideoModeOK( p_vout->p_sys->i_width,
553                            p_vout->p_sys->i_height,
554                            p_vout->i_screen_depth, flags );
555
556     if(bpp == 0)
557     {
558         intf_ErrMsg( "vout error: no video mode available" );
559         return( 1 );
560     }
561
562     p_vout->p_sys->p_display = SDL_SetVideoMode(p_vout->p_sys->i_width,
563                                                 p_vout->p_sys->i_height,
564                                                 bpp, flags);
565
566     if( p_vout->p_sys->p_display == NULL )
567     {
568         intf_ErrMsg( "vout error: cannot set video mode" );
569         return( 1 );
570     }
571
572     SDL_LockSurface(p_vout->p_sys->p_display);
573
574     if( p_vout->p_sys->b_fullscreen )
575         SDL_ShowCursor( 0 );
576     else
577         SDL_ShowCursor( 1 );
578
579     SDL_WM_SetCaption( VOUT_TITLE " (SDL output)",
580                        VOUT_TITLE " (SDL output)" );
581     SDL_EventState(SDL_KEYUP , SDL_IGNORE);                /* ignore keys up */
582
583     if( p_vout->b_need_render )
584     {
585         p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
586         SDL_Flip(p_vout->p_sys->p_display);
587         p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
588         SDL_Flip(p_vout->p_sys->p_display);
589
590         /* Set clipping for text */
591         clipping_rect.x = 0;
592         clipping_rect.y = 0;
593         clipping_rect.w = p_vout->p_sys->p_display->w;
594         clipping_rect.h = p_vout->p_sys->p_display->h;
595         SDL_SetClipRect(p_vout->p_sys->p_display, &clipping_rect);
596
597         /* Set thread information */
598         p_vout->i_width =           p_vout->p_sys->p_display->w;
599         p_vout->i_height =          p_vout->p_sys->p_display->h;
600         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
601
602         p_vout->i_screen_depth =
603             p_vout->p_sys->p_display->format->BitsPerPixel;
604         p_vout->i_bytes_per_pixel =
605             p_vout->p_sys->p_display->format->BytesPerPixel;
606
607         p_vout->i_red_mask =        p_vout->p_sys->p_display->format->Rmask;
608         p_vout->i_green_mask =      p_vout->p_sys->p_display->format->Gmask;
609         p_vout->i_blue_mask =       p_vout->p_sys->p_display->format->Bmask;
610
611         /* FIXME: palette in 8bpp ?? */
612         /* Set and initialize buffers */
613         vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
614                                  p_vout->p_sys->p_sdl_buf[ 1 ] );
615     }
616     else
617     {
618         p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
619         p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
620
621         /* Set thread information */
622         p_vout->i_width =           p_vout->p_sys->p_display->w;
623         p_vout->i_height =          p_vout->p_sys->p_display->h;
624         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
625
626         vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
627                                  p_vout->p_sys->p_sdl_buf[ 1 ] );
628     }
629
630     p_vout->p_sys->b_reopen_display = 0;
631
632     return( 0 );
633 }
634
635 /*****************************************************************************
636  * SDLCloseDisplay: close and reset SDL device
637  *****************************************************************************
638  * This function returns all resources allocated by SDLOpenDisplay and restore
639  * the original state of the device.
640  *****************************************************************************/
641 static void SDLCloseDisplay( vout_thread_t *p_vout )
642 {
643     if( p_vout->p_sys->p_display != NULL )
644     {
645         if( p_vout->p_sys->p_overlay != NULL )
646         {            
647             SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
648             p_vout->p_sys->p_overlay = NULL;
649         }
650
651         SDL_UnlockSurface ( p_vout->p_sys->p_display );
652         SDL_FreeSurface( p_vout->p_sys->p_display );
653         p_vout->p_sys->p_display = NULL;
654     }
655 }
656