|
Packit |
971217 |
/*
|
|
Packit |
971217 |
* GStreamer
|
|
Packit |
971217 |
* Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
971217 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
971217 |
* License as published by the Free Software Foundation; either
|
|
Packit |
971217 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
971217 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
971217 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
971217 |
* Library General Public License for more details.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
971217 |
* License along with this library; if not, write to the
|
|
Packit |
971217 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
971217 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
971217 |
#include "config.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <gmodule.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* FIXME: Sharing contexts requires the EGLDisplay to be the same
|
|
Packit |
971217 |
* may need to box it.
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include "gstglcontext_egl.h"
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <gst/gl/gstglcontext_private.h>
|
|
Packit |
971217 |
#include <gst/gl/gstglfeature.h>
|
|
Packit |
971217 |
#include <gst/gl/gstglwindow.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include "gstegl.h"
|
|
Packit |
971217 |
#include "../utils/opengl_versions.h"
|
|
Packit |
971217 |
#include "../utils/gles_versions.h"
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_X11
|
|
Packit |
971217 |
#include "../x11/gstglwindow_x11.h"
|
|
Packit |
971217 |
#include <gst/gl/x11/gstgldisplay_x11.h>
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_WAYLAND
|
|
Packit |
971217 |
#include "../wayland/gstglwindow_wayland_egl.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_WIN32
|
|
Packit |
971217 |
#include "../win32/gstglwindow_win32.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_DISPMANX
|
|
Packit |
971217 |
#include "../dispmanx/gstglwindow_dispmanx_egl.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_GBM
|
|
Packit |
971217 |
#include "../gbm/gstglwindow_gbm_egl.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#define GST_CAT_DEFAULT gst_gl_context_debug
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean gst_gl_context_egl_create_context (GstGLContext * context,
|
|
Packit |
971217 |
GstGLAPI gl_api, GstGLContext * other_context, GError ** error);
|
|
Packit |
971217 |
static void gst_gl_context_egl_destroy_context (GstGLContext * context);
|
|
Packit |
971217 |
static gboolean gst_gl_context_egl_choose_format (GstGLContext * context,
|
|
Packit |
971217 |
GError ** error);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean gst_gl_context_egl_activate (GstGLContext * context,
|
|
Packit |
971217 |
gboolean activate);
|
|
Packit |
971217 |
static void gst_gl_context_egl_swap_buffers (GstGLContext * context);
|
|
Packit |
971217 |
static guintptr gst_gl_context_egl_get_gl_context (GstGLContext * context);
|
|
Packit |
971217 |
static GstGLAPI gst_gl_context_egl_get_gl_api (GstGLContext * context);
|
|
Packit |
971217 |
static GstGLPlatform gst_gl_context_egl_get_gl_platform (GstGLContext *
|
|
Packit |
971217 |
context);
|
|
Packit |
971217 |
static gboolean gst_gl_context_egl_check_feature (GstGLContext * context,
|
|
Packit |
971217 |
const gchar * feature);
|
|
Packit |
971217 |
static void gst_gl_context_egl_get_gl_platform_version (GstGLContext * context,
|
|
Packit |
971217 |
gint * major, gint * minor);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
G_DEFINE_TYPE (GstGLContextEGL, gst_gl_context_egl, GST_TYPE_GL_CONTEXT);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_egl_class_init (GstGLContextEGLClass * klass)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextClass *context_class = (GstGLContextClass *) klass;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_class->get_gl_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_gl_context);
|
|
Packit |
971217 |
context_class->activate = GST_DEBUG_FUNCPTR (gst_gl_context_egl_activate);
|
|
Packit |
971217 |
context_class->create_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_create_context);
|
|
Packit |
971217 |
context_class->destroy_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_destroy_context);
|
|
Packit |
971217 |
context_class->choose_format =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_choose_format);
|
|
Packit |
971217 |
context_class->swap_buffers =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_swap_buffers);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_class->get_gl_api = GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_gl_api);
|
|
Packit |
971217 |
context_class->get_gl_platform =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_gl_platform);
|
|
Packit |
971217 |
context_class->get_proc_address =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_proc_address);
|
|
Packit |
971217 |
context_class->check_feature =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_check_feature);
|
|
Packit |
971217 |
context_class->get_current_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_current_context);
|
|
Packit |
971217 |
context_class->get_gl_platform_version =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_egl_get_gl_platform_version);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_egl_init (GstGLContextEGL * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* Must be called in the gl thread */
|
|
Packit |
971217 |
GstGLContextEGL *
|
|
Packit |
971217 |
gst_gl_context_egl_new (GstGLDisplay * display)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *context;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* XXX: display type could theoretically be anything, as long as
|
|
Packit |
971217 |
* eglGetDisplay supports it. */
|
|
Packit |
971217 |
context = g_object_new (GST_TYPE_GL_CONTEXT_EGL, NULL);
|
|
Packit |
971217 |
gst_object_ref_sink (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return context;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_egl_choose_format (GstGLContext * context, GError ** error)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_X11
|
|
Packit |
971217 |
if (GST_IS_GL_WINDOW_X11 (context->window)) {
|
|
Packit |
971217 |
GstGLWindow *window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
Packit |
971217 |
gint ret;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
window_x11->visual_info = g_new0 (XVisualInfo, 1);
|
|
Packit |
971217 |
ret = XMatchVisualInfo (window_x11->device, window_x11->screen_num,
|
|
Packit |
971217 |
window_x11->depth, TrueColor, window_x11->visual_info);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (ret == 0) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Failed to match XVisualInfo");
|
|
Packit |
971217 |
return FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return TRUE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_egl_choose_config (GstGLContextEGL * egl, GstGLAPI gl_api,
|
|
Packit |
971217 |
gint major, GError ** error)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
gboolean create_context;
|
|
Packit |
971217 |
EGLint numConfigs;
|
|
Packit |
971217 |
gint i = 0;
|
|
Packit |
971217 |
EGLint config_attrib[20];
|
|
Packit |
971217 |
|
|
Packit |
971217 |
create_context =
|
|
Packit |
971217 |
gst_gl_check_extension ("EGL_KHR_create_context", egl->egl_exts);
|
|
Packit |
971217 |
/* silence unused warnings */
|
|
Packit |
971217 |
(void) create_context;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
config_attrib[i++] = EGL_SURFACE_TYPE;
|
|
Packit |
971217 |
config_attrib[i++] = EGL_WINDOW_BIT;
|
|
Packit |
971217 |
config_attrib[i++] = EGL_RENDERABLE_TYPE;
|
|
Packit |
971217 |
if (gl_api & GST_GL_API_GLES2) {
|
|
Packit |
971217 |
if (major == 3) {
|
|
Packit |
971217 |
#if defined(EGL_KHR_create_context)
|
|
Packit |
971217 |
if (create_context) {
|
|
Packit |
971217 |
config_attrib[i++] = EGL_OPENGL_ES3_BIT_KHR;
|
|
Packit |
971217 |
} else
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
config_attrib[i++] = EGL_OPENGL_ES2_BIT;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
} else
|
|
Packit |
971217 |
config_attrib[i++] = EGL_OPENGL_BIT;
|
|
Packit |
971217 |
#if defined(USE_EGL_RPI) && GST_GL_HAVE_WINDOW_WAYLAND
|
|
Packit |
971217 |
/* The configurations with a=0 seems to be buggy whereas
|
|
Packit |
971217 |
* it works when using dispmanx directly */
|
|
Packit |
971217 |
config_attrib[i++] = EGL_ALPHA_SIZE;
|
|
Packit |
971217 |
config_attrib[i++] = 1;
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
config_attrib[i++] = EGL_DEPTH_SIZE;
|
|
Packit |
971217 |
config_attrib[i++] = 16;
|
|
Packit |
971217 |
config_attrib[i++] = EGL_RED_SIZE;
|
|
Packit |
971217 |
config_attrib[i++] = 1;
|
|
Packit |
971217 |
config_attrib[i++] = EGL_GREEN_SIZE;
|
|
Packit |
971217 |
config_attrib[i++] = 1;
|
|
Packit |
971217 |
config_attrib[i++] = EGL_BLUE_SIZE;
|
|
Packit |
971217 |
config_attrib[i++] = 1;
|
|
Packit |
971217 |
config_attrib[i++] = EGL_NONE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (eglChooseConfig (egl->egl_display, config_attrib,
|
|
Packit |
971217 |
&egl->egl_config, 1, &numConfigs)) {
|
|
Packit |
971217 |
GST_INFO ("config set: %" G_GUINTPTR_FORMAT ", %u",
|
|
Packit |
971217 |
(guintptr) egl->egl_config, (unsigned int) numConfigs);
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Failed to set window configuration: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return TRUE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
failure:
|
|
Packit |
971217 |
return FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static EGLContext
|
|
Packit |
971217 |
_create_context_with_flags (GstGLContextEGL * egl, EGLContext share_context,
|
|
Packit |
971217 |
GstGLAPI gl_api, gint major, gint minor, gint contextFlags,
|
|
Packit |
971217 |
gint profileMask)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
gboolean create_context;
|
|
Packit |
971217 |
#define N_ATTRIBS 20
|
|
Packit |
971217 |
gint attribs[N_ATTRIBS];
|
|
Packit |
971217 |
gint n = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* fail creation of apis/versions/flags that require EGL_KHR_create_context
|
|
Packit |
971217 |
* if the extension doesn't exist, namely:0
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* - profile mask
|
|
Packit |
971217 |
* - context flags
|
|
Packit |
971217 |
* - GL3 > 3.1
|
|
Packit |
971217 |
* - GLES2 && minor > 0
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
create_context =
|
|
Packit |
971217 |
gst_gl_check_extension ("EGL_KHR_create_context", egl->egl_exts);
|
|
Packit |
971217 |
(void) create_context;
|
|
Packit |
971217 |
if (!create_context && (profileMask || contextFlags
|
|
Packit |
971217 |
|| ((gl_api & GST_GL_API_OPENGL3)
|
|
Packit |
971217 |
&& GST_GL_CHECK_GL_VERSION (major, minor, 3, 2))
|
|
Packit |
971217 |
|| ((gl_api & GST_GL_API_GLES2) && minor > 0))) {
|
|
Packit |
971217 |
return 0;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_DEBUG_OBJECT (egl, "attempting to create OpenGL%s context version %d.%d "
|
|
Packit |
971217 |
"flags %x profile %x", gl_api & GST_GL_API_GLES2 ? " ES" : "", major,
|
|
Packit |
971217 |
minor, contextFlags, profileMask);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#if defined(EGL_KHR_create_context)
|
|
Packit |
971217 |
if (create_context) {
|
|
Packit |
971217 |
if (major) {
|
|
Packit |
971217 |
attribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
|
|
Packit |
971217 |
attribs[n++] = major;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (minor) {
|
|
Packit |
971217 |
attribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR;
|
|
Packit |
971217 |
attribs[n++] = minor;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (contextFlags) {
|
|
Packit |
971217 |
attribs[n++] = EGL_CONTEXT_FLAGS_KHR;
|
|
Packit |
971217 |
attribs[n++] = contextFlags;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (profileMask) {
|
|
Packit |
971217 |
attribs[n++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
Packit |
971217 |
attribs[n++] = profileMask;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
} else
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
attribs[n++] = EGL_CONTEXT_CLIENT_VERSION;
|
|
Packit |
971217 |
attribs[n++] = major;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
attribs[n++] = EGL_NONE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_assert (n < N_ATTRIBS);
|
|
Packit |
971217 |
#undef N_ATTRIBS
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return eglCreateContext (egl->egl_display, egl->egl_config, share_context,
|
|
Packit |
971217 |
attribs);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_egl_create_context (GstGLContext * context,
|
|
Packit |
971217 |
GstGLAPI gl_api, GstGLContext * other_context, GError ** error)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *egl;
|
|
Packit |
971217 |
GstGLWindow *window = NULL;
|
|
Packit |
971217 |
guintptr window_handle = 0;
|
|
Packit |
971217 |
EGLint egl_major;
|
|
Packit |
971217 |
EGLint egl_minor;
|
|
Packit |
971217 |
gboolean need_surface = TRUE;
|
|
Packit |
971217 |
guintptr external_gl_context = 0;
|
|
Packit |
971217 |
guintptr egl_display;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl = GST_GL_CONTEXT_EGL (context);
|
|
Packit |
971217 |
window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_DEBUG_OBJECT (context, "Creating EGL context");
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (other_context) {
|
|
Packit |
971217 |
if (gst_gl_context_get_gl_platform (other_context) != GST_GL_PLATFORM_EGL) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Cannot share context with non-EGL context");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
external_gl_context = gst_gl_context_get_gl_context (other_context);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if ((gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3 | GST_GL_API_GLES2)) ==
|
|
Packit |
971217 |
GST_GL_API_NONE) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API,
|
|
Packit |
971217 |
"EGL supports opengl or gles2");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!egl->display_egl) {
|
|
Packit |
971217 |
GstGLDisplay *display = gst_gl_context_get_display (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->display_egl = gst_gl_display_egl_from_gl_display (display);
|
|
Packit |
971217 |
if (!egl->display_egl) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
|
|
Packit |
971217 |
"Failed to create EGLDisplay from native display");
|
|
Packit |
971217 |
gst_object_unref (display);
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (display);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl_display = gst_gl_display_get_handle (GST_GL_DISPLAY (egl->display_egl));
|
|
Packit |
971217 |
egl->egl_display = (EGLDisplay) egl_display;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (eglInitialize (egl->egl_display, &egl_major, &egl_minor)) {
|
|
Packit |
971217 |
GST_INFO ("egl initialized, version: %d.%d", egl_major, egl_minor);
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
|
|
Packit |
971217 |
"Failed to initialize egl: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3)) {
|
|
Packit |
971217 |
GstGLAPI chosen_gl_api = 0;
|
|
Packit |
971217 |
gint i;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* egl + opengl only available with EGL 1.4+ */
|
|
Packit |
971217 |
if (egl_major == 1 && egl_minor <= 3) {
|
|
Packit |
971217 |
if ((gl_api & ~GST_GL_API_OPENGL) == GST_GL_API_NONE) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS,
|
|
Packit |
971217 |
"EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)",
|
|
Packit |
971217 |
egl_major, egl_minor);
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
GST_WARNING
|
|
Packit |
971217 |
("EGL version (%i.%i) too old for OpenGL support, (needed at least 1.4)",
|
|
Packit |
971217 |
egl_major, egl_minor);
|
|
Packit |
971217 |
if (gl_api & GST_GL_API_GLES2) {
|
|
Packit |
971217 |
goto try_gles2;
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Failed to choose a suitable OpenGL API");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!eglBindAPI (EGL_OPENGL_API)) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
Packit |
971217 |
"Failed to bind OpenGL API: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_INFO ("Bound OpenGL");
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* api, version only matters for gles */
|
|
Packit |
971217 |
if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_OPENGL, 0, error)) {
|
|
Packit |
971217 |
g_assert (error == NULL || *error != NULL);
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
for (i = 0; i < G_N_ELEMENTS (opengl_versions); i++) {
|
|
Packit |
971217 |
gint profileMask = 0;
|
|
Packit |
971217 |
gint contextFlags = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (GST_GL_CHECK_GL_VERSION (opengl_versions[i].major,
|
|
Packit |
971217 |
opengl_versions[i].minor, 3, 2)) {
|
|
Packit |
971217 |
/* skip gl3 contexts if requested */
|
|
Packit |
971217 |
if ((gl_api & GST_GL_API_OPENGL3) == 0)
|
|
Packit |
971217 |
continue;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
chosen_gl_api = GST_GL_API_OPENGL3;
|
|
Packit |
971217 |
#if defined(EGL_KHR_create_context)
|
|
Packit |
971217 |
profileMask |= EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
|
|
Packit |
971217 |
contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
} else if (opengl_versions[i].major == 3 && opengl_versions[i].minor == 1) {
|
|
Packit |
971217 |
/* skip 3.1, the implementation is free to give us either a core or a
|
|
Packit |
971217 |
* compatibility context (we have no say) */
|
|
Packit |
971217 |
continue;
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
/* skip legacy contexts if requested */
|
|
Packit |
971217 |
if ((gl_api & GST_GL_API_OPENGL) == 0)
|
|
Packit |
971217 |
continue;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
chosen_gl_api = GST_GL_API_OPENGL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->egl_context =
|
|
Packit |
971217 |
_create_context_with_flags (egl, (EGLContext) external_gl_context,
|
|
Packit |
971217 |
chosen_gl_api, opengl_versions[i].major,
|
|
Packit |
971217 |
opengl_versions[i].minor, contextFlags, profileMask);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_context)
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#if defined(EGL_KHR_create_context)
|
|
Packit |
971217 |
profileMask &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->egl_context =
|
|
Packit |
971217 |
_create_context_with_flags (egl, (EGLContext) external_gl_context,
|
|
Packit |
971217 |
chosen_gl_api, opengl_versions[i].major,
|
|
Packit |
971217 |
opengl_versions[i].minor, contextFlags, profileMask);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_context)
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->gl_api = chosen_gl_api;
|
|
Packit |
971217 |
} else if (gl_api & GST_GL_API_GLES2) {
|
|
Packit |
971217 |
gint i;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
try_gles2:
|
|
Packit |
971217 |
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
Packit |
971217 |
"Failed to bind OpenGL|ES API: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_INFO ("Bound OpenGL|ES");
|
|
Packit |
971217 |
|
|
Packit |
971217 |
for (i = 0; i < G_N_ELEMENTS (gles2_versions); i++) {
|
|
Packit |
971217 |
gint profileMask = 0;
|
|
Packit |
971217 |
gint contextFlags = 0;
|
|
Packit |
971217 |
guint maj = gles2_versions[i].major;
|
|
Packit |
971217 |
guint min = gles2_versions[i].minor;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_GLES2, maj, error)) {
|
|
Packit |
971217 |
GST_DEBUG_OBJECT (context, "Failed to choose a GLES%d config: %s",
|
|
Packit |
971217 |
maj, error && *error ? (*error)->message : "Unknown");
|
|
Packit |
971217 |
g_clear_error (error);
|
|
Packit |
971217 |
continue;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#if defined(EGL_KHR_create_context)
|
|
Packit |
971217 |
/* try a debug context */
|
|
Packit |
971217 |
contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->egl_context =
|
|
Packit |
971217 |
_create_context_with_flags (egl, (EGLContext) external_gl_context,
|
|
Packit |
971217 |
GST_GL_API_GLES2, maj, min, contextFlags, profileMask);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_context)
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* try without a debug context */
|
|
Packit |
971217 |
contextFlags &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->egl_context =
|
|
Packit |
971217 |
_create_context_with_flags (egl, (EGLContext) external_gl_context,
|
|
Packit |
971217 |
GST_GL_API_GLES2, maj, min, contextFlags, profileMask);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_context)
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
egl->gl_api = GST_GL_API_GLES2;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_context != EGL_NO_CONTEXT) {
|
|
Packit |
971217 |
GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT,
|
|
Packit |
971217 |
(guintptr) egl->egl_context);
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
|
|
Packit |
971217 |
"Failed to create a OpenGL context: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
/* FIXME do we want a window vfunc ? */
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_X11
|
|
Packit |
971217 |
if (GST_IS_GL_WINDOW_X11 (context->window)) {
|
|
Packit |
971217 |
gst_gl_window_x11_create_window ((GstGLWindowX11 *) context->window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (other_context == NULL) {
|
|
Packit |
971217 |
/* FIXME: fails to show two outputs at all. We need a property/option for
|
|
Packit |
971217 |
* glimagesink to say its a visible context */
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_WAYLAND
|
|
Packit |
971217 |
if (GST_IS_GL_WINDOW_WAYLAND_EGL (context->window)) {
|
|
Packit |
971217 |
gst_gl_window_wayland_egl_create_window ((GstGLWindowWaylandEGL *)
|
|
Packit |
971217 |
context->window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_WIN32
|
|
Packit |
971217 |
if (GST_IS_GL_WINDOW_WIN32 (context->window)) {
|
|
Packit |
971217 |
gst_gl_window_win32_create_window ((GstGLWindowWin32 *) context->window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_DISPMANX
|
|
Packit |
971217 |
if (GST_IS_GL_WINDOW_DISPMANX_EGL (context->window)) {
|
|
Packit |
971217 |
gst_gl_window_dispmanx_egl_create_window ((GstGLWindowDispmanxEGL *)
|
|
Packit |
971217 |
context->window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_GBM
|
|
Packit |
971217 |
if (GST_IS_GL_WINDOW_GBM_EGL (context->window)) {
|
|
Packit |
971217 |
gst_gl_window_gbm_egl_create_window ((GstGLWindowGBMEGL *)
|
|
Packit |
971217 |
context->window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (window)
|
|
Packit |
971217 |
window_handle = gst_gl_window_get_window_handle (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (window_handle) {
|
|
Packit |
971217 |
GST_DEBUG ("Creating EGLSurface from window_handle %p",
|
|
Packit |
971217 |
(void *) window_handle);
|
|
Packit |
971217 |
egl->egl_surface =
|
|
Packit |
971217 |
eglCreateWindowSurface (egl->egl_display, egl->egl_config,
|
|
Packit |
971217 |
(EGLNativeWindowType) window_handle, NULL);
|
|
Packit |
971217 |
/* Store window handle for later comparision */
|
|
Packit |
971217 |
egl->window_handle = window_handle;
|
|
Packit |
971217 |
} else if (!gst_gl_check_extension ("EGL_KHR_surfaceless_context",
|
|
Packit |
971217 |
egl->egl_exts)) {
|
|
Packit |
971217 |
EGLint surface_attrib[7];
|
|
Packit |
971217 |
gint j = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_DEBUG ("Surfaceless context, creating PBufferSurface");
|
|
Packit |
971217 |
/* FIXME: Width/height doesn't seem to matter but we can't leave them
|
|
Packit |
971217 |
* at 0, otherwise X11 complains about BadValue */
|
|
Packit |
971217 |
surface_attrib[j++] = EGL_WIDTH;
|
|
Packit |
971217 |
surface_attrib[j++] = 1;
|
|
Packit |
971217 |
surface_attrib[j++] = EGL_HEIGHT;
|
|
Packit |
971217 |
surface_attrib[j++] = 1;
|
|
Packit |
971217 |
surface_attrib[j++] = EGL_LARGEST_PBUFFER;
|
|
Packit |
971217 |
surface_attrib[j++] = EGL_TRUE;
|
|
Packit |
971217 |
surface_attrib[j++] = EGL_NONE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl->egl_surface =
|
|
Packit |
971217 |
eglCreatePbufferSurface (egl->egl_display, egl->egl_config,
|
|
Packit |
971217 |
surface_attrib);
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
GST_DEBUG ("No surface/handle !");
|
|
Packit |
971217 |
egl->egl_surface = EGL_NO_SURFACE;
|
|
Packit |
971217 |
need_surface = FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (need_surface) {
|
|
Packit |
971217 |
if (egl->egl_surface != EGL_NO_SURFACE) {
|
|
Packit |
971217 |
GST_INFO ("surface created");
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
Packit |
971217 |
"Failed to create window surface: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
egl->egl_major = egl_major;
|
|
Packit |
971217 |
egl->egl_minor = egl_minor;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (window)
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return TRUE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
failure:
|
|
Packit |
971217 |
if (window)
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_egl_destroy_context (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *egl;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl = GST_GL_CONTEXT_EGL (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_gl_context_egl_activate (context, FALSE);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_surface) {
|
|
Packit |
971217 |
eglDestroySurface (egl->egl_display, egl->egl_surface);
|
|
Packit |
971217 |
egl->egl_surface = EGL_NO_SURFACE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_context) {
|
|
Packit |
971217 |
eglDestroyContext (egl->egl_display, egl->egl_context);
|
|
Packit |
971217 |
egl->egl_context = NULL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
egl->window_handle = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
eglReleaseThread ();
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->display_egl) {
|
|
Packit |
971217 |
gst_object_unref (egl->display_egl);
|
|
Packit |
971217 |
egl->display_egl = NULL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_egl_activate (GstGLContext * context, gboolean activate)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *egl;
|
|
Packit |
971217 |
gboolean result;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl = GST_GL_CONTEXT_EGL (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (activate) {
|
|
Packit |
971217 |
GstGLWindow *window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
guintptr handle = 0;
|
|
Packit |
971217 |
/* Check if the backing handle changed */
|
|
Packit |
971217 |
if (window) {
|
|
Packit |
971217 |
handle = gst_gl_window_get_window_handle (window);
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (handle && handle != egl->window_handle) {
|
|
Packit |
971217 |
GST_DEBUG_OBJECT (context,
|
|
Packit |
971217 |
"Handle changed (have:%p, now:%p), switching surface",
|
|
Packit |
971217 |
(void *) egl->window_handle, (void *) handle);
|
|
Packit |
971217 |
if (egl->egl_surface) {
|
|
Packit |
971217 |
result = eglDestroySurface (egl->egl_display, egl->egl_surface);
|
|
Packit |
971217 |
egl->egl_surface = EGL_NO_SURFACE;
|
|
Packit |
971217 |
if (!result) {
|
|
Packit |
971217 |
GST_ERROR_OBJECT (context, "Failed to destroy old window surface: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
goto done;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
egl->egl_surface =
|
|
Packit |
971217 |
eglCreateWindowSurface (egl->egl_display, egl->egl_config,
|
|
Packit |
971217 |
(EGLNativeWindowType) handle, NULL);
|
|
Packit |
971217 |
egl->window_handle = handle;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (egl->egl_surface == EGL_NO_SURFACE) {
|
|
Packit |
971217 |
GST_ERROR_OBJECT (context, "Failed to create window surface: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
result = FALSE;
|
|
Packit |
971217 |
goto done;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
result = eglMakeCurrent (egl->egl_display, egl->egl_surface,
|
|
Packit |
971217 |
egl->egl_surface, egl->egl_context);
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
result = eglMakeCurrent (egl->egl_display, EGL_NO_SURFACE,
|
|
Packit |
971217 |
EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!result) {
|
|
Packit |
971217 |
GST_ERROR_OBJECT (context,
|
|
Packit |
971217 |
"Failed to bind context to the current rendering thread: %s",
|
|
Packit |
971217 |
gst_egl_get_error_string (eglGetError ()));
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
done:
|
|
Packit |
971217 |
return result;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static guintptr
|
|
Packit |
971217 |
gst_gl_context_egl_get_gl_context (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return (guintptr) GST_GL_CONTEXT_EGL (context)->egl_context;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_egl_swap_buffers (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *egl;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
egl = GST_GL_CONTEXT_EGL (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
eglSwapBuffers (egl->egl_display, egl->egl_surface);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GstGLAPI
|
|
Packit |
971217 |
gst_gl_context_egl_get_gl_api (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return GST_GL_CONTEXT_EGL (context)->gl_api;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GstGLPlatform
|
|
Packit |
971217 |
gst_gl_context_egl_get_gl_platform (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return GST_GL_PLATFORM_EGL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GModule *module_egl;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gpointer
|
|
Packit |
971217 |
load_egl_module (gpointer user_data)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
#ifdef GST_GL_LIBEGL_MODULE_NAME
|
|
Packit |
971217 |
module_egl = g_module_open (GST_GL_LIBEGL_MODULE_NAME, G_MODULE_BIND_LAZY);
|
|
Packit |
971217 |
#else
|
|
Packit |
971217 |
/* On Linux the .so is only in -dev packages, try with a real soname
|
|
Packit |
971217 |
* Proper compilers will optimize away the strcmp */
|
|
Packit |
971217 |
if (g_strcmp0 (G_MODULE_SUFFIX, "so") == 0)
|
|
Packit |
971217 |
module_egl = g_module_open ("libEGL.so.1", G_MODULE_BIND_LAZY);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* This automatically handles the suffix and even .la files */
|
|
Packit |
971217 |
if (!module_egl)
|
|
Packit |
971217 |
module_egl = g_module_open ("libEGL", G_MODULE_BIND_LAZY);
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return NULL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gpointer
|
|
Packit |
971217 |
gst_gl_context_egl_get_proc_address (GstGLAPI gl_api, const gchar * name)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
gpointer result = NULL;
|
|
Packit |
971217 |
static GOnce g_once = G_ONCE_INIT;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#ifdef __APPLE__
|
|
Packit |
971217 |
#if GST_GL_HAVE_OPENGL && !defined(GST_GL_LIBGL_MODULE_NAME)
|
|
Packit |
971217 |
if (!result && (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3))) {
|
|
Packit |
971217 |
static GModule *module_opengl = NULL;
|
|
Packit |
971217 |
if (g_once_init_enter (&module_opengl)) {
|
|
Packit |
971217 |
GModule *setup_module_opengl =
|
|
Packit |
971217 |
g_module_open ("libGL.dylib", G_MODULE_BIND_LAZY);
|
|
Packit |
971217 |
g_once_init_leave (&module_opengl, setup_module_opengl);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (module_opengl)
|
|
Packit |
971217 |
g_module_symbol (module_opengl, name, &result);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#if GST_GL_HAVE_GLES2 && !defined(GST_GL_LIBGLESV2_MODULE_NAME)
|
|
Packit |
971217 |
if (!result && (gl_api & (GST_GL_API_GLES2))) {
|
|
Packit |
971217 |
static GModule *module_gles2 = NULL;
|
|
Packit |
971217 |
if (g_once_init_enter (&module_gles2)) {
|
|
Packit |
971217 |
GModule *setup_module_gles2 =
|
|
Packit |
971217 |
g_module_open ("libGLESv2.dylib", G_MODULE_BIND_LAZY);
|
|
Packit |
971217 |
g_once_init_leave (&module_gles2, setup_module_gles2);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (module_gles2)
|
|
Packit |
971217 |
g_module_symbol (module_gles2, name, &result);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
#endif // __APPLE__
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!result)
|
|
Packit |
971217 |
result = gst_gl_context_default_get_proc_address (gl_api, name);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_once (&g_once, load_egl_module, NULL);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!result && module_egl) {
|
|
Packit |
971217 |
g_module_symbol (module_egl, name, &result);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* FIXME: On Android this returns wrong addresses for non-EGL functions */
|
|
Packit |
971217 |
#if GST_GL_HAVE_WINDOW_ANDROID
|
|
Packit |
971217 |
if (!result && g_str_has_prefix (name, "egl")) {
|
|
Packit |
971217 |
#else
|
|
Packit |
971217 |
if (!result) {
|
|
Packit |
971217 |
result = eglGetProcAddress (name);
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return result;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_egl_check_feature (GstGLContext * context, const gchar * feature)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return gst_gl_check_extension (feature, context_egl->egl_exts);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
guintptr
|
|
Packit |
971217 |
gst_gl_context_egl_get_current_context (void)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return (guintptr) eglGetCurrentContext ();
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_egl_get_gl_platform_version (GstGLContext * context,
|
|
Packit |
971217 |
gint * major, gint * minor)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextEGL *context_egl = GST_GL_CONTEXT_EGL (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
*major = context_egl->egl_major;
|
|
Packit |
971217 |
*minor = context_egl->egl_minor;
|
|
Packit |
971217 |
}
|