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

[701/906] display: move context creation into window

parent 9c633e65
This diff is collapsed.
......@@ -28,6 +28,7 @@
#include <gst/video/video.h>
typedef struct _GstGLShader GstGLShader;
typedef struct _GstGLWindow GstGLWindow;
#include "gstglwindow.h"
#include "gstglshader.h"
......@@ -89,12 +90,6 @@ struct _GstGLDisplay
/* thread safe */
GMutex mutex;
/* gl context */
GThread *gl_thread;
GstGLWindow *gl_window;
gboolean isAlive;
gboolean context_created;
/* gl API we are using */
GstGLAPI gl_api;
/* foreign gl context */
......@@ -115,9 +110,6 @@ struct _GstGLDisplayClass
GstGLDisplay *gst_gl_display_new (void);
gboolean gst_gl_display_create_context (GstGLDisplay * display,
gulong external_gl_context);
void gst_gl_display_thread_add (GstGLDisplay * display,
GstGLDisplayThreadFunc func, gpointer data);
......@@ -126,15 +118,17 @@ void gst_gl_display_activate_gl_context (GstGLDisplay * display, gboolean activa
/* Must be called inside a lock/unlock on display, or within the glthread */
void gst_gl_display_set_error (GstGLDisplay * display, const char * format, ...);
gboolean gst_gl_display_check_framebuffer_status (GstGLDisplay * display);
void gst_gl_display_lock (GstGLDisplay * display);
void gst_gl_display_unlock (GstGLDisplay * display);
GstGLAPI gst_gl_display_get_gl_api (GstGLDisplay * display);
GstGLAPI gst_gl_display_get_gl_api_unlocked (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);
G_END_DECLS
#endif /* __GST_GL_H__ */
......@@ -43,11 +43,11 @@
* calling thread.
*/
#define USING_OPENGL(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_OPENGL)
#define USING_OPENGL3(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_OPENGL3)
#define USING_GLES(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_GLES)
#define USING_GLES2(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_GLES2)
#define USING_GLES3(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_GLES3)
#define USING_OPENGL(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_OPENGL)
#define USING_OPENGL3(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_OPENGL3)
#define USING_GLES(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_GLES)
#define USING_GLES2(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_GLES2)
#define USING_GLES3(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_GLES3)
static void _do_download (GstGLDisplay * display, GstGLDownload * download);
static void _init_download (GstGLDisplay * display, GstGLDownload * download);
......
......@@ -150,6 +150,7 @@ _gst_gl_feature_check (GstGLDisplay * display,
const char *suffix = NULL;
int func_num;
GstGLFuncs *gst_gl = display->gl_vtable;
GstGLWindow *window = NULL;
/* First check whether the functions should be directly provided by
GL */
......@@ -172,6 +173,9 @@ _gst_gl_feature_check (GstGLDisplay * display,
if (suffix == NULL)
goto error;
window = gst_gl_display_get_window (display);
g_assert (window);
/* Try to get all of the entry points */
for (func_num = 0; data->functions[func_num].name; func_num++) {
void *func;
......@@ -183,8 +187,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 (display->gl_window, full_function_name);
func = gst_gl_window_get_proc_address (window, full_function_name);
if (func == NULL && in_core) {
GST_TRACE ("%s was not found in core, trying the extension version",
......@@ -196,8 +199,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 (display->gl_window,
full_function_name);
func = gst_gl_window_get_proc_address (window, full_function_name);
}
}
......@@ -212,6 +214,7 @@ _gst_gl_feature_check (GstGLDisplay * display,
}
g_free (full_function_name);
gst_object_unref (window);
return TRUE;
......@@ -230,6 +233,9 @@ error:
g_free (full_function_name);
}
if (window)
gst_object_unref (window);
return FALSE;
}
......
......@@ -253,11 +253,18 @@ gst_gl_filter_start (GstBaseTransform * bt)
filter->display =
g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
else {
GstGLWindow *window;
GError *error = NULL;
GST_INFO ("Creating GstGLDisplay");
filter->display = gst_gl_display_new ();
if (!gst_gl_display_create_context (filter->display, 0)) {
window = gst_gl_window_new (filter->display);
gst_gl_display_set_window (filter->display, window);
g_object_unref (window);
if (!gst_gl_window_create_context (window, 0, &error)) {
GST_ELEMENT_ERROR (filter, RESOURCE, NOT_FOUND,
GST_GL_DISPLAY_ERR_MSG (filter->display), (NULL));
("%s", error->message), (NULL));
return FALSE;
}
}
......@@ -727,9 +734,10 @@ gst_gl_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps,
if (filter_class->display_init_cb != NULL) {
gst_gl_display_thread_add (filter->display, gst_gl_filter_start_gl, filter);
}
#if 0
if (!filter->display->isAlive)
goto error;
#endif
if (filter_class->onInitFBO) {
if (!filter_class->onInitFBO (filter))
......
......@@ -25,6 +25,7 @@
#include <gst/video/video.h>
#include "gstglmemory.h"
#include "gstglutils.h"
/**
* SECTION:gstglmemory
......
......@@ -935,11 +935,18 @@ gst_gl_mixer_activate (GstGLMixer * mix, gboolean activate)
mix->display =
g_object_ref (GST_GL_DISPLAY (g_value_get_pointer (id_value)));
else {
GstGLWindow *window;
GError *error = NULL;
GST_INFO ("Creating GstGLDisplay");
mix->display = gst_gl_display_new ();
if (!gst_gl_display_create_context (mix->display, 0)) {
window = gst_gl_window_new (mix->display);
gst_gl_display_set_window (mix->display, window);
g_object_unref (window);
if (!gst_gl_window_create_context (window, 0, &error)) {
GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND,
GST_GL_DISPLAY_ERR_MSG (mix->display), (NULL));
("%s", error->message), (NULL));
return FALSE;
}
}
......
......@@ -43,11 +43,11 @@
* calling thread.
*/
#define USING_OPENGL(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_OPENGL)
#define USING_OPENGL3(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_OPENGL3)
#define USING_GLES(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_GLES)
#define USING_GLES2(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_GLES2)
#define USING_GLES3(display) (gst_gl_display_get_gl_api_unlocked (display) & GST_GL_API_GLES3)
#define USING_OPENGL(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_OPENGL)
#define USING_OPENGL3(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_OPENGL3)
#define USING_GLES(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_GLES)
#define USING_GLES2(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_GLES2)
#define USING_GLES3(display) (gst_gl_display_get_gl_api (display) & GST_GL_API_GLES3)
static void _do_upload (GstGLDisplay * display, GstGLUpload * upload);
static void _do_upload_fill (GstGLDisplay * display, GstGLUpload * upload);
......
......@@ -234,18 +234,24 @@ void
gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
GstVideoFormat v_format, GLint width, GLint height)
{
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
gen_texture_width = width;
gen_texture_height = height;
gen_texture_video_format = v_format;
gst_gl_window_send_message (display->gl_window,
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (gst_gl_display_gen_texture_window_cb), display);
*pTexture = gen_texture;
} else
*pTexture = 0;
gst_object_unref (window);
gst_gl_display_unlock (display);
}
......@@ -263,21 +269,26 @@ gboolean
gst_gl_display_gen_fbo (GstGLDisplay * display, gint width, gint height,
GLuint * fbo, GLuint * depthbuffer)
{
gboolean isAlive = FALSE;
gboolean alive = FALSE;
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
gen_fbo_width = width;
gen_fbo_height = height;
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (_gen_fbo),
display);
gst_gl_window_send_message (window, GST_GL_WINDOW_CB (_gen_fbo), display);
*fbo = generated_fbo;
*depthbuffer = generated_depth_buffer;
}
isAlive = display->isAlive;
alive = gst_gl_window_is_running (window);
gst_object_unref (window);
gst_gl_display_unlock (display);
return isAlive;
return alive;
}
......@@ -297,10 +308,13 @@ gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
gdouble proj_param2, gdouble proj_param3, gdouble proj_param4,
GstGLDisplayProjection projection, gpointer * stuff)
{
gboolean isAlive;
gboolean alive;
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
use_fbo = fbo;
use_depth_buffer = depth_buffer;
use_fbo_texture = texture_fbo;
......@@ -316,13 +330,14 @@ gst_gl_display_use_fbo (GstGLDisplay * display, gint texture_fbo_width,
input_texture_width = input_tex_width;
input_texture_height = input_tex_height;
input_texture = input_tex;
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (_use_fbo),
display);
gst_gl_window_send_message (window, GST_GL_WINDOW_CB (_use_fbo), display);
}
isAlive = display->isAlive;
alive = gst_gl_window_is_running (window);
gst_object_unref (window);
gst_gl_display_unlock (display);
return isAlive;
return alive;
}
gboolean
......@@ -330,10 +345,13 @@ gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
gint texture_fbo_height, GLuint fbo, GLuint depth_buffer,
GLuint texture_fbo, GLCB_V2 cb, gpointer * stuff)
{
gboolean isAlive;
gboolean alive;
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
use_fbo = fbo;
use_depth_buffer = depth_buffer;
use_fbo_texture = texture_fbo;
......@@ -341,26 +359,33 @@ gst_gl_display_use_fbo_v2 (GstGLDisplay * display, gint texture_fbo_width,
use_fbo_height = texture_fbo_height;
use_fbo_scene_cb_v2 = cb;
use_fbo_stuff = stuff;
gst_gl_window_send_message (display->gl_window,
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (_use_fbo_v2), display);
}
isAlive = display->isAlive;
alive = gst_gl_window_is_running (window);
gst_object_unref (window);
gst_gl_display_unlock (display);
return isAlive;
return alive;
}
/* Called by gltestsrc and glfilter */
void
gst_gl_display_del_fbo (GstGLDisplay * display, GLuint fbo, GLuint depth_buffer)
{
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
del_fbo = fbo;
del_depth_buffer = depth_buffer;
gst_gl_window_send_message (display->gl_window, GST_GL_WINDOW_CB (_del_fbo),
display);
gst_gl_window_send_message (window, GST_GL_WINDOW_CB (_del_fbo), display);
}
gst_object_unref (window);
gst_gl_display_unlock (display);
}
......@@ -371,13 +396,16 @@ gst_gl_display_gen_shader (GstGLDisplay * display,
const gchar * shader_vertex_source,
const gchar * shader_fragment_source, GstGLShader ** shader)
{
gboolean isAlive;
gboolean alive;
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
gen_shader_vertex_source = shader_vertex_source;
gen_shader_fragment_source = shader_fragment_source;
gst_gl_window_send_message (display->gl_window,
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (_gen_shader), display);
if (shader)
*shader = gen_shader;
......@@ -385,10 +413,12 @@ gst_gl_display_gen_shader (GstGLDisplay * display,
gen_shader_vertex_source = NULL;
gen_shader_fragment_source = NULL;
}
isAlive = display->isAlive;
alive = gst_gl_window_is_running (window);
gst_object_unref (window);
gst_gl_display_unlock (display);
return isAlive;
return alive;
}
......@@ -396,12 +426,18 @@ gst_gl_display_gen_shader (GstGLDisplay * display,
void
gst_gl_display_del_shader (GstGLDisplay * display, GstGLShader * shader)
{
GstGLWindow *window;
gst_gl_display_lock (display);
if (display->isAlive) {
window = gst_gl_display_get_window_unlocked (display);
if (gst_gl_window_is_running (window)) {
del_shader = shader;
gst_gl_window_send_message (display->gl_window,
gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (_del_shader), display);
}
gst_object_unref (window);
gst_gl_display_unlock (display);
}
......
......@@ -99,4 +99,6 @@ gboolean gst_gl_display_gen_shader (GstGLDisplay * display,
const gchar * shader_fragment_source, GstGLShader ** shader);
void gst_gl_display_del_shader (GstGLDisplay * display, GstGLShader * shader);
gboolean gst_gl_display_check_framebuffer_status (GstGLDisplay * display);
#endif /* __GST_GL_UTILS_H__ */
This diff is collapsed.
......@@ -22,9 +22,12 @@
#ifndef __GST_GL_WINDOW_H__
#define __GST_GL_WINDOW_H__
typedef struct _GstGLDisplay GstGLDisplay;
#include <gst/gst.h>
#include "gstglapi.h"
#include "gstgldisplay.h"
G_BEGIN_DECLS
......@@ -90,6 +93,8 @@ struct _GstGLWindow {
/*< private >*/
gpointer _reserved[GST_PADDING];
GstGLWindowPrivate *priv;
};
struct _GstGLWindowClass {
......@@ -119,7 +124,7 @@ struct _GstGLWindowClass {
GQuark gst_gl_window_error_quark (void);
GType gst_gl_window_get_type (void);
GstGLWindow * gst_gl_window_new (void);
GstGLWindow * gst_gl_window_new (GstGLDisplay *display);
void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowResizeCB callback, gpointer data);
......@@ -140,11 +145,12 @@ gpointer gst_gl_window_get_proc_address (GstGLWindow *window, const gchar *
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, GstGLAPI gl_api,
guintptr external_gl_context, GError ** error);
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);
gboolean gst_gl_window_is_running (GstGLWindow *window);
GST_DEBUG_CATEGORY_EXTERN (gst_gl_window_debug);
G_END_DECLS
......
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