]> git.sesse.net Git - vlc/blobdiff - plugins/sdl/vout_sdl.c
* ./extras/MacOSX_dvdioctl: removed outdated files.
[vlc] / plugins / sdl / vout_sdl.c
index 5be925da6436f27d4e69cef08ddd407404279598..8a1e4e34741f6d19bdbb813e21a5d746d5b7f9d7 100644 (file)
@@ -2,7 +2,7 @@
  * vout_sdl.c: SDL video output display method
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: vout_sdl.c,v 1.80 2002/01/12 01:25:57 sam Exp $
+ * $Id: vout_sdl.c,v 1.85 2002/03/18 19:14:52 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Pierre Baillet <oct@zoy.org>
@@ -70,9 +70,6 @@ typedef struct vout_sys_s
 
     /* For RGB output */
     int i_surfaces;
-    int i_red_mask;
-    int i_green_mask;
-    int i_blue_mask;
 
     boolean_t   b_cursor;
     boolean_t   b_cursor_autohidden;
@@ -120,7 +117,6 @@ static __inline__ void vout_Seek( off_t i_seek )
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static int  vout_Probe      ( probedata_t *p_data );
 static int  vout_Create     ( struct vout_thread_s * );
 static int  vout_Init       ( struct vout_thread_s * );
 static void vout_End        ( struct vout_thread_s * );
@@ -129,9 +125,10 @@ static int  vout_Manage     ( struct vout_thread_s * );
 static void vout_Render     ( struct vout_thread_s *, struct picture_s * );
 static void vout_Display    ( struct vout_thread_s *, struct picture_s * );
 
-static int  SDLOpenDisplay      ( vout_thread_t *p_vout );
-static void SDLCloseDisplay     ( vout_thread_t *p_vout );
-static int  SDLNewPicture       ( vout_thread_t *p_vout, picture_t *p_pic );
+static int  OpenDisplay     ( struct vout_thread_s * );
+static void CloseDisplay    ( struct vout_thread_s * );
+static int  NewPicture      ( struct vout_thread_s *, struct picture_s * );
+static void SetPalette      ( struct vout_thread_s *, u16 *, u16 *, u16 * );
 
 /*****************************************************************************
  * Functions exported as capabilities. They are declared as static so that
@@ -139,7 +136,6 @@ static int  SDLNewPicture       ( vout_thread_t *p_vout, picture_t *p_pic );
  *****************************************************************************/
 void _M( vout_getfunctions )( function_list_t * p_function_list )
 {
-    p_function_list->pf_probe = vout_Probe;
     p_function_list->functions.vout.pf_create     = vout_Create;
     p_function_list->functions.vout.pf_init       = vout_Init;
     p_function_list->functions.vout.pf_end        = vout_End;
@@ -149,22 +145,6 @@ void _M( vout_getfunctions )( function_list_t * p_function_list )
     p_function_list->functions.vout.pf_display    = vout_Display;
 }
 
