📄 glwin32.c
字号:
/***************************************************************************** * glwin32.c: Windows OpenGL provider ***************************************************************************** * Copyright (C) 2001-2004 VideoLAN * $Id: glwin32.c 11257 2005-06-02 17:06:00Z fkuehne $ * * Authors: 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. *****************************************************************************/#include <errno.h> /* ENOMEM */#include <stdlib.h> /* free() */#include <string.h> /* strerror() */#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/vout.h>#include <windows.h>#include <ddraw.h>#include <commctrl.h>#include <multimon.h>#undef GetSystemMetrics#ifndef MONITOR_DEFAULTTONEAREST# define MONITOR_DEFAULTTONEAREST 2#endif#include <GL/gl.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 * );/***************************************************************************** * Module descriptor *****************************************************************************/vlc_module_begin(); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VOUT ); set_shortname( "OpenGL" ); set_description( _("OpenGL video output") ); set_capability( "opengl provider", 100 ); add_shortcut( "glwin32" ); set_callbacks( OpenVideo, CloseVideo ); /* FIXME: Hack to avoid unregistering our window class */ linked_with_a_crap_library_which_uses_atexit( );vlc_module_end();#if 0 /* FIXME */ /* check if we registered a window class because we need to * unregister it */ WNDCLASS wndclass; if( GetClassInfo( GetModuleHandle(NULL), "VLC DirectX", &wndclass ) ) UnregisterClass( "VLC DirectX", GetModuleHandle(NULL) );#endif/***************************************************************************** * OpenVideo: allocate OpenGL provider ***************************************************************************** * This function creates and initializes a video window. *****************************************************************************/static int OpenVideo( vlc_object_t *p_this ){ vout_thread_t * p_vout = (vout_thread_t *)p_this; vlc_value_t val; /* 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 VLC_ENOMEM; } memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) ); /* Initialisations */ p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_swap = GLSwapBuffers; p_vout->p_sys->p_ddobject = NULL; p_vout->p_sys->p_display = NULL; p_vout->p_sys->p_current_surface = NULL; p_vout->p_sys->p_clipper = NULL; p_vout->p_sys->hwnd = p_vout->p_sys->hvideownd = NULL; p_vout->p_sys->hparent = p_vout->p_sys->hfswnd = NULL; p_vout->p_sys->i_changes = 0; p_vout->p_sys->b_wallpaper = 0; vlc_mutex_init( p_vout, &p_vout->p_sys->lock ); SetRectEmpty( &p_vout->p_sys->rect_display ); SetRectEmpty( &p_vout->p_sys->rect_parent ); var_Create( p_vout, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); p_vout->p_sys->b_cursor_hidden = 0; p_vout->p_sys->i_lastmoved = mdate(); /* Set main window's size */ p_vout->p_sys->i_window_width = p_vout->i_window_width; p_vout->p_sys->i_window_height = p_vout->i_window_height; /* Create the DirectXEventThread, this thread is created by us to isolate * the Win32 PeekMessage function calls. We want to do this because * Windows can stay blocked inside this call for a long time, and when * this happens it thus blocks vlc's video_output thread. * DirectXEventThread will take care of the creation of the video * window (because PeekMessage has to be called from the same thread which * created the window). */ msg_Dbg( p_vout, "creating DirectXEventThread" ); p_vout->p_sys->p_event = vlc_object_create( p_vout, sizeof(event_thread_t) ); p_vout->p_sys->p_event->p_vout = p_vout; if( vlc_thread_create( p_vout->p_sys->p_event, "DirectX Events Thread", E_(DirectXEventThread), 0, 1 ) ) { msg_Err( p_vout, "cannot create DirectXEventThread" ); vlc_object_destroy( p_vout->p_sys->p_event ); p_vout->p_sys->p_event = NULL; goto error; } if( p_vout->p_sys->p_event->b_error ) { msg_Err( p_vout, "DirectXEventThread failed" ); goto error; } vlc_object_attach( p_vout->p_sys->p_event, p_vout ); msg_Dbg( p_vout, "DirectXEventThread running" ); /* Variable to indicate if the window should be on top of others */ /* Trigger a callback right now */ var_Get( p_vout, "video-on-top", &val ); var_Set( p_vout, "video-on-top", val ); return VLC_SUCCESS; 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 */ PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 ); p_vout->p_sys->hGLDC = GetDC( p_vout->p_sys->hvideownd ); /* Set the pixel format for the DC */ memset( &pfd, 0, sizeof( pfd ) ); pfd.nSize = sizeof( pfd ); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat( p_vout->p_sys->hGLDC, &pfd ); SetPixelFormat( p_vout->p_sys->hGLDC, iFormat, &pfd ); /* Create and enable the render context */ p_vout->p_sys->hGLRC = wglCreateContext( p_vout->p_sys->hGLDC ); wglMakeCurrent( p_vout->p_sys->hGLDC, p_vout->p_sys->hGLRC ); return VLC_SUCCESS;}/***************************************************************************** * End: terminate Sys video thread output method ***************************************************************************** * Terminate an output method created by Create. * It is called at the end of the thread. *****************************************************************************/static void End( vout_thread_t *p_vout ){ wglMakeCurrent( NULL, NULL ); wglDeleteContext( p_vout->p_sys->hGLRC ); ReleaseDC( p_vout->p_sys->hvideownd, p_vout->p_sys->hGLDC ); return;}/***************************************************************************** * CloseVideo: destroy Sys video thread output method ***************************************************************************** * 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; msg_Dbg( p_vout, "CloseVideo" ); if( p_vout->p_sys->p_event ) { vlc_object_detach( p_vout->p_sys->p_event ); /* Kill DirectXEventThread */ p_vout->p_sys->p_event->b_die = VLC_TRUE; /* we need to be sure DirectXEventThread won't stay stuck in * GetMessage, so we send a fake message */ if( p_vout->p_sys->hwnd ) { PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -