]> git.sesse.net Git - vlc/commitdiff
* modules/video_output/x11/*: the glx "opengl provider" makes use of xcommon.c.
authorGildas Bazin <gbazin@videolan.org>
Thu, 22 Jul 2004 21:27:45 +0000 (21:27 +0000)
committerGildas Bazin <gbazin@videolan.org>
Thu, 22 Jul 2004 21:27:45 +0000 (21:27 +0000)
* modules/video_output/opengl.c: new platform independant OpenGL vout (uses an "opengl provider" module).
* modules/visualization/galaktos/*: uses the new "opengl provider" module.

12 files changed:
configure.ac
include/video_output.h
include/vlc_opengl.h [deleted file]
modules/video_output/Modules.am
modules/video_output/opengl.c [new file with mode: 0644]
modules/video_output/x11/Modules.am
modules/video_output/x11/glx.c
modules/video_output/x11/xcommon.c
modules/video_output/x11/xcommon.h
modules/visualization/galaktos/main.c
modules/visualization/galaktos/plugin.c
modules/visualization/galaktos/plugin.h

index 2ace4444930fff5e4db6942a6117b305ff82a4a9..252e14aac1e2f8af44d9a017ac0ac9bd26a33bc5 100644 (file)
@@ -2414,6 +2414,24 @@ if test "${enable_xvideo}" != "no" &&
   CPPFLAGS="${CPPFLAGS_save}")
 fi
 
+dnl
+dnl  GLX module
+dnl  (enabled by default except on win32)
+dnl
+AC_ARG_ENABLE(glx,
+  [  --enable-glx            X11 OpenGL (GLX) support (default enabled)])
+if test "${enable_glx}" != "no" &&
+  (test "${SYS}" != "mingw32" || test "${enable_glx}" = "yes"); then
+  CPPFLAGS="${CPPFLAGS_save} -I${x_includes}"
+  AC_CHECK_HEADERS(X11/Xlib.h, [
+    AC_CHECK_HEADERS(GL/glx.h, [
+      VLC_ADD_PLUGINS([glx])
+      VLC_ADD_LDFLAGS([glx],[-L${x_libraries} -lX11 -lXext -lGL -lGLU])
+      VLC_ADD_CPPFLAGS([glx],[-I${x_includes}])
+  ]) ])
+  CPPFLAGS="${CPPFLAGS_save}"
+fi
+
 dnl
 dnl  Check for the Xinerama extension
 dnl
@@ -2426,11 +2444,13 @@ if test "${enable_xvideo}" != "no" &&
     AC_CHECK_LIB(Xinerama_pic, XineramaQueryExtension,[
       VLC_ADD_LDFLAGS([xvideo],[-lXinerama_pic])
       VLC_ADD_LDFLAGS([x11],[-lXinerama_pic])
+      VLC_ADD_LDFLAGS([glx],[-lXinerama_pic])
       ac_cv_have_xinerama="yes"
     ],[
       AC_CHECK_LIB(Xinerama, XineramaQueryExtension,[
         VLC_ADD_LDFLAGS([xvideo],[-lXinerama])
         VLC_ADD_LDFLAGS([x11],[-lXinerama])
+        VLC_ADD_LDFLAGS([glx],[-lXinerama])
         ac_cv_have_xinerama="yes"
       ])
     ])
@@ -2442,6 +2462,20 @@ if test "${enable_xvideo}" != "no" &&
   CPPFLAGS="${CPPFLAGS_save}"
 fi
 
+dnl
+dnl  GLX module
+dnl  (enabled by default except on win32)
+dnl
+AC_ARG_ENABLE(opengl,
+  [  --enable-opengl            OpenGL support (default enabled)])
+if test "${enable_opengl}" != "no"; then
+  AC_CHECK_HEADERS(GL/gl.h, [
+      VLC_ADD_PLUGINS([opengl])
+      VLC_ADD_LDFLAGS([opengl],[-L${x_libraries} -lGL -lGLU])
+  ])
+  CPPFLAGS="${CPPFLAGS_save}"
+fi
+
 dnl
 dnl  SDL module
 dnl
@@ -2754,18 +2788,6 @@ then
       fi ])
 fi
 
-dnl
-dnl  GLX module
-dnl
-AC_ARG_ENABLE(glx,
-  [  --enable-glx            X11 OpenGL (GLX) support (default disabled)])
-if test "${enable_glx}" = "yes"
-then
-  VLC_ADD_PLUGINS([glx])
-  VLC_ADD_LDFLAGS([glx],[-lGL -lGLU])
-fi
-
-
 dnl
 dnl  AA plugin
 dnl
index cb4d5f3b536814ac3353aa289a7226c1a1f8b9f7..7f099184cfcd3d9740e663a6e5a39096d2eef2c0 100644 (file)
@@ -102,6 +102,7 @@ struct vout_thread_t
     int       ( *pf_manage )     ( vout_thread_t * );
     void      ( *pf_render )     ( vout_thread_t *, picture_t * );
     void      ( *pf_display )    ( vout_thread_t *, picture_t * );
+    void      ( *pf_swap )       ( vout_thread_t * );         /* OpenGL only */
     int       ( *pf_control )    ( vout_thread_t *, int, va_list );
     /**@}*/
 
diff --git a/include/vlc_opengl.h b/include/vlc_opengl.h
deleted file mode 100644 (file)
index a1acf67..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*****************************************************************************
- * vlc_opengl.h: OpenGL provider interface
- *****************************************************************************
- * Copyright (C) 2004 VideoLAN
- * $Id$
- *
- * Authors: Cyril Deguet  <asmax@videolan.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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- *****************************************************************************/
-
-#ifndef _VLC_OPENGL_H
-#define _VLC_OPENGL_H 1
-
-
-struct opengl_t
-{
-    VLC_COMMON_MEMBERS
-
-    int             i_width;        /* window width */
-    int             i_height;       /* window height */
-    int             b_fullscreen;   /* fullscreen flag */
-
-    opengl_sys_t    *p_sys;         /* private data */
-
-    /* Create an OpenGL window of the requested size (if possible) */
-    int     ( *pf_init )( opengl_t *, int i_width, int i_height );
-
-    /* Swap front/back buffers */
-    void    ( *pf_swap )( opengl_t * );
-
-    /* Handle window events */
-    int     ( *pf_handle_events )( opengl_t * );
-};
-
-#endif
index 15ebae4de2eee426a2b23cd6b30ded1084054526..4f43844e1b7552e6bc824abd30a6ad218a47847c 100644 (file)
@@ -9,3 +9,4 @@ SOURCES_wingdi = wingdi.c
 SOURCES_mga = mga.c
 SOURCES_hd1000v = hd1000v.cpp
 SOURCES_snapshot = snapshot.c
+SOURCES_opengl = opengl.c
diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
new file mode 100644 (file)
index 0000000..0203ad0
--- /dev/null
@@ -0,0 +1,354 @@
+/*****************************************************************************
+ * opengl.c: OpenGL video output
+ *****************************************************************************
+ * Copyright (C) 2004 VideoLAN
+ * $Id$
+ *
+ * Authors: Cyril Deguet <asmax@videolan.org>
+ *          Gildas Bazin <gbazin@videolan.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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <errno.h>                                                 /* ENOMEM */
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
+
+#include <GL/gl.h>
+
+/* RV16 */
+//#define VLCGL_RGB_FORMAT GL_RGB
+//#define VLCGL_RGB_TYPE GL_UNSIGNED_SHORT_5_6_5
+
+/* RV24 */
+//#define VLCGL_RGB_FORMAT GL_RGB
+//#define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE
+
+/* RV32 */
+#define VLCGL_RGB_FORMAT GL_RGBA
+#define VLCGL_RGB_TYPE GL_UNSIGNED_BYTE
+
+/*****************************************************************************
+ * Vout interface
+ *****************************************************************************/
+static int  CreateVout   ( vlc_object_t * );
+static void DestroyVout  ( vlc_object_t * );
+static int  Init         ( vout_thread_t * );
+static void End          ( vout_thread_t * );
+static void Render       ( vout_thread_t *p_vout, picture_t *p_pic );
+static void DisplayVideo ( vout_thread_t *, picture_t * );
+
+static inline int GetAlignedSize( int i_size );
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+vlc_module_begin();
+    set_description( _("OpenGL video output") );
+    set_capability( "video output", 20 );
+    add_shortcut( "opengl" );
+    set_callbacks( CreateVout, DestroyVout );
+vlc_module_end();
+
+/*****************************************************************************
+ * vout_sys_t: video output method descriptor
+ *****************************************************************************
+ * This structure is part of the video output thread descriptor.
+ * It describes the OpenGL specific properties of the output thread.
+ *****************************************************************************/
+struct vout_sys_t
+{
+    vout_thread_t *p_vout;
+
+    uint8_t     *p_buffer;
+    int         i_index;
+    int         i_tex_width;
+    int         i_tex_height;
+    GLuint      texture;
+
+    int         i_effect; //XXX
+
+};
+
+/*****************************************************************************
+ * CreateVout: This function allocates and initializes the OpenGL vout method.
+ *****************************************************************************/
+static int CreateVout( vlc_object_t *p_this )
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+    vout_sys_t *p_sys;
+
+    /* Allocate structure */
+    p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
+    if( p_sys == NULL )
+    {
+        msg_Err( p_vout, "out of memory" );
+        return VLC_EGENERIC;
+    }
+
+    //XXX set to 0 to disable the cube effect
+    p_sys->i_effect = 1;
+
+    /* A texture must have a size aligned on a power of 2 */
+    p_sys->i_tex_width  = GetAlignedSize( p_vout->render.i_width );
+    p_sys->i_tex_height = GetAlignedSize( p_vout->render.i_height );
+
+    msg_Dbg( p_vout, "Texture size: %dx%d", p_sys->i_tex_width,
+             p_sys->i_tex_height );
+
+    /* Get window */
+    p_sys->p_vout =
+        (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
+    if( p_sys->p_vout == NULL )
+    {
+        msg_Err( p_vout, "out of memory" );
+        return VLC_ENOMEM;
+    }
+
+    p_sys->p_vout->i_window_width = p_vout->i_window_width;
+    p_sys->p_vout->i_window_height = p_vout->i_window_height;
+    p_sys->p_vout->b_fullscreen = p_vout->b_fullscreen;
+
+    p_sys->p_vout->p_module =
+        module_Need( p_sys->p_vout, "opengl provider", NULL, 0 );
+    if( p_sys->p_vout->p_module == NULL )
+    {
+        msg_Err( p_vout, "No OpenGL provider found" );
+        vlc_object_destroy( p_sys->p_vout );
+        return VLC_ENOOBJ;
+    }
+    vlc_object_attach( p_sys->p_vout, p_this );
+
+    p_vout->pf_init = Init;
+    p_vout->pf_end = End;
+    p_vout->pf_render = Render;
+    p_vout->pf_display = DisplayVideo;
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Init: initialize the OpenGL video thread output method
+ *****************************************************************************/
+static int Init( vout_thread_t *p_vout )
+{
+    vout_sys_t *p_sys = p_vout->p_sys;
+    int i_pixel_pitch;
+
+    /* No YUV textures :( */
+
+#if VLCGL_RGB_FORMAT == GL_RGB
+#   if VLCGL_RGB_TYPE == GL_UNSIGNED_BYTE
+    p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
+    p_vout->output.i_rmask = 0x000000ff;
+    p_vout->output.i_gmask = 0x0000ff00;
+    p_vout->output.i_bmask = 0x00ff0000;
+    i_pixel_pitch = 3;
+#   else
+    p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
+    p_vout->output.i_rmask = 0xf800;
+    p_vout->output.i_gmask = 0x07e0;
+    p_vout->output.i_bmask = 0x001f;
+    i_pixel_pitch = 2;
+#   endif
+#else
+    p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
+    p_vout->output.i_rmask = 0x000000ff;
+    p_vout->output.i_gmask = 0x0000ff00;
+    p_vout->output.i_bmask = 0x00ff0000;
+    i_pixel_pitch = 4;
+#endif
+
+    /* Since OpenGL can do rescaling for us, stick to the default
+     * coordinates and aspect. */
+    p_vout->output.i_width  = p_vout->render.i_width;
+    p_vout->output.i_height = p_vout->render.i_height;
+    p_vout->output.i_aspect = p_vout->render.i_aspect;
+
+    /* We know the chroma, allocate a buffer which will be used
+     * directly by the decoder */
+    p_vout->p_picture[0].i_planes = 1;
+    p_sys->p_buffer =
+        malloc( p_sys->i_tex_width * p_sys->i_tex_height * i_pixel_pitch );
+    if( !p_sys->p_buffer )
+    {
+        msg_Err( p_vout, "Out of memory" );
+        return -1;
+    }
+
+    p_vout->p_picture[0].p->p_pixels = p_sys->p_buffer;
+    p_vout->p_picture[0].p->i_lines = p_vout->output.i_height;
+    p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch;
+    p_vout->p_picture[0].p->i_pitch = p_sys->i_tex_width *
+        p_vout->p_picture[0].p->i_pixel_pitch;
+    p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width *
+        p_vout->p_picture[0].p->i_pixel_pitch;
+
+    p_vout->p_picture[0].i_status = DESTROYED_PICTURE;
+    p_vout->p_picture[0].i_type   = DIRECT_PICTURE;
+
+    PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0];
+    I_OUTPUTPICTURES = 1;
+
+    /* Set the texture parameters */
+    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+
+    if( p_sys->i_effect )
+    {
+        glEnable( GL_CULL_FACE);
+        /* glDisable( GL_DEPTH_TEST );
+        glEnable( GL_BLEND );
+        glBlendFunc( GL_SRC_ALPHA, GL_ONE );*/
+
+        /* Set the perpective */
+        glMatrixMode( GL_PROJECTION );
+        glLoadIdentity();
+        glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
+        glMatrixMode( GL_MODELVIEW );
+        glLoadIdentity();
+        glTranslatef( 0.0, 0.0, - 5.0 );
+    }
+
+    return 0;
+}
+
+/*****************************************************************************
+ * End: terminate GLX video thread output method
+ *****************************************************************************/
+static void End( vout_thread_t *p_vout )
+{
+    glFinish();
+    glFlush();
+}
+
+/*****************************************************************************
+ * Destroy: destroy GLX video thread output method
+ *****************************************************************************
+ * Terminate an output method created by CreateVout
+ *****************************************************************************/
+static void DestroyVout( vlc_object_t *p_this )
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+    vout_sys_t *p_sys = p_vout->p_sys;
+
+    module_Unneed( p_sys->p_vout, p_sys->p_vout->p_module );
+    vlc_object_detach( p_sys->p_vout );
+    vlc_object_destroy( p_sys->p_vout );
+
+    /* Free the texture buffer*/
+    if( p_sys->p_buffer ) free( p_sys->p_buffer );
+
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * Render: render previously calculated output
+ *****************************************************************************/
+static void Render( vout_thread_t *p_vout, picture_t *p_pic )
+{
+    vout_sys_t *p_sys = p_vout->p_sys;
+    float f_width = (float)p_vout->output.i_width / p_sys->i_tex_width;
+    float f_height = (float)p_vout->output.i_height / p_sys->i_tex_height;
+
+    glClear( GL_COLOR_BUFFER_BIT );
+
+    glTexImage2D( GL_TEXTURE_2D, 0, 3,
+                  p_sys->i_tex_width, p_sys->i_tex_height , 0,
+                  VLCGL_RGB_FORMAT, VLCGL_RGB_TYPE, p_sys->p_buffer );
+
+    if( !p_sys->i_effect )
+    {
+        glEnable( GL_TEXTURE_2D );
+        glBegin( GL_POLYGON );
+        glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, 1.0 );
+        glTexCoord2f( f_width, 0.0 ); glVertex2f( 1.0, 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 );
+        glTexCoord2f( 0.0, f_height ); glVertex2f( -1.0, -1.0 );
+        glEnd();
+    }
+    else
+    {
+        glRotatef( 1.0, 0.3, 0.5, 0.7 );
+
+        glEnable( GL_TEXTURE_2D );
+        glBegin( GL_QUADS );
+
+        /* Front */
+        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, 1.0 );
+        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
+        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, 1.0 );
+
+        /* Left */
+        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
+        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
+        glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, 1.0 );
+
+        /* Back */
+        glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
+        glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
+        glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
+
+        /* Right */
+        glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, 1.0 );
+        glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
+        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
+
+        /* Top */
+        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
+        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, 1.0, 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 );
+        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
+
+        /* Bottom */
+        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, - 1.0, 1.0 );
+        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
+        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
+        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, - 1.0, 1.0 );
+        glEnd();
+    }
+
+    glDisable( GL_TEXTURE_2D);
+}
+
+/*****************************************************************************
+ * DisplayVideo: displays previously rendered output
+ *****************************************************************************/
+static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
+{
+    vout_sys_t *p_sys = p_vout->p_sys;
+    p_sys->p_vout->pf_swap( p_sys->p_vout );
+}
+
+int GetAlignedSize( int i_size )
+{
+    /* Return the nearest power of 2 */
+    int i_result = 1;
+    while( i_result < i_size )
+    {
+        i_result *= 2;
+    }
+    return i_result;
+}
index 49244221c4057beb349d624db40e716b656ad765..9b5c70f00e6e40fb92458b1e2e401cfd251bb1ee 100644 (file)
@@ -11,5 +11,7 @@ SOURCES_xvideo = \
        $(NULL)
 
 SOURCES_glx = \
-    glx.c \
-    $(NULL)
+       glx.c \
+       xcommon.c \
+       xcommon.h \
+       $(NULL)
index 8cc7c588fb8b882e924f94baba0ef491907b766a..057c948bb7ed63a8a29da5f883efd4e21fa87cf4 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
- * glx.c: GLX video output
+ * glx.c: GLX OpenGL provider
  *****************************************************************************
  * Copyright (C) 2004 VideoLAN
  * $Id$
  *
  * Authors: Cyril Deguet <asmax@videolan.org>
+ *          Gildas Bazin <gbazin@videolan.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
 /* For the opengl provider interface */
 #include "vlc_opengl.h"
 
+#ifdef HAVE_SYS_SHM_H
+#   include <sys/shm.h>                                /* shmget(), shmctl() */
+#endif
+
 #include <X11/Xlib.h>
+#include <X11/Xmd.h>
 #include <X11/Xutil.h>
+#include <X11/keysym.h>
+#ifdef HAVE_SYS_SHM_H
+#   include <X11/extensions/XShm.h>
+#endif
+#ifdef DPMSINFO_IN_DPMS_H
+#   include <X11/extensions/dpms.h>
+#endif
+
 #include <GL/glx.h>
 
-/* Data common to vout and opengl provider structures */
-typedef struct glx_t
-{
-    Display     *p_display;
-    int         b_glx13;
-    int         i_width;
-    int         i_height;
-    int         b_fullscreen;
-    GLXContext  gwctx;
-    Window      wnd;
-    GLXWindow   gwnd;
-    Atom        wm_delete;
-
-} glx_t;
+#include "xcommon.h"
 
 /* RV16 */
 //#define VLCGL_RGB_FORMAT GL_RGB
@@ -68,742 +69,255 @@ typedef struct glx_t
 
 
 /*****************************************************************************
- * Vout interface
- *****************************************************************************/
-static int  CreateVout   ( vlc_object_t * );
-static void DestroyVout  ( vlc_object_t * );
-static int  Init         ( vout_thread_t * );
-static void End          ( vout_thread_t * );
-static int  Manage       ( vout_thread_t * );
-static void Render       ( vout_thread_t *p_vout, picture_t *p_pic );
-static void DisplayVideo ( vout_thread_t *, picture_t * );
-
-/*****************************************************************************
- * OpenGL providerinterface
+ * OpenGL provider interface
  *****************************************************************************/
 static int  CreateOpenGL ( vlc_object_t * );
 static void DestroyOpenGL( vlc_object_t * );
-static int  InitOpenGL   ( opengl_t *, int, int );
-static void SwapBuffers  ( opengl_t * );
-static int  HandleEvents ( opengl_t * );
+static void SwapBuffers  ( vout_thread_t * );
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  OpenDisplay ( vlc_object_t *, glx_t * );
-static void CloseDisplay( glx_t * );
-static int  InitGLX12   ( vlc_object_t *, glx_t * );
-static int  InitGLX13   ( vlc_object_t *, glx_t * );
-static void CreateWindow( vlc_object_t *, glx_t *, XVisualInfo *);
-static int  HandleX11Events( vlc_object_t *, glx_t * );
-static void SwitchContext( glx_t * );
-
-static inline int GetAlignedSize( int i_size );
+static int  CheckGLX     ( vlc_object_t *, vlc_bool_t * );
+static int  InitGLX12    ( vout_thread_t * );
+static int  InitGLX13    ( vout_thread_t * );
+static void SwitchContext( vout_thread_t * );
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("X11 OpenGL (GLX) video output") );
-    set_capability( "video output", 20 );
-    add_shortcut( "glx" );
-    set_callbacks( CreateVout, DestroyVout );
-
-    add_submodule();
     set_description( _("X11 OpenGL provider") );
     set_capability( "opengl provider", 50 );
     set_callbacks( CreateOpenGL, DestroyOpenGL );
 vlc_module_end();
 
 /*****************************************************************************
- * vout_sys_t: GLX video output method descriptor
- *****************************************************************************
- * This structure is part of the video output thread descriptor.
- * It describes the GLX specific properties of an output thread.
+ * Exported prototypes
  *****************************************************************************/
