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>
35 #undef GetSystemMetrics
37 #ifndef MONITOR_DEFAULTTONEAREST
38 # define MONITOR_DEFAULTTONEAREST 2
41 #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", 160)
57 add_shortcut("glwin32", "opengl")
58 set_callbacks(Open, Close)
61 /*****************************************************************************
63 *****************************************************************************/
64 static picture_pool_t *Pool (vout_display_t *, unsigned);
65 static void Prepare(vout_display_t *, picture_t *, subpicture_t *);
66 static void Display(vout_display_t *, picture_t *, subpicture_t *);
67 static int Control(vout_display_t *, int, va_list);
68 static void Manage (vout_display_t *);
70 static void Swap (vlc_gl_t *);
71 static void *OurGetProcAddress(vlc_gl_t *, const char *);
74 * It creates an OpenGL vout display.
76 static int Open(vlc_object_t *object)
78 vout_display_t *vd = (vout_display_t *)object;
79 vout_display_sys_t *sys;
81 /* Allocate structure */
82 vd->sys = sys = calloc(1, sizeof(*sys));
90 EventThreadUpdateTitle(sys->event, VOUT_TITLE " (OpenGL output)");
93 sys->hGLDC = GetDC(sys->hvideownd);
95 /* Set the pixel format for the DC */
96 PIXELFORMATDESCRIPTOR pfd;
97 memset(&pfd, 0, sizeof(pfd));
98 pfd.nSize = sizeof(pfd);
100 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
101 pfd.iPixelType = PFD_TYPE_RGBA;
104 pfd.iLayerType = PFD_MAIN_PLANE;
105 SetPixelFormat(sys->hGLDC,
106 ChoosePixelFormat(sys->hGLDC, &pfd), &pfd);
108 /* Create and enable the render context */
109 sys->hGLRC = wglCreateContext(sys->hGLDC);
110 wglMakeCurrent(sys->hGLDC, sys->hGLRC);
112 const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
113 #ifdef WGL_EXT_swap_control
114 if (HasExtension(extensions, "WGL_EXT_swap_control")) {
115 PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
123 sys->gl.unlock = NULL;
125 sys->gl.getProcAddress = OurGetProcAddress;
128 video_format_t fmt = vd->fmt;
129 const vlc_fourcc_t *subpicture_chromas;
130 sys->vgl = vout_display_opengl_New(&fmt, &subpicture_chromas, &sys->gl);
134 vout_display_info_t info = vd->info;
135 info.has_double_click = true;
136 info.has_hide_mouse = false;
137 info.has_event_thread = true;
138 info.subpicture_chromas = subpicture_chromas;
140 /* Setup vout_display now that everything is fine */
145 vd->prepare = Prepare;
146 vd->display = Display;
147 vd->control = Control;
158 * It destroys an OpenGL vout display.
160 static void Close(vlc_object_t *object)
162 vout_display_t *vd = (vout_display_t *)object;
163 vout_display_sys_t *sys = vd->sys;
166 vout_display_opengl_Delete(sys->vgl);
168 if (sys->hGLDC && sys->hGLRC)
169 wglMakeCurrent(NULL, NULL);
171 wglDeleteContext(sys->hGLRC);
173 ReleaseDC(sys->hvideownd, sys->hGLDC);
181 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
183 vout_display_sys_t *sys = vd->sys;
186 sys->pool = vout_display_opengl_GetPool(sys->vgl, count);
190 static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
192 vout_display_sys_t *sys = vd->sys;
194 vout_display_opengl_Prepare(sys->vgl, picture, subpicture);
197 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
199 vout_display_sys_t *sys = vd->sys;
201 vout_display_opengl_Display(sys->vgl, &vd->source);
203 picture_Release(picture);
205 subpicture_Delete(subpicture);
210 static int Control(vout_display_t *vd, int query, va_list args)
213 case VOUT_DISPLAY_GET_OPENGL: {
214 vlc_gl_t **gl = va_arg(args, vlc_gl_t **);
221 return CommonControl(vd, query, args);
225 static void Manage (vout_display_t *vd)
227 vout_display_sys_t *sys = vd->sys;
231 const int width = sys->rect_dest.right - sys->rect_dest.left;
232 const int height = sys->rect_dest.bottom - sys->rect_dest.top;
233 glViewport(0, 0, width, height);
236 static void Swap(vlc_gl_t *gl)
238 vout_display_t *vd = gl->sys;
240 SwapBuffers(vd->sys->hGLDC);
243 static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
246 return wglGetProcAddress(name);