Changeset bb13e2278049b34b5d8400f3887a5f2356e2cf4b

Show
Ignore:
Timestamp:
22/07/04 23:27:45 (4 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1090531665 +0000
git-parent:

[6129f1ce2060d74635559b70116c5b617244b970]

git-author:
Gildas Bazin <gbazin@videolan.org> 1090531665 +0000
Message:

* modules/video_output/x11/*: the glx "opengl provider" makes use of xcommon.c.
* modules/video_output/opengl.c: new platform independant OpenGL vout (uses an "opengl provider" module).
* modules/visualization/galaktos/*: uses the new "opengl provider" module.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.ac

    r6129f1c rbb13e22  
    24162416 
    24172417dnl 
     2418dnl  GLX module 
     2419dnl  (enabled by default except on win32) 
     2420dnl 
     2421AC_ARG_ENABLE(glx, 
     2422  [  --enable-glx            X11 OpenGL (GLX) support (default enabled)]) 
     2423if test "${enable_glx}" != "no" && 
     2424  (test "${SYS}" != "mingw32" || test "${enable_glx}" = "yes"); then 
     2425  CPPFLAGS="${CPPFLAGS_save} -I${x_includes}" 
     2426  AC_CHECK_HEADERS(X11/Xlib.h, [ 
     2427    AC_CHECK_HEADERS(GL/glx.h, [ 
     2428      VLC_ADD_PLUGINS([glx]) 
     2429      VLC_ADD_LDFLAGS([glx],[-L${x_libraries} -lX11 -lXext -lGL -lGLU]) 
     2430      VLC_ADD_CPPFLAGS([glx],[-I${x_includes}]) 
     2431  ]) ]) 
     2432  CPPFLAGS="${CPPFLAGS_save}" 
     2433fi 
     2434 
     2435dnl 
    24182436dnl  Check for the Xinerama extension 
    24192437dnl 
     
    24272445      VLC_ADD_LDFLAGS([xvideo],[-lXinerama_pic]) 
    24282446      VLC_ADD_LDFLAGS([x11],[-lXinerama_pic]) 
     2447      VLC_ADD_LDFLAGS([glx],[-lXinerama_pic]) 
    24292448      ac_cv_have_xinerama="yes" 
    24302449    ],[ 
     
    24322451        VLC_ADD_LDFLAGS([xvideo],[-lXinerama]) 
    24332452        VLC_ADD_LDFLAGS([x11],[-lXinerama]) 
     2453        VLC_ADD_LDFLAGS([glx],[-lXinerama]) 
    24342454        ac_cv_have_xinerama="yes" 
    24352455      ]) 
     
    24402460  fi 
    24412461  CFLAGS="${CFLAGS_save}" 
     2462  CPPFLAGS="${CPPFLAGS_save}" 
     2463fi 
     2464 
     2465dnl 
     2466dnl  GLX module 
     2467dnl  (enabled by default except on win32) 
     2468dnl 
     2469AC_ARG_ENABLE(opengl, 
     2470  [  --enable-opengl            OpenGL support (default enabled)]) 
     2471if test "${enable_opengl}" != "no"; then 
     2472  AC_CHECK_HEADERS(GL/gl.h, [ 
     2473      VLC_ADD_PLUGINS([opengl]) 
     2474      VLC_ADD_LDFLAGS([opengl],[-L${x_libraries} -lGL -lGLU]) 
     2475  ]) 
    24422476  CPPFLAGS="${CPPFLAGS_save}" 
    24432477fi 
     
    27542788      fi ]) 
    27552789fi 
    2756  
    2757 dnl 
    2758 dnl  GLX module 
    2759 dnl 
    2760 AC_ARG_ENABLE(glx, 
    2761   [  --enable-glx            X11 OpenGL (GLX) support (default disabled)]) 
    2762 if test "${enable_glx}" = "yes" 
    2763 then 
    2764   VLC_ADD_PLUGINS([glx]) 
    2765   VLC_ADD_LDFLAGS([glx],[-lGL -lGLU]) 
    2766 fi 
    2767  
    27682790 
    27692791dnl 
  • include/video_output.h

    r8f80181 rbb13e22  
    103103    void      ( *pf_render )     ( vout_thread_t *, picture_t * ); 
    104104    void      ( *pf_display )    ( vout_thread_t *, picture_t * ); 
     105    void      ( *pf_swap )       ( vout_thread_t * );         /* OpenGL only */ 
    105106    int       ( *pf_control )    ( vout_thread_t *, int, va_list ); 
    106107    /**@}*/ 
  • modules/video_output/Modules.am

    r3cb9a09 rbb13e22  
    1010SOURCES_hd1000v = hd1000v.cpp 
    1111SOURCES_snapshot = snapshot.c 
     12SOURCES_opengl = opengl.c 
  • modules/video_output/x11/Modules.am

    rc0a1dbe rbb13e22  
    1212 
    1313SOURCES_glx = \ 
    14     glx.c \ 
    15     $(NULL) 
     14    glx.c \ 
     15    xcommon.c \ 
     16    xcommon.h \ 
     17    $(NULL) 
  • modules/video_output/x11/glx.c

    r23d3f63 rbb13e22  
    11/***************************************************************************** 
    2  * glx.c: GLX video output 
     2 * glx.c: GLX OpenGL provider 
    33 ***************************************************************************** 
    44 * Copyright (C) 2004 VideoLAN 
     
    66 * 
    77 * Authors: Cyril Deguet <asmax@videolan.org> 
     8 *          Gildas Bazin <gbazin@videolan.org> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    3637#include "vlc_opengl.h" 
    3738 
     39#ifdef HAVE_SYS_SHM_H 
     40#   include <sys/shm.h>                                /* shmget(), shmctl() */ 
     41#endif 
     42 
    3843#include <X11/Xlib.h> 
     44#include <X11/Xmd.h> 
    3945#include <X11/Xutil.h> 
     46#include <X11/keysym.h> 
     47#ifdef HAVE_SYS_SHM_H 
     48#   include <X11/extensions/XShm.h> 
     49#endif 
     50#ifdef DPMSINFO_IN_DPMS_H 
     51#   include <X11/extensions/dpms.h> 
     52#endif 
     53 
    4054#include <GL/glx.h> 
    4155 
    42 /* Data common to vout and opengl provider structures */ 
    43 typedef struct glx_t 
    44 
    45     Display     *p_display; 
    46     int         b_glx13; 
    47     int         i_width; 
    48     int         i_height; 
    49     int         b_fullscreen; 
    50     GLXContext  gwctx; 
    51     Window      wnd; 
    52     GLXWindow   gwnd; 
    53     Atom        wm_delete; 
    54  
    55 } glx_t; 
     56#include "xcommon.h" 
    5657 
    5758/* RV16 */ 
     
    6970 
    7071/***************************************************************************** 
    71  * Vout interface 
    72  *****************************************************************************/ 
    73 static int  CreateVout   ( vlc_object_t * ); 
    74 static void DestroyVout  ( vlc_object_t * ); 
    75 static int  Init         ( vout_thread_t * ); 
    76 static void End          ( vout_thread_t * ); 
    77 static int  Manage       ( vout_thread_t * ); 
    78 static void Render       ( vout_thread_t *p_vout, picture_t *p_pic ); 
    79 static void DisplayVideo ( vout_thread_t *, picture_t * ); 
    80  
    81 /***************************************************************************** 
    82  * OpenGL providerinterface 
     72 * OpenGL provider interface 
    8373 *****************************************************************************/ 
    8474static int  CreateOpenGL ( vlc_object_t * ); 
    8575static void DestroyOpenGL( vlc_object_t * ); 
    86 static int  InitOpenGL   ( opengl_t *, int, int ); 
    87 static void SwapBuffers  ( opengl_t * ); 
    88 static int  HandleEvents ( opengl_t * ); 
     76static void SwapBuffers  ( vout_thread_t * ); 
    8977 
    9078/***************************************************************************** 
    9179 * Local prototypes 
    9280 *****************************************************************************/ 
    93 static int  OpenDisplay ( vlc_object_t *, glx_t * ); 
    94 static void CloseDisplay( glx_t * ); 
    95 static int  InitGLX12   ( vlc_object_t *, glx_t * ); 
    96 static int  InitGLX13   ( vlc_object_t *, glx_t * ); 
    97 static void CreateWindow( vlc_object_t *, glx_t *, XVisualInfo *); 
    98 static int  HandleX11Events( vlc_object_t *, glx_t * ); 
    99 static void SwitchContext( glx_t * ); 
    100  
    101 static inline int GetAlignedSize( int i_size ); 
     81static int  CheckGLX     ( vlc_object_t *, vlc_bool_t * ); 
     82static int  InitGLX12    ( vout_thread_t * ); 
     83static int  InitGLX13    ( vout_thread_t * ); 
     84static void SwitchContext( vout_thread_t * ); 
    10285 
    10386/***************************************************************************** 
     
    10588 *****************************************************************************/ 
    10689vlc_module_begin(); 
    107     set_description( _("X11 OpenGL (GLX) video output") ); 
    108     set_capability( "video output", 20 ); 
    109     add_shortcut( "glx" ); 
    110     set_callbacks( CreateVout, DestroyVout ); 
    111  
    112     add_submodule(); 
    11390    set_description( _("X11 OpenGL provider") ); 
    11491    set_capability( "opengl provider", 50 ); 
     
    11794 
    11895/***************************************************************************** 
    119  * vout_sys_t: GLX video output method descriptor 
    120  ***************************************************************************** 
    121  * This structure is part of the video output thread descriptor. 
    122  * It describes the GLX specific properties of an output thread. 
    123  *****************************************************************************/ 
    124 struct vout_sys_t 
    125 
    126     uint8_t     *p_buffer; 
    127     int         i_index; 
    128     int         i_tex_width; 
    129     int         i_tex_height; 
    130     GLuint      texture; 
    131     int         i_effect; //XXX 
    132  
    133     glx_t       glx; 
    134 }; 
    135  
    136 struct opengl_sys_t 
    137 
    138     glx_t       glx; 
    139 }; 
    140  
    141  
    142 #define MWM_HINTS_DECORATIONS   (1L << 1) 
    143 #define PROP_MWM_HINTS_ELEMENTS 5 
    144 typedef struct mwmhints_t 
    145 
    146     uint32_t flags; 
    147     uint32_t functions; 
    148     uint32_t decorations; 
    149     int32_t  input_mode; 
    150     uint32_t status; 
    151 } mwmhints_t; 
    152  
    153  
    154 /***************************************************************************** 
    155  * CreateVout: allocates GLX video thread output method 
    156  ***************************************************************************** 
    157  * This function allocates and initializes a GLX vout method. 
    158  *****************************************************************************/ 
    159 static int CreateVout( vlc_object_t *p_this ) 
     96 * Exported prototypes 
     97 *****************************************************************************/ 
     98extern int  E_(Activate)   ( vlc_object_t * ); 
     99extern void E_(Deactivate) ( vlc_object_t * ); 
     100 
     101/***************************************************************************** 
     102 * CreateOpenGL: initialize an OpenGL provider 
     103 *****************************************************************************/ 
     104static int CreateOpenGL( vlc_object_t *p_this ) 
    160105{ 
    161106    vout_thread_t *p_vout = (vout_thread_t *)p_this; 
    162  
    163     /* Allocate structure */ 
    164     p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); 
    165     if( p_vout->p_sys == NULL ) 
    166     { 
    167         msg_Err( p_vout, "out of memory" ); 
    168         return( 1 ); 
    169     } 
    170  
    171     //XXX set to 0 to disable the cube effect 
    172     p_vout->p_sys->i_effect = 1; 
    173  
    174     p_vout->p_sys->glx.i_width = p_vout->i_window_width; 
    175     p_vout->p_sys->glx.i_height = p_vout->i_window_height; 
    176     p_vout->p_sys->glx.b_fullscreen = 0; 
    177  
    178     /* A texture must have a size aligned on a power of 2 */ 
    179     p_vout->p_sys->i_tex_width  = GetAlignedSize( p_vout->render.i_width ); 
    180     p_vout->p_sys->i_tex_height = GetAlignedSize( p_vout->render.i_height ); 
    181  
    182     msg_Dbg( p_vout, "Texture size: %dx%d", p_vout->p_sys->i_tex_width, 
    183              p_vout->p_sys->i_tex_height ); 
    184  
    185     /* Open and initialize device */ 
    186     if( OpenDisplay( p_this, &p_vout->p_sys->glx ) ) 
    187     { 
    188         msg_Err( p_vout, "cannot open display" ); 
    189         free( p_vout->p_sys ); 
    190         return( 1 ); 
    191     } 
    192  
    193     p_vout->pf_init = Init; 
    194     p_vout->pf_end = End; 
    195     p_vout->pf_manage = Manage; 
    196     p_vout->pf_render = Render; 
    197     p_vout->pf_display = DisplayVideo; 
    198  
    199     return( 0 ); 
    200 
    201  
    202 /***************************************************************************** 
    203  * Init: initialize GLX video thread output method 
    204  *****************************************************************************/ 
    205 static int Init( vout_thread_t *p_vout ) 
    206 
    207     int i_pixel_pitch; 
    208  
    209     /* No YUV textures :( */ 
    210  
    211 #if VLCGL_RGB_FORMAT == GL_RGB 
    212 #   if VLCGL_RGB_TYPE == GL_UNSIGNED_BYTE 
    213     p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); 
    214     p_vout->output.i_rmask = 0x000000ff; 
    215     p_vout->output.i_gmask = 0x0000ff00; 
    216     p_vout->output.i_bmask = 0x00ff0000; 
    217     i_pixel_pitch = 3; 
    218 #   else 
    219     p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); 
    220     p_vout->output.i_rmask = 0xf800; 
    221     p_vout->output.i_gmask = 0x07e0; 
    222     p_vout->output.i_bmask = 0x001f; 
    223     i_pixel_pitch = 2; 
    224 #   endif 
    225 #else 
    226     p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); 
    227     p_vout->output.i_rmask = 0x000000ff; 
    228     p_vout->output.i_gmask = 0x0000ff00; 
    229     p_vout->output.i_bmask = 0x00ff0000; 
    230     i_pixel_pitch = 4; 
    231 #endif 
    232  
    233     /* Since OpenGL can do rescaling for us, stick to the default 
    234      * coordinates and aspect. */ 
    235     p_vout->output.i_width  = p_vout->render.i_width; 
    236     p_vout->output.i_height = p_vout->render.i_height; 
    237     p_vout->output.i_aspect = p_vout->render.i_aspect; 
    238  
    239     /* We know the chroma, allocate a buffer which will be used 
    240      * directly by the decoder */ 
    241     p_vout->p_picture[0].i_planes = 1; 
    242     p_vout->p_sys->p_buffer = 
    243         malloc( p_vout->p_sys->i_tex_width * p_vout->p_sys->i_tex_height * 
    244                 i_pixel_pitch ); 
    245     if( !p_vout->p_sys->p_buffer ) 
    246     { 
    247         msg_Err( p_vout, "Out of memory" ); 
    248         return -1; 
    249     } 
    250  
    251     p_vout->p_picture[0].p->p_pixels = p_vout->p_sys->p_buffer; 
    252     p_vout->p_picture[0].p->i_lines = p_vout->output.i_height; 
    253     p_vout->p_picture[0].p->i_pixel_pitch = i_pixel_pitch; 
    254     p_vout->p_picture[0].p->i_pitch = p_vout->p_sys->i_tex_width * 
    255         p_vout->p_picture[0].p->i_pixel_pitch; 
    256     p_vout->p_picture[0].p->i_visible_pitch = p_vout->output.i_width * 
    257         p_vout->p_picture[0].p->i_pixel_pitch; 
    258  
    259     p_vout->p_picture[0].i_status = DESTROYED_PICTURE; 
    260     p_vout->p_picture[0].i_type   = DIRECT_PICTURE; 
    261  
    262     PP_OUTPUTPICTURE[ 0 ] = &p_vout->p_picture[0]; 
    263     I_OUTPUTPICTURES = 1; 
    264  
    265     SwitchContext( &p_vout->p_sys->glx ); 
    266  
    267     /* Set the texture parameters */ 
    268     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 
    269     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 
    270  
    271     if( p_vout->p_sys->i_effect ) 
    272     { 
    273         glEnable( GL_CULL_FACE); 
    274         /* glDisable( GL_DEPTH_TEST ); 
    275         glEnable( GL_BLEND ); 
    276         glBlendFunc( GL_SRC_ALPHA, GL_ONE );*/ 
    277  
    278         /* Set the perpective */ 
    279         glMatrixMode( GL_PROJECTION ); 
    280         glLoadIdentity(); 
    281         glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 ); 
    282         glMatrixMode( GL_MODELVIEW ); 
    283         glLoadIdentity(); 
    284         glTranslatef( 0.0, 0.0, - 5.0 ); 
    285     } 
    286  
    287     return 0; 
    288 
    289  
    290 /***************************************************************************** 
    291  * End: terminate GLX video thread output method 
    292  *****************************************************************************/ 
    293 static void End( vout_thread_t *p_vout ) 
    294 
    295     ; 
    296 
    297  
    298 /***************************************************************************** 
    299  * Destroy: destroy GLX video thread output method 
    300  ***************************************************************************** 
    301  * Terminate an output method created by CreateVout 
    302  *****************************************************************************/ 
    303 static void DestroyVout( vlc_object_t *p_this ) 
     107    vlc_bool_t b_glx13; 
     108 
     109    if( CheckGLX( p_this, &b_glx13 ) != VLC_SUCCESS ) 
     110    { 
     111        msg_Err( p_vout, "no GLX support" ); 
     112        return VLC_EGENERIC; 
     113    } 
     114 
     115    if( E_(Activate)( p_this ) != VLC_SUCCESS ) 
     116    { 
     117        return VLC_EGENERIC; 
     118    } 
     119 
     120    /* Set the function pointer */ 
     121    p_vout->pf_swap = SwapBuffers; 
     122    p_vout->p_sys->b_glx13 = b_glx13; 
     123 
     124    /* Initialize GLX */ 
     125    if( !b_glx13 ) 
     126    { 
     127        if( InitGLX12( p_vout ) != VLC_SUCCESS ) 
     128        { 
     129            return VLC_EGENERIC; 
     130        } 
     131    } 
     132    else 
     133    { 
     134        if( InitGLX13( p_vout ) != VLC_SUCCESS ) 
     135        { 
     136            return VLC_EGENERIC; 
     137        } 
     138    } 
     139 
     140    /* Set the OpenGL context _for the current thread_ */ 
     141    SwitchContext( p_vout ); 
     142 
     143    return VLC_SUCCESS; 
     144
     145 
     146/***************************************************************************** 
     147 * DestroyOpenGL: destroys an OpenGL provider 
     148 *****************************************************************************/ 
     149static void DestroyOpenGL( vlc_object_t *p_this ) 
    304150{ 
    305151    vout_thread_t *p_vout = (vout_thread_t *)p_this; 
    306  
    307     CloseDisplay( &p_vout->p_sys->glx ); 
    308  
    309     /* Free the texture buffer*/ 
    310     if( p_vout->p_sys->p_buffer ) 
    311     { 
    312         free( p_vout->p_sys->p_buffer ); 
    313     } 
    314  
    315     free( p_vout->p_sys ); 
    316 
    317  
    318 /***************************************************************************** 
    319  * CreateOpenGL: initialize an OpenGL provider 
    320  *****************************************************************************/ 
    321 static int CreateOpenGL( vlc_object_t *p_this ) 
    322 
    323     opengl_t *p_opengl = (opengl_t*)p_this; 
    324  
    325     /* Allocate the structure */ 
    326     p_opengl->p_sys = malloc(sizeof(opengl_sys_t)); 
    327  
    328     /* Set the function pointers */ 
    329     p_opengl->pf_init = InitOpenGL; 
    330     p_opengl->pf_swap = SwapBuffers; 
    331     p_opengl->pf_handle_events = HandleEvents; 
    332  
    333     p_opengl->p_sys->glx.wnd = None; 
    334  
    335     return VLC_SUCCESS; 
    336 
    337  
    338 /***************************************************************************** 
    339  * DestroyOpenGL: destroys an OpenGL provider 
    340  *****************************************************************************/ 
    341 static void DestroyOpenGL( vlc_object_t *p_this ) 
    342 
    343     opengl_t *p_opengl = (opengl_t*)p_this; 
    344  
    345     /* Free the structure */ 
    346     free(p_opengl->p_sys); 
    347 
    348  
    349 /***************************************************************************** 
    350  * InitOpenGL: creates the OpenGL window 
    351  *****************************************************************************/ 
    352 static int InitOpenGL( opengl_t *p_opengl, int i_width, int i_height ) 
    353 
    354     p_opengl->p_sys->glx.i_width = i_width; 
    355     p_opengl->p_sys->glx.i_height = i_height; 
    356     p_opengl->p_sys->glx.b_fullscreen = 0; 
    357  
    358     if( OpenDisplay( (vlc_object_t*)p_opengl, &p_opengl->p_sys->glx ) ) 
    359     { 
    360         msg_Err( p_opengl, "Cannot create OpenGL window" ); 
    361         return VLC_EGENERIC; 
    362     } 
    363  
    364     /* Set the OpenGL context _for the current thread_ */ 
    365     SwitchContext( &p_opengl->p_sys->glx ); 
    366  
    367     return VLC_SUCCESS; 
    368 
    369  
    370 /***************************************************************************** 
    371  * SwapBuffers: swap front/back buffers 
    372  *****************************************************************************/ 
    373 static void SwapBuffers( opengl_t *p_opengl ) 
    374 
    375     if( p_opengl->p_sys->glx.b_glx13 ) 
    376     { 
    377         glXSwapBuffers( p_opengl->p_sys->glx.p_display, 
    378                         p_opengl->p_sys->glx.gwnd ); 
    379     } 
    380     else 
    381     { 
    382         glXSwapBuffers( p_opengl->p_sys->glx.p_display, 
    383                         p_opengl->p_sys->glx.wnd ); 
    384     } 
    385 
    386  
    387 /***************************************************************************** 
    388  * HandleEvents: handle window events 
    389  *****************************************************************************/ 
    390 static int HandleEvents( opengl_t *p_opengl ) 
    391 
    392     int i_ret = 
    393         HandleX11Events( (vlc_object_t*)p_opengl, &p_opengl->p_sys->glx ); 
    394     if( i_ret ) 
    395     { 
    396         /* close the window */ 
    397         CloseDisplay( &p_opengl->p_sys->glx ); 
    398     } 
    399     return i_ret; 
    400 
    401  
    402 /***************************************************************************** 
    403  * Manage: handle X11 events 
    404  ***************************************************************************** 
    405  * This function should be called regularly by video output thread. It manages 
    406  * console events. It returns a non null value on error. 
    407  *****************************************************************************/ 
    408 static int Manage( vout_thread_t *p_vout ) 
    409 
    410     if( HandleX11Events( (vlc_object_t*)p_vout, &p_vout->p_sys->glx ) ) 
    411     { 
    412         /* the user wants to close the window */ 
    413         playlist_t * p_playlist = 
    414             (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, 
    415                                            FIND_ANYWHERE ); 
    416         if( p_playlist != NULL ) 
    417         { 
    418             playlist_Stop( p_playlist ); 
    419             vlc_object_release( p_playlist ); 
    420         } 
    421     } 
    422     return 0; 
    423 
    424  
    425 static int HandleX11Events( vlc_object_t *p_thread, glx_t *p_glx ) 
    426 
    427     Display *p_display; 
    428  
    429     p_display = p_glx->p_display; 
    430  
    431     /* loop on X11 events */ 
    432     while( XPending( p_display ) > 0 ) 
    433     { 
    434         XEvent evt; 
    435         XNextEvent( p_display, &evt ); 
    436         switch( evt.type ) 
    437         { 
    438             case ClientMessage: 
    439             { 
    440                 /* Delete notification */ 
    441                 if( (evt.xclient.format == 32) && 
    442                     ((Atom)evt.xclient.data.l[0] == 
    443                      p_glx->wm_delete) ) 
    444                 { 
    445                     return -1; 
    446                 } 
    447                 break; 
    448             } 
    449         } 
    450     } 
    451     return 0; 
    452 
    453  
    454 /***************************************************************************** 
    455  * Render: render previously calculated output 
    456  *****************************************************************************/ 
    457 static void Render( vout_thread_t *p_vout, picture_t *p_pic ) 
    458 
    459     vout_sys_t *p_sys = p_vout->p_sys; 
    460     float f_width = (float)p_vout->output.i_width / p_sys->i_tex_width; 
    461     float f_height = (float)p_vout->output.i_height / p_sys->i_tex_height; 
    462  
    463     glClear(GL_COLOR_BUFFER_BIT); 
    464  
    465     glTexImage2D (GL_TEXTURE_2D, 0, 3, p_vout->p_sys->i_tex_width, 
    466                   p_vout->p_sys->i_tex_height , 0, 
    467                   VLCGL_RGB_FORMAT, VLCGL_RGB_TYPE, 
    468                   p_vout->p_sys->p_buffer); 
    469  
    470     if( !p_vout->p_sys->i_effect ) 
    471     { 
    472         glEnable( GL_TEXTURE_2D ); 
    473         glBegin( GL_POLYGON ); 
    474         glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, 1.0 ); 
    475         glTexCoord2f( f_width, 0.0 ); glVertex2f( 1.0, 1.0 ); 
    476         glTexCoord2f( f_width, f_height ); glVertex2f( 1.0, -1.0 ); 
    477         glTexCoord2f( 0.0, f_height ); glVertex2f( -1.0, -1.0 ); 
    478         glEnd(); 
    479     } 
    480     else 
    481     { 
    482         glRotatef( 1.0, 0.3, 0.5, 0.7 ); 
    483  
    484         glEnable( GL_TEXTURE_2D ); 
    485         glBegin( GL_QUADS ); 
    486  
    487         /* Front */ 
    488         glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, 1.0 ); 
    489         glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 ); 
    490         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, 1.0 ); 
    491         glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, 1.0 ); 
    492  
    493         /* Left */ 
    494         glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 ); 
    495         glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 ); 
    496         glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, 1.0 ); 
    497         glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, 1.0 ); 
    498  
    499         /* Back */ 
    500         glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, - 1.0 ); 
    501         glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 ); 
    502         glTexCoord2f( f_width, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 ); 
    503         glTexCoord2f( f_width, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 ); 
    504  
    505         /* Right */ 
    506         glTexCoord2f( 0, 0 ); glVertex3f( 1.0, 1.0, 1.0 ); 
    507         glTexCoord2f( 0, f_height ); glVertex3f( 1.0, - 1.0, 1.0 ); 
    508         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 ); 
    509         glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 ); 
    510  
    511         /* Top */ 
    512         glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, 1.0, - 1.0 ); 
    513         glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, 1.0, 1.0 ); 
    514         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, 1.0, 1.0 ); 
    515         glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, 1.0, - 1.0 ); 
    516  
    517         /* Bottom */ 
    518         glTexCoord2f( 0, 0 ); glVertex3f( - 1.0, - 1.0, 1.0 ); 
    519         glTexCoord2f( 0, f_height ); glVertex3f( - 1.0, - 1.0, - 1.0 ); 
    520         glTexCoord2f( f_width, f_height ); glVertex3f( 1.0, - 1.0, - 1.0 ); 
    521         glTexCoord2f( f_width, 0 ); glVertex3f( 1.0, - 1.0, 1.0 ); 
    522         glEnd(); 
    523     } 
    524  
    525     glDisable( GL_TEXTURE_2D); 
    526 
    527  
    528 /***************************************************************************** 
    529  * DisplayVideo: displays previously rendered output 
    530  *****************************************************************************/ 
    531 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic ) 
    532 
    533     if( p_vout->p_sys->glx.b_glx13 ) 
    534     { 
    535         glXSwapBuffers( p_vout->p_sys->glx.p_display, 
    536                         p_vout->p_sys->glx.gwnd ); 
    537     } 
    538     else 
    539     { 
    540         glXSwapBuffers( p_vout->p_sys->glx.p_display, 
    541                         p_vout->p_sys->glx.wnd ); 
    542     } 
     152    vout_sys_t *p_sys = p_vout->p_sys; 
     153 
     154    glXDestroyContext( p_sys->p_display, p_sys->gwctx ); 
     155    if( p_sys->b_glx13 ) 
     156    { 
     157        glXDestroyWindow( p_sys->p_display, p_sys->gwnd ); 
     158    } 
     159 
     160    E_(Deactivate)( p_this ); 
    543161} 
    544162 
     
    546164 * OpenDisplay: open and initialize OpenGL device 
    547165 *****************************************************************************/ 
    548 static int OpenDisplay( vlc_object_t *p_thread, glx_t *p_glx
     166static int CheckGLX( vlc_object_t *p_this, vlc_bool_t *b_glx13
    549167{ 
    550168    Display *p_display; 
     
    553171 
    554172    /* Open the display */ 
    555     p_glx->p_display = p_display = XOpenDisplay( NULL ); 
     173    p_display = XOpenDisplay( NULL ); 
    556174    if( !p_display ) 
    557175    { 
    558         msg_Err( p_thread, "Cannot open display" ); 
    559         return -1
     176        msg_Err( p_this, "Cannot open display" ); 
     177        return VLC_EGENERIC
    560178    } 
    561179 
     
    563181    if( !XQueryExtension( p_display, "GLX", &i_opcode, &i_evt, &i_err ) ) 
    564182    { 
    565         msg_Err( p_thread, "GLX extension not supported" ); 
    566         return -1
     183        msg_Err( p_this, "GLX extension not supported" ); 
     184        return VLC_EGENERIC
    567185    } 
    568186    if( !glXQueryExtension( p_display, &i_err, &i_evt ) ) 
    569187    { 
    570         msg_Err( p_thread, "glXQueryExtension failed" ); 
    571         return -1
     188        msg_Err( p_this, "glXQueryExtension failed" ); 
     189        return VLC_EGENERIC
    572190    } 
    573191 
     
    575193    if (!glXQueryVersion( p_display, &i_maj, &i_min ) ) 
    576194    { 
    577         msg_Err( p_thread, "glXQueryVersion failed" ); 
    578         return -1
     195        msg_Err( p_this, "glXQueryVersion failed" ); 
     196        return VLC_EGENERIC
    579197    } 
    580198    if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) ) 
    581199    { 
    582         p_glx->b_glx13 = 0; 
    583         msg_Dbg( p_thread, "Using GLX 1.2 API" ); 
    584         if( InitGLX12( p_thread, p_glx ) == -1 ) 
    585         { 
    586             return -1; 
    587         } 
     200        *b_glx13 = VLC_FALSE; 
     201        msg_Dbg( p_this, "Using GLX 1.2 API" ); 
    588202    } 
    589203    else 
    590204    { 
    591         p_glx->b_glx13 = 1; 
    592         msg_Dbg( p_thread, "Using GLX 1.3 API" ); 
    593         if( InitGLX13( p_thread, p_glx ) == -1 ) 
    594         { 
    595             return -1; 
    596         } 
    597     } 
    598  
    599     XMapWindow( p_display, p_glx->wnd ); 
    600     if( p_glx->b_fullscreen ) 
    601     { 
    602         //XXX 
    603         XMoveWindow( p_display, p_glx->wnd, 0, 0 ); 
    604     } 
    605     XFlush( p_display ); 
    606     return 0; 
    607 
    608  
    609 /***************************************************************************** 
    610  * CloseDisplay: close and reset OpenGL device 
    611  ***************************************************************************** 
    612  * Returns all resources allocated by OpenDisplay and restore the original 
    613  * state of the device. 
    614  *****************************************************************************/ 
    615 static void CloseDisplay( glx_t *p_glx ) 
    616 
    617     Display *p_display; 
    618  
    619     if (p_glx->wnd == None ) 
    620     { 
    621         // Already closed or not opened... 
    622         return; 
    623     } 
    624  
    625     glFlush(); 
    626     p_display = p_glx->p_display; 
    627     glXDestroyContext( p_display, p_glx->gwctx ); 
    628     if( p_glx->b_glx13 ) 
    629     { 
    630         glXDestroyWindow( p_display, p_glx->gwnd ); 
    631     } 
    632     XDestroyWindow( p_display, p_glx->wnd ); 
    633     p_glx->wnd = None; 
    634 
    635  
    636 int InitGLX12( vlc_object_t *p_thread, glx_t *p_glx ) 
    637 
    638     Display *p_display; 
     205        *b_glx13 = VLC_TRUE; 
     206        msg_Dbg( p_this, "Using GLX 1.3 API" ); 
     207    } 
     208 
     209    return VLC_SUCCESS; 
     210
     211 
     212int InitGLX12( vout_thread_t *p_vout ) 
     213
     214    vout_sys_t *p_sys = p_vout->p_sys; 
    639215    XVisualInfo *p_vi; 
    640     GLXContext gwctx; 
    641216    int p_attr[] = { GLX_RGBA, GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5, 
    642                      GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, 
    643                      0 }; 
    644  
    645     p_display = p_glx->p_display; 
    646  
    647     p_vi = glXChooseVisual( p_display, DefaultScreen( p_display), p_attr ); 
     217                     GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, 0 }; 
     218 
     219    p_vi = glXChooseVisual( p_sys->p_display, 
     220                            DefaultScreen( p_sys->p_display), p_attr ); 
    648221    if(! p_vi ) 
    649222    { 
    650         msg_Err( p_thread, "Cannot get GLX 1.2 visual" ); 
    651         return -1; 
    652     } 
    653  
    654     /* Create the window */ 
    655     CreateWindow( p_thread, p_glx, p_vi ); 
    656  
    657      /* Create an OpenGL context */ 
    658     p_glx->gwctx = gwctx = glXCreateContext( p_display, p_vi, 0, True ); 
    659     if( !gwctx ) 
    660     { 
    661         msg_Err( p_thread, "Cannot create OpenGL context"); 
    662         XFree( p_vi ); 
    663         return -1; 
    664     } 
     223        msg_Err( p_vout, "Cannot get GLX 1.2 visual" ); 
     224        return VLC_EGENERIC; 
     225    } 
     226 
     227    /* Create an OpenGL context */ 
     228    p_sys->gwctx = glXCreateContext( p_sys->p_display, p_vi, 0, True ); 
    665229    XFree( p_vi ); 
    666  
    667     return 0; 
    668 
    669  
    670 int InitGLX13( vlc_object_t *p_thread, glx_t *p_glx ) 
    671 
    672     Display *p_display; 
     230    if( !p_sys->gwctx ) 
     231    { 
     232        msg_Err( p_vout, "Cannot create OpenGL context"); 
     233        return VLC_EGENERIC; 
     234    } 
     235 
     236    return VLC_SUCCESS; 
     237
     238 
     239int InitGLX13( vout_thread_t *p_vout ) 
     240
     241    vout_sys_t *p_sys = p_vout->p_sys; 
    673242    int i_nbelem; 
    674243    GLXFBConfig *p_fbconfs, fbconf; 
    675244    XVisualInfo *p_vi; 
    676     GLXContext gwctx; 
    677245    int p_attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5, 
    678246                     GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True, 
    679247                     GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0 }; 
    680248 
    681     p_display = p_glx->p_display; 
    682  
    683249    /* Get the FB configuration */ 
    684     p_fbconfs = glXChooseFBConfig( p_display, 0, p_attr, &i_nbelem ); 
     250    p_fbconfs = glXChooseFBConfig( p_sys->p_display, 0, p_attr, &i_nbelem ); 
    685251    if( (i_nbelem <= 0) || !p_fbconfs ) 
    686252    { 
    687         msg_Err( p_thread, "Cannot get FB configurations"); 
    688         if( p_fbconfs ) 
    689         { 
    690             XFree( p_fbconfs ); 
    691         } 
    692         return -1; 
     253        msg_Err( p_vout, "Cannot get FB configurations"); 
     254        if( p_fbconfs ) XFree( p_fbconfs ); 
     255        return VLC_EGENERIC; 
    693256    } 
    694257    fbconf = p_fbconfs[0]; 
    695258 
    696259    /* Get the X11 visual */ 
    697     p_vi = glXGetVisualFromFBConfig( p_display, fbconf ); 
     260    p_vi = glXGetVisualFromFBConfig( p_sys->p_display, fbconf ); 
    698261    if( !p_vi ) 
    699262    { 
    700         msg_Err( p_thread, "Cannot get X11 visual" ); 
     263        msg_Err( p_vout, "Cannot get X11 visual" ); 
    701264        XFree( p_fbconfs ); 
    702         return -1; 
    703     } 
    704  
    705     /* Create the window */ 
    706     CreateWindow( p_thread, p_glx, p_vi ); 
    707  
     265        return VLC_EGENERIC; 
     266    } 
    708267    XFree( p_vi ); 
    709268 
    710269    /* Create the GLX window */ 
    711     p_glx->gwnd = glXCreateWindow( p_display, fbconf, p_glx->wnd, NULL ); 
    712     if( p_glx->gwnd == None ) 
    713     { 
    714         msg_Err( p_thread, "Cannot create GLX window" ); 
    715         return -1; 
     270    p_sys->gwnd = glXCreateWindow( p_sys->p_display, fbconf, 
     271                                   p_sys->p_win->video_window, NULL ); 
     272    if( p_sys->gwnd == None ) 
     273    { 
     274        msg_Err( p_vout, "Cannot create GLX window" ); 
     275        return VLC_EGENERIC; 
    716276    } 
    717277 
    718278    /* Create an OpenGL context */ 
    719     p_glx->gwctx = gwctx = glXCreateNewContext( p_display, fbconf, 
    720                                                   GLX_RGBA_TYPE, NULL, True ); 
    721     if( !gwctx ) 
    722     { 
    723         msg_Err( p_thread, "Cannot create OpenGL context"); 
    724         XFree( p_fbconfs ); 
    725         return -1; 
    726     } 
     279    p_sys->gwctx = glXCreateNewContext( p_sys->p_display, fbconf, 
     280                                        GLX_RGBA_TYPE, NULL, True ); 
    727281    XFree( p_fbconfs ); 
    728  
    729     return 0; 
    730 
    731  
    732 void CreateWindow( vlc_object_t *p_thread, glx_t *p_glx, XVisualInfo *p_vi ) 
    733 
    734     Display *p_display; 
    735     XSetWindowAttributes xattr; 
    736     Window wnd; 
    737     Colormap cm; 
    738     XSizeHints* p_size_hints; 
    739     Atom prop; 
    740     mwmhints_t mwmhints; 
    741  
    742     p_display = p_glx->p_display; 
    743  
    744     /* Create a colormap */ 
    745     cm = XCreateColormap( p_display, RootWindow( p_display, p_vi->screen ), 
    746                           p_vi->visual, AllocNone ); 
    747  
    748     /* Create the window */ 
    749     xattr.background_pixel = BlackPixel( p_display, DefaultScreen(p_display) ); 
    750     xattr.border_pixel = 0; 
    751     xattr.colormap = cm; 
    752     p_glx->wnd = wnd = XCreateWindow( p_display, DefaultRootWindow(p_display), 
    753             0, 0, p_glx->i_width, p_glx->i_height, 0, p_vi->depth, 
    754             InputOutput, p_vi->visual, 
    755             CWBackPixel | CWBorderPixel | CWColormap, &xattr); 
    756  
    757     /* Allow the window to be deleted by the window manager */ 
    758     p_glx->wm_delete = XInternAtom( p_display, "WM_DELETE_WINDOW", False ); 
    759     XSetWMProtocols( p_display, wnd, &p_glx->wm_delete, 1 ); 
    760  
    761     if( p_glx->b_fullscreen ) 
    762     { 
    763         mwmhints.flags = MWM_HINTS_DECORATIONS; 
    764         mwmhints.decorations = False; 
    765  
    766         prop = XInternAtom( p_display, "_MOTIF_WM_HINTS", False ); 
    767         XChangeProperty( p_display, wnd, prop, prop, 32, PropModeReplace, 
    768                          (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS ); 
     282    if( !p_sys->gwctx ) 
     283    { 
     284        msg_Err( p_vout, "Cannot create OpenGL context"); 
     285        return VLC_EGENERIC; 
     286    } 
     287 
     288    return VLC_SUCCESS; 
     289
     290 
     291/***************************************************************************** 
     292 * SwapBuffers: swap front/back buffers 
     293 *****************************************************************************/ 
     294static void SwapBuffers( vout_thread_t *p_vout ) 
     295
     296    vout_sys_t *p_sys = p_vout->p_sys; 
     297 
     298    if( p_sys->b_glx13 ) 
     299    { 
     300        glXSwapBuffers( p_sys->p_display, p_sys->gwnd ); 
    769301    } 
    770302    else 
    771303    { 
    772         /* Prevent the window from being resized */ 
    773         p_size_hints = XAllocSizeHints(); 
    774         p_size_hints->flags = PMinSize | PMaxSize; 
    775         p_size_hints->min_width = p_glx->i_width; 
    776         p_size_hints->min_height = p_glx->i_height; 
    777         p_size_hints->max_width = p_glx->i_width; 
    778         p_size_hints->max_height = p_glx->i_height; 
    779         XSetWMNormalHints( p_display, wnd, p_size_hints ); 
    780         XFree( p_size_hints ); 
    781     } 
    782     XSelectInput( p_display, wnd, KeyPressMask ); 
    783 
    784  
    785 void SwitchContext( glx_t *p_glx ) 
    786 
     304        glXSwapBuffers( p_sys->p_display, p_sys->p_win->video_window ); 
     305    } 
     306
     307 
     308void SwitchContext( vout_thread_t *p_vout ) 
     309
     310    vout_sys_t *p_sys = p_vout->p_sys; 
     311 
    787312    /* Change the current OpenGL context */ 
    788     if( p_glx->b_glx13 ) 
    789     { 
    790         glXMakeContextCurrent( p_glx->p_display, p_glx->gwnd, 
    791                                p_glx->gwnd, p_glx->gwctx ); 
     313    if( p_sys->b_glx13 ) 
     314    { 
     315        glXMakeContextCurrent( p_sys->p_display, p_sys->gwnd, 
     316                               p_sys->gwnd, p_sys->gwctx ); 
    792317    } 
    793318    else 
    794319    { 
    795         glXMakeCurrent( p_glx->p_display, p_glx->wnd, 
    796                         p_glx->gwctx ); 
    797     } 
    798 
    799  
    800 int GetAlignedSize( int i_size ) 
    801 
    802     /* Return the nearest power of 2 */ 
    803     int i_result = 1; 
    804     while( i_result < i_size ) 
    805     { 
    806         i_result *= 2; 
    807     } 
    808     return i_result; 
    809 
     320        glXMakeCurrent( p_sys->p_display, p_sys->p_win->video_window, 
     321                        p_sys->gwctx ); 
     322    } 
     323
  • modules/video_output/x11/xcommon.c

    r1954049