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