Commit e80533dc authored by Matthew Waters's avatar Matthew Waters 🐨 Committed by Tim-Philipp Müller

[793/906] add a GstGLContext object that will be the basis of OpenGL contexts

At the moment it just sits in between GstGLDisplay and GstGLWindow
performing some of the stuff that GstGLWindow used to do.
parent 175f2884
......@@ -8,6 +8,7 @@ noinst_HEADERS =
libgstgl_@GST_API_VERSION@_la_SOURCES = \
gstgldisplay.c \
gstglcontext.c \
gstglmemory.c \
gstglbufferpool.c \
gstglfilter.c \
......@@ -64,6 +65,7 @@ libgstgl_@GST_API_VERSION@include_HEADERS = \
gstglconfig.h \
gstglwindow.h \
gstgldisplay.h \
gstglcontext.h \
gstglmemory.h \
gstglbufferpool.h \
gstgles2.h \
......
......@@ -28,6 +28,9 @@
#include "config.h"
#endif
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include "gstglwindow_android_egl.h"
#define GST_CAT_DEFAULT gst_gl_window_debug
......@@ -307,13 +310,14 @@ static gpointer
gst_gl_window_android_egl_get_proc_address (GstGLWindow * window,
const gchar * name)
{
GstGLContext *context = NULL;
GstGLWindowAndroidEGL *window_egl;
gpointer result;
window_egl = GST_GL_WINDOW_ANDROID_EGL (window);
if (!(result = gst_gl_egl_get_proc_address (window_egl->egl, name))) {
result = gst_gl_window_default_get_proc_address (window, name);
result = gst_gl_context_default_get_proc_address (context, name);
}
return result;
......
......@@ -25,6 +25,7 @@
#include <gst/gl/gstglconfig.h>
#include <gst/gl/gstglapi.h>
#include <gst/gl/gstgldisplay.h>
#include <gst/gl/gstglcontext.h>
#include <gst/gl/gstglfeature.h>
#include <gst/gl/gstglutils.h>
#include <gst/gl/gstglwindow.h>
......
......@@ -31,6 +31,10 @@ typedef struct _GstGLDisplay GstGLDisplay;
typedef struct _GstGLDisplayClass GstGLDisplayClass;
typedef struct _GstGLDisplayPrivate GstGLDisplayPrivate;
typedef struct _GstGLContext GstGLContext;
typedef struct _GstGLContextClass GstGLContextClass;
typedef struct _GstGLContextPrivate GstGLContextPrivate;
typedef struct _GstGLWindow GstGLWindow;
typedef struct _GstGLWindowPrivate GstGLWindowPrivate;
typedef struct _GstGLWindowClass GstGLWindowClass;
......
This diff is collapsed.
/*
* 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.
*/
#ifndef __GST_GL_CONTEXT_H__
#define __GST_GL_CONTEXT_H__
#include <gst/gst.h>
#include <gst/gl/gstgl_fwd.h>
G_BEGIN_DECLS
#define GST_GL_TYPE_CONTEXT (gst_gl_context_get_type())
#define GST_GL_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_GL_TYPE_CONTEXT, GstGLContext))
#define GST_GL_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS((k), GST_GL_TYPE_CONTEXT, GstGLContextClass))
#define GST_GL_IS_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_GL_TYPE_CONTEXT))
#define GST_GL_IS_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_GL_TYPE_CONTEXT))
#define GST_GL_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_GL_TYPE_CONTEXT, GstGLContextClass))
GType gst_gl_context_get_type (void);
#define GST_GL_CONTEXT_ERROR (gst_gl_context_error_quark ())
GQuark gst_gl_window_error_quark (void);
typedef enum
{
GST_GL_CONTEXT_ERROR_FAILED,
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
GST_GL_CONTEXT_ERROR_WRONG_API,
GST_GL_CONTEXT_ERROR_OLD_LIBS,
GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
} GstGLContextError;
struct _GstGLContext {
/*< private >*/
GObject parent;
/*< public >*/
GstGLWindow *window;
/*< private >*/
gpointer _reserved[GST_PADDING];
GstGLContextPrivate *priv;
};
struct _GstGLContextClass {
/*< private >*/
GObjectClass parent_class;
guintptr (*get_gl_context) (GstGLContext *context);
GstGLAPI (*get_gl_api) (GstGLContext *context);
gpointer (*get_proc_address) (GstGLContext *context, const gchar *name);
gboolean (*activate) (GstGLContext *context, gboolean activate);
gboolean (*create_context) (GstGLContext *context, GstGLAPI gl_api,
guintptr external_gl_context, GError ** error);
/*< private >*/
gpointer _reserved[GST_PADDING];
};
/* methods */
GstGLContext * gst_gl_context_new (GstGLDisplay *display);
gboolean gst_gl_context_activate (GstGLContext *context, gboolean activate);
gpointer gst_gl_context_get_proc_address (GstGLContext *context, const gchar *name);
GstGLPlatform gst_gl_context_get_platform (GstGLContext *context);
GstGLAPI gst_gl_context_get_gl_api (GstGLContext *context);
gboolean gst_gl_context_create (GstGLContext *context, guintptr external_gl_context, GError ** error);
gpointer gst_gl_context_default_get_proc_address (GstGLContext *context, const gchar *name);
gboolean gst_gl_context_set_window (GstGLContext *context, GstGLWindow *window);
GstGLWindow * gst_gl_context_get_window (GstGLContext *context);
G_END_DECLS
#endif /* __GST_GL_CONTEXT_H__ */
......@@ -81,14 +81,21 @@ gst_gl_display_finalize (GObject * object)
display->gl_vtable = NULL;
}
if (display->window) {
gst_object_unref (display->window);
display->window = NULL;
if (display->context) {
gst_object_unref (display->context);
display->context = NULL;
}
G_OBJECT_CLASS (gst_gl_display_parent_class)->finalize (object);
}
GstGLDisplay *
gst_gl_display_new (void)
{
return g_object_new (GST_TYPE_GL_DISPLAY, NULL);
}
#if 1
typedef struct
{
GstGLDisplay *display;
......@@ -104,37 +111,36 @@ _gst_gl_display_thread_run_generic (RunGenericData * data)
data->func (data->display, data->data);
}
GstGLDisplay *
gst_gl_display_new (void)
{
return g_object_new (GST_TYPE_GL_DISPLAY, NULL);
}
void
gst_gl_display_thread_add (GstGLDisplay * display,
GstGLDisplayThreadFunc func, gpointer data)
{
GstGLWindow *window;
RunGenericData rdata;
g_return_if_fail (GST_IS_GL_DISPLAY (display));
g_return_if_fail (GST_GL_IS_WINDOW (display->window));
g_return_if_fail (GST_GL_IS_CONTEXT (display->context));
g_return_if_fail (func != NULL);
rdata.display = display;
rdata.data = data;
rdata.func = func;
gst_gl_window_send_message (display->window,
window = gst_gl_context_get_window (display->context);
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (_gst_gl_display_thread_run_generic), &rdata);
gst_object_unref (window);
}
GstGLAPI
gst_gl_display_get_gl_api (GstGLDisplay * display)
{
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_API_NONE);
g_return_val_if_fail (GST_GL_IS_WINDOW (display->window), GST_GL_API_NONE);
g_return_val_if_fail (GST_GL_IS_CONTEXT (display->context), GST_GL_API_NONE);
return gst_gl_window_get_gl_api (display->window);
return gst_gl_context_get_gl_api (display->context);
}
gpointer
......@@ -144,45 +150,46 @@ gst_gl_display_get_gl_vtable (GstGLDisplay * display)
return display->gl_vtable;
}
#endif
void
gst_gl_display_set_window (GstGLDisplay * display, GstGLWindow * window)
gst_gl_display_set_context (GstGLDisplay * display, GstGLContext * context)
{
g_return_if_fail (GST_IS_GL_DISPLAY (display));
g_return_if_fail (GST_GL_IS_WINDOW (window));
g_return_if_fail (GST_GL_IS_CONTEXT (context));
gst_gl_display_lock (display);
if (display->window)
gst_object_unref (display->window);
if (display->context)
gst_object_unref (display->context);
display->window = gst_object_ref (window);
display->context = gst_object_ref (context);
gst_gl_display_unlock (display);
}
GstGLWindow *
gst_gl_display_get_window (GstGLDisplay * display)
GstGLContext *
gst_gl_display_get_context (GstGLDisplay * display)
{
GstGLWindow *window;
GstGLContext *context;
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
gst_gl_display_lock (display);
window = display->window ? gst_object_ref (display->window) : NULL;
context = display->context ? gst_object_ref (display->context) : NULL;
gst_gl_display_unlock (display);
return window;
return context;
}
GstGLWindow *
gst_gl_display_get_window_unlocked (GstGLDisplay * display)
GstGLContext *
gst_gl_display_get_context_unlocked (GstGLDisplay * display)
{
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
return display->window ? gst_object_ref (display->window) : NULL;
return display->context ? gst_object_ref (display->context) : NULL;
}
void
......
......@@ -57,7 +57,7 @@ struct _GstGLDisplay
GstObject object;
/* <private> */
GstGLWindow *window;
GstGLContext *context;
GstGLAPI gl_api;
GstGLFuncs *gl_vtable;
......@@ -75,11 +75,11 @@ GstGLDisplay *gst_gl_display_new (void);
#define gst_gl_display_lock(display) GST_OBJECT_LOCK (display)
#define gst_gl_display_unlock(display) GST_OBJECT_UNLOCK (display)
GstGLAPI gst_gl_display_get_gl_api (GstGLDisplay * display);
gpointer gst_gl_display_get_gl_vtable (GstGLDisplay * display);
void gst_gl_display_set_window (GstGLDisplay * display, GstGLWindow * window);
GstGLWindow * gst_gl_display_get_window (GstGLDisplay * display);
GstGLWindow * gst_gl_display_get_window_unlocked (GstGLDisplay * display);
GstGLAPI gst_gl_display_get_gl_api (GstGLDisplay * display);
gpointer gst_gl_display_get_gl_vtable (GstGLDisplay * display);
void gst_gl_display_set_context (GstGLDisplay * display, GstGLContext * context);
GstGLContext * gst_gl_display_get_context (GstGLDisplay * display);
GstGLContext * gst_gl_display_get_context_unlocked (GstGLDisplay * display);
void gst_gl_display_thread_add (GstGLDisplay * display,
GstGLDisplayThreadFunc func, gpointer data);
......
......@@ -149,7 +149,7 @@ _gst_gl_feature_check (GstGLDisplay * display,
const char *suffix = NULL;
int func_num;
GstGLFuncs *gst_gl = display->gl_vtable;
GstGLWindow *window = NULL;
GstGLContext *context = NULL;
/* First check whether the functions should be directly provided by
GL */
......@@ -172,8 +172,8 @@ _gst_gl_feature_check (GstGLDisplay * display,
if (suffix == NULL)
goto error;
window = gst_gl_display_get_window (display);
g_assert (window);
context = gst_gl_display_get_context (display);
g_assert (context);
/* Try to get all of the entry points */
for (func_num = 0; data->functions[func_num].name; func_num++) {
......@@ -186,7 +186,7 @@ _gst_gl_feature_check (GstGLDisplay * display,
suffix, NULL);
GST_TRACE ("%s should %sbe in core", full_function_name,
in_core ? "" : "not ");
func = gst_gl_window_get_proc_address (window, full_function_name);
func = gst_gl_context_get_proc_address (context, full_function_name);
if (func == NULL && in_core) {
GST_TRACE ("%s was not found in core, trying the extension version",
......@@ -198,7 +198,7 @@ _gst_gl_feature_check (GstGLDisplay * display,
g_free (full_function_name);
full_function_name = g_strconcat ("gl", data->functions[func_num].name,
suffix, NULL);
func = gst_gl_window_get_proc_address (window, full_function_name);
func = gst_gl_context_get_proc_address (context, full_function_name);
}
}
......@@ -213,7 +213,7 @@ _gst_gl_feature_check (GstGLDisplay * display,
}
g_free (full_function_name);
gst_object_unref (window);
gst_object_unref (context);
return TRUE;
......@@ -232,8 +232,8 @@ error:
g_free (full_function_name);
}
if (window)
gst_object_unref (window);
if (context)
gst_object_unref (context);
return FALSE;
}
......
......@@ -256,16 +256,16 @@ gst_gl_filter_start (GstBaseTransform * bt)
filter->display =
gst_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
else {
GstGLWindow *window;
GstGLContext *context;
GError *error = NULL;
GST_INFO ("Creating GstGLDisplay");
filter->display = gst_gl_display_new ();
window = gst_gl_window_new (filter->display);
gst_gl_display_set_window (filter->display, window);
gst_object_unref (window);
context = gst_gl_context_new (filter->display);
gst_gl_display_set_context (filter->display, context);
gst_object_unref (context);
if (!gst_gl_window_create_context (window, 0, &error)) {
if (!gst_gl_context_create (context, 0, &error)) {
GST_ELEMENT_ERROR (filter, RESOURCE, NOT_FOUND,
("%s", error->message), (NULL));
return FALSE;
......
......@@ -935,16 +935,16 @@ gst_gl_mixer_activate (GstGLMixer * mix, gboolean activate)
mix->display =
gst_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
else {
GstGLWindow *window;
GstGLContext *context;
GError *error = NULL;
GST_INFO ("Creating GstGLDisplay");
mix->display = gst_gl_display_new ();
window = gst_gl_window_new (mix->display);
gst_gl_display_set_window (mix->display, window);
gst_object_unref (window);
context = gst_gl_context_new (mix->display);
gst_gl_display_set_context (mix->display, context);
gst_object_unref (context);
if (!gst_gl_window_create_context (window, 0, &error)) {
if (!gst_gl_context_create (context, 0, &error)) {
GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND,
("%s", error->message), (NULL));
return FALSE;
......
......@@ -141,32 +141,34 @@ gst_gl_display_check_framebuffer_status (GstGLDisplay * display)
void
gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activate)
{
GstGLWindow *window;
GstGLContext *context;
g_return_if_fail (GST_IS_GL_DISPLAY (display));
if (!activate)
gst_gl_display_lock (display);
window = gst_gl_display_get_window_unlocked (display);
context = gst_gl_display_get_context_unlocked (display);
gst_gl_window_activate (window, activate);
gst_gl_context_activate (context, activate);
if (activate)
gst_gl_display_unlock (display);
gst_object_unref (window);
gst_object_unref (context);
}
void
gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height)
{
GstGLContext *context;
GstGLWindow *window;
gst_gl_display_lock (display);
window = gst_gl_display_get_window_unlocked (display);
context = gst_gl_display_get_context_unlocked (display);
window = gst_gl_context_get_window (context);
if (gst_gl_window_is_running (window)) {
gen_texture_width = width;
......@@ -178,6 +180,7 @@ gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
} else
*pTexture = 0;
gst_object_unref (context);
gst_object_unref (window);
gst_gl_display_unlock (display);
......@@ -186,17 +189,20 @@ gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
void
gst_gl_display_del_texture (GstGLDisplay * display, GLuint * pTexture)
{
GstGLContext *context;
GstGLWindow *window;
gst_gl_display_lock (display);
window = gst_gl_display_get_window_unlocked (display);
context = gst_gl_display_get_context_unlocked (display);
window = gst_gl_context_get_window (context);
if (gst_gl_window_is_running (window) && *pTexture) {
del_texture = pTexture;
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (gst_gl_display_del_texture_window_cb), display);
}
gst_object_unref (context);
gst_object_unref (window);
gst_gl_display_unlock (display);
......
This diff is collapsed.
......@@ -75,6 +75,8 @@ struct _GstGLWindow {
GMutex lock;
gboolean need_lock;
GWeakRef context_ref;
guintptr external_gl_context;
GstGLWindowCB draw;
......@@ -131,7 +133,6 @@ void gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB
void gst_gl_window_set_need_lock (GstGLWindow *window, gboolean need_lock);
guintptr gst_gl_window_get_gl_context (GstGLWindow *window);
gboolean gst_gl_window_activate (GstGLWindow *window, gboolean activate);
void gst_gl_window_set_window_handle (GstGLWindow *window, guintptr handle);
guintptr gst_gl_window_get_window_handle (GstGLWindow *window);
void gst_gl_window_draw_unlocked (GstGLWindow *window, guint width, guint height);
......@@ -140,13 +141,7 @@ void gst_gl_window_run (GstGLWindow *window);
void gst_gl_window_quit (GstGLWindow *window);
void gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
gpointer gst_gl_window_get_proc_address (GstGLWindow *window, const gchar *name);
GstGLPlatform gst_gl_window_get_platform (GstGLWindow *window);
GstGLAPI gst_gl_window_get_gl_api (GstGLWindow *window);
gboolean gst_gl_window_create_context (GstGLWindow *window, guintptr external_gl_context, GError ** error);
gpointer gst_gl_window_default_get_proc_address (GstGLWindow *window, const gchar *name);
GstGLContext * gst_gl_window_get_context (GstGLWindow *window);
gboolean gst_gl_window_is_running (GstGLWindow *window);
......
......@@ -27,6 +27,9 @@
#include "wayland_event_source.h"
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include "gstglwindow_wayland_egl.h"
const gchar *WlEGLErrorString ();
......@@ -572,13 +575,14 @@ static gpointer
gst_gl_window_wayland_egl_get_proc_address (GstGLWindow * window,
const gchar * name)
{
GstGLContext *context = NULL;
GstGLWindowWaylandEGL *window_egl;
gpointer result;
window_egl = GST_GL_WINDOW_WAYLAND_EGL (window);
if (!(result = gst_gl_egl_get_proc_address (window_egl->egl, name))) {
result = gst_gl_window_default_get_proc_address (window, name);
result = gst_gl_context_default_get_proc_address (context, name);
}
return result;
......
......@@ -25,6 +25,9 @@
#include <gst/gst.h>
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include "gstglwindow_win32_egl.h"
static guintptr gst_gl_window_win32_wgl_get_gl_context (GstGLWindowWin32 *
......
......@@ -27,6 +27,9 @@
#include <gst/gst.h>
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include "gstglwindow_win32_wgl.h"
#define GST_CAT_DEFAULT gst_gl_window_debug
......@@ -215,10 +218,11 @@ static gpointer
gst_gl_window_win32_wgl_get_proc_address (GstGLWindow * window,
const gchar * name)
{
GstGLContext *context;
gpointer result;
if (!(result = wglGetProcAddress ((LPCSTR) name))) {
result = gst_gl_window_default_get_proc_address (window, name);
result = gst_gl_context_default_get_proc_address (context, name);
}
return result;
......
......@@ -25,6 +25,9 @@
#include "config.h"
#endif
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include "gstglwindow_x11_egl.h"
const gchar *X11EGLErrorString ();
......@@ -188,11 +191,12 @@ static gpointer
gst_gl_window_x11_egl_get_proc_address (GstGLWindow * window,
const gchar * name)
{
GstGLContext *context = NULL;
GstGLWindowX11EGL *window_egl = GST_GL_WINDOW_X11_EGL (window);
gpointer result;
if (!(result = gst_gl_egl_get_proc_address (window_egl->egl, name))) {
result = gst_gl_window_default_get_proc_address (window, name);
result = gst_gl_context_default_get_proc_address (context, name);
}
return result;
......
......@@ -27,6 +27,9 @@
#include <gst/gst.h>
#include "../gstgl_fwd.h"
#include <gst/gl/gstglcontext.h>
#include <gst/gl/gl.h>
#include "gstglwindow_x11_glx.h"
......@@ -352,10 +355,11 @@ static gpointer
gst_gl_window_x11_glx_get_proc_address (GstGLWindow * window,
const gchar * name)
{
GstGLContext *context = NULL;
gpointer result;
if (!(result = glXGetProcAddressARB ((const GLubyte *) name))) {
result = gst_gl_window_default_get_proc_address (window, name);
result = gst_gl_context_default_get_proc_address (context, name);
}
return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment