Changeset bb13e2278049b34b5d8400f3887a5f2356e2cf4b
- Timestamp:
- 22/07/04 23:27:45 (4 years ago)
- git-parent:
- Files:
-
- configure.ac (modified) (5 diffs)
- include/video_output.h (modified) (1 diff)
- include/vlc_opengl.h (deleted)
- modules/video_output/Modules.am (modified) (1 diff)
- modules/video_output/opengl.c (added)
- modules/video_output/x11/Modules.am (modified) (1 diff)
- modules/video_output/x11/glx.c (modified) (10 diffs)
- modules/video_output/x11/xcommon.c (modified) (8 diffs)
- modules/video_output/x11/xcommon.h (modified) (2 diffs)
- modules/visualization/galaktos/main.c (modified) (2 diffs)
- modules/visualization/galaktos/plugin.c (modified) (7 diffs)
- modules/visualization/galaktos/plugin.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
configure.ac
r6129f1c rbb13e22 2416 2416 2417 2417 dnl 2418 dnl GLX module 2419 dnl (enabled by default except on win32) 2420 dnl 2421 AC_ARG_ENABLE(glx, 2422 [ --enable-glx X11 OpenGL (GLX) support (default enabled)]) 2423 if 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}" 2433 fi 2434 2435 dnl 2418 2436 dnl Check for the Xinerama extension 2419 2437 dnl … … 2427 2445 VLC_ADD_LDFLAGS([xvideo],[-lXinerama_pic]) 2428 2446 VLC_ADD_LDFLAGS([x11],[-lXinerama_pic]) 2447 VLC_ADD_LDFLAGS([glx],[-lXinerama_pic]) 2429 2448 ac_cv_have_xinerama="yes" 2430 2449 ],[ … … 2432 2451 VLC_ADD_LDFLAGS([xvideo],[-lXinerama]) 2433 2452 VLC_ADD_LDFLAGS([x11],[-lXinerama]) 2453 VLC_ADD_LDFLAGS([glx],[-lXinerama]) 2434 2454 ac_cv_have_xinerama="yes" 2435 2455 ]) … … 2440 2460 fi 2441 2461 CFLAGS="${CFLAGS_save}" 2462 CPPFLAGS="${CPPFLAGS_save}" 2463 fi 2464 2465 dnl 2466 dnl GLX module 2467 dnl (enabled by default except on win32) 2468 dnl 2469 AC_ARG_ENABLE(opengl, 2470 [ --enable-opengl OpenGL support (default enabled)]) 2471 if 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 ]) 2442 2476 CPPFLAGS="${CPPFLAGS_save}" 2443 2477 fi … … 2754 2788 fi ]) 2755 2789 fi 2756 2757 dnl2758 dnl GLX module2759 dnl2760 AC_ARG_ENABLE(glx,2761 [ --enable-glx X11 OpenGL (GLX) support (default disabled)])2762 if test "${enable_glx}" = "yes"2763 then2764 VLC_ADD_PLUGINS([glx])2765 VLC_ADD_LDFLAGS([glx],[-lGL -lGLU])2766 fi2767 2768 2790 2769 2791 dnl include/video_output.h
r8f80181 rbb13e22 103 103 void ( *pf_render ) ( vout_thread_t *, picture_t * ); 104 104 void ( *pf_display ) ( vout_thread_t *, picture_t * ); 105 void ( *pf_swap ) ( vout_thread_t * ); /* OpenGL only */ 105 106 int ( *pf_control ) ( vout_thread_t *, int, va_list ); 106 107 /**@}*/ modules/video_output/Modules.am
r3cb9a09 rbb13e22 10 10 SOURCES_hd1000v = hd1000v.cpp 11 11 SOURCES_snapshot = snapshot.c 12 SOURCES_opengl = opengl.c modules/video_output/x11/Modules.am
rc0a1dbe rbb13e22 12 12 13 13 SOURCES_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 1 1 /***************************************************************************** 2 * glx.c: GLX video output2 * glx.c: GLX OpenGL provider 3 3 ***************************************************************************** 4 4 * Copyright (C) 2004 VideoLAN … … 6 6 * 7 7 * Authors: Cyril Deguet <asmax@videolan.org> 8 * Gildas Bazin <gbazin@videolan.org> 8 9 * 9 10 * This program is free software; you can redistribute it and/or modify … … 36 37 #include "vlc_opengl.h" 37 38 39 #ifdef HAVE_SYS_SHM_H 40 # include <sys/shm.h> /* shmget(), shmctl() */ 41 #endif 42 38 43 #include <X11/Xlib.h> 44 #include <X11/Xmd.h> 39 45 #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 40 54 #include <GL/glx.h> 41 55 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" 56 57 57 58 /* RV16 */ … … 69 70 70 71 /***************************************************************************** 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 83 73 *****************************************************************************/ 84 74 static int CreateOpenGL ( vlc_object_t * ); 85 75 static 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 * ); 76 static void SwapBuffers ( vout_thread_t * ); 89 77 90 78 /***************************************************************************** 91 79 * Local prototypes 92 80 *****************************************************************************/ 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 ); 81 static int CheckGLX ( vlc_object_t *, vlc_bool_t * ); 82 static int InitGLX12 ( vout_thread_t * ); 83 static int InitGLX13 ( vout_thread_t * ); 84 static void SwitchContext( vout_thread_t * ); 102 85 103 86 /***************************************************************************** … … 105 88 *****************************************************************************/ 106 89 vlc_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();113 90 set_description( _("X11 OpenGL provider") ); 114 91 set_capability( "opengl provider", 50 ); … … 117 94 118 95 /***************************************************************************** 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 *****************************************************************************/ 98 extern int E_(Activate) ( vlc_object_t * ); 99 extern void E_(Deactivate) ( vlc_object_t * ); 100 101 /***************************************************************************** 102 * CreateOpenGL: initialize an OpenGL provider 103 *****************************************************************************/ 104 static int CreateOpenGL( vlc_object_t *p_this ) 160 105 { 161 106 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 *****************************************************************************/ 149 static void DestroyOpenGL( vlc_object_t *p_this ) 304 150 { 305 151 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 ); 543 161 } 544 162 … … 546 164 * OpenDisplay: open and initialize OpenGL device 547 165 *****************************************************************************/ 548 static int OpenDisplay( vlc_object_t *p_thread, glx_t *p_glx)166 static int CheckGLX( vlc_object_t *p_this, vlc_bool_t *b_glx13 ) 549 167 { 550 168 Display *p_display; … … 553 171 554 172 /* Open the display */ 555 p_ glx->p_display = p_display = XOpenDisplay( NULL );173 p_display = XOpenDisplay( NULL ); 556 174 if( !p_display ) 557 175 { 558 msg_Err( p_th read, "Cannot open display" );559 return -1;176 msg_Err( p_this, "Cannot open display" ); 177 return VLC_EGENERIC; 560 178 } 561 179 … … 563 181 if( !XQueryExtension( p_display, "GLX", &i_opcode, &i_evt, &i_err ) ) 564 182 { 565 msg_Err( p_th read, "GLX extension not supported" );566 return -1;183 msg_Err( p_this, "GLX extension not supported" ); 184 return VLC_EGENERIC; 567 185 } 568 186 if( !glXQueryExtension( p_display, &i_err, &i_evt ) ) 569 187 { 570 msg_Err( p_th read, "glXQueryExtension failed" );571 return -1;188 msg_Err( p_this, "glXQueryExtension failed" ); 189 return VLC_EGENERIC; 572 190 } 573 191 … … 575 193 if (!glXQueryVersion( p_display, &i_maj, &i_min ) ) 576 194 { 577 msg_Err( p_th read, "glXQueryVersion failed" );578 return -1;195 msg_Err( p_this, "glXQueryVersion failed" ); 196 return VLC_EGENERIC; 579 197 } 580 198 if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) ) 581 199 { 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" ); 588 202 } 589 203 else 590 204 { 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 212 int InitGLX12( vout_thread_t *p_vout ) 213 { 214 vout_sys_t *p_sys = p_vout->p_sys; 639 215 XVisualInfo *p_vi; 640 GLXContext gwctx;641 216 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 ); 648 221 if(! p_vi ) 649 222 { 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 ); 665 229 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 239 int InitGLX13( vout_thread_t *p_vout ) 240 { 241 vout_sys_t *p_sys = p_vout->p_sys; 673 242 int i_nbelem; 674 243 GLXFBConfig *p_fbconfs, fbconf; 675 244 XVisualInfo *p_vi; 676 GLXContext gwctx;677 245 int p_attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5, 678 246 GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True, 679 247 GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0 }; 680 248 681 p_display = p_glx->p_display;682 683 249 /* 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 ); 685 251 if( (i_nbelem <= 0) || !p_fbconfs ) 686 252 { 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; 693 256 } 694 257 fbconf = p_fbconfs[0]; 695 258 696 259 /* Get the X11 visual */ 697 p_vi = glXGetVisualFromFBConfig( p_ display, fbconf );260 p_vi = glXGetVisualFromFBConfig( p_sys->p_display, fbconf ); 698 261 if( !p_vi ) 699 262 { 700 msg_Err( p_ thread, "Cannot get X11 visual" );263 msg_Err( p_vout, "Cannot get X11 visual" ); 701 264 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 } 708 267 XFree( p_vi ); 709 268 710 269 /* 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; 716 276 } 717 277 718 278 /* 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 ); 727 281 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 *****************************************************************************/ 294 static 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 ); 769 301 } 770 302 else 771 303 { 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 308 void SwitchContext( vout_thread_t *p_vout ) 309 { 310 vout_sys_t *p_sys = p_vout->p_sys; 311 787 312 /* 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 ); 792 317 } 793 318 else 794 319 { 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
