3 * @brief OpenGL video output module
5 /*****************************************************************************
6 * Copyright © 2010-2011 Rémi Denis-Courmont
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_vout_display.h>
33 #include <vlc_opengl.h>
36 /* Plugin callbacks */
37 static int Open (vlc_object_t *);
38 static void Close (vlc_object_t *);
40 #define GL_TEXT N_("OpenGL extension")
41 #define GLES2_TEXT N_("OpenGL ES 2 extension")
42 #define GLES_TEXT N_("OpenGL ES extension")
43 #define PROVIDER_LONGTEXT N_( \
44 "Extension through which to use the Open Graphics Library (OpenGL).")
47 #if USE_OPENGL_ES == 2
48 # error The OpenGL ES2 plugin is incomplete and not functional. FIXME.
49 # define API VLC_OPENGL_ES2
50 # define MODULE_VARNAME "gles2"
51 set_shortname (N_("OpenGL ES2"))
52 set_description (N_("OpenGL for Embedded Systems 2 video output"))
53 set_capability ("vout display", /*165*/0)
54 set_callbacks (Open, Close)
55 add_shortcut ("opengles2", "gles2")
56 add_module ("gles2", "opengl es2", NULL,
57 GLES2_TEXT, PROVIDER_LONGTEXT, true)
59 #elif USE_OPENGL_ES == 1
60 # define API VLC_OPENGL_ES
61 # define MODULE_VARNAME "gles"
62 set_shortname (N_("OpenGL ES"))
63 set_description (N_("OpenGL for Embedded Systems video output"))
64 set_capability ("vout display", /*160*/0)
65 set_callbacks (Open, Close)
66 add_shortcut ("opengles", "gles")
67 add_module ("gles", "opengl es", NULL,
68 GLES_TEXT, PROVIDER_LONGTEXT, true)
70 # define API VLC_OPENGL
71 # define MODULE_VARNAME "gl"
72 set_shortname (N_("OpenGL"))
73 set_description (N_("OpenGL video output"))
74 set_category (CAT_VIDEO)
75 set_subcategory (SUBCAT_VIDEO_VOUT)
76 set_capability ("vout display", /*170*/0)
77 set_callbacks (Open, Close)
78 add_shortcut ("opengl", "gl")
79 add_module ("gl", "opengl", NULL,
80 GL_TEXT, PROVIDER_LONGTEXT, true)
84 struct vout_display_sys_t
86 vout_display_opengl_t *vgl;
88 vout_window_t *window;
93 /* Display callbacks */
94 static picture_pool_t *Pool (vout_display_t *, unsigned);
95 static void PictureRender (vout_display_t *, picture_t *, subpicture_t *);
96 static void PictureDisplay (vout_display_t *, picture_t *, subpicture_t *);
97 static int Control (vout_display_t *, int, va_list);
99 static vout_window_t *MakeWindow (vout_display_t *vd)
101 vout_window_cfg_t wnd_cfg;
103 memset (&wnd_cfg, 0, sizeof (wnd_cfg));
104 wnd_cfg.type = VOUT_WINDOW_TYPE_NATIVE;
105 wnd_cfg.x = var_InheritInteger (vd, "video-x");
106 wnd_cfg.y = var_InheritInteger (vd, "video-y");
107 wnd_cfg.width = vd->cfg->display.width;
108 wnd_cfg.height = vd->cfg->display.height;
110 vout_window_t *wnd = vout_display_NewWindow (vd, &wnd_cfg);
112 msg_Err (vd, "parent window not available");
117 * Allocates a surface and an OpenGL context for video output.
119 static int Open (vlc_object_t *obj)
121 vout_display_t *vd = (vout_display_t *)obj;
122 vout_display_sys_t *sys = malloc (sizeof (*sys));
123 if (unlikely(sys == NULL))
129 sys->window = MakeWindow (vd);
130 if (sys->window == NULL)
133 sys->gl = vlc_gl_Create (sys->window, API, "$" MODULE_VARNAME);
137 if (vlc_gl_MakeCurrent (sys->gl))
140 /* Initialize video display */
141 sys->vgl = vout_display_opengl_New (&vd->fmt, NULL, sys->gl);
146 vd->info.has_pictures_invalid = false;
147 vd->info.has_event_thread = false;
149 vd->prepare = PictureRender;
150 vd->display = PictureDisplay;
151 vd->control = Control;
157 vlc_gl_Destroy (sys->gl);
158 if (sys->window != NULL)
159 vout_display_DeleteWindow (vd, sys->window);
165 * Destroys the OpenGL context.
167 static void Close (vlc_object_t *obj)
169 vout_display_t *vd = (vout_display_t *)obj;
170 vout_display_sys_t *sys = vd->sys;
172 vout_display_opengl_Delete (sys->vgl);
173 vlc_gl_Destroy (sys->gl);
174 vout_display_DeleteWindow (vd, sys->window);
179 * Returns picture buffers
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 PictureRender (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
192 vout_display_sys_t *sys = vd->sys;
194 vout_display_opengl_Prepare (sys->vgl, pic, subpicture);
197 static void PictureDisplay (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
199 vout_display_sys_t *sys = vd->sys;
201 vout_display_opengl_Display (sys->vgl, &vd->source);
202 picture_Release (pic);
206 static int Control (vout_display_t *vd, int query, va_list ap)
208 vout_display_sys_t *sys = vd->sys;
212 case VOUT_DISPLAY_HIDE_MOUSE: /* FIXME TODO */
215 case VOUT_DISPLAY_RESET_PICTURES: // not needed
218 case VOUT_DISPLAY_CHANGE_FULLSCREEN:
220 const vout_display_cfg_t *cfg =
221 va_arg (ap, const vout_display_cfg_t *);
223 return vout_window_SetFullScreen (sys->window, cfg->is_fullscreen);
226 case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
228 unsigned state = va_arg (ap, unsigned);
230 return vout_window_SetState (sys->window, state);
233 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
234 case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
235 case VOUT_DISPLAY_CHANGE_ZOOM:
237 const vout_display_cfg_t *cfg = va_arg (ap, const vout_display_cfg_t *);
238 const video_format_t *src = &vd->source;
240 if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
244 force = va_arg (ap, int);
246 && (cfg->display.width != vd->cfg->display.width
247 || cfg->display.height != vd->cfg->display.height)
248 && vout_window_SetSize (sys->window,
249 cfg->display.width, cfg->display.height))
253 vout_display_place_t place;
255 vout_display_PlacePicture (&place, src, cfg, false);
256 glViewport (0, 0, place.width, place.height);
260 case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
261 case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
263 const vout_display_cfg_t *cfg = vd->cfg;
264 const video_format_t *src = va_arg (ap, const video_format_t *);
265 vout_display_place_t place;
267 vout_display_PlacePicture (&place, src, cfg, false);
268 glViewport (0, 0, place.width, place.height);
272 case VOUT_DISPLAY_GET_OPENGL:
274 vlc_gl_t **pgl = va_arg (ap, vlc_gl_t **);
281 msg_Err (vd, "Unknown request %d", query);