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__
55 #include <gst/video/gstvideopool.h>
57 #if defined (USE_EGL_RPI) && defined(__GNUC__)
59 #define __VCCOREVER__ 0x04000000
62 #pragma GCC diagnostic push
63 #pragma GCC diagnostic ignored "-Wredundant-decls"
64 #pragma GCC optimize ("gnu89-inline")
67 #define EGL_EGLEXT_PROTOTYPES
68 #define GL_GLEXT_PROTOTYPES
70 #include <gst/egl/egl.h>
73 #include <OpenGLES/ES2/gl.h>
76 #include <EGL/eglext.h>
77 #include <GLES2/gl2.h>
78 #include <GLES2/gl2ext.h>
81 #if defined (USE_EGL_RPI) && defined(__GNUC__)
82 #pragma GCC reset_options
83 #pragma GCC diagnostic pop
86 #define GST_EGLGLESSINK_EGL_MIN_VERSION 1
88 static const EGLint eglglessink_RGBA8888_attribs[] = {
93 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
94 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
100 typedef struct _GstEglAdaptationContext GstEglAdaptationContext;
101 typedef struct _GstEglGlesImageFmt GstEglGlesImageFmt;
104 typedef struct _GstEaglContext GstEaglContext;
106 typedef struct _GstEglGlesRenderContext GstEglGlesRenderContext;
109 typedef struct _coord5
114 float a; /* texpos x */
115 float b; /* texpos y */
121 } GstEGLGLESImageData;
124 * GstEglAdaptationContext:
125 * @have_vbo: Set if the GLES VBO setup has been performed
126 * @have_texture: Set if the GLES texture setup has been performed
127 * @have_surface: Set if the EGL surface setup has been performed
129 * The #GstEglAdaptationContext data structure.
131 struct _GstEglAdaptationContext
136 GstEaglContext *eaglctx;
138 GstEglGlesRenderContext *eglglesctx;
141 GstEGLDisplay *display, *set_display;
142 EGLNativeWindowType window, used_window;
144 GLuint fragshader[2]; /* frame, border */
145 GLuint vertshader[2]; /* frame, border */
146 GLuint glslprogram[2]; /* frame, border */
147 GLuint texture[3]; /* RGB/Y, U/UV, V */
149 GLuint position_loc[2]; /* frame, border */
150 GLuint texpos_loc[1]; /* frame */
151 GLuint tex_scale_loc[1][3]; /* [frame] RGB/Y, U/UV, V */
152 GLuint tex_loc[1][3]; /* [frame] RGB/Y, U/UV, V */
153 coord5 position_array[16]; /* 4 x Frame x-normal,y-normal, 4x Frame x-normal,y-flip, 4 x Border1, 4 x Border2 */
154 unsigned short index_array[4];
155 unsigned int position_buffer, index_buffer;
158 EGLint surface_width;
159 EGLint surface_height;
160 EGLint pixel_aspect_ratio_n;
161 EGLint pixel_aspect_ratio_d;
164 gboolean have_texture;
165 gboolean have_surface;
166 gboolean buffer_preserved;
169 GST_DEBUG_CATEGORY_EXTERN (egladaption_debug);
171 void gst_egl_adaption_init (void);
173 GstEglAdaptationContext * gst_egl_adaptation_context_new (GstElement * element);
174 void gst_egl_adaptation_context_free (GstEglAdaptationContext * ctx);
175 void gst_egl_adaptation_init (GstEglAdaptationContext * ctx);
176 void gst_egl_adaptation_deinit (GstEglAdaptationContext * ctx);
178 gboolean gst_egl_adaptation_create_surface (GstEglAdaptationContext * ctx);
179 void gst_egl_adaptation_query_buffer_preserved (GstEglAdaptationContext * ctx);
180 void gst_egl_adaptation_query_par (GstEglAdaptationContext * ctx);
181 void gst_egl_adaptation_destroy_surface (GstEglAdaptationContext * ctx);
182 void gst_egl_adaptation_destroy_context (GstEglAdaptationContext * ctx);
185 gst_egl_adaptation_create_egl_context (GstEglAdaptationContext * ctx);
187 /* platform window */
188 gboolean gst_egl_adaptation_create_native_window (GstEglAdaptationContext
189 * ctx, gint width, gint height, gpointer * own_window_data);
190 void gst_egl_adaptation_destroy_native_window (GstEglAdaptationContext * ctx, gpointer * own_window_data);
192 GstCaps *gst_egl_adaptation_fill_supported_fbuffer_configs (GstEglAdaptationContext * ctx);
193 gboolean gst_egl_adaptation_init_egl_display (GstEglAdaptationContext * ctx);
194 gboolean gst_egl_adaptation_choose_config (GstEglAdaptationContext * ctx);
195 gboolean gst_egl_adaptation_init_egl_surface (GstEglAdaptationContext * ctx, GstVideoFormat format);
196 void gst_egl_adaptation_init_egl_exts (GstEglAdaptationContext * ctx);
197 gboolean gst_egl_adaptation_update_surface_dimensions (GstEglAdaptationContext * ctx);
198 gboolean _gst_egl_choose_config (GstEglAdaptationContext * ctx, gboolean try_only, gint * num_configs);
200 gboolean got_gl_error (const char *wtf);
201 gboolean got_egl_error (const char *wtf);
203 void gst_egl_adaptation_set_window (GstEglAdaptationContext * ctx, guintptr window);
205 gboolean gst_egl_adaptation_context_make_current (GstEglAdaptationContext * ctx, gboolean bind);
206 void gst_egl_adaptation_cleanup (GstEglAdaptationContext * ctx);
209 gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx, GstAllocator * allocator,
210 GstVideoFormat format, gint width, gint height);
212 gst_egl_adaptation_context_swap_buffers (GstEglAdaptationContext * ctx);
216 #endif /* __GST_EGL_ADAPTATION_H__ */