]> git.sesse.net Git - vlc/blobdiff - plugins/ggi/ggi.c
* ALL: the first libvlc commit.
[vlc] / plugins / ggi / ggi.c
index 08455a82cefee739105bf99819d7eb0bc8c37ea7..25afcf951fbb6489ee1427f2fd8163bdacc1669b 100644 (file)
@@ -2,7 +2,7 @@
  * ggi.c : GGI plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: ggi.c,v 1.12 2002/01/12 01:25:57 sam Exp $
+ * $Id: ggi.c,v 1.21 2002/06/01 12:31:59 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
 
 #include <ggi/ggi.h>
 
-#include <videolan/vlc.h>
-
-#include "video.h"
-#include "video_output.h"
-
-#include "intf_msg.h"
-#include "interface.h"
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
+#include <vlc/vout.h>
 
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
 static void vout_getfunctions( function_list_t * p_function_list );
 
-static int  vout_Probe     ( probedata_t *p_data );
 static int  vout_Create    ( vout_thread_t * );
 static int  vout_Init      ( vout_thread_t * );
 static void vout_End       ( vout_thread_t * );
@@ -55,17 +50,24 @@ static void vout_Display   ( vout_thread_t *, picture_t * );
 
 static int  OpenDisplay    ( vout_thread_t * );
 static void CloseDisplay   ( vout_thread_t * );
+static void SetPalette     ( vout_thread_t *, u16 *, u16 *, u16 * );
 
 /*****************************************************************************
  * Building configuration tree
  *****************************************************************************/
+#define DISPLAY_TEXT N_("X11 display name")
+#define DISPLAY_LONGTEXT N_("Specify the X11 hardware display you want to use."\
+                           "\nBy default vlc will use the value of the DISPLAY"\
+                           " environment variable.")
+
 MODULE_CONFIG_START
+ADD_CATEGORY_HINT( N_("Miscellaneous"), NULL )
+ADD_STRING  ( "ggi_display", NULL, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT )
 MODULE_CONFIG_STOP
 
 MODULE_INIT_START
     SET_DESCRIPTION( "General Graphics Interface video output" )
     ADD_CAPABILITY( VOUT, 30 )
-    ADD_SHORTCUT( "ggi" )
 MODULE_INIT_STOP
 
 MODULE_ACTIVATE_START
@@ -81,7 +83,7 @@ MODULE_DEACTIVATE_STOP
  * This structure is part of the video output thread descriptor.
  * It describes the GGI specific properties of an output thread.
  *****************************************************************************/
-typedef struct vout_sys_s
+struct vout_sys_s
 {
     /* GGI system informations */
     ggi_visual_t        p_display;                         /* display device */
@@ -93,8 +95,8 @@ typedef struct vout_sys_s
     ggi_directbuffer *  pp_buffer[2];                             /* buffers */
     int                 i_index;
 
-    boolean_t           b_must_acquire;   /* must be acquired before writing */
-} vout_sys_t;
+    vlc_bool_t          b_must_acquire;   /* must be acquired before writing */
+};
 
 /*****************************************************************************
  * Functions exported as capabilities. They are declared as static so that
@@ -102,7 +104,6 @@ typedef struct vout_sys_s
  *****************************************************************************/
 static void 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;
@@ -112,17 +113,6 @@ static void 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 GGI and returns a score to the
- * plugin manager so that it can select the best plugin.
- *****************************************************************************/
-static int vout_Probe( probedata_t *p_data )
-{
-    return( 1 );
-}
-
 /*****************************************************************************
  * vout_Create: allocate GGI video thread output method
  *****************************************************************************
@@ -136,14 +126,14 @@ int vout_Create( vout_thread_t *p_vout )
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
     {
-        intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
+        msg_Err( p_vout, "out of memory" );
         return( 1 );
     }
 
     /* Open and initialize device */
     if( OpenDisplay( p_vout ) )
     {
-        intf_ErrMsg( "vout error: can't initialize GGI display" );
+        msg_Err( p_vout, "cannot initialize GGI display" );
         free( p_vout->p_sys );
         return( 1 );
     }
