]> git.sesse.net Git - vlc/blobdiff - plugins/ggi/vout_ggi.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / ggi / vout_ggi.c
index 8833348a444c2c63d7f3f82d40aa9910b1223bc8..39942f964e46eca1b54c8a02cb56e096689175f1 100644 (file)
@@ -1,9 +1,10 @@
 /*****************************************************************************
  * vout_ggi.c: GGI video output display method
  *****************************************************************************
- * Copyright (C) 1998, 1999, 2000 VideoLAN
+ * Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
  *
- * Authors:
+ * Authors: Vincent Seguin <seguin@via.ecp.fr>
+ *          Samuel Hocevar <sam@zoy.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME ggi
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
+#include "tests.h"
+#include "modules.h"
 
 #include "video.h"
 #include "video_output.h"
 
 #include "intf_msg.h"
+#include "interface.h"
+
+#include "main.h"
 
 /*****************************************************************************
  * vout_sys_t: video output GGI method descriptor
@@ -53,38 +61,78 @@ typedef struct vout_sys_s
     /* GGI system informations */
     ggi_visual_t        p_display;                         /* display device */
 
-    /* Buffers informations */
+    /* Buffer information */
     ggi_directbuffer *  p_buffer[2];                              /* buffers */
     boolean_t           b_must_acquire;   /* must be acquired before writing */
 } vout_sys_t;
 
 /*****************************************************************************
- * Local prototypes
+ * 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 * );
+static void vout_Destroy   ( struct vout_thread_s * );
+static int  vout_Manage    ( struct vout_thread_s * );
+static void vout_Display   ( struct vout_thread_s * );
+
+static int  GGIOpenDisplay ( vout_thread_t *p_vout );
+static void GGICloseDisplay( vout_thread_t *p_vout );
+
+/*****************************************************************************
+ * Functions exported as capabilities. They are declared as static so that
+ * we don't pollute the namespace too much.
+ *****************************************************************************/
+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;
+    p_function_list->functions.vout.pf_destroy    = vout_Destroy;
+    p_function_list->functions.vout.pf_manage     = vout_Manage;
+    p_function_list->functions.vout.pf_display    = vout_Display;
+    p_function_list->functions.vout.pf_setpalette = NULL;
+}
+
+/*****************************************************************************
+ * 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     GGIOpenDisplay   ( vout_thread_t *p_vout, char *psz_display, void *p_data );
-static void    GGICloseDisplay  ( vout_thread_t *p_vout );
+static int vout_Probe( probedata_t *p_data )
+{
+    if( TestMethod( VOUT_METHOD_VAR, "ggi" ) )
+    {
+        return( 999 );
+    }
+
+    return( 40 );
+}
 
 /*****************************************************************************
- * vout_GGICreate: allocate GGI video thread output method
+ * vout_Create: allocate GGI video thread output method
  *****************************************************************************
  * This function allocate and initialize a GGI vout method. It uses some of the
  * vout properties to choose the correct mode, and change them according to the
  * mode actually used.
  *****************************************************************************/
