1 /*****************************************************************************
2 * glwin32.c: Windows OpenGL provider
3 *****************************************************************************
4 * Copyright (C) 2001-2009 VLC authors and VideoLAN
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 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_vout_display.h>
34 #include <versionhelpers.h>
37 #include "../opengl/vout_helper.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Open (vlc_object_t
*);
46 static void Close(vlc_object_t
*);
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
)
59 /*****************************************************************************
61 *****************************************************************************/
62 struct vout_display_sys_t
64 vout_display_sys_win32_t sys
;
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
);
92 static vout_window_t
*EmbedVideoWindow_Create(vout_display_t
*vd
)
94 vout_display_sys_t
*sys
= vd
->sys
;
96 if (!sys
->sys
.hvideownd
)
99 vout_window_t
*wnd
= vlc_object_create(vd
, sizeof(vout_window_t
));
103 wnd
->type
= VOUT_WINDOW_TYPE_HWND
;
104 wnd
->handle
.hwnd
= sys
->sys
.hvideownd
;
105 wnd
->control
= EmbedVideoWindow_Control
;
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())
121 /* Allocate structure */
122 vd
->sys
= sys
= calloc(1, sizeof(*sys
));
130 EventThreadUpdateTitle(sys
->sys
.event
, VOUT_TITLE
" (OpenGL output)");
132 vout_window_t
*surface
= EmbedVideoWindow_Create(vd
);
136 char *modlist
= var_InheritString(surface
, "gl");
137 sys
->gl
= vlc_gl_Create (surface
, VLC_OPENGL
, modlist
);
141 vlc_object_release(surface
);
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
))
151 sys
->vgl
= vout_display_opengl_New(&fmt
, &subpicture_chromas
, sys
->gl
,
152 &vd
->cfg
->viewpoint
);
153 vlc_gl_ReleaseCurrent (sys
->gl
);
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 */
166 vd
->prepare
= Prepare
;
167 vd
->display
= Display
;
168 vd
->control
= Control
;
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
;
188 vout_window_t
*surface
= gl
->surface
;
191 vlc_gl_MakeCurrent (gl
);
192 vout_display_opengl_Delete(sys
->vgl
);
193 vlc_gl_ReleaseCurrent (gl
);
196 vlc_object_release(surface
);
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
,
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
);
243 subpicture_Delete(subpicture
);
248 static void Manage (vout_display_t
*vd
)
250 vout_display_sys_t
*sys
= vd
->sys
;
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
)
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
);