@@ -158,6 +148,7 @@ int vout_Create( vout_thread_t *p_vout )
  *****************************************************************************/
 int vout_Init( vout_thread_t *p_vout )
 {
+#define p_b p_vout->p_sys->pp_buffer
     int i_index;
     picture_t *p_pic;
 
@@ -171,21 +162,29 @@ int vout_Init( vout_thread_t *p_vout )
 
     switch( p_vout->p_sys->i_bits_per_pixel )
     {
-        case 8: /* FIXME: set the palette */
-            p_vout->output.i_chroma = FOURCC_BI_RGB; break;
+        case 8:
+            p_vout->output.i_chroma = FOURCC_RGB2;
+            p_vout->output.pf_setpalette = SetPalette;
+            break;
         case 15:
             p_vout->output.i_chroma = FOURCC_RV15; break;
         case 16:
             p_vout->output.i_chroma = FOURCC_RV16; break;
         case 24:
-            p_vout->output.i_chroma = FOURCC_BI_BITFIELDS; break;
+            p_vout->output.i_chroma = FOURCC_RV24; break;
         case 32:
-            p_vout->output.i_chroma = FOURCC_BI_BITFIELDS; break;
+            p_vout->output.i_chroma = FOURCC_RV32; break;
         default:
-            intf_ErrMsg( "vout error: unknown screen depth" );
+            msg_Err( p_vout, "unknown screen depth %i",
+                     p_vout->p_sys->i_bits_per_pixel );
             return 0;
     }
 
+    /* Only useful for bits_per_pixel != 8 */
+    p_vout->output.i_rmask = p_b[ 0 ]->buffer.plb.pixelformat->red_mask;
+    p_vout->output.i_gmask = p_b[ 0 ]->buffer.plb.pixelformat->green_mask;
+    p_vout->output.i_bmask = p_b[ 0 ]->buffer.plb.pixelformat->blue_mask;
+
     p_pic = NULL;
 
     /* Find an empty picture slot */
@@ -203,7 +202,6 @@ int vout_Init( vout_thread_t *p_vout )
         return 0;
     }
 
-#define p_b p_vout->p_sys->pp_buffer
     /* We know the chroma, allocate a buffer which will be used
      * directly by the decoder */
     p_vout->p_sys->i_index = 0;
@@ -227,11 +225,6 @@ int vout_Init( vout_thread_t *p_vout )
         p_pic->p->i_pitch = p_b[ 0 ]->buffer.plb.stride;
     }
 
-    /* Only useful for bits_per_pixel != 8 */
-    p_pic->p->i_red_mask =   p_b[ 0 ]->buffer.plb.pixelformat->red_mask;
-    p_pic->p->i_green_mask = p_b[ 0 ]->buffer.plb.pixelformat->green_mask;
-    p_pic->p->i_blue_mask =  p_b[ 0 ]->buffer.plb.pixelformat->blue_mask;
-
     p_pic->i_planes = 1;
 
     p_pic->i_status = DESTROYED_PICTURE;
@@ -317,7 +310,7 @@ int vout_Manage( vout_thread_t *p_vout )
                     case 'Q':
                     case GIIUC_Escape:
                         /* FIXME pass message ! */
-                        p_main->p_intf->b_die = 1;
+                        p_vout->p_vlc->b_die = 1;
                         break;
 
                     default:
@@ -330,8 +323,16 @@ int vout_Manage( vout_thread_t *p_vout )
                 switch( event.pbutton.button )
                 {
                     case GII_PBUTTON_RIGHT:
-                        /* FIXME: need locking ! */
-                        p_main->p_intf->b_menu_change = 1;
+                        {
+                            intf_thread_t *p_intf;
+                            p_intf = vlc_object_find( p_vout->p_vlc,
+                                             VLC_OBJECT_INTF, FIND_CHILD );
+                            if( p_intf )
+                            {
+                                p_intf->b_menu_change = 1;
+                                vlc_object_release( p_intf );
+                            }
+                        }
                         break;
                 }
                 break;
@@ -404,28 +405,27 @@ static int OpenDisplay( vout_thread_t *p_vout )
     /* Initialize library */
     if( ggiInit() )
     {
-        intf_ErrMsg( "vout error: can't initialize GGI library" );
+        msg_Err( p_vout, "cannot initialize GGI library" );
         return( 1 );
     }
 
     /* Open display */
-    psz_display = main_GetPszVariable( VOUT_DISPLAY_VAR, NULL );
+    psz_display = config_GetPsz( p_vout, "ggi_display" );
 
     p_vout->p_sys->p_display = ggiOpen( psz_display, NULL );
+    if( psz_display ) free( psz_display );
 
     if( p_vout->p_sys->p_display == NULL )
     {
-        intf_ErrMsg( "vout error: can't open GGI default display" );
+        msg_Err( p_vout, "cannot open GGI default display" );
         ggiExit();
         return( 1 );
     }
 
     /* Find most appropriate mode */
     p_vout->p_sys->mode.frames =    2;                          /* 2 buffers */
-    p_vout->p_sys->mode.visible.x = main_GetIntVariable( VOUT_WIDTH_VAR,
-                                                         VOUT_WIDTH_DEFAULT );
-    p_vout->p_sys->mode.visible.y = main_GetIntVariable( VOUT_HEIGHT_VAR,
-                                                         VOUT_HEIGHT_DEFAULT );
+    p_vout->p_sys->mode.visible.x = config_GetInt( p_vout, "width" );
+    p_vout->p_sys->mode.visible.y = config_GetInt( p_vout, "height" );
     p_vout->p_sys->mode.virt.x =    GGI_AUTO;
     p_vout->p_sys->mode.virt.y =    GGI_AUTO;
     p_vout->p_sys->mode.size.x =    GGI_AUTO;
@@ -440,7 +440,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
     /* Set mode */
     if( ggiSetMode( p_vout->p_sys->p_display, &p_vout->p_sys->mode ) )
     {
-        intf_ErrMsg( "vout error: can't set GGI mode" );
+        msg_Err( p_vout, "cannot set GGI mode" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
         return( 1 );
@@ -456,7 +456,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
                                                 i_index );
         if( p_b[ i_index ] == NULL )
         {
-            intf_ErrMsg( "vout error: double buffering is not possible" );
+            msg_Err( p_vout, "double buffering is not possible" );
             ggiClose( p_vout->p_sys->p_display );
             ggiExit();
             return( 1 );
@@ -469,7 +469,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
            || ( p_b[ i_index ]->noaccess != 0 )
            || ( p_b[ i_index ]->align != 0 ) )
         {
-            intf_ErrMsg( "vout error: incorrect video memory type" );
+            msg_Err( p_vout, "incorrect video memory type" );
             ggiClose( p_vout->p_sys->p_display );
             ggiExit();
             return( 1 );
@@ -482,11 +482,6 @@ static int OpenDisplay( vout_thread_t *p_vout )
         }
     }
 
-    if( p_vout->p_sys->b_must_acquire )
-    {
-        intf_DbgMsg("buffers must be acquired");
-    }
-
     /* Set graphic context colors */
     col_fg.r = col_fg.g = col_fg.b = -1;
     col_bg.r = col_bg.g = col_bg.b = 0;
@@ -495,7 +490,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
         ggiSetGCBackground(p_vout->p_sys->p_display,
                            ggiMapColor(p_vout->p_sys->p_display,&col_bg)) )
     {
-        intf_ErrMsg( "vout error: can't set colors" );
+        msg_Err( p_vout, "cannot set colors" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
         return( 1 );
@@ -506,7 +501,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
                           p_vout->p_sys->mode.visible.x,
                           p_vout->p_sys->mode.visible.y ) )
     {
-        intf_ErrMsg( "vout error: can't set clipping" );
+        msg_Err( p_vout, "cannot set clipping" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
         return( 1 );
@@ -534,3 +529,27 @@ static void CloseDisplay( vout_thread_t *p_vout )
     ggiExit();
 }
 
+/*****************************************************************************
+ * SetPalette: sets an 8 bpp palette
+ *****************************************************************************/
+static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
+{
+    ggi_color colors[256];
+    int i;
+  
+    /* Fill colors with color information */
+    for( i = 0; i < 256; i++ )
+    {
+        colors[ i ].r = red[ i ];
+        colors[ i ].g = green[ i ];
+        colors[ i ].b = blue[ i ];
+        colors[ i ].a = 0;
+    }
+
+    /* Set palette */
+    if( ggiSetPalette( p_vout->p_sys->p_display, 0, 256, colors ) < 0 )
+    {
+        msg_Err( p_vout, "failed setting palette" );
+    }
+}
+