[630/906] display: add gl api checking

i.e. check for cases where the window wants a different API than
what the library was compiled with
This commit is contained in:
Matthew Waters 2012-12-09 09:32:48 +11:00 committed by Tim-Philipp Müller
parent c3526080aa
commit 1ec4ffc824
6 changed files with 163 additions and 53 deletions

View file

@ -13,7 +13,8 @@ libgstgl_@GST_API_VERSION@_la_SOURCES = \
gstglshadervariables.c \
gstgldownload.c \
gstglupload.c \
gstglwindow.c
gstglwindow.c \
gstglapi.c
libgstgl_@GST_API_VERSION@_la_LIBADD = \
$(GST_PLUGINS_BASE_LIBS) \

116
gst-libs/gst/gl/gstglapi.c Normal file
View file

@ -0,0 +1,116 @@
/*
* GStreamer
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
*
* 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.
*/
#include "gstglapi.h"
#define GST_GL_EXT_BEGIN(name, min_gl, maj_gl, in_gles, ext_suf, ext_name)
#define GST_GL_EXT_FUNCTION(ret, name, args) \
NULL,
#define GST_GL_EXT_END()
#if HAVE_OPENGL
static GstGLFuncs gst_gl = {
#include "glprototypes/opengl.h"
{NULL,},
#include "glprototypes/gles1opengl.h"
{NULL,},
#include "glprototypes/gles2opengl.h"
{NULL,},
#include "glprototypes/gles1gles2opengl.h"
{NULL,},
};
const GstGLFuncs *
gst_gl_get_opengl_vtable (void)
{
return &gst_gl;
}
#endif
#if HAVE_GLES2
static GstGLES2Funcs gst_gles2 = {
#include "glprototypes/gles1gles2.h"
{NULL,},
#include "glprototypes/gles1gles2opengl.h"
{NULL,},
#include "glprototypes/gles2.h"
{NULL,},
#include "glprototypes/gles2opengl.h"
{NULL,},
};
const GstGLES2Funcs *
gst_gl_get_gles2_vtable (void)
{
return &gst_gles2;
}
#endif
#undef GST_GL_EXT_BEGIN
#undef GST_GL_EXT_FUNCTION
#undef GST_GL_EXT_END
gchar *
gst_gl_api_string (GstGLAPI api)
{
GString *str = NULL;
if (api == GST_GL_API_NONE) {
str = g_string_new ("none");
return str->str;
} else if (api == GST_GL_API_ANY) {
str = g_string_new ("any");
return str->str;
}
if (api & GST_GL_API_OPENGL) {
str = g_string_new ("opengl");
}
if (api & GST_GL_API_OPENGL3) {
if (str) {
g_string_append (str, " opengl3");
} else {
str = g_string_new ("opengl3");
}
}
if (api & GST_GL_API_GLES) {
if (str) {
g_string_append (str, " gles1");
} else {
str = g_string_new ("gles1");
}
}
if (api & GST_GL_API_GLES2) {
if (str) {
g_string_append (str, " gles2");
} else {
str = g_string_new ("gles2");
}
}
if (api & GST_GL_API_GLES3) {
if (str) {
g_string_append (str, " gles3");
} else {
str = g_string_new ("gles3");
}
}
return str->str;
}

View file

@ -109,6 +109,8 @@ const GstGLES2Funcs *gst_gl_get_gles2_vtable (void);
#undef GST_GL_EXT_FUNCTION
#undef GST_GL_EXT_END
gchar * gst_gl_api_string (GstGLAPI api);
G_END_DECLS
#endif /* __GST_GL_API_H__ */

View file

@ -444,18 +444,40 @@ _create_context_opengl (GstGLDisplay * display, gint * gl_major, gint * gl_minor
}
#endif
GstGLAPI
_compiled_api (void)
{
GstGLAPI ret = GST_GL_API_NONE;
#if HAVE_OPENGL
ret |= GST_GL_API_OPENGL;
#endif
#if HAVE_GLES2
ret |= GST_GL_API_GLES2;
#endif
return ret;
}
gpointer
gst_gl_display_thread_create_context (GstGLDisplay * display)
{
gint gl_major = 0, gl_minor = 0;
gboolean ret = FALSE;
GError *error = NULL;
GstGLAPI compiled_api;
gchar *api_string;
gchar *compiled_api_s;
gst_gl_display_lock (display);
display->gl_window =
gst_gl_window_new (GST_GL_API_ANY, display->external_gl_context);
if (!display->gl_window) {
gst_gl_display_set_error (display, "Failed to create gl window");
compiled_api = _compiled_api ();
display->gl_window =
gst_gl_window_new (compiled_api, display->external_gl_context, &error);
if (!display->gl_window || error) {
gst_gl_display_set_error (display, error ? error->message : "Failed to create gl window");
g_cond_signal (display->cond_create_context);
gst_gl_display_unlock (display);
return NULL;
@ -464,9 +486,22 @@ gst_gl_display_thread_create_context (GstGLDisplay * display)
GST_INFO ("gl window created");
display->gl_api = gst_gl_window_get_gl_api (display->gl_window);
g_assert (display->gl_api != GST_GL_API_NONE && display->gl_api != GST_GL_API_ANY);
api_string = gst_gl_api_string (display->gl_api);
GST_INFO ("available GL APIs: %s", api_string);
compiled_api_s = gst_gl_api_string (compiled_api);
GST_INFO ("compiled api support: %s", compiled_api_s);
if ((compiled_api & display->gl_api) == GST_GL_API_NONE)
gst_gl_display_set_error (display, "failed to create_context, window "
"could not provide correct api. compiled api supports:%s, window "
"supports:%s", compiled_api_s, api_string);
g_free (api_string);
g_free (compiled_api_s);
/* gl api specific code */
#if HAVE_OPENGL
if (!ret && USING_OPENGL(display))
@ -474,11 +509,11 @@ gst_gl_display_thread_create_context (GstGLDisplay * display)
#endif
#if HAVE_GLES2
if (!ret && USING_GLES2(display))
ret = _create_context_gles2 (display, &gl_major, &gl_minor);
ret = _create_context_gles2 (display, &gl_major, &gl_minor);
#endif
if (!ret || !gl_major)
gst_gl_display_set_error (display, "failed to create context");
gst_gl_display_set_error (display, "failed to create context, unknown reason");
/* setup callbacks */
gst_gl_window_set_resize_callback (display->gl_window,

View file

@ -124,50 +124,6 @@ static const GstGLFeatureData cogl_feature_ext_functions_data_gles2[] = {
#undef GST_GL_EXT_FUNCTION
#undef GST_GL_EXT_END
#define GST_GL_EXT_BEGIN(name, min_gl_major, min_gl_minor, gles_availability, \
namespaces, extension_names)
#define GST_GL_EXT_FUNCTION(ret, name, args) \
NULL,
#define GST_GL_EXT_END()
#if HAVE_OPENGL
static GstGLFuncs gst_gl = {
#include "glprototypes/opengl.h"
{NULL,},
#include "glprototypes/gles1opengl.h"
{NULL,},
#include "glprototypes/gles2opengl.h"
{NULL,},
#include "glprototypes/gles1gles2opengl.h"
{NULL,},
};
const GstGLFuncs *
gst_gl_get_opengl_vtable (void)
{
return &gst_gl;
}
#endif
#if HAVE_GLES2
static GstGLES2Funcs gst_gles2 = {
#include "glprototypes/gles1gles2.h"
{NULL,},
#include "glprototypes/gles1gles2opengl.h"
{NULL,},
#include "glprototypes/gles2.h"
{NULL,},
#include "glprototypes/gles2opengl.h"
{NULL,},
};
const GstGLES2Funcs *
gst_gl_get_gles2_vtable (void)
{
return &gst_gles2;
}
#endif
gboolean
_gst_gl_feature_check (GstGLDisplay * display,
const char *driver_prefix,

View file

@ -51,7 +51,7 @@ struct _GstGLFeatureData
without needing an extension. Set to 255,255 if it's only
provided in an extension */
int min_gl_major, min_gl_minor;
/* Flags specifying which versions of GLES the feature is available
/* Flags specifying which versions of GL the feature is available
in core in */
GstGLApi gl_availability;
/* \0 separated list of namespaces to try. Eg "EXT\0ARB\0" */