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