Commit 8edf3ea9 authored by Laurent Aimar's avatar Laurent Aimar

Converted glwin32 to vout display.

parent 1930ef7e
...@@ -16,10 +16,10 @@ SOURCES_direct3d = \ ...@@ -16,10 +16,10 @@ SOURCES_direct3d = \
SOURCES_glwin32 = \ SOURCES_glwin32 = \
glwin32.c \ glwin32.c \
vout.h \ common.h \
events_vo.h \ events.h \
events_vo.c \ events.c \
common_vo.c \ common.c \
$(NULL) $(NULL)
SOURCES_wingdi = \ SOURCES_wingdi = \
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include <d3d9.h> #include <d3d9.h>
#endif #endif
#ifdef MODULE_NAME_IS_glwin32 #ifdef MODULE_NAME_IS_glwin32
#include <GL/gl.h> #include "../opengl.h"
#endif #endif
#include "common.h" #include "common.h"
......
...@@ -148,8 +148,11 @@ struct vout_display_sys_t ...@@ -148,8 +148,11 @@ struct vout_display_sys_t
#endif #endif
#ifdef MODULE_NAME_IS_glwin32 #ifdef MODULE_NAME_IS_glwin32
HDC hGLDC; HDC hGLDC;
HGLRC hGLRC; HGLRC hGLRC;
vout_opengl_t gl;
vout_display_opengl_t vgl;
picture_pool_t *pool;
#endif #endif
#ifdef MODULE_NAME_IS_direct3d #ifdef MODULE_NAME_IS_direct3d
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
#include <d3d9.h> #include <d3d9.h>
#endif #endif
#ifdef MODULE_NAME_IS_glwin32 #ifdef MODULE_NAME_IS_glwin32
#include <GL/gl.h> #include "../opengl.h"
#endif #endif
#include <vlc_keys.h> #include <vlc_keys.h>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_vout.h> #include <vlc_vout_display.h>
#include <windows.h> #include <windows.h>
#include <ddraw.h> #include <ddraw.h>
...@@ -39,185 +39,193 @@ ...@@ -39,185 +39,193 @@
# define MONITOR_DEFAULTTONEAREST 2 # define MONITOR_DEFAULTTONEAREST 2
#endif #endif
#include <GL/gl.h> #include "../opengl.h"
#include "common.h"
#include "vout.h"
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
static int OpenVideo ( vlc_object_t * );
static void CloseVideo ( vlc_object_t * );
static int Init ( vout_thread_t * );
static void End ( vout_thread_t * );
static int Manage ( vout_thread_t * );
static void GLSwapBuffers( vout_thread_t * );
static void FirstSwap( vout_thread_t * );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
vlc_module_begin () static int Open (vlc_object_t *);
set_category( CAT_VIDEO ) static void Close(vlc_object_t *);
set_subcategory( SUBCAT_VIDEO_VOUT )
set_shortname( "OpenGL" ) vlc_module_begin()
set_description( N_("OpenGL video output") ) set_category(CAT_VIDEO)
set_capability( "opengl provider", 100 ) set_subcategory(SUBCAT_VIDEO_VOUT)
add_shortcut( "glwin32" ) set_shortname("OpenGL")
set_callbacks( OpenVideo, CloseVideo ) set_description(N_("OpenGL video output"))
set_capability("vout display", 20)
add_shortcut("glwin32")
set_callbacks(Open, Close)
/* FIXME: Hack to avoid unregistering our window class */ /* FIXME: Hack to avoid unregistering our window class */
linked_with_a_crap_library_which_uses_atexit () linked_with_a_crap_library_which_uses_atexit ()
vlc_module_end () vlc_module_end()
#if 0 /* FIXME */ #if 0 /* FIXME */
/* check if we registered a window class because we need to /* check if we registered a window class because we need to
* unregister it */ * unregister it */
WNDCLASS wndclass; WNDCLASS wndclass;
if( GetClassInfo( GetModuleHandle(NULL), "VLC DirectX", &wndclass ) ) if(GetClassInfo(GetModuleHandle(NULL), "VLC DirectX", &wndclass))
UnregisterClass( "VLC DirectX", GetModuleHandle(NULL) ); UnregisterClass("VLC DirectX", GetModuleHandle(NULL));
#endif #endif
/***************************************************************************** /*****************************************************************************
* OpenVideo: allocate OpenGL provider * Local prototypes.
*****************************************************************************
* This function creates and initializes a video window.
*****************************************************************************/ *****************************************************************************/
static int OpenVideo( vlc_object_t *p_this ) static picture_t *Get (vout_display_t *);
static void Prepare(vout_display_t *, picture_t *);
static void Display(vout_display_t *, picture_t *);
static int Control(vout_display_t *, int, va_list);
static void Manage (vout_display_t *);
static void Swap (vout_opengl_t *);
/**
* It creates an OpenGL vout display.
*/
static int Open(vlc_object_t *object)
{ {
vout_thread_t * p_vout = (vout_thread_t *)p_this; vout_display_t *vd = (vout_display_t *)object;
vout_display_sys_t *sys;
/* Allocate structure */ /* Allocate structure */
p_vout->p_sys = calloc( 1, sizeof( vout_sys_t ) ); vd->sys = sys = calloc(1, sizeof(*sys));
if( p_vout->p_sys == NULL ) if (!sys)
return VLC_ENOMEM; return VLC_ENOMEM;
/* Initialisations */ /* */
p_vout->pf_init = Init; if (CommonInit(vd))
p_vout->pf_end = End;
p_vout->pf_manage = Manage;
p_vout->pf_swap = FirstSwap;
p_vout->pf_control = Control;
if( CommonInit( p_vout ) )
goto error; goto error;
return VLC_SUCCESS; EventThreadUpdateTitle(sys->event, VOUT_TITLE " (OpenGL output)");
error:
CloseVideo( VLC_OBJECT(p_vout) );
return VLC_EGENERIC;
}
/*****************************************************************************
* Init: initialize video thread output method
*****************************************************************************/
static int Init( vout_thread_t *p_vout )
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* Change the window title bar text */
EventThreadUpdateTitle( p_vout->p_sys->p_event, VOUT_TITLE " (OpenGL output)" );
p_vout->p_sys->hGLDC = GetDC( p_vout->p_sys->hvideownd ); /* */
sys->hGLDC = GetDC(sys->hvideownd);
/* Set the pixel format for the DC */ /* Set the pixel format for the DC */
memset( &pfd, 0, sizeof( pfd ) ); PIXELFORMATDESCRIPTOR pfd;
pfd.nSize = sizeof( pfd ); memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1; pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA; pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24; pfd.cColorBits = 24;
pfd.cDepthBits = 16; pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE; pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( p_vout->p_sys->hGLDC, &pfd ); SetPixelFormat(sys->hGLDC,
SetPixelFormat( p_vout->p_sys->hGLDC, iFormat, &pfd ); ChoosePixelFormat(sys->hGLDC, &pfd), &pfd);
/* Create and enable the render context */ /* Create and enable the render context */
p_vout->p_sys->hGLRC = wglCreateContext( p_vout->p_sys->hGLDC ); sys->hGLRC = wglCreateContext(sys->hGLDC);
wglMakeCurrent( p_vout->p_sys->hGLDC, p_vout->p_sys->hGLRC ); wglMakeCurrent(sys->hGLDC, sys->hGLRC);
/* */
sys->gl.lock = NULL;
sys->gl.unlock = NULL;
sys->gl.swap = Swap;
sys->gl.sys = vd;
video_format_t fmt = vd->fmt;
if (vout_display_opengl_Init(&sys->vgl, &fmt, &sys->gl))
goto error;
vout_display_info_t info = vd->info;
info.has_double_click = true;
info.has_hide_mouse = true;
info.has_pictures_invalid = true;
/* Setup vout_display now that everything is fine */
vd->fmt = fmt;
vd->info = info;
vd->get = Get;
vd->prepare = Prepare;
vd->display = Display;
vd->control = Control;
vd->manage = Manage;
return VLC_SUCCESS; return VLC_SUCCESS;
error:
Close(object);
return VLC_EGENERIC;
} }
/***************************************************************************** /**
* End: terminate Sys video thread output method * It destroys an OpenGL vout display.
***************************************************************************** */
* Terminate an output method created by Create. static void Close(vlc_object_t *object)
* It is called at the end of the thread.
*****************************************************************************/
static void End( vout_thread_t *p_vout )
{ {
wglMakeCurrent( NULL, NULL ); vout_display_t *vd = (vout_display_t *)object;
wglDeleteContext( p_vout->p_sys->hGLRC ); vout_display_sys_t *sys = vd->sys;
ReleaseDC( p_vout->p_sys->hvideownd, p_vout->p_sys->hGLDC );
return; if (sys->vgl.gl)
vout_display_opengl_Clean(&sys->vgl);
if (sys->hGLDC && sys->hGLRC)
wglMakeCurrent(NULL, NULL);
if (sys->hGLRC)
wglDeleteContext(sys->hGLRC);
if (sys->hGLDC)
ReleaseDC(sys->hvideownd, sys->hGLDC);
CommonClean(vd);
free(sys);
} }
/***************************************************************************** /* */
* CloseVideo: destroy Sys video thread output method static picture_t *Get(vout_display_t *vd)
*****************************************************************************
* Terminate an output method created by Create
*****************************************************************************/
static void CloseVideo( vlc_object_t *p_this )
{ {
vout_thread_t * p_vout = (vout_thread_t *)p_this; vout_display_sys_t *sys = vd->sys;
if (!sys->pool) {
sys->pool = vout_display_opengl_GetPool(&sys->vgl);
if (!sys->pool)
return NULL;
}
return picture_pool_Get(sys->pool);
}
CommonClean( p_vout ); static void Prepare(vout_display_t *vd, picture_t *picture)
{
vout_display_sys_t *sys = vd->sys;
free( p_vout->p_sys ); vout_display_opengl_Prepare(&sys->vgl, picture);
} }
/***************************************************************************** static void Display(vout_display_t *vd, picture_t *picture)
* Manage: handle Sys events
*****************************************************************************
* This function should be called regularly by the video output thread.
* It returns a non null value if an error occurred.
*****************************************************************************/
static int Manage( vout_thread_t *p_vout )
{ {
vout_sys_t *p_sys = p_vout->p_sys; vout_display_sys_t *sys = vd->sys;
const int i_width = p_sys->rect_dest.right - p_sys->rect_dest.left; vout_display_opengl_Display(&sys->vgl, &vd->source);
const int i_height = p_sys->rect_dest.bottom - p_sys->rect_dest.top;
glViewport( 0, 0, i_width, i_height );
CommonManage( p_vout ); picture_Release(picture);
return VLC_SUCCESS;
CommonDisplay(vd);
} }
/***************************************************************************** static int Control(vout_display_t *vd, int query, va_list args)
* GLSwapBuffers: swap front/back buffers
*****************************************************************************/
static void GLSwapBuffers( vout_thread_t *p_vout )
{ {
SwapBuffers( p_vout->p_sys->hGLDC ); return CommonControl(vd, query, args);
} }
/* static void Manage (vout_display_t *vd)
** this function is only used once when the first picture is received {
** this function will show the video window once a picture is ready vout_display_sys_t *sys = vd->sys;
*/
CommonManage(vd);
static void FirstSwap( vout_thread_t *p_vout ) const int width = sys->rect_dest.right - sys->rect_dest.left;
const int height = sys->rect_dest.bottom - sys->rect_dest.top;
glViewport(0, 0, width, height);
}
static void Swap(vout_opengl_t *gl)
{ {
/* get initial picture buffer swapped to front buffer */ vout_display_t *vd = gl->sys;
GLSwapBuffers( p_vout );
SwapBuffers(vd->sys->hGLDC);
/*
** Video window is initially hidden, show it now since we got a
** picture to show.
*/
SetWindowPos( p_vout->p_sys->hvideownd, NULL, 0, 0, 0, 0,
SWP_ASYNCWINDOWPOS|
SWP_FRAMECHANGED|
SWP_SHOWWINDOW|
SWP_NOMOVE|
SWP_NOSIZE|
SWP_NOZORDER );
/* use and restores proper swap function for further pictures */
p_vout->pf_swap = GLSwapBuffers;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment