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"
44 /*****************************************************************************
46 *****************************************************************************/
47 static int Open (vlc_object_t *);
48 static void Close(vlc_object_t *);
51 set_category(CAT_VIDEO)
52 set_subcategory(SUBCAT_VIDEO_VOUT)
53 set_shortname("OpenGL")
54 set_description(N_("OpenGL video output"))
55 set_capability("vout display", 160)
56 add_shortcut("glwin32", "opengl")
57 set_callbacks(Open, Close)
60 /*****************************************************************************
62 *****************************************************************************/
63 static picture_pool_t *Pool (vout_display_t *, unsigned);
64 static void Prepare(vout_display_t *, picture_t *, subpicture_t *);
65 static void Display(vout_display_t *, picture_t *, subpicture_t *);
66 static int Control(vout_display_t *, int, va_list);
67 static void Manage (vout_display_t *);
69 static void Swap (vlc_gl_t *);
70 static void *OurGetProcAddress(vlc_gl_t *, const char *);
73 * It creates an OpenGL vout display.
75 static int Open(vlc_object_t *object)
77 vout_display_t *vd = (vout_display_t *)object;
78 vout_display_sys_t *sys;
80 /* Allocate structure */
81 vd->sys = sys = calloc(1, sizeof(*sys));
89 EventThreadUpdateTitle(sys->event, VOUT_TITLE " (OpenGL output)");
92 sys->hGLDC = GetDC(sys->hvideownd);
94 /* Set the pixel format for the DC */
95 PIXELFORMATDESCRIPTOR pfd;
96 memset(&pfd, 0, sizeof(pfd));
97 pfd.nSize = sizeof(pfd);
99 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
100 pfd.iPixelType = PFD_TYPE_RGBA;
103 pfd.iLayerType = PFD_MAIN_PLANE;
104 SetPixelFormat(sys->hGLDC,
105 ChoosePixelFormat(sys->hGLDC, &pfd), &pfd);
107 /* Create and enable the render context */
108 sys->hGLRC = wglCreateContext(sys->hGLDC);
109 wglMakeCurrent(sys->hGLDC, sys->hGLRC);
113 sys->gl.unlock = NULL;
115 sys->gl.getProcAddress = OurGetProcAddress;
118 video_format_t fmt = vd->fmt;
119 sys->vgl = vout_display_opengl_New(&fmt, &sys->gl);
123 vout_display_info_t info = vd->info;
124 info.has_double_click = true;
125 info.has_hide_mouse = false;
126 info.has_pictures_invalid = true;
127 info.has_event_thread = true;
129 /* Setup vout_display now that everything is fine */
134 vd->prepare = Prepare;
135 vd->display = Display;
136 vd->control = Control;
147 * It destroys an OpenGL vout display.
149 static void Close(vlc_object_t *object)
151 vout_display_t *vd = (vout_display_t *)object;
152 vout_display_sys_t *sys = vd->sys;
155 vout_display_opengl_Delete(sys->vgl);
157 if (sys->hGLDC && sys->hGLRC)
158 wglMakeCurrent(NULL, NULL);
160 wglDeleteContext(sys->hGLRC);
162 ReleaseDC(sys->hvideownd, sys->hGLDC);
170 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
172 vout_display_sys_t *sys = vd->sys;
176 sys->pool = vout_display_opengl_GetPool(sys->vgl);
180 static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
182 vout_display_sys_t *sys = vd->sys;
184 vout_display_opengl_Prepare(sys->vgl, picture);
185 VLC_UNUSED(subpicture);
188 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
190 vout_display_sys_t *sys = vd->sys;
192 vout_display_opengl_Display(sys->vgl, &vd->source);
194 picture_Release(picture);
195 VLC_UNUSED(subpicture);
200 static int Control(vout_display_t *vd, int query, va_list args)
203 case VOUT_DISPLAY_GET_OPENGL: {
204 vlc_gl_t **gl = va_arg(args, vlc_gl_t **);
211 return CommonControl(vd, query, args);
215 static void Manage (vout_display_t *vd)
217 vout_display_sys_t *sys = vd->sys;
221 const int width = sys->rect_dest.right - sys->rect_dest.left;
222 const int height = sys->rect_dest.bottom - sys->rect_dest.top;
223 glViewport(0, 0, width, height);
226 static void Swap(vlc_gl_t *gl)
228 vout_display_t *vd = gl->sys;
230 SwapBuffers(vd->sys->hGLDC);
233 static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
235 return wglGetProcAddress(name);