2 * GStreamer EGL/GLES Sink Adaptation
3 * Copyright (C) 2012-2013 Collabora Ltd.
4 * @author: Reynaldo H. Verdejo Pinochet <reynaldo@collabora.com>
5 * @author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * @author: Thiago Santos <thiago.sousa.santos@collabora.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Alternatively, the contents of this file may be used under the
27 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 * which case the following provisions apply instead of the ones
31 * This library is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU Library General Public
33 * License as published by the Free Software Foundation; either
34 * version 2 of the License, or (at your option) any later version.
36 * This library is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 * Library General Public License for more details.
41 * You should have received a copy of the GNU Library General Public
42 * License along with this library; if not, write to the
43 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 * Boston, MA 02111-1307, USA.
47 #ifndef __GST_EGL_ADAPTATION_H__
48 #define __GST_EGL_ADAPTATION_H__
54 #define EGL_EGLEXT_PROTOTYPES
55 #define GL_GLEXT_PROTOTYPES
58 #include <gst/egl/egl.h>
59 #include <gst/video/gstvideopool.h>
62 #include <OpenGLES/ES2/gl.h>
66 #include <EGL/eglext.h>
67 #include <GLES2/gl2.h>
68 #include <GLES2/gl2ext.h>
71 #define GST_EGLGLESSINK_EGL_MIN_VERSION 1
73 static const EGLint eglglessink_RGBA8888_attribs[] = {
78 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
79 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
85 typedef struct _GstEglAdaptationContext GstEglAdaptationContext;
86 typedef struct _GstEglGlesImageFmt GstEglGlesImageFmt;
89 typedef struct _GstEaglContext GstEaglContext;
91 typedef struct _GstEglGlesRenderContext GstEglGlesRenderContext;
94 typedef struct _coord5
99 float a; /* texpos x */
100 float b; /* texpos y */
106 } GstEGLGLESImageData;
109 * GstEglAdaptationContext:
110 * @have_vbo: Set if the GLES VBO setup has been performed
111 * @have_texture: Set if the GLES texture setup has been performed
112 * @have_surface: Set if the EGL surface setup has been performed
114 * The #GstEglAdaptationContext data structure.
116 struct _GstEglAdaptationContext
121 GstEaglContext *eaglctx;
123 GstEglGlesRenderContext *eglglesctx;
126 GstEGLDisplay *display, *set_display;
127 EGLNativeWindowType window, used_window;
129 GLuint fragshader[2]; /* frame, border */
130 GLuint vertshader[2]; /* frame, border */
131 GLuint glslprogram[2]; /* frame, border */
132 GLuint texture[3]; /* RGB/Y, U/UV, V */
134 GLuint position_loc[2]; /* frame, border */
135 GLuint texpos_loc[1]; /* frame */
136 GLuint tex_scale_loc[1][3]; /* [frame] RGB/Y, U/UV, V */
137 GLuint tex_loc[1][3]; /* [frame] RGB/Y, U/UV, V */
138 coord5 position_array[16]; /* 4 x Frame x-normal,y-normal, 4x Frame x-normal,y-flip, 4 x Border1, 4 x Border2 */
139 unsigned short index_array[4];
140 unsigned int position_buffer, index_buffer;
143 EGLint surface_width;
144 EGLint surface_height;
145 EGLint pixel_aspect_ratio_n;
146 EGLint pixel_aspect_ratio_d;
149 gboolean have_texture;
150 gboolean have_surface;
151 gboolean buffer_preserved;
154 GST_DEBUG_CATEGORY_EXTERN (egladaption_debug);
156 void gst_egl_adaption_init (void);
158 GstEglAdaptationContext * gst_egl_adaptation_context_new (GstElement * element);
159 void gst_egl_adaptation_context_free (GstEglAdaptationContext * ctx);
160 void gst_egl_adaptation_init (GstEglAdaptationContext * ctx);
161 void gst_egl_adaptation_deinit (GstEglAdaptationContext * ctx);
163 gboolean gst_egl_adaptation_create_surface (GstEglAdaptationContext * ctx);
164 void gst_egl_adaptation_query_buffer_preserved (GstEglAdaptationContext * ctx);
165 void gst_egl_adaptation_query_par (GstEglAdaptationContext * ctx);
166 void gst_egl_adaptation_destroy_surface (GstEglAdaptationContext * ctx);
167 void gst_egl_adaptation_destroy_context (GstEglAdaptationContext * ctx);
170 gst_egl_adaptation_create_egl_context (GstEglAdaptationContext * ctx);
172 /* platform window */
173 gboolean gst_egl_adaptation_create_native_window (GstEglAdaptationContext
174 * ctx, gint width, gint height, gpointer * own_window_data);
175 void gst_egl_adaptation_destroy_native_window (GstEglAdaptationContext * ctx, gpointer * own_window_data);
177 GstCaps *gst_egl_adaptation_fill_supported_fbuffer_configs (GstEglAdaptationContext * ctx);
178 gboolean gst_egl_adaptation_init_egl_display (GstEglAdaptationContext * ctx);
179 gboolean gst_egl_adaptation_choose_config (GstEglAdaptationContext * ctx);
180 gboolean gst_egl_adaptation_init_egl_surface (GstEglAdaptationContext * ctx, GstVideoFormat format);
181 void gst_egl_adaptation_init_egl_exts (GstEglAdaptationContext * ctx);
182 gboolean gst_egl_adaptation_update_surface_dimensions (GstEglAdaptationContext * ctx);
183 gboolean _gst_egl_choose_config (GstEglAdaptationContext * ctx, gboolean try_only, gint * num_configs);
185 gboolean got_gl_error (const char *wtf);
186 gboolean got_egl_error (const char *wtf);
188 void gst_egl_adaptation_set_window (GstEglAdaptationContext * ctx, guintptr window);
190 gboolean gst_egl_adaptation_context_make_current (GstEglAdaptationContext * ctx, gboolean bind);
191 void gst_egl_adaptation_cleanup (GstEglAdaptationContext * ctx);
194 gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx, GstAllocator * allocator,
195 GstVideoFormat format, gint width, gint height);
197 gst_egl_adaptation_context_swap_buffers (GstEglAdaptationContext * ctx);
201 #endif /* __GST_EGL_ADAPTATION_H__ */