1 /*****************************************************************************
2 * glwin32.c: Windows OpenGL provider
3 *****************************************************************************
4 * Copyright (C) 2001-2009 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_vout_display.h>
36 #undef GetSystemMetrics
38 #ifndef MONITOR_DEFAULTTONEAREST
39 # define MONITOR_DEFAULTTONEAREST 2
42 #include "../opengl.h"
45 /*****************************************************************************
47 *****************************************************************************/
48 static int Open (vlc_object_t *);
49 static void Close(vlc_object_t *);
52 set_category(CAT_VIDEO)
53 set_subcategory(SUBCAT_VIDEO_VOUT)
54 set_shortname("OpenGL")
55 set_description(N_("OpenGL video output"))
56 set_capability("vout display", 20)
57 add_shortcut("glwin32")
58 add_shortcut("opengl")
59 set_callbacks(Open, Close)
61 /* FIXME: Hack to avoid unregistering our window class */
62 linked_with_a_crap_library_which_uses_atexit ()
66 /* check if we registered a window class because we need to
69 if(GetClassInfo(GetModuleHandle(NULL), "VLC DirectX", &wndclass))
70 UnregisterClass("VLC DirectX", GetModuleHandle(NULL));
74 /*****************************************************************************
76 *****************************************************************************/
77 static picture_pool_t *Pool (vout_display_t *, unsigned);
78 static void Prepare(vout_display_t *, picture_t *);
79 static void Display(vout_display_t *, picture_t *);
80 static int Control(vout_display_t *, int, va_list);
81 static void Manage (vout_display_t *);
83 static void Swap (vout_opengl_t *);
86 * It creates an OpenGL vout display.
88 static int Open(vlc_object_t *object)
90 vout_display_t *vd = (vout_display_t *)object;
91 vout_display_sys_t *sys;
93 /* Allocate structure */
94 vd->sys = sys = calloc(1, sizeof(*sys));
102 EventThreadUpdateTitle(sys->event, VOUT_TITLE " (OpenGL output)");
105 sys->hGLDC = GetDC(sys->hvideownd);
107 /* Set the pixel format for the DC */
108 PIXELFORMATDESCRIPTOR pfd;
109 memset(&pfd, 0, sizeof(pfd));
110 pfd.nSize = sizeof(pfd);
112 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
113 pfd.iPixelType = PFD_TYPE_RGBA;
116 pfd.iLayerType = PFD_MAIN_PLANE;
117 SetPixelFormat(sys->hGLDC,
118 ChoosePixelFormat(sys->hGLDC, &pfd), &pfd);
120 /* Create and enable the render context */
121 sys->hGLRC = wglCreateContext(sys->hGLDC);
122 wglMakeCurrent(sys->hGLDC, sys->hGLRC);
126 sys->gl.unlock = NULL;
130 video_format_t fmt = vd->fmt;
131 if (vout_display_opengl_Init(&sys->vgl, &fmt, &sys->gl))
134 vout_display_info_t info = vd->info;
135 info.has_double_click = true;
136 info.has_hide_mouse = true;
137 info.has_pictures_invalid = true;
139 /* Setup vout_display now that everything is fine */
144 vd->prepare = Prepare;
145 vd->display = Display;
146 vd->control = Control;
157 * It destroys an OpenGL vout display.
159 static void Close(vlc_object_t *object)
161 vout_display_t *vd = (vout_display_t *)object;
162 vout_display_sys_t *sys = vd->sys;
165 vout_display_opengl_Clean(&sys->vgl);
167 if (sys->hGLDC && sys->hGLRC)
168 wglMakeCurrent(NULL, NULL);
170 wglDeleteContext(sys->hGLRC);
172 ReleaseDC(sys->hvideownd, sys->hGLDC);
180 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
182 vout_display_sys_t *sys = vd->sys;
186 sys->pool = vout_display_opengl_GetPool(&sys->vgl);
190 static void Prepare(vout_display_t *vd, picture_t *picture)
192 vout_display_sys_t *sys = vd->sys;
194 vout_display_opengl_Prepare(&sys->vgl, picture);
197 static void Display(vout_display_t *vd, picture_t *picture)
199 vout_display_sys_t *sys = vd->sys;
201 vout_display_opengl_Display(&sys->vgl, &vd->source);
203 picture_Release(picture);
208 static int Control(vout_display_t *vd, int query, va_list args)
211 case VOUT_DISPLAY_GET_OPENGL: {
212 vout_opengl_t **gl = va_arg(args, vout_opengl_t **);
217 return CommonControl(vd, query, args);
221 static void Manage (vout_display_t *vd)
223 vout_display_sys_t *sys = vd->sys;
227 const int width = sys->rect_dest.right - sys->rect_dest.left;
228 const int height = sys->rect_dest.bottom - sys->rect_dest.top;
229 glViewport(0, 0, width, height);
232 static void Swap(vout_opengl_t *gl)
234 vout_display_t *vd = gl->sys;
236 SwapBuffers(vd->sys->hGLDC);