-struct vout_sys_t
-{
-    uint8_t     *p_buffer;
-    int         i_index;
-    int         i_tex_width;
-    int         i_tex_height;
-    GLuint      texture;
-    int         i_effect; //XXX
-
-    glx_t       glx;
-};
-
-struct opengl_sys_t
-{
-    glx_t       glx;
-};
-
-
-#define MWM_HINTS_DECORATIONS   (1L << 1)
-#define PROP_MWM_HINTS_ELEMENTS 5
-typedef struct mwmhints_t
-{
-    uint32_t flags;
-    uint32_t functions;
-    uint32_t decorations;
-    int32_t  input_mode;
-    uint32_t status;
-} mwmhints_t;
-
-
-/*****************************************************************************
- * CreateVout: allocates GLX video thread output method
- *****************************************************************************
- * This function allocates and initializes a GLX vout method.
- *****************************************************************************/
-static int CreateVout( vlc_object_t *p_this )
-{
-    vout_thread_t *p_vout = (vout_thread_t *)p_this;
-
-    /* Allocate structure */
-    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
-    if( p_vout->p_sys == NULL )
-    {
-        msg_Err( p_vout, "out of memory" );
-        return( 1 );
-    }
-
-    //XXX set to 0 to disable the cube effect
-    p_vout->p_sys->i_effect = 1;
-
-    p_vout->p_sys->glx.i_width = p_vout->i_window_width;
-    p_vout->p_sys->glx.i_height = p_vout->i_window_height;
-    p_vout->p_sys->glx.b_fullscreen = 0;
-
-    /* A texture must have a size aligned on a power of 2 */
-    p_vout->p_sys->i_tex_width  = GetAlignedSize( p_vout->render.i_width );
-    p_vout->p_sys->i_tex_height = GetAlignedSize( p_vout->render.i_height );
-
-    msg_Dbg( p_vout, "Texture size: %dx%d", p_vout->p_sys->i_tex_width,
-             p_vout->p_sys->i_tex_height );
-
-    /* Open and initialize device */
-    if( OpenDisplay( p_this, &p_vout->p_sys->glx ) )
-    {
-        msg_Err( p_vout, "cannot open display" );
-        free( p_vout->p_sys );
-        return( 1 );
-    }
-
-    p_vout->pf_init = Init;
-    p_vout->pf_end = End;
-    p_vout->pf_manage = Manage;
-    p_vout->pf_render = Render;
-    p_vout->pf_display = DisplayVideo;
-
-    return( 0 );
-}
-
-/*****************************************************************************
- * Init: initialize GLX video thread output method
- *****************************************************************************/
-static int Init( vout_thread_t *p_vout )
-{
-    int i_pixel_pitch;
-
-    /* No YUV textures :( */
-
-#if VLCGL_RGB_FORMAT == GL_RGB
-#   if VLCGL_RGB_TYPE == GL_UNSIGNED_BYTE
-    p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
-    p_vout->output.i_rmask = 0x000000ff;
-    p_vout->output.i_gmask = 0x0000ff00;
-    p_vout->output.i_bmask = 0x00ff0000;
-    i_pixel_pitch = 3;
-#   else
-    p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
-    p_vout->output.i_rmask = 0xf800;
-    p_vout->output.i_gmask = 0x07e0;
-    p_vout->output.i_bmask = 0x001f;
-    i_pixel_pitch = 2;
-#   endif
-#else
-    p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
-    p_vout->output.i_rmask = 0x000000ff;
-    p_vout->output.i_gmask = 0x0000ff00;
-    p_vout->output.i_bmask = 0x00ff0000;
-    i_pixel_pitch = 4;
-#endif
-
-    /* Since OpenGL can do rescaling for us, stick to the default
-     * coordinates and aspect. */
-    p_vout->output.i_width  = p_vout->render.i_width;
-    p_vout->output.i_height = p_vout->render.i_height;
-    p_vout->output.i_aspect = p_vout->render.i_aspect;
-
-    /* We know the chroma, allocate a buffer which will be used
-     * directly by the decoder */
-    p_vout->p_picture[0].i_planes = 1;
-    p_vout->p_sys->p_buffer =
-        malloc( p_vout->p_sys->i_tex_width * p_vout->p_sys->i_tex_height *
-                i_pixel_pitch );
-    if( !p_vout->p_sys->p_buffer )
-    {
-        msg_Err( p_vout, "Out of memory" );
-        return -1;
-    }
-
-    p_vout->p_picture[0].p->p_pixels = p_vout->p_sys->p_buffer;
-    p_vout->p_picture[0].p->i_lines = p_vout->output.i_height;
-    p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch;
-    p_vout->p_picture[0].p->i_pitch = p_vout->p_sys->i_tex_width *
-        p_vout->p_picture[0].p->i_pixel_pitch;
-    p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width *
-        p_vout->p_picture[0].p->i_pixel_pitch;
-
-    p_vout->p_picture[0].i_status = DESTROYED_PICTURE;
-    p_vout->p_picture[0].i_type   = DIRECT_PICTURE;
-
-    PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0];
-    I_OUTPUTPICTURES = 1;
-
-    SwitchContext( &p_vout->p_sys->glx );
-
-    /* Set the texture parameters */
-    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-
-    if( p_vout->p_sys->i_effect )
-    {
-        glEnable( GL_CULL_FACE);
-        /* glDisable( GL_DEPTH_TEST );
-        glEnable( GL_BLEND );
-        glBlendFunc( GL_SRC_ALPHA, GL_ONE );*/
-
-        /* Set the perpective */
-        glMatrixMode( GL_PROJECTION );
-        glLoadIdentity();
-        glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );
-        glMatrixMode( GL_MODELVIEW );
-        glLoadIdentity();
-        glTranslatef( 0.0, 0.0, - 5.0 );
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * End: terminate GLX video thread output method
- *****************************************************************************/
-static void End( vout_thread_t *p_vout )
-{
-    ;
-}
-
-/*****************************************************************************
- * Destroy: destroy GLX video thread output method
- *****************************************************************************
- * Terminate an output method created by CreateVout
- *****************************************************************************/
-static void DestroyVout( vlc_object_t *p_this )
-{
-    vout_thread_t *p_vout = (vout_thread_t *)p_this;
-
-    CloseDisplay( &p_vout->p_sys->glx );
-
-    /* Free the texture buffer*/
-    if( p_vout->p_sys->p_buffer )
-    {
-        free( p_vout->p_sys->p_buffer );
-    }
-
-    free( p_vout->p_sys );
-}
+extern int  E_(Activate)   ( vlc_object_t * );
+extern void E_(Deactivate) ( vlc_object_t * );
 
 /*****************************************************************************
  * CreateOpenGL: initialize an OpenGL provider
  *****************************************************************************/
 static int CreateOpenGL( vlc_object_t *p_this )
 {
-    opengl_t *p_opengl = (opengl_t*)p_this;
-
-    /* Allocate the structure */
-    p_opengl->p_sys = malloc(sizeof(opengl_sys_t));
-
-    /* Set the function pointers */
-    p_opengl->pf_init = InitOpenGL;
-    p_opengl->pf_swap = SwapBuffers;
-    p_opengl->pf_handle_events = HandleEvents;
-
-    p_opengl->p_sys->glx.wnd = None;
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * DestroyOpenGL: destroys an OpenGL provider
- *****************************************************************************/
-static void DestroyOpenGL( vlc_object_t *p_this )
-{
-    opengl_t *p_opengl = (opengl_t*)p_this;
-
-    /* Free the structure */
-    free(p_opengl->p_sys);
-}
-
-/*****************************************************************************
- * InitOpenGL: creates the OpenGL window
- *****************************************************************************/
-static int InitOpenGL( opengl_t *p_opengl, int i_width, int i_height )
-{
-    p_opengl->p_sys->glx.i_width = i_width;
-    p_opengl->p_sys->glx.i_height = i_height;
-    p_opengl->p_sys->glx.b_fullscreen = 0;
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+    vlc_bool_t b_glx13;
 
-    if( OpenDisplay( (vlc_object_t*)p_opengl, &p_opengl->p_sys->glx ) )
+    if( CheckGLX( p_this, &b_glx13 ) != VLC_SUCCESS )
     {
-        msg_Err( p_opengl, "Cannot create OpenGL window" );
+        msg_Err( p_vout, "no GLX support" );
         return VLC_EGENERIC;
     }
 
-    /* Set the OpenGL context _for the current thread_ */
-    SwitchContext( &p_opengl->p_sys->glx );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * SwapBuffers: swap front/back buffers
- *****************************************************************************/
-static void SwapBuffers( opengl_t *p_opengl )
-{
-    if( p_opengl->p_sys->glx.b_glx13 )
-    {
-        glXSwapBuffers( p_opengl->p_sys->glx.p_display,
-                        p_opengl->p_sys->glx.gwnd );
-    }
-    else
+    if( E_(Activate)( p_this ) != VLC_SUCCESS )
     {
-        glXSwapBuffers( p_opengl->p_sys->glx.p_display,
-                        p_opengl->p_sys->glx.wnd );
+        return VLC_EGENERIC;
     }
-}
 
-/*****************************************************************************
- * HandleEvents: handle window events
- *****************************************************************************/
-static int HandleEvents( opengl_t *p_opengl )
-{
-    int i_ret =
-        HandleX11Events( (vlc_object_t*)p_opengl, &p_opengl->p_sys->glx );
-    if( i_ret )
-    {
-        /* close the window */
-        CloseDisplay( &p_opengl->p_sys->glx );
-    }
-    return i_ret;
-}
+    /* Set the function pointer */
+    p_vout->pf_swap = SwapBuffers;
+    p_vout->p_sys->b_glx13 = b_glx13;
 
-/*****************************************************************************
- * Manage: handle X11 events
- *****************************************************************************
- * This function should be called regularly by video output thread. It manages
- * console events. It returns a non null value on error.
- *****************************************************************************/
-static int Manage( vout_thread_t *p_vout )
-{
-    if( HandleX11Events( (vlc_object_t*)p_vout, &p_vout->p_sys->glx ) )
+    /* Initialize GLX */
+    if( !b_glx13 )
     {
-        /* the user wants to close the window */
-        playlist_t * p_playlist =
-            (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
-                                           FIND_ANYWHERE );
-        if( p_playlist != NULL )
+        if( InitGLX12( p_vout ) != VLC_SUCCESS )
         {
-            playlist_Stop( p_playlist );
-            vlc_object_release( p_playlist );
+            return VLC_EGENERIC;
         }
     }
-    return 0;
-}
-
-static int HandleX11Events( vlc_object_t *p_thread, glx_t *p_glx )
-{
-    Display *p_display;
-
-    p_display = p_glx->p_display;
-
-    /* loop on X11 events */
-    while( XPending( p_display ) > 0 )
+    else
     {
-        XEvent evt;
-        XNextEvent( p_display, &evt );
-        switch( evt.type )
+        if( InitGLX13( p_vout ) != VLC_SUCCESS )
         {
-            case ClientMessage:
-            {
-                /* Delete notification */
-                if( (evt.xclient.format == 32) &&
-                    ((Atom)evt.xclient.data.l[0] ==
-                     p_glx->wm_delete) )
-                {
-                    return -1;
-                }
-                break;
-            }
+            return VLC_EGENERIC;
         }
     }
-    return 0;
+
+    /* Set the OpenGL context _for the current thread_ */
+    SwitchContext( p_vout );
+
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
- * Render: render previously calculated output
+ * DestroyOpenGL: destroys an OpenGL provider
  *****************************************************************************/
-static void Render( vout_thread_t *p_vout, picture_t *p_pic )
+static void DestroyOpenGL( vlc_object_t *p_this )
 {
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
     vout_sys_t *p_sys = p_vout->p_sys;
-    float f_width = (float)p_vout->output.i_width / p_sys->i_tex_width;
-    float f_height = (float)p_vout->output.i_height / p_sys->i_tex_height;
 
-    glClear(GL_COLOR_BUFFER_BIT);
-
-    glTexImage2D (GL_TEXTURE_2D, 0, 3, p_vout->p_sys->i_tex_width,
-                  p_vout->p_sys->i_tex_height , 0,
-                  VLCGL_RGB_FORMAT, VLCGL_RGB_TYPE,
-                  p_vout->p_sys->p_buffer);
-
-    if( !p_vout->p_sys->i_effect )
+    glXDestroyContext( p_sys->p_display, p_sys->gwctx );
+    if( p_sys->b_glx13 )
     {
-        glEnable( GL_TEXTURE_2D );
-        glBegin( GL_POLYGON );
-        glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, 1.0 );
-        glTexCoord2f( f_width, 0.0 ); glVertex2f( 1.0, 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 );
-        glTexCoord2f( 0.0, f_height ); glVertex2f( -1.0, -1.0 );
-        glEnd();
+        glXDestroyWindow( p_sys->p_display, p_sys->gwnd );
     }
-    else
-    {
-        glRotatef( 1.0, 0.3, 0.5, 0.7 );
-
-        glEnable( GL_TEXTURE_2D );
-        glBegin( GL_QUADS );
-
-        /* Front */
-        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, 1.0 );
-        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
-        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, 1.0 );
-
-        /* Left */
-        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
-        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 );
-        glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, 1.0 );
-
-        /* Back */
-        glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
-        glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
-        glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
-
-        /* Right */
-        glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, 1.0 );
-        glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
-        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
-
-        /* Top */
-        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 );
-        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, 1.0, 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 );
-        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 );
-
-        /* Bottom */
-        glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, - 1.0, 1.0 );
-        glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 );
-        glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 );
-        glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, - 1.0, 1.0 );
-        glEnd();
-    }
-
-    glDisable( GL_TEXTURE_2D);
-}
 
-/*****************************************************************************
- * DisplayVideo: displays previously rendered output
- *****************************************************************************/
-static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
-{
-    if( p_vout->p_sys->glx.b_glx13 )
-    {
-        glXSwapBuffers( p_vout->p_sys->glx.p_display,
-                        p_vout->p_sys->glx.gwnd );
-    }
-    else
-    {
-        glXSwapBuffers( p_vout->p_sys->glx.p_display,
-                        p_vout->p_sys->glx.wnd );
-    }
+    E_(Deactivate)( p_this );
 }
 
 /*****************************************************************************
  * OpenDisplay: open and initialize OpenGL device
  *****************************************************************************/
-static int OpenDisplay( vlc_object_t *p_thread, glx_t *p_glx )
+static int CheckGLX( vlc_object_t *p_this, vlc_bool_t *b_glx13 )
 {
     Display *p_display;
     int i_opcode, i_evt, i_err;
     int i_maj, i_min;
 
     /* Open the display */
-    p_glx->p_display = p_display = XOpenDisplay( NULL );
+    p_display = XOpenDisplay( NULL );
     if( !p_display )
     {
-        msg_Err( p_thread, "Cannot open display" );
-        return -1;
+        msg_Err( p_this, "Cannot open display" );
+        return VLC_EGENERIC;
     }
 
     /* Check for GLX extension */
     if( !XQueryExtension( p_display, "GLX", &i_opcode, &i_evt, &i_err ) )
     {
-        msg_Err( p_thread, "GLX extension not supported" );
-        return -1;
+        msg_Err( p_this, "GLX extension not supported" );
+        return VLC_EGENERIC;
     }
     if( !glXQueryExtension( p_display, &i_err, &i_evt ) )
     {
-        msg_Err( p_thread, "glXQueryExtension failed" );
-        return -1;
+        msg_Err( p_this, "glXQueryExtension failed" );
+        return VLC_EGENERIC;
     }
 
     /* Check GLX version */
     if (!glXQueryVersion( p_display, &i_maj, &i_min ) )
     {
-        msg_Err( p_thread, "glXQueryVersion failed" );
-        return -1;
+        msg_Err( p_this, "glXQueryVersion failed" );
+        return VLC_EGENERIC;
     }
     if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) )
     {
-        p_glx->b_glx13 = 0;
-        msg_Dbg( p_thread, "Using GLX 1.2 API" );
-        if( InitGLX12( p_thread, p_glx ) == -1 )
-        {
-            return -1;
-        }
+        *b_glx13 = VLC_FALSE;
+        msg_Dbg( p_this, "Using GLX 1.2 API" );
     }
     else
     {
-        p_glx->b_glx13 = 1;
-        msg_Dbg( p_thread, "Using GLX 1.3 API" );
-        if( InitGLX13( p_thread, p_glx ) == -1 )
-        {
-            return -1;
-        }
-    }
-
-    XMapWindow( p_display, p_glx->wnd );
-    if( p_glx->b_fullscreen )
-    {
-        //XXX
-        XMoveWindow( p_display, p_glx->wnd, 0, 0 );
+        *b_glx13 = VLC_TRUE;
+        msg_Dbg( p_this, "Using GLX 1.3 API" );
     }
-    XFlush( p_display );
-    return 0;
-}
-
-/*****************************************************************************
- * CloseDisplay: close and reset OpenGL device
- *****************************************************************************
- * Returns all resources allocated by OpenDisplay and restore the original
- * state of the device.
- *****************************************************************************/
-static void CloseDisplay( glx_t *p_glx )
-{
-    Display *p_display;
 
-    if (p_glx->wnd == None )
-    {
-        // Already closed or not opened...
-        return;
-    }
-
-    glFlush();
-    p_display = p_glx->p_display;
-    glXDestroyContext( p_display, p_glx->gwctx );
-    if( p_glx->b_glx13 )
-    {
-        glXDestroyWindow( p_display, p_glx->gwnd );
-    }
-    XDestroyWindow( p_display, p_glx->wnd );
-    p_glx->wnd = None;
+    return VLC_SUCCESS;
 }
 
-int InitGLX12( vlc_object_t *p_thread, glx_t *p_glx )
+int InitGLX12( vout_thread_t *p_vout )
 {
-    Display *p_display;
+    vout_sys_t *p_sys = p_vout->p_sys;
     XVisualInfo *p_vi;
-    GLXContext gwctx;
     int p_attr[] = { GLX_RGBA, GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5,
-                     GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER,
-                     0 };
+                     GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, 0 };
 
-    p_display = p_glx->p_display;
-
-    p_vi = glXChooseVisual( p_display, DefaultScreen( p_display), p_attr );
+    p_vi = glXChooseVisual( p_sys->p_display,
+                            DefaultScreen( p_sys->p_display), p_attr );
     if(! p_vi )
     {
-        msg_Err( p_thread, "Cannot get GLX 1.2 visual" );
-        return -1;
+        msg_Err( p_vout, "Cannot get GLX 1.2 visual" );
+        return VLC_EGENERIC;
     }
 
-    /* Create the window */
-    CreateWindow( p_thread, p_glx, p_vi );
-
-     /* Create an OpenGL context */
-    p_glx->gwctx = gwctx = glXCreateContext( p_display, p_vi, 0, True );
-    if( !gwctx )
+    /* Create an OpenGL context */
+    p_sys->gwctx = glXCreateContext( p_sys->p_display, p_vi, 0, True );
+    XFree( p_vi );
+    if( !p_sys->gwctx )
     {
-        msg_Err( p_thread, "Cannot create OpenGL context");
-        XFree( p_vi );
-        return -1;
+        msg_Err( p_vout, "Cannot create OpenGL context");
+        return VLC_EGENERIC;
     }
-    XFree( p_vi );
 
-    return 0;
+    return VLC_SUCCESS;
 }
 
-int InitGLX13( vlc_object_t *p_thread, glx_t *p_glx )
+int InitGLX13( vout_thread_t *p_vout )
 {
-    Display *p_display;
+    vout_sys_t *p_sys = p_vout->p_sys;
     int i_nbelem;
     GLXFBConfig *p_fbconfs, fbconf;
     XVisualInfo *p_vi;
-    GLXContext gwctx;
     int p_attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5,
                      GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True,
                      GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0 };
 
-    p_display = p_glx->p_display;
-
     /* Get the FB configuration */
-    p_fbconfs = glXChooseFBConfig( p_display, 0, p_attr, &i_nbelem );
+    p_fbconfs = glXChooseFBConfig( p_sys->p_display, 0, p_attr, &i_nbelem );
     if( (i_nbelem <= 0) || !p_fbconfs )
     {
-        msg_Err( p_thread, "Cannot get FB configurations");
-        if( p_fbconfs )
-        {
-            XFree( p_fbconfs );
-        }
-        return -1;
+        msg_Err( p_vout, "Cannot get FB configurations");
+        if( p_fbconfs ) XFree( p_fbconfs );
+        return VLC_EGENERIC;
     }
     fbconf = p_fbconfs[0];
 
     /* Get the X11 visual */
-    p_vi = glXGetVisualFromFBConfig( p_display, fbconf );
+    p_vi = glXGetVisualFromFBConfig( p_sys->p_display, fbconf );
     if( !p_vi )
     {
-        msg_Err( p_thread, "Cannot get X11 visual" );
+        msg_Err( p_vout, "Cannot get X11 visual" );
         XFree( p_fbconfs );
-        return -1;
+        return VLC_EGENERIC;
     }
-
-    /* Create the window */
-    CreateWindow( p_thread, p_glx, p_vi );
-
     XFree( p_vi );
 
     /* Create the GLX window */
-    p_glx->gwnd = glXCreateWindow( p_display, fbconf, p_glx->wnd, NULL );
-    if( p_glx->gwnd == None )
+    p_sys->gwnd = glXCreateWindow( p_sys->p_display, fbconf,
+                                   p_sys->p_win->video_window, NULL );
+    if( p_sys->gwnd == None )
     {
-        msg_Err( p_thread, "Cannot create GLX window" );
-        return -1;
+        msg_Err( p_vout, "Cannot create GLX window" );
+        return VLC_EGENERIC;
     }
 
     /* Create an OpenGL context */
-    p_glx->gwctx = gwctx = glXCreateNewContext( p_display, fbconf,
-                                                  GLX_RGBA_TYPE, NULL, True );
-    if( !gwctx )
+    p_sys->gwctx = glXCreateNewContext( p_sys->p_display, fbconf,
+                                        GLX_RGBA_TYPE, NULL, True );
+    XFree( p_fbconfs );
+    if( !p_sys->gwctx )
     {
-        msg_Err( p_thread, "Cannot create OpenGL context");
-        XFree( p_fbconfs );
-        return -1;
+        msg_Err( p_vout, "Cannot create OpenGL context");
+        return VLC_EGENERIC;
     }
-    XFree( p_fbconfs );
 
-    return 0;
+    return VLC_SUCCESS;
 }
 
-void CreateWindow( vlc_object_t *p_thread, glx_t *p_glx, XVisualInfo *p_vi )
+/*****************************************************************************
+ * SwapBuffers: swap front/back buffers
+ *****************************************************************************/
+static void SwapBuffers( vout_thread_t *p_vout )
 {
-    Display *p_display;
-    XSetWindowAttributes xattr;
-    Window wnd;
-    Colormap cm;
-    XSizeHints* p_size_hints;
-    Atom prop;
-    mwmhints_t mwmhints;
-
-    p_display = p_glx->p_display;
-
-    /* Create a colormap */
-    cm = XCreateColormap( p_display, RootWindow( p_display, p_vi->screen ),
-                          p_vi->visual, AllocNone );
-
-    /* Create the window */
-    xattr.background_pixel = BlackPixel( p_display, DefaultScreen(p_display) );
-    xattr.border_pixel = 0;
-    xattr.colormap = cm;
-    p_glx->wnd = wnd = XCreateWindow( p_display, DefaultRootWindow(p_display),
-            0, 0, p_glx->i_width, p_glx->i_height, 0, p_vi->depth,
-            InputOutput, p_vi->visual,
-            CWBackPixel | CWBorderPixel | CWColormap, &xattr);
-
-    /* Allow the window to be deleted by the window manager */
-    p_glx->wm_delete = XInternAtom( p_display, "WM_DELETE_WINDOW", False );
-    XSetWMProtocols( p_display, wnd, &p_glx->wm_delete, 1 );
-
-    if( p_glx->b_fullscreen )
-    {
-        mwmhints.flags = MWM_HINTS_DECORATIONS;
-        mwmhints.decorations = False;
+    vout_sys_t *p_sys = p_vout->p_sys;
 
-        prop = XInternAtom( p_display, "_MOTIF_WM_HINTS", False );
-        XChangeProperty( p_display, wnd, prop, prop, 32, PropModeReplace,
-                         (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS );
+    if( p_sys->b_glx13 )
+    {
+        glXSwapBuffers( p_sys->p_display, p_sys->gwnd );
     }
     else
     {
-        /* Prevent the window from being resized */
-        p_size_hints = XAllocSizeHints();
-        p_size_hints->flags = PMinSize | PMaxSize;
-        p_size_hints->min_width = p_glx->i_width;
-        p_size_hints->min_height = p_glx->i_height;
-        p_size_hints->max_width = p_glx->i_width;
-        p_size_hints->max_height = p_glx->i_height;
-        XSetWMNormalHints( p_display, wnd, p_size_hints );
-        XFree( p_size_hints );
+        glXSwapBuffers( p_sys->p_display, p_sys->p_win->video_window );
     }
-    XSelectInput( p_display, wnd, KeyPressMask );
 }
 
-void SwitchContext( glx_t *p_glx )
+void SwitchContext( vout_thread_t *p_vout )
 {
+    vout_sys_t *p_sys = p_vout->p_sys;
+
     /* Change the current OpenGL context */
-    if( p_glx->b_glx13 )
+    if( p_sys->b_glx13 )
     {
-        glXMakeContextCurrent( p_glx->p_display, p_glx->gwnd,
-                               p_glx->gwnd, p_glx->gwctx );
+        glXMakeContextCurrent( p_sys->p_display, p_sys->gwnd,
+                               p_sys->gwnd, p_sys->gwctx );
     }
     else
     {
-        glXMakeCurrent( p_glx->p_display, p_glx->wnd,
-                        p_glx->gwctx );
-    }
-}
-
-int GetAlignedSize( int i_size )
-{
-    /* Return the nearest power of 2 */
-    int i_result = 1;
-    while( i_result < i_size )
-    {
-        i_result *= 2;
+        glXMakeCurrent( p_sys->p_display, p_sys->p_win->video_window,
+                        p_sys->gwctx );
     }
-    return i_result;
 }
index 6055ec0ee4bdf4f82b87735548dc6388994eddb5..2edf66b6aafa324bdf7680bbb0c8fdb8bde4db64 100644 (file)
 #   include <X11/extensions/Xvlib.h>
 #endif
 
+#ifdef MODULE_NAME_IS_glx
+#   include <GL/glx.h>
+#endif
+
 #ifdef HAVE_XINERAMA
 #   include <X11/extensions/Xinerama.h>
 #endif
@@ -318,7 +322,7 @@ void E_(Deactivate) ( vlc_object_t *p_this )
     {
         XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
     }
-#else
+#elif defined(MODULE_NAME_IS_xvideo)
     XVideoReleasePort( p_vout, p_vout->p_sys->i_xvport );
 #endif
 
@@ -368,7 +372,7 @@ static int InitVideo( vout_thread_t *p_vout )
             break;
     }
 
-#else
+#elif defined(MODULE_NAME_IS_x11)
     /* Initialize the output structure: RGB with square pixels, whatever
      * the input format is, since it's the only format we know */
     switch( p_vout->p_sys->i_screen_depth )
@@ -431,7 +435,7 @@ static int InitVideo( vout_thread_t *p_vout )
     return VLC_SUCCESS;
 }
 
- /*****************************************************************************
+/*****************************************************************************
  * DisplayVideo: displays previously rendered output
  *****************************************************************************
  * This function sends the currently rendered image to X11 server.
@@ -1140,6 +1144,8 @@ static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
  *****************************************************************************/
 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
+#ifndef MODULE_NAME_IS_glx
+
 #ifdef MODULE_NAME_IS_xvideo
     int i_plane;
 #endif
@@ -1259,6 +1265,8 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
             return -1;
     }
 
+#endif /* !MODULE_NAME_IS_glx */
+
     return 0;
 }
 
@@ -2015,7 +2023,7 @@ static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout,
     /* Allocate memory for image */
 #ifdef MODULE_NAME_IS_xvideo
     p_data = (byte_t *) malloc( i_width * i_height * i_bits_per_pixel / 8 );
-#else
+#elif defined(MODULE_NAME_IS_x11)
     i_bytes_per_line = i_width * i_bytes_per_pixel;
     p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
 #endif
@@ -2046,7 +2054,7 @@ static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout,
 #ifdef MODULE_NAME_IS_xvideo
     p_image = XvCreateImage( p_display, i_xvport, i_chroma,
                              p_data, i_width, i_height );
-#else
+#elif defined(MODULE_NAME_IS_x11)
     p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
                             p_data, i_width, i_height, i_quantum, 0 );
 #endif
index b6974ee90abf0e59187ce9b9b9f034aba89b83d0..1e6f6b654435efd49bbfbdb8ceb01e0749c0e1b6 100644 (file)
@@ -142,6 +142,13 @@ struct vout_sys_t
     vlc_bool_t          b_net_wm_state_stays_on_top;
     Atom                net_wm_state_below;
     vlc_bool_t          b_net_wm_state_below;
+
+#ifdef MODULE_NAME_IS_glx
+    /* GLX properties */
+    int                 b_glx13;
+    GLXContext          gwctx;
+    GLXWindow           gwnd;
+#endif
 };
 
 /*****************************************************************************
@@ -174,6 +181,7 @@ typedef struct mwmhints_t
     uint32_t decorations;
     int32_t  input_mode;
     uint32_t status;
+
 } mwmhints_t;
 
 /*****************************************************************************
index e9c60ae2e81a196e900b452e92ec5db386d30108..9edc78c7f2c3df306e78cab625c6fea9e1936118 100644 (file)
@@ -23,7 +23,6 @@
  *****************************************************************************/
 
 #include "plugin.h"
-#include "vlc_opengl.h"
 #include <GL/gl.h>
 #include <GL/glu.h>
 #include <unistd.h>
@@ -270,10 +269,12 @@ int galaktos_update( galaktos_thread_t *p_thread )
     glFinish();
     glFlush();
     //  printf("Flush %d\n",(SDL_GetTicks()-timestart));
-    (p_thread->p_opengl->pf_swap)( p_thread->p_opengl );
+
+    p_thread->p_opengl->pf_swap( p_thread->p_opengl );
 
     /* Process events */
-    if( (p_thread->p_opengl->pf_handle_events)( p_thread->p_opengl ) )
+    if( p_thread->p_opengl->pf_manage &&
+        p_thread->p_opengl->pf_manage( p_thread->p_opengl ) )
     {
         return 1;
     }
index 35e9cd428600bda2ad483ea1c980345dfdac12ab..a62bea1ce2ac4c5480a8d4f34e9cb53c84fbbfc7 100644 (file)
@@ -37,7 +37,6 @@
 #include <vlc/input.h>
 #include <vlc/vout.h>
 #include "aout_internal.h"
-#include "vlc_opengl.h"
 
 /*****************************************************************************
  * Module descriptor
@@ -79,7 +78,6 @@ static int Open( vlc_object_t *p_this )
     aout_filter_t     *p_filter = (aout_filter_t *)p_this;
     aout_filter_sys_t *p_sys;
     galaktos_thread_t *p_thread;
-    vlc_value_t       width, height;
 
     if ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2' )
          || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
@@ -104,25 +102,6 @@ static int Open( vlc_object_t *p_this )
         vlc_object_create( p_filter, sizeof( galaktos_thread_t ) );
     vlc_object_attach( p_thread, p_this );
 
-    /* Get on OpenGL provider */
-    p_thread->p_opengl =
-        (opengl_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
-    if( p_thread->p_opengl == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
-        return VLC_ENOMEM;
-    }
-
-    p_thread->p_module =
-        module_Need( p_thread->p_opengl, "opengl provider", NULL, 0 );
-    if( p_thread->p_module == NULL )
-    {
-        msg_Err( p_filter, "No OpenGL provider found" );
-        vlc_object_destroy( p_thread->p_opengl );
-        p_thread->p_opengl = NULL;
-        return VLC_ENOOBJ;
-    }
-
 /*
     var_Create( p_thread, "galaktos-width", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
     var_Get( p_thread, "galaktos-width", &width );
@@ -155,7 +134,6 @@ static int Open( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
-
 /*****************************************************************************
  * float to s16 conversion
  *****************************************************************************/
@@ -169,7 +147,6 @@ static inline int16_t FloatToInt16( float f )
         return (int16_t)( f * 32768.0 );
 }
 
-
 /*****************************************************************************
  * DoWork: process samples buffer
  *****************************************************************************
@@ -221,9 +198,31 @@ static void Thread( vlc_object_t *p_this )
     int timestart=0;
     int mspf=0;
 
-    /* Initialize the opengl provider */
-    (p_thread->p_opengl->pf_init)(p_thread->p_opengl, p_thread->i_width,
-                                  p_thread->i_height);
+    /* Get on OpenGL provider */
+    p_thread->p_opengl =
+        (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
+    if( p_thread->p_opengl == NULL )
+    {
+        msg_Err( p_thread, "out of memory" );
+        return;
+    }
+
+    p_thread->p_opengl->i_window_width = p_thread->i_width;
+    p_thread->p_opengl->i_window_height = p_thread->i_height;
+    p_thread->p_opengl->render.i_width = p_thread->i_width;
+    p_thread->p_opengl->render.i_height = p_thread->i_width;
+    p_thread->p_opengl->render.i_aspect = VOUT_ASPECT_FACTOR;
+
+    p_thread->p_module =
+        module_Need( p_thread->p_opengl, "opengl provider", NULL, 0 );
+    if( p_thread->p_module == NULL )
+    {
+        msg_Err( p_thread, "No OpenGL provider found" );
+        vlc_object_destroy( p_thread->p_opengl );
+        return;
+    }
+
+    vlc_object_attach( p_thread->p_opengl, p_this );
 
     setup_opengl( p_thread->i_width, p_thread->i_height );
     CreateRenderTarget(512, &RenderTargetTextureID, NULL);
@@ -275,6 +274,7 @@ static void Close( vlc_object_t *p_this )
 
     /* Free the openGL provider */
     module_Unneed( p_sys->p_thread->p_opengl, p_sys->p_thread->p_module );
+    vlc_object_detach( p_sys->p_thread->p_opengl );
     vlc_object_destroy( p_sys->p_thread->p_opengl );
 
     /* Free data */
index 74cda7f9d7827ecf17585cc835acf47bd78d6c47..724ab8a1cbc12d69432c1fbd9237eeef60378139 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc/aout.h>
+#include <vlc/vout.h>
 
 #define MAX_BLOCKS 10
 
@@ -36,7 +37,7 @@ typedef struct
     char          *psz_title;
 
     /* OpenGL provider */
-    opengl_t      *p_opengl;
+    vout_thread_t *p_opengl;
     module_t      *p_module;
 
     /* Window properties */