-/*****************************************************************************
- * vout_Probe: probe the video driver and return a score
- *****************************************************************************
- * This function tries to initialize SDL and returns a score to the
- * plugin manager so that it can select the best plugin.
- *****************************************************************************/
-static int vout_Probe( probedata_t *p_data )
-{
-    if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
-    {
-        return( 0 );
-    }
-
-    return( 100 );
-}
-
 /*****************************************************************************
  * vout_Create: allocate SDL video thread output method
  *****************************************************************************
@@ -174,6 +154,8 @@ static int vout_Probe( probedata_t *p_data )
  *****************************************************************************/
 static int vout_Create( vout_thread_t *p_vout )
 {
+    char *psz_method;
+
     if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
     {
         return( 1 );
@@ -187,6 +169,20 @@ static int vout_Create( vout_thread_t *p_vout )
         return( 1 );
     }
 
+    psz_method = config_GetPszVariable( "vout" );
+    if( psz_method )
+    {
+        while( *psz_method && *psz_method != ':' )
+        {
+            psz_method++;
+        }
+
+        if( *psz_method )
+        {
+            setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
+        }
+    }
+
     /* Initialize library */
     if( SDL_Init( SDL_INIT_VIDEO
 #ifndef WIN32
@@ -236,7 +232,7 @@ static int vout_Create( vout_thread_t *p_vout )
     }
 #endif
 
-    if( SDLOpenDisplay( p_vout ) )
+    if( OpenDisplay( p_vout ) )
     {
         intf_ErrMsg( "vout error: can't set up SDL (%s)", SDL_GetError() );
         SDL_QuitSubSystem( SDL_INIT_VIDEO );
@@ -296,7 +292,7 @@ static int vout_Init( vout_thread_t *p_vout )
         }
 
         /* Allocate the picture if we found one */
-        if( p_pic == NULL || SDLNewPicture( p_vout, p_pic ) )
+        if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
         {
             break;
         }
@@ -347,7 +343,7 @@ static void vout_End( vout_thread_t *p_vout )
  *****************************************************************************/
 static void vout_Destroy( vout_thread_t *p_vout )
 {
-    SDLCloseDisplay( p_vout );
+    CloseDisplay( p_vout );
 
     SDL_QuitSubSystem( SDL_INIT_VIDEO );
 
@@ -372,8 +368,8 @@ static int vout_Manage( vout_thread_t *p_vout )
         case SDL_VIDEORESIZE:                          /* Resizing of window */
             p_vout->p_sys->i_width = event.resize.w;
             p_vout->p_sys->i_height = event.resize.h;
-            SDLCloseDisplay( p_vout );
-            SDLOpenDisplay( p_vout );
+            CloseDisplay( p_vout );
+            OpenDisplay( p_vout );
             break;
 
         case SDL_MOUSEMOTION:
@@ -491,7 +487,6 @@ static int vout_Manage( vout_thread_t *p_vout )
             case SDLK_F9:  network_ChannelJoin( 9 ); break;
 
             default:
-                intf_DbgMsg( "unhandled key %i", event.key.keysym.sym );
                 break;
             }
             break;
@@ -569,12 +564,12 @@ static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
 /* following functions are local */
 
 /*****************************************************************************
- * SDLOpenDisplay: open and initialize SDL device
+ * OpenDisplay: open and initialize SDL device
  *****************************************************************************
  * Open and initialize display according to preferences specified in the vout
  * thread fields.
  *****************************************************************************/
-static int SDLOpenDisplay( vout_thread_t *p_vout )
+static int OpenDisplay( vout_thread_t *p_vout )
 {
     Uint32 i_flags;
     int    i_bpp;
@@ -629,7 +624,6 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
     p_vout->p_sys->p_overlay =
         SDL_CreateYUVOverlay( 32, 32, p_vout->output.i_chroma,
                               p_vout->p_sys->p_display );
-
     /* FIXME: if the first overlay we find is software, don't stop,
      * because we may find a hardware one later ... */
 
@@ -667,7 +661,8 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
         switch( p_vout->p_sys->p_display->format->BitsPerPixel )
         {
             case 8:
-                p_vout->output.i_chroma = FOURCC_BI_RGB;
+                p_vout->output.i_chroma = FOURCC_RGB2;
+                p_vout->output.pf_setpalette = SetPalette;
                 break;
             case 15:
                 p_vout->output.i_chroma = FOURCC_RV15;
@@ -676,10 +671,10 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
                 p_vout->output.i_chroma = FOURCC_RV16;
                 break;
             case 24:
-                p_vout->output.i_chroma = FOURCC_BI_BITFIELDS;
+                p_vout->output.i_chroma = FOURCC_RV24;
                 break;
             case 32:
-                p_vout->output.i_chroma = FOURCC_BI_BITFIELDS;
+                p_vout->output.i_chroma = FOURCC_RV32;
                 break;
             default:
                 intf_ErrMsg( "vout error: unknown screen depth" );
@@ -688,9 +683,9 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
                 return( -1 );
         }
 
-        p_vout->p_sys->i_red_mask = p_vout->p_sys->p_display->format->Rmask;
-        p_vout->p_sys->i_green_mask = p_vout->p_sys->p_display->format->Gmask;
-        p_vout->p_sys->i_blue_mask = p_vout->p_sys->p_display->format->Bmask;
+        p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
+        p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
+        p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
 
         SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
                            VOUT_TITLE " (software RGB SDL output)" );
@@ -715,12 +710,12 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * SDLCloseDisplay: close and reset SDL device
+ * CloseDisplay: close and reset SDL device
  *****************************************************************************
- * This function returns all resources allocated by SDLOpenDisplay and restore
+ * This function returns all resources allocated by OpenDisplay and restore
  * the original state of the device.
  *****************************************************************************/
-static void SDLCloseDisplay( vout_thread_t *p_vout )
+static void CloseDisplay( vout_thread_t *p_vout )
 {
     SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
     SDL_UnlockSurface ( p_vout->p_sys->p_display );
@@ -728,11 +723,11 @@ static void SDLCloseDisplay( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * SDLNewPicture: allocate a picture
+ * NewPicture: allocate a picture
  *****************************************************************************
  * Returns 0 on success, -1 otherwise
  *****************************************************************************/
-static int SDLNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
+static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
     int i_width  = p_vout->output.i_width;
     int i_height = p_vout->output.i_height;
@@ -753,12 +748,29 @@ static int SDLNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
             return -1;
         }
 
+        switch( p_vout->p_sys->p_display->format->BitsPerPixel )
+        {
+            case 8:
+                p_pic->p->i_pixel_bytes = 1;
+                break;
+            case 15:
+            case 16:
+                p_pic->p->i_pixel_bytes = 2;
+                break;
+            case 24:
+            case 32:
+                p_pic->p->i_pixel_bytes = 4;
+                break;
+            default:
+                return( -1 );
+        }
+
         p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
         p_pic->p->i_lines = p_vout->p_sys->p_display->h;
         p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
-        p_pic->p->i_pixel_bytes = 2;
 
-        if( p_pic->p->i_pitch == 2 * p_vout->p_sys->p_display->w )
+        if( p_pic->p->i_pitch ==
+                p_pic->p->i_pixel_bytes * p_vout->p_sys->p_display->w )
         {
             p_pic->p->b_margin = 0;
         }
@@ -766,13 +778,10 @@ static int SDLNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
         {
             p_pic->p->b_margin = 1;
             p_pic->p->b_hidden = 1;
-            p_pic->p->i_visible_bytes = 2 * p_vout->p_sys->p_display->w;
+            p_pic->p->i_visible_bytes =
+                p_pic->p->i_pixel_bytes * p_vout->p_sys->p_display->w;
         }
 
-        p_pic->p->i_red_mask = p_vout->p_sys->p_display->format->Rmask;
-        p_pic->p->i_green_mask = p_vout->p_sys->p_display->format->Gmask;
-        p_pic->p->i_blue_mask = p_vout->p_sys->p_display->format->Bmask;
-
         p_vout->p_sys->i_surfaces++;
 
         p_pic->i_planes = 1;
@@ -855,3 +864,26 @@ static int SDLNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
     return 0;
 }
 
+/*****************************************************************************
+ * SetPalette: sets an 8 bpp palette
+ *****************************************************************************/
+static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
+{
+    SDL_Color colors[256];
+    int i;
+  
+    /* Fill colors with color information */
+    for( i = 0; i < 256; i++ )
+    {
+        colors[ i ].r = red[ i ] >> 8;
+        colors[ i ].g = green[ i ] >> 8;
+        colors[ i ].b = blue[ i ] >> 8;
+    }
+
+    /* Set palette */
+    if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
+    {
+        intf_ErrMsg( "vout error: failed setting palette" );
+    }
+}
+