2013-07-03 07:12:39 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-08-29 14:28:04 +00:00
|
|
|
/* FIXME: Sharing contexts requires the EGLDisplay to be the same
|
2013-08-29 10:10:42 +00:00
|
|
|
* may need to box it.
|
|
|
|
*/
|
|
|
|
|
2013-08-21 04:05:56 +00:00
|
|
|
#include "gstglcontext_egl.h"
|
2013-08-15 07:09:04 +00:00
|
|
|
#include <gst/gl/gl.h>
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
2013-08-21 04:05:56 +00:00
|
|
|
#include "../x11/gstglwindow_x11.h"
|
2013-08-15 07:09:04 +00:00
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_WINDOW_WIN32
|
2013-08-21 04:05:56 +00:00
|
|
|
#include "../win32/gstglwindow_win32.h"
|
2013-08-15 07:09:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean gst_gl_context_egl_create_context (GstGLContext * context,
|
2013-08-29 10:10:42 +00:00
|
|
|
GstGLAPI gl_api, GstGLContext * other_context, GError ** error);
|
2013-08-15 07:09:04 +00:00
|
|
|
static void gst_gl_context_egl_destroy_context (GstGLContext * context);
|
|
|
|
static gboolean gst_gl_context_egl_choose_format (GstGLContext * context,
|
|
|
|
GError ** error);
|
|
|
|
|
|
|
|
static gboolean gst_gl_context_egl_activate (GstGLContext * context,
|
|
|
|
gboolean activate);
|
|
|
|
static void gst_gl_context_egl_swap_buffers (GstGLContext * context);
|
|
|
|
static guintptr gst_gl_context_egl_get_gl_context (GstGLContext * context);
|
|
|
|
static GstGLAPI gst_gl_context_egl_get_gl_api (GstGLContext * context);
|
|
|
|
static gpointer gst_gl_context_egl_get_proc_address (GstGLContext * context,
|
|
|
|
const gchar * name);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstGLContextEGL, gst_gl_context_egl, GST_GL_TYPE_CONTEXT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_context_egl_class_init (GstGLContextEGLClass * klass)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class = (GstGLContextClass *) klass;
|
|
|
|
|
|
|
|
context_class->get_gl_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_gl_context);
|
|
|
|
context_class->activate = GST_DEBUG_FUNCPTR (gst_gl_context_egl_activate);
|
|
|
|
context_class->create_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_egl_create_context);
|
|
|
|
context_class->destroy_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_egl_destroy_context);
|
|
|
|
context_class->choose_format =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_egl_choose_format);
|
|
|
|
context_class->swap_buffers =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_egl_swap_buffers);
|
|
|
|
|
|
|
|
context_class->get_gl_api = GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_gl_api);
|
|
|
|
context_class->get_proc_address =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_proc_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_context_egl_init (GstGLContextEGL * context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
|
|
|
GstGLContextEGL *
|
|
|
|
gst_gl_context_egl_new (void)
|
|
|
|
{
|
|
|
|
GstGLContextEGL *window = g_object_new (GST_GL_TYPE_CONTEXT_EGL, NULL);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
2013-07-03 07:12:39 +00:00
|
|
|
|
|
|
|
static const gchar *
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_context_egl_get_error_string (void)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
|
|
|
EGLint nErr = eglGetError ();
|
|
|
|
|
|
|
|
switch (nErr) {
|
|
|
|
case EGL_SUCCESS:
|
|
|
|
return "EGL_SUCCESS";
|
|
|
|
case EGL_BAD_DISPLAY:
|
|
|
|
return "EGL_BAD_DISPLAY";
|
|
|
|
case EGL_NOT_INITIALIZED:
|
|
|
|
return "EGL_NOT_INITIALIZED";
|
|
|
|
case EGL_BAD_ACCESS:
|
|
|
|
return "EGL_BAD_ACCESS";
|
|
|
|
case EGL_BAD_ALLOC:
|
|
|
|
return "EGL_BAD_ALLOC";
|
|
|
|
case EGL_BAD_ATTRIBUTE:
|
|
|
|
return "EGL_BAD_ATTRIBUTE";
|
|
|
|
case EGL_BAD_CONFIG:
|
|
|
|
return "EGL_BAD_CONFIG";
|
|
|
|
case EGL_BAD_CONTEXT:
|
|
|
|
return "EGL_BAD_CONTEXT";
|
|
|
|
case EGL_BAD_CURRENT_SURFACE:
|
|
|
|
return "EGL_BAD_CURRENT_SURFACE";
|
|
|
|
case EGL_BAD_MATCH:
|
|
|
|
return "EGL_BAD_MATCH";
|
|
|
|
case EGL_BAD_NATIVE_PIXMAP:
|
|
|
|
return "EGL_BAD_NATIVE_PIXMAP";
|
|
|
|
case EGL_BAD_NATIVE_WINDOW:
|
|
|
|
return "EGL_BAD_NATIVE_WINDOW";
|
|
|
|
case EGL_BAD_PARAMETER:
|
|
|
|
return "EGL_BAD_PARAMETER";
|
|
|
|
case EGL_BAD_SURFACE:
|
|
|
|
return "EGL_BAD_SURFACE";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_context_egl_choose_format (GstGLContext * context, GError ** error)
|
|
|
|
{
|
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
|
|
|
if (GST_GL_IS_WINDOW_X11 (context->window)) {
|
|
|
|
GstGLWindow *window = gst_gl_context_get_window (context);
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
window_x11->visual_info = g_new0 (XVisualInfo, 1);
|
|
|
|
ret = XMatchVisualInfo (window_x11->device, window_x11->screen_num,
|
|
|
|
window_x11->depth, TrueColor, window_x11->visual_info);
|
|
|
|
|
|
|
|
gst_object_unref (window);
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2013-09-03 11:49:18 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
|
|
GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Failed to match XVisualInfo");
|
2013-08-15 07:09:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-08-29 10:10:42 +00:00
|
|
|
gst_gl_context_egl_choose_config (GstGLContextEGL * egl,
|
|
|
|
GstGLContext * other_context, GError ** error)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
|
|
|
EGLint numConfigs;
|
|
|
|
gint i = 0;
|
|
|
|
EGLint config_attrib[20];
|
|
|
|
|
2013-08-29 14:28:04 +00:00
|
|
|
config_attrib[i++] = EGL_SURFACE_TYPE;
|
|
|
|
config_attrib[i++] = EGL_WINDOW_BIT;
|
|
|
|
config_attrib[i++] = EGL_RENDERABLE_TYPE;
|
|
|
|
if (egl->gl_api & GST_GL_API_GLES2)
|
|
|
|
config_attrib[i++] = EGL_OPENGL_ES2_BIT;
|
|
|
|
else
|
|
|
|
config_attrib[i++] = EGL_OPENGL_BIT;
|
2013-10-01 11:44:00 +00:00
|
|
|
#if defined(USE_EGL_RPI) && defined(GST_GL_HAVE_WINDOW_WAYLAND)
|
|
|
|
/* The configurations r=5 g=6 b=5 seems to be buggy whereas
|
|
|
|
* it works when using dispmanx directly */
|
|
|
|
config_attrib[i++] = EGL_BUFFER_SIZE;
|
|
|
|
config_attrib[i++] = 24;
|
|
|
|
/* same with a=0 */
|
|
|
|
config_attrib[i++] = EGL_ALPHA_SIZE;
|
|
|
|
config_attrib[i++] = 1;
|
|
|
|
#endif
|
2013-08-29 14:28:04 +00:00
|
|
|
config_attrib[i++] = EGL_DEPTH_SIZE;
|
|
|
|
config_attrib[i++] = 16;
|
|
|
|
config_attrib[i++] = EGL_NONE;
|
2013-07-03 07:12:39 +00:00
|
|
|
|
|
|
|
if (eglChooseConfig (egl->egl_display, config_attrib,
|
|
|
|
&egl->egl_config, 1, &numConfigs)) {
|
2013-08-29 10:10:42 +00:00
|
|
|
GST_INFO ("config set: %" G_GUINTPTR_FORMAT ", %u",
|
|
|
|
(guintptr) egl->egl_config, (unsigned int) numConfigs);
|
2013-07-03 07:12:39 +00:00
|
|
|
} else {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
2013-07-03 07:12:39 +00:00
|
|
|
"Failed to set window configuration: %s",
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_context_egl_get_error_string ());
|
2013-07-03 07:12:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_context_egl_create_context (GstGLContext * context,
|
2013-08-29 10:10:42 +00:00
|
|
|
GstGLAPI gl_api, GstGLContext * other_context, GError ** error)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextEGL *egl;
|
|
|
|
GstGLWindow *window = NULL;
|
|
|
|
EGLNativeWindowType window_handle;
|
2013-07-03 07:12:39 +00:00
|
|
|
gint i = 0;
|
|
|
|
EGLint context_attrib[3];
|
|
|
|
EGLint majorVersion;
|
|
|
|
EGLint minorVersion;
|
2013-07-24 11:34:20 +00:00
|
|
|
const gchar *egl_exts;
|
|
|
|
gboolean need_surface = TRUE;
|
2013-08-29 10:10:42 +00:00
|
|
|
guintptr external_gl_context = 0;
|
2013-07-03 07:12:39 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
egl = GST_GL_CONTEXT_EGL (context);
|
|
|
|
window = gst_gl_context_get_window (context);
|
2013-07-03 07:12:39 +00:00
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
if (other_context) {
|
|
|
|
if (!GST_GL_IS_CONTEXT_EGL (other_context)) {
|
2013-09-03 11:49:18 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
|
|
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
2013-08-29 10:10:42 +00:00
|
|
|
"Cannot share context with non-EGL context");
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
external_gl_context = gst_gl_context_get_gl_context (other_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((gl_api & (GST_GL_API_OPENGL | GST_GL_API_GLES2)) == GST_GL_API_NONE) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API,
|
2013-08-29 10:10:42 +00:00
|
|
|
"EGL supports opengl or gles2");
|
2013-07-03 07:12:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
if (other_context) {
|
|
|
|
GstGLContextEGL *other_egl = (GstGLContextEGL *) other_context;
|
|
|
|
egl->egl_display = other_egl->egl_display;
|
|
|
|
} else {
|
|
|
|
egl->egl_display = eglGetDisplay ((EGLNativeDisplayType)
|
|
|
|
gst_gl_window_get_display (window));
|
|
|
|
}
|
2013-07-03 07:12:39 +00:00
|
|
|
|
|
|
|
if (eglInitialize (egl->egl_display, &majorVersion, &minorVersion)) {
|
|
|
|
GST_INFO ("egl initialized, version: %d.%d", majorVersion, minorVersion);
|
|
|
|
} else {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
|
|
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
|
|
|
|
"Failed to initialize egl: %s", gst_gl_context_egl_get_error_string ());
|
2013-07-03 07:12:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_api & GST_GL_API_OPENGL) {
|
|
|
|
/* egl + opengl only available with EGL 1.4+ */
|
|
|
|
if (majorVersion == 1 && minorVersion <= 3) {
|
|
|
|
if ((gl_api & ~GST_GL_API_OPENGL) == GST_GL_API_NONE) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS,
|
2013-07-03 07:12:39 +00:00
|
|
|
"EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)",
|
|
|
|
majorVersion, minorVersion);
|
|
|
|
goto failure;
|
|
|
|
} else {
|
|
|
|
GST_WARNING
|
|
|
|
("EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)",
|
|
|
|
majorVersion, minorVersion);
|
|
|
|
if (gl_api & GST_GL_API_GLES2) {
|
|
|
|
goto try_gles2;
|
|
|
|
} else {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
|
|
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
2013-07-03 07:12:39 +00:00
|
|
|
"Failed to choose a suitable OpenGL API");
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglBindAPI (EGL_OPENGL_API)) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
2013-08-29 10:10:42 +00:00
|
|
|
"Failed to bind OpenGL API: %s",
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_context_egl_get_error_string ());
|
2013-07-03 07:12:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
GST_INFO ("Using OpenGL");
|
2013-07-03 07:12:39 +00:00
|
|
|
egl->gl_api = GST_GL_API_OPENGL;
|
|
|
|
} else if (gl_api & GST_GL_API_GLES2) {
|
|
|
|
try_gles2:
|
|
|
|
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"Failed to bind OpenGL|ES API: %s",
|
|
|
|
gst_gl_context_egl_get_error_string ());
|
2013-07-03 07:12:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
GST_INFO ("Using OpenGL|ES 2.0");
|
2013-07-03 07:12:39 +00:00
|
|
|
egl->gl_api = GST_GL_API_GLES2;
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
if (!gst_gl_context_egl_choose_config (egl, other_context, error)) {
|
2013-07-03 07:12:39 +00:00
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("about to create gl context\n");
|
|
|
|
|
|
|
|
if (egl->gl_api & GST_GL_API_GLES2) {
|
|
|
|
context_attrib[i++] = EGL_CONTEXT_CLIENT_VERSION;
|
|
|
|
context_attrib[i++] = 2;
|
|
|
|
}
|
|
|
|
context_attrib[i++] = EGL_NONE;
|
|
|
|
|
|
|
|
egl->egl_context =
|
|
|
|
eglCreateContext (egl->egl_display, egl->egl_config,
|
|
|
|
(EGLContext) external_gl_context, context_attrib);
|
|
|
|
|
|
|
|
if (egl->egl_context != EGL_NO_CONTEXT) {
|
2013-08-29 10:10:42 +00:00
|
|
|
GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT,
|
|
|
|
(guintptr) egl->egl_context);
|
2013-07-03 07:12:39 +00:00
|
|
|
} else {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
|
|
GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
|
2013-07-03 07:12:39 +00:00
|
|
|
"Failed to create a OpenGL context: %s",
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_context_egl_get_error_string ());
|
2013-07-03 07:12:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-07-24 11:34:20 +00:00
|
|
|
egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS);
|
2013-07-15 16:01:55 +00:00
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
if (other_context == NULL) {
|
|
|
|
/* FIXME do we want a window vfunc ? */
|
2013-08-15 07:09:04 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
2013-08-29 10:10:42 +00:00
|
|
|
if (GST_GL_IS_WINDOW_X11 (context->window)) {
|
|
|
|
gst_gl_window_x11_create_window ((GstGLWindowX11 *) context->window);
|
|
|
|
}
|
2013-08-15 07:09:04 +00:00
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_WINDOW_WIN32
|
2013-08-29 10:10:42 +00:00
|
|
|
if (GST_GL_IS_WINDOW_WIN32 (context->window)) {
|
|
|
|
gst_gl_window_win32_create_window ((GstGLWindowWin32 *) context->window);
|
|
|
|
}
|
2013-08-15 07:09:04 +00:00
|
|
|
#endif
|
2013-08-29 10:10:42 +00:00
|
|
|
}
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2013-08-30 13:12:37 +00:00
|
|
|
window_handle =
|
|
|
|
(EGLNativeWindowType) gst_gl_window_get_window_handle (window);
|
2013-08-15 07:09:04 +00:00
|
|
|
|
|
|
|
if (window_handle) {
|
2013-07-15 16:01:55 +00:00
|
|
|
egl->egl_surface =
|
2013-08-15 07:09:04 +00:00
|
|
|
eglCreateWindowSurface (egl->egl_display, egl->egl_config,
|
|
|
|
window_handle, NULL);
|
2013-07-24 11:34:20 +00:00
|
|
|
} else if (!gst_gl_check_extension ("EGL_KHR_surfaceless_context", egl_exts)) {
|
2013-07-15 16:01:55 +00:00
|
|
|
EGLint surface_attrib[7];
|
|
|
|
gint j = 0;
|
|
|
|
|
|
|
|
/* FIXME: Width/height doesn't seem to matter but we can't leave them
|
|
|
|
* at 0, otherwise X11 complains about BadValue */
|
|
|
|
surface_attrib[j++] = EGL_WIDTH;
|
|
|
|
surface_attrib[j++] = 1;
|
|
|
|
surface_attrib[j++] = EGL_HEIGHT;
|
|
|
|
surface_attrib[j++] = 1;
|
|
|
|
surface_attrib[j++] = EGL_LARGEST_PBUFFER;
|
|
|
|
surface_attrib[j++] = EGL_TRUE;
|
|
|
|
surface_attrib[j++] = EGL_NONE;
|
|
|
|
|
|
|
|
egl->egl_surface =
|
|
|
|
eglCreatePbufferSurface (egl->egl_display, egl->egl_config,
|
|
|
|
surface_attrib);
|
2013-07-24 11:34:20 +00:00
|
|
|
} else {
|
|
|
|
egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
need_surface = FALSE;
|
2013-07-15 16:01:55 +00:00
|
|
|
}
|
2013-07-03 07:12:39 +00:00
|
|
|
|
2013-07-24 11:34:20 +00:00
|
|
|
if (need_surface) {
|
|
|
|
if (egl->egl_surface != EGL_NO_SURFACE) {
|
|
|
|
GST_INFO ("surface created");
|
|
|
|
} else {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
2013-07-24 11:34:20 +00:00
|
|
|
"Failed to create window surface: %s",
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_context_egl_get_error_string ());
|
2013-07-24 11:34:20 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2013-07-03 07:12:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_object_unref (window);
|
2013-07-03 07:12:39 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
return TRUE;
|
2013-07-03 07:12:39 +00:00
|
|
|
|
|
|
|
failure:
|
2013-08-15 07:09:04 +00:00
|
|
|
if (window)
|
|
|
|
gst_object_unref (window);
|
2013-07-03 07:12:39 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
return FALSE;
|
2013-07-03 07:12:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
|
|
|
gst_gl_context_egl_destroy_context (GstGLContext * context)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextEGL *egl;
|
|
|
|
|
|
|
|
egl = GST_GL_CONTEXT_EGL (context);
|
|
|
|
|
|
|
|
gst_gl_context_egl_activate (context, FALSE);
|
2013-07-03 07:12:39 +00:00
|
|
|
|
|
|
|
if (egl->egl_surface)
|
|
|
|
eglDestroySurface (egl->egl_surface, egl->egl_display);
|
|
|
|
|
|
|
|
if (egl->egl_context)
|
|
|
|
eglDestroyContext (egl->egl_display, egl->egl_context);
|
|
|
|
|
|
|
|
if (egl->egl_display) {
|
|
|
|
eglTerminate (egl->egl_display);
|
|
|
|
eglReleaseThread ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_context_egl_activate (GstGLContext * context, gboolean activate)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextEGL *egl;
|
2013-07-03 07:12:39 +00:00
|
|
|
gboolean result;
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
egl = GST_GL_CONTEXT_EGL (context);
|
|
|
|
|
2013-07-03 07:12:39 +00:00
|
|
|
if (activate)
|
|
|
|
result = eglMakeCurrent (egl->egl_display, egl->egl_surface,
|
|
|
|
egl->egl_surface, egl->egl_context);
|
|
|
|
else
|
|
|
|
result = eglMakeCurrent (egl->egl_display, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr
|
|
|
|
gst_gl_context_egl_get_gl_context (GstGLContext * context)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
return (guintptr) GST_GL_CONTEXT_EGL (context)->egl_context;
|
2013-07-03 07:12:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
|
|
|
gst_gl_context_egl_swap_buffers (GstGLContext * context)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextEGL *egl;
|
|
|
|
|
|
|
|
egl = GST_GL_CONTEXT_EGL (context);
|
|
|
|
|
2013-07-03 07:12:39 +00:00
|
|
|
eglSwapBuffers (egl->egl_display, egl->egl_surface);
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static GstGLAPI
|
|
|
|
gst_gl_context_egl_get_gl_api (GstGLContext * context)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
return GST_GL_CONTEXT_EGL (context)->gl_api;
|
2013-07-03 07:12:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static gpointer
|
|
|
|
gst_gl_context_egl_get_proc_address (GstGLContext * context, const gchar * name)
|
2013-07-03 07:12:39 +00:00
|
|
|
{
|
2013-10-01 13:47:54 +00:00
|
|
|
gpointer result = NULL;
|
2013-07-03 07:12:39 +00:00
|
|
|
|
2013-07-10 09:31:17 +00:00
|
|
|
/* FIXME: On Android this returns wrong addresses for non-EGL functions */
|
|
|
|
#ifdef GST_GL_HAVE_WINDOW_ANDROID
|
2013-10-01 13:47:54 +00:00
|
|
|
if (!(result = gst_gl_context_default_get_proc_address (context, name))) {
|
|
|
|
if (g_str_has_prefix (name, "egl"))
|
|
|
|
result = eglGetProcAddress (name);
|
|
|
|
}
|
|
|
|
#else
|
2013-08-15 07:09:04 +00:00
|
|
|
if (!(result = eglGetProcAddress (name))) {
|
|
|
|
result = gst_gl_context_default_get_proc_address (context, name);
|
|
|
|
}
|
2013-10-01 13:47:54 +00:00
|
|
|
#endif
|
2013-07-03 07:12:39 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|