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 # define API VLC_OPENGL_ES2
49 # define MODULE_VARNAME "gles2"
50 set_shortname (N_("OpenGL ES2"))
51 set_description (N_("OpenGL for Embedded Systems 2 video output"))
52 set_capability ("vout display", /*265*/0)
53 set_callbacks (Open, Close)
54 add_shortcut ("opengles2", "gles2")
55 add_module ("gles2", "opengl es2", NULL,
56 GLES2_TEXT, PROVIDER_LONGTEXT, true)
58 #elif USE_OPENGL_ES == 1
59 # define API VLC_OPENGL_ES
60 # define MODULE_VARNAME "gles"
61 set_shortname (N_("OpenGL ES"))
62 set_description (N_("OpenGL for Embedded Systems video output"))
63 set_capability ("vout display", /*260*/0)
64 set_callbacks (Open, Close)
65 add_shortcut ("opengles", "gles")
66 add_module ("gles", "opengl es", NULL,
67 GLES_TEXT, PROVIDER_LONGTEXT, true)
69 # define API VLC_OPENGL
70 # define MODULE_VARNAME "gl"
71 set_shortname (N_("OpenGL"))
72 set_description (N_("OpenGL video output (experimental)"))
73 set_category (CAT_VIDEO)
74 set_subcategory (SUBCAT_VIDEO_VOUT)
75 set_capability ("vout display", /*270*/0)
76 set_callbacks (Open, Close)
77 add_shortcut ("opengl", "gl")
78 add_module ("gl", "opengl", NULL,
79 GL_TEXT, PROVIDER_LONGTEXT, true)
83 struct vout_display_sys_t
85 vout_display_opengl_t *vgl;
90 /* Display callbacks */
91 static picture_pool_t *Pool (vout_display_t *, unsigned);
92 static void PictureRender (vout_display_t *, picture_t *, subpicture_t *);
93 static void PictureDisplay (vout_display_t *, picture_t *, subpicture_t *);
94 static int Control (vout_display_t *, int, va_list);
97 * Allocates a surface and an OpenGL context for video output.
99 static int Open (vlc_object_t *obj)
101 vout_display_t *vd = (vout_display_t *)obj;
102 vout_display_sys_t *sys = malloc (sizeof (*sys));
103 if (unlikely(sys == NULL))
109 vout_window_t *surface = vout_display_NewWindow (vd, VOUT_WINDOW_TYPE_INVALID);
112 msg_Err (vd, "parent window not available");
116 sys->gl = vlc_gl_Create (surface, API, "$" MODULE_VARNAME);
120 vlc_gl_Resize (sys->gl, vd->cfg->display.width, vd->cfg->display.height);
122 /* Initialize video display */
123 const vlc_fourcc_t *spu_chromas;
125 if (vlc_gl_MakeCurrent (sys->gl))
128 sys->vgl = vout_display_opengl_New (&vd->fmt, &spu_chromas, sys->gl);
129 vlc_gl_ReleaseCurrent (sys->gl);
131 if (sys->vgl == NULL)
135 vd->info.has_pictures_invalid = false;
136 vd->info.has_event_thread = false;
137 vd->info.subpicture_chromas = spu_chromas;
139 vd->prepare = PictureRender;
140 vd->display = PictureDisplay;
141 vd->control = Control;
147 vlc_gl_Destroy (sys->gl);
149 vout_display_DeleteWindow (vd, surface);
155 * Destroys the OpenGL context.
157 static void Close (vlc_object_t *obj)
159 vout_display_t *vd = (vout_display_t *)obj;
160 vout_display_sys_t *sys = vd->sys;
161 vlc_gl_t *gl = sys->gl;
162 vout_window_t *surface = gl->surface;
164 vlc_gl_MakeCurrent (gl);
165 vout_display_opengl_Delete (sys->vgl);
166 vlc_gl_ReleaseCurrent (gl);
169 vout_display_DeleteWindow (vd, surface);
174 * Returns picture buffers
176 static picture_pool_t *Pool (vout_display_t *vd, unsigned count)
178 vout_display_sys_t *sys = vd->sys;
182 vlc_gl_MakeCurrent (sys->gl);
183 sys->pool = vout_display_opengl_GetPool (sys->vgl, count);
184 vlc_gl_ReleaseCurrent (sys->gl);
189 static void PictureRender (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
191 vout_display_sys_t *sys = vd->sys;
193 vlc_gl_MakeCurrent (sys->gl);
194 vout_display_opengl_Prepare (sys->vgl, pic, subpicture);
195 vlc_gl_ReleaseCurrent (sys->gl);
198 static void PictureDisplay (vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
200 vout_display_sys_t *sys = vd->sys;
202 vlc_gl_MakeCurrent (sys->gl);
203 vout_display_opengl_Display (sys->vgl, &vd->source);
204 vlc_gl_ReleaseCurrent (sys->gl);
206 picture_Release (pic);
210 static int Control (vout_display_t *vd, int query, va_list ap)
212 vout_display_sys_t *sys = vd->sys;
216 case VOUT_DISPLAY_HIDE_MOUSE: /* FIXME TODO */
219 case VOUT_DISPLAY_RESET_PICTURES: // not needed
223 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
224 case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
225 case VOUT_DISPLAY_CHANGE_ZOOM:
227 const vout_display_cfg_t *c = va_arg (ap, const vout_display_cfg_t *);
228 const video_format_t *src = &vd->source;
229 vout_display_place_t place;
231 vout_display_PlacePicture (&place, src, c, false);
232 vlc_gl_Resize (sys->gl, place.width, place.height);
233 vlc_gl_MakeCurrent (sys->gl);
234 glViewport (place.x, place.y, place.width, place.height);
235 vlc_gl_ReleaseCurrent (sys->gl);
239 case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
240 case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
242 const vout_display_cfg_t *cfg = vd->cfg;
243 const video_format_t *src = va_arg (ap, const video_format_t *);
244 vout_display_place_t place;
246 vout_display_PlacePicture (&place, src, cfg, false);
247 vlc_gl_MakeCurrent (sys->gl);
248 glViewport (place.x, place.y, place.width, place.height);
249 vlc_gl_ReleaseCurrent (sys->gl);
253 msg_Err (vd, "Unknown request %d", query);