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)
62 /*****************************************************************************
64 *****************************************************************************/
65 static picture_pool_t *Pool (vout_display_t *, unsigned);
66 static void Prepare(vout_display_t *, picture_t *);
67 static void Display(vout_display_t *, picture_t *);
68 static int Control(vout_display_t *, int, va_list);
69 static void Manage (vout_display_t *);
71 static void Swap (vout_opengl_t *);
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);
114 sys->gl.unlock = NULL;
118 video_format_t fmt = vd->fmt;
119 if (vout_display_opengl_Init(&sys->vgl, &fmt, &sys->gl))
122 vout_display_info_t info = vd->info;
123 info.has_double_click = true;
124 info.has_hide_mouse = false;
125 info.has_pictures_invalid = true;
126 info.has_event_thread = true;
128 /* Setup vout_display now that everything is fine */
133 vd->prepare = Prepare;
134 vd->display = Display;
135 vd->control = Control;
146 * It destroys an OpenGL vout display.
148 static void Close(vlc_object_t *object)
150 vout_display_t *vd = (vout_display_t *)object;
151 vout_display_sys_t *sys = vd->sys;
154 vout_display_opengl_Clean(&sys->vgl);
156 if (sys->hGLDC && sys->hGLRC)
157 wglMakeCurrent(NULL, NULL);
159 wglDeleteContext(sys->hGLRC);
161 ReleaseDC(sys->hvideownd, sys->hGLDC);
169 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
171 vout_display_sys_t *sys = vd->sys;
175 sys->pool = vout_display_opengl_GetPool(&sys->vgl);
179 static void Prepare(vout_display_t *vd, picture_t *picture)
181 vout_display_sys_t *sys = vd->sys;
183 vout_display_opengl_Prepare(&sys->vgl, picture);
186 static void Display(vout_display_t *vd, picture_t *picture)
188 vout_display_sys_t *sys = vd->sys;
190 vout_display_opengl_Display(&sys->vgl, &vd->source);
192 picture_Release(picture);
197 static int Control(vout_display_t *vd, int query, va_list args)
200 case VOUT_DISPLAY_GET_OPENGL: {
201 vout_opengl_t **gl = va_arg(args, vout_opengl_t **);
206 return CommonControl(vd, query, args);
210 static void Manage (vout_display_t *vd)
212 vout_display_sys_t *sys = vd->sys;
216 const int width = sys->rect_dest.right - sys->rect_dest.left;
217 const int height = sys->rect_dest.bottom - sys->rect_dest.top;
218 glViewport(0, 0, width, height);
221 static void Swap(vout_opengl_t *gl)
223 vout_display_t *vd = gl->sys;
225 SwapBuffers(vd->sys->hGLDC);