-int vout_GGICreate( vout_thread_t *p_vout, char *psz_display, int i_root_window, void *p_data )
+int vout_Create( vout_thread_t *p_vout )
 {
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
     {
-        intf_ErrMsg("error: %s", strerror(ENOMEM) );
+        intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
         return( 1 );
     }
 
     /* Open and initialize device */
-    if( GGIOpenDisplay( p_vout, psz_display, p_data ) )
+    if( GGIOpenDisplay( p_vout ) )
     {
-        intf_ErrMsg("error: can't initialize GGI display");
+        intf_ErrMsg( "vout error: can't initialize GGI display" );
         free( p_vout->p_sys );
         return( 1 );
     }
@@ -92,11 +140,11 @@ int vout_GGICreate( vout_thread_t *p_vout, char *psz_display, int i_root_window,
 }
 
 /*****************************************************************************
- * vout_GGIInit: initialize GGI video thread output method
+ * vout_Init: initialize GGI video thread output method
  *****************************************************************************
  * This function initialize the GGI display device.
  *****************************************************************************/
-int vout_GGIInit( vout_thread_t *p_vout )
+int vout_Init( vout_thread_t *p_vout )
 {
     /* Acquire first buffer */
     if( p_vout->p_sys->b_must_acquire )
@@ -108,11 +156,11 @@ int vout_GGIInit( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * vout_GGIEnd: terminate Sys video thread output method
+ * vout_End: terminate GGI video thread output method
  *****************************************************************************
- * Terminate an output method created by vout_GGICreate
+ * Terminate an output method created by vout_Create
  *****************************************************************************/
-void vout_GGIEnd( vout_thread_t *p_vout )
+void vout_End( vout_thread_t *p_vout )
 {
     /* Release buffer */
     if( p_vout->p_sys->b_must_acquire )
@@ -122,35 +170,53 @@ void vout_GGIEnd( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * vout_GGIDestroy: destroy Sys video thread output method
+ * vout_Destroy: destroy GGI video thread output method
  *****************************************************************************
- * Terminate an output method created by vout_GGICreate
+ * Terminate an output method created by vout_Create
  *****************************************************************************/
-void vout_GGIDestroy( vout_thread_t *p_vout )
+void vout_Destroy( vout_thread_t *p_vout )
 {
     GGICloseDisplay( p_vout );
+
     free( p_vout->p_sys );
 }
 
 /*****************************************************************************
- * vout_GGIManage: handle Sys events
+ * vout_Manage: handle GGI events
  *****************************************************************************
  * This function should be called regularly by video output thread. It returns
  * a non null value if an error occured.
  *****************************************************************************/
-int vout_GGIManage( vout_thread_t *p_vout )
+int vout_Manage( vout_thread_t *p_vout )
 {
-    /* FIXME: 8bpp: change palette ?? */
+    int         i_key;                                        /* unicode key */
+
+    /* For all events in queue */
+    while( ggiKbhit( p_vout->p_sys->p_display ) )
+    {
+        i_key = ggiGetc( p_vout->p_sys->p_display );
+        switch( i_key )
+        {
+        case 'q':
+            /* FIXME pass message ! */
+            p_main->p_intf->b_die = 1;
+            break;
+
+        default:
+            break;
+        }
+    }
+
     return( 0 );
 }
 
 /*****************************************************************************
- * vout_GGIDisplay: displays previously rendered output
+ * vout_Display: displays previously rendered output
  *****************************************************************************
  * This function send the currently rendered image to the display, wait until
  * it is displayed and switch the two rendering buffer, preparing next frame.
  *****************************************************************************/
-void vout_GGIDisplay( vout_thread_t *p_vout )
+void vout_Display( vout_thread_t *p_vout )
 {
     /* Change display frame */
     if( p_vout->p_sys->b_must_acquire )
@@ -179,36 +245,39 @@ void vout_GGIDisplay( vout_thread_t *p_vout )
  * Open and initialize display according to preferences specified in the vout
  * thread fields.
  *****************************************************************************/
-static int GGIOpenDisplay( vout_thread_t *p_vout, char *psz_display, void *p_data )
+static int GGIOpenDisplay( vout_thread_t *p_vout )
 {
     ggi_mode    mode;                                     /* mode descriptor */
     ggi_color   col_fg;                                  /* foreground color */
     ggi_color   col_bg;                                  /* background color */
     int         i_index;                               /* all purposes index */
+    char        *psz_display;
 
     /* Initialize library */
     if( ggiInit() )
     {
-        intf_ErrMsg("error: can't initialize GGI library");
+        intf_ErrMsg( "vout error: can't initialize GGI library" );
         return( 1 );
     }
 
     /* Open display */
+    psz_display = main_GetPszVariable( VOUT_DISPLAY_VAR, NULL );
+
     p_vout->p_sys->p_display = ggiOpen( psz_display, NULL );
+
     if( p_vout->p_sys->p_display == NULL )
     {
-        intf_ErrMsg("error: can't open GGI default display");
+        intf_ErrMsg( "vout error: can't open GGI default display" );
         ggiExit();
         return( 1 );
     }
 
-    /* give the data back to the interface */
-    *(ggi_visual_t *)p_data = p_vout->p_sys->p_display;
-
     /* Find most appropriate mode */
     mode.frames =       2;                                      /* 2 buffers */
-    mode.visible.x =    p_vout->i_width;                    /* minimum width */
-    mode.visible.y =    p_vout->i_height;                  /* minimum height */
+    mode.visible.x =    main_GetIntVariable( VOUT_WIDTH_VAR,
+                                             VOUT_WIDTH_DEFAULT );
+    mode.visible.y =    main_GetIntVariable( VOUT_HEIGHT_VAR,
+                                             VOUT_HEIGHT_DEFAULT );
     mode.virt.x =       GGI_AUTO;
     mode.virt.y =       GGI_AUTO;
     mode.size.x =       GGI_AUTO;
@@ -224,7 +293,7 @@ static int GGIOpenDisplay( vout_thread_t *p_vout, char *psz_display, void *p_dat
     /* Set mode */
     if( ggiSetMode( p_vout->p_sys->p_display, &mode ) )
     {
-        intf_ErrMsg("error: can't set GGI mode");
+        intf_ErrMsg( "vout error: can't set GGI mode" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
         return( 1 );
@@ -239,7 +308,7 @@ static int GGIOpenDisplay( vout_thread_t *p_vout, char *psz_display, void *p_dat
             (ggi_directbuffer *)ggiDBGetBuffer( p_vout->p_sys->p_display, i_index );
         if( p_vout->p_sys->p_buffer[ i_index ] == NULL )
         {
-            intf_ErrMsg("error: double buffering is not possible");
+            intf_ErrMsg( "vout error: double buffering is not possible" );
             ggiClose( p_vout->p_sys->p_display );
             ggiExit();
             return( 1 );
@@ -252,7 +321,7 @@ static int GGIOpenDisplay( vout_thread_t *p_vout, char *psz_display, void *p_dat
             (p_vout->p_sys->p_buffer[ i_index ]->noaccess != 0) ||
             (p_vout->p_sys->p_buffer[ i_index ]->align != 0) )
         {
-            intf_ErrMsg("error: incorrect video memory type");
+            intf_ErrMsg( "vout error: incorrect video memory type" );
             ggiClose( p_vout->p_sys->p_display );
             ggiExit();
             return( 1 );
@@ -279,7 +348,7 @@ static int GGIOpenDisplay( vout_thread_t *p_vout, char *psz_display, void *p_dat
         ggiSetGCBackground(p_vout->p_sys->p_display,
                            ggiMapColor(p_vout->p_sys->p_display,&col_bg)) )
     {
-        intf_ErrMsg("error: can't set colors");
+        intf_ErrMsg( "vout error: can't set colors" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
         return( 1 );
@@ -289,7 +358,7 @@ static int GGIOpenDisplay( vout_thread_t *p_vout, char *psz_display, void *p_dat
     if( ggiSetGCClipping(p_vout->p_sys->p_display, 0, 0,
                          mode.visible.x, mode.visible.y ) )
     {
-        intf_ErrMsg("error: can't set clipping");
+        intf_ErrMsg( "vout error: can't set clipping" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
         return( 1 );