glwin32: don't activate on XP
[vlc.git] / modules / video_output / win32 / glwin32.c
blob6427ccf6584485922da286eaa5e4584ba7ea4c5c
1 /*****************************************************************************
2 * glwin32.c: Windows OpenGL provider
3 *****************************************************************************
4 * Copyright (C) 2001-2009 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <assert.h>
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_vout_display.h>
33 #include <windows.h>
34 #include <versionhelpers.h>
36 #define GLEW_STATIC
37 #include "../opengl/vout_helper.h"
38 #include <GL/wglew.h>
40 #include "common.h"
42 /*****************************************************************************
43 * Module descriptor
44 *****************************************************************************/
45 static int Open (vlc_object_t *);
46 static void Close(vlc_object_t *);
48 vlc_module_begin()
49 set_category(CAT_VIDEO)
50 set_subcategory(SUBCAT_VIDEO_VOUT)
51 set_shortname("OpenGL")
52 set_description(N_("OpenGL video output for Windows"))
53 set_capability("vout display", 275)
54 add_shortcut("glwin32", "opengl")
55 set_callbacks(Open, Close)
56 add_glopts()
57 vlc_module_end()
59 /*****************************************************************************
60 * Local prototypes.
61 *****************************************************************************/
62 struct vout_display_sys_t
64 vout_display_sys_win32_t sys;
66 vlc_gl_t *gl;
67 vout_display_opengl_t *vgl;
70 static picture_pool_t *Pool (vout_display_t *, unsigned);
71 static void Prepare(vout_display_t *, picture_t *, subpicture_t *, vlc_tick_t);
72 static void Display(vout_display_t *, picture_t *, subpicture_t *);
73 static void Manage (vout_display_t *);
75 static int Control(vout_display_t *vd, int query, va_list args)
77 vout_display_sys_t *sys = vd->sys;
79 if (query == VOUT_DISPLAY_CHANGE_VIEWPOINT)
80 return vout_display_opengl_SetViewpoint(sys->vgl,
81 &va_arg (args, const vout_display_cfg_t* )->viewpoint);
83 return CommonControl(vd, query, args);
86 static int EmbedVideoWindow_Control(vout_window_t *wnd, int query, va_list ap)
88 VLC_UNUSED( ap ); VLC_UNUSED( query );
89 return VLC_EGENERIC;
92 static vout_window_t *EmbedVideoWindow_Create(vout_display_t *vd)
94 vout_display_sys_t *sys = vd->sys;
96 if (!sys->sys.hvideownd)
97 return NULL;
99 vout_window_t *wnd = vlc_object_create(vd, sizeof(vout_window_t));
100 if (!wnd)
101 return NULL;
103 wnd->type = VOUT_WINDOW_TYPE_HWND;
104 wnd->handle.hwnd = sys->sys.hvideownd;
105 wnd->control = EmbedVideoWindow_Control;
106 return wnd;
110 * It creates an OpenGL vout display.
112 static int Open(vlc_object_t *object)
114 vout_display_t *vd = (vout_display_t *)object;
115 vout_display_sys_t *sys;
117 /* do not use OpenGL on XP unless forced */
118 if(!object->obj.force && !IsWindowsVistaOrGreater())
119 return VLC_EGENERIC;
121 /* Allocate structure */
122 vd->sys = sys = calloc(1, sizeof(*sys));
123 if (!sys)
124 return VLC_ENOMEM;
126 /* */
127 if (CommonInit(vd))
128 goto error;
130 EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (OpenGL output)");
132 vout_window_t *surface = EmbedVideoWindow_Create(vd);
133 if (!surface)
134 goto error;
136 char *modlist = var_InheritString(surface, "gl");
137 sys->gl = vlc_gl_Create (surface, VLC_OPENGL, modlist);
138 free(modlist);
139 if (!sys->gl)
141 vlc_object_release(surface);
142 goto error;
145 vlc_gl_Resize (sys->gl, vd->cfg->display.width, vd->cfg->display.height);
147 video_format_t fmt = vd->fmt;
148 const vlc_fourcc_t *subpicture_chromas;
149 if (vlc_gl_MakeCurrent (sys->gl))
150 goto error;
151 sys->vgl = vout_display_opengl_New(&fmt, &subpicture_chromas, sys->gl,
152 &vd->cfg->viewpoint);
153 vlc_gl_ReleaseCurrent (sys->gl);
154 if (!sys->vgl)
155 goto error;
157 vout_display_info_t info = vd->info;
158 info.has_double_click = true;
159 info.subpicture_chromas = subpicture_chromas;
161 /* Setup vout_display now that everything is fine */
162 vd->fmt = fmt;
163 vd->info = info;
165 vd->pool = Pool;
166 vd->prepare = Prepare;
167 vd->display = Display;
168 vd->control = Control;
170 return VLC_SUCCESS;
172 error:
173 Close(object);
174 return VLC_EGENERIC;
178 * It destroys an OpenGL vout display.
180 static void Close(vlc_object_t *object)
182 vout_display_t *vd = (vout_display_t *)object;
183 vout_display_sys_t *sys = vd->sys;
184 vlc_gl_t *gl = sys->gl;
186 if (gl)
188 vout_window_t *surface = gl->surface;
189 if (sys->vgl)
191 vlc_gl_MakeCurrent (gl);
192 vout_display_opengl_Delete(sys->vgl);
193 vlc_gl_ReleaseCurrent (gl);
195 vlc_gl_Release (gl);
196 vlc_object_release(surface);
199 CommonClean(vd);
201 free(sys);
204 /* */
205 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
207 vout_display_sys_t *sys = vd->sys;
209 if (!sys->sys.pool && vlc_gl_MakeCurrent (sys->gl) == VLC_SUCCESS)
211 sys->sys.pool = vout_display_opengl_GetPool(sys->vgl, count);
212 vlc_gl_ReleaseCurrent (sys->gl);
214 return sys->sys.pool;
217 static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture,
218 vlc_tick_t date)
220 Manage(vd);
221 VLC_UNUSED(date);
222 vout_display_sys_t *sys = vd->sys;
224 if (vlc_gl_MakeCurrent (sys->gl) == VLC_SUCCESS)
226 vout_display_opengl_Prepare (sys->vgl, picture, subpicture);
227 vlc_gl_ReleaseCurrent (sys->gl);
231 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
233 vout_display_sys_t *sys = vd->sys;
235 if (vlc_gl_MakeCurrent (sys->gl) == VLC_SUCCESS)
237 vout_display_opengl_Display (sys->vgl, &vd->source);
238 vlc_gl_ReleaseCurrent (sys->gl);
241 picture_Release(picture);
242 if (subpicture)
243 subpicture_Delete(subpicture);
245 CommonDisplay(vd);
248 static void Manage (vout_display_t *vd)
250 vout_display_sys_t *sys = vd->sys;
252 CommonManage(vd);
254 const int width = sys->sys.rect_dest.right - sys->sys.rect_dest.left;
255 const int height = sys->sys.rect_dest.bottom - sys->sys.rect_dest.top;
256 vlc_gl_Resize (sys->gl, width, height);
257 if (vlc_gl_MakeCurrent (sys->gl) != VLC_SUCCESS)
258 return;
259 vout_display_opengl_SetWindowAspectRatio(sys->vgl, (float)width / height);
260 vout_display_opengl_Viewport(sys->vgl, 0, 0, width, height);
261 vlc_gl_ReleaseCurrent (sys->gl);