Skip to content

Commit

Permalink
[812/906] move the GL vtable from GstGLDisplay to GstGLContext
Browse files Browse the repository at this point in the history
Conflicts:
	tests/check/libs/gstglcontext.c
  • Loading branch information
ystreet authored and tp-m committed Dec 9, 2017
1 parent adb7edd commit 711ad48
Show file tree
Hide file tree
Showing 26 changed files with 508 additions and 533 deletions.
12 changes: 6 additions & 6 deletions gst-libs/gst/gl/gstglbufferpool.c
Expand Up @@ -168,7 +168,7 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
}

if (!(gl_mem =
gst_gl_memory_alloc (glpool->display, GST_VIDEO_INFO_FORMAT (info),
gst_gl_memory_alloc (glpool->context, GST_VIDEO_INFO_FORMAT (info),
GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info))))
goto mem_create_failed;
gst_buffer_append_memory (buf, gl_mem);
Expand Down Expand Up @@ -206,12 +206,12 @@ gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
* Returns: a #GstBufferPool that allocates buffers with #GstGLMemory
*/
GstBufferPool *
gst_gl_buffer_pool_new (GstGLDisplay * display)
gst_gl_buffer_pool_new (GstGLContext * context)
{
GstGLBufferPool *pool;

pool = g_object_new (GST_TYPE_GL_BUFFER_POOL, NULL);
pool->display = gst_object_ref (display);
pool->context = gst_object_ref (context);

GST_LOG_OBJECT (pool, "new GL buffer pool %p", pool);

Expand Down Expand Up @@ -245,9 +245,9 @@ gst_gl_buffer_pool_dispose (GObject * object)
{
GstGLBufferPool *pool = GST_GL_BUFFER_POOL_CAST (object);

if (pool->display) {
gst_object_unref (pool->display);
pool->display = NULL;
if (pool->context) {
gst_object_unref (pool->context);
pool->context = NULL;
}

G_OBJECT_CLASS (gst_gl_buffer_pool_parent_class)->dispose (object);
Expand Down
4 changes: 2 additions & 2 deletions gst-libs/gst/gl/gstglbufferpool.h
Expand Up @@ -49,7 +49,7 @@ struct _GstGLBufferPool
{
GstBufferPool bufferpool;

GstGLDisplay *display;
GstGLContext *context;

GstGLBufferPoolPrivate *priv;
};
Expand All @@ -64,7 +64,7 @@ struct _GstGLBufferPoolClass
GstBufferPoolClass parent_class;
};

GstBufferPool *gst_gl_buffer_pool_new (GstGLDisplay * display);
GstBufferPool *gst_gl_buffer_pool_new (GstGLContext * context);

G_END_DECLS

Expand Down
66 changes: 57 additions & 9 deletions gst-libs/gst/gl/gstglcontext.c
Expand Up @@ -101,6 +101,8 @@ gst_gl_context_init (GstGLContext * context)
{
context->priv = GST_GL_CONTEXT_GET_PRIVATE (context);

context->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs));

g_mutex_init (&context->priv->render_lock);

g_cond_init (&context->priv->create_cond);
Expand Down Expand Up @@ -196,6 +198,11 @@ gst_gl_context_finalize (GObject * object)

gst_object_unref (context->window);

if (context->gl_vtable) {
g_slice_free (GstGLFuncs, context->gl_vtable);
context->gl_vtable = NULL;
}

g_mutex_clear (&context->priv->render_lock);

g_cond_clear (&context->priv->destroy_cond);
Expand Down Expand Up @@ -367,12 +374,10 @@ static gboolean
_create_context_gles2 (GstGLContext * context, gint * gl_major, gint * gl_minor,
GError ** error)
{
GstGLDisplay *display;
const GstGLFuncs *gl;
GLenum gl_err = GL_NO_ERROR;

display = context->priv->display;
gl = display->gl_vtable;
gl = context->gl_vtable;

GST_INFO ("GL_VERSION: %s", gl->GetString (GL_VERSION));
GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
Expand All @@ -394,7 +399,7 @@ _create_context_gles2 (GstGLContext * context, gint * gl_major, gint * gl_minor,
}
#endif

_gst_gl_feature_check_ext_functions (display, 0, 0,
_gst_gl_feature_check_ext_functions (context, 0, 0,
(const gchar *) gl->GetString (GL_EXTENSIONS));

if (gl_major)
Expand All @@ -409,14 +414,12 @@ gboolean
_create_context_opengl (GstGLContext * context, gint * gl_major,
gint * gl_minor, GError ** error)
{
GstGLDisplay *display;
const GstGLFuncs *gl;
guint maj, min;
GLenum gl_err = GL_NO_ERROR;
GString *opengl_version = NULL;

display = context->priv->display;
gl = display->gl_vtable;
gl = context->gl_vtable;

GST_INFO ("GL_VERSION: %s", gl->GetString (GL_VERSION));
GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
Expand Down Expand Up @@ -445,7 +448,7 @@ _create_context_opengl (GstGLContext * context, gint * gl_major,
return FALSE;
}

_gst_gl_feature_check_ext_functions (display, maj, min,
_gst_gl_feature_check_ext_functions (context, maj, min,
(const gchar *) gl->GetString (GL_EXTENSIONS));

if (gl_major)
Expand Down Expand Up @@ -541,7 +544,7 @@ gst_gl_context_create_thread (GstGLContext * context)
}

display = context->priv->display;
gl = display->gl_vtable;
gl = context->gl_vtable;
compiled_api = _compiled_api ();

user_choice = g_getenv ("GST_GL_API");
Expand Down Expand Up @@ -681,3 +684,48 @@ gst_gl_context_get_gl_context (GstGLContext * context)

return result;
}

GstGLDisplay *
gst_gl_context_get_display (GstGLContext * context)
{
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), NULL);

return gst_object_ref (context->priv->display);
}

typedef struct
{
GstGLContext *context;
GstGLContextThreadFunc func;
gpointer data;
} RunGenericData;

static void
_gst_gl_context_thread_run_generic (RunGenericData * data)
{
GST_TRACE ("running function:%p data:%p", data->func, data->data);

data->func (data->context, data->data);
}

void
gst_gl_context_thread_add (GstGLContext * context,
GstGLContextThreadFunc func, gpointer data)
{
GstGLWindow *window;
RunGenericData rdata;

g_return_if_fail (GST_GL_IS_CONTEXT (context));
g_return_if_fail (func != NULL);

rdata.context = context;
rdata.data = data;
rdata.func = func;

window = gst_gl_context_get_window (context);

gst_gl_window_send_message (window,
GST_GL_WINDOW_CB (_gst_gl_context_thread_run_generic), &rdata);

gst_object_unref (window);
}
16 changes: 16 additions & 0 deletions gst-libs/gst/gl/gstglcontext.h
Expand Up @@ -38,6 +38,15 @@ GType gst_gl_context_get_type (void);
#define GST_GL_CONTEXT_ERROR (gst_gl_context_error_quark ())
GQuark gst_gl_context_error_quark (void);

/**
* GstGLContextThreadFunc:
* @display: a #GstGLDisplay
* @data: user data
*
* Represents a function to run in the GL thread
*/
typedef void (*GstGLContextThreadFunc) (GstGLContext * context, gpointer data);

typedef enum
{
GST_GL_CONTEXT_ERROR_FAILED,
Expand All @@ -55,6 +64,8 @@ struct _GstGLContext {
/*< public >*/
GstGLWindow *window;

GstGLFuncs *gl_vtable;

/*< private >*/
gpointer _reserved[GST_PADDING];

Expand Down Expand Up @@ -85,6 +96,7 @@ GstGLContext * gst_gl_context_new (GstGLDisplay *display);

gboolean gst_gl_context_activate (GstGLContext *context, gboolean activate);

GstGLDisplay * gst_gl_context_get_display (GstGLContext *context);
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);
Expand All @@ -97,6 +109,10 @@ gpointer gst_gl_context_default_get_proc_address (GstGLContext *context, co
gboolean gst_gl_context_set_window (GstGLContext *context, GstGLWindow *window);
GstGLWindow * gst_gl_context_get_window (GstGLContext *context);

/* FIXME: remove */
void gst_gl_context_thread_add (GstGLContext * display,
GstGLContextThreadFunc func, gpointer data);

G_END_DECLS

#endif /* __GST_GL_CONTEXT_H__ */
55 changes: 0 additions & 55 deletions gst-libs/gst/gl/gstgldisplay.c
Expand Up @@ -64,8 +64,6 @@ gst_gl_display_init (GstGLDisplay * display)
{
display->priv = GST_GL_DISPLAY_GET_PRIVATE (display);

display->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs));

display->gl_api = GST_GL_API_NONE;

gst_gl_memory_init ();
Expand All @@ -76,11 +74,6 @@ gst_gl_display_finalize (GObject * object)
{
GstGLDisplay *display = GST_GL_DISPLAY (object);

if (display->gl_vtable) {
g_slice_free (GstGLFuncs, display->gl_vtable);
display->gl_vtable = NULL;
}

if (display->context) {
gst_object_unref (display->context);
display->context = NULL;
Expand All @@ -95,45 +88,6 @@ gst_gl_display_new (void)
return g_object_new (GST_TYPE_GL_DISPLAY, NULL);
}

#if 1
typedef struct
{
GstGLDisplay *display;
GstGLDisplayThreadFunc func;
gpointer data;
} RunGenericData;

static void
_gst_gl_display_thread_run_generic (RunGenericData * data)
{
GST_TRACE ("running function:%p data:%p", data->func, data->data);

data->func (data->display, data->data);
}

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_CONTEXT (display->context));
g_return_if_fail (func != NULL);

rdata.display = display;
rdata.data = data;
rdata.func = func;

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)
{
Expand All @@ -143,15 +97,6 @@ gst_gl_display_get_gl_api (GstGLDisplay * display)
return gst_gl_context_get_gl_api (display->context);
}

gpointer
gst_gl_display_get_gl_vtable (GstGLDisplay * display)
{
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);

return display->gl_vtable;
}
#endif

void
gst_gl_display_set_context (GstGLDisplay * display, GstGLContext * context)
{
Expand Down
14 changes: 0 additions & 14 deletions gst-libs/gst/gl/gstgldisplay.h
Expand Up @@ -37,15 +37,6 @@ GType gst_gl_display_get_type (void);
#define GST_IS_GL_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_GL_DISPLAY))
#define GST_GL_DISPLAY_CAST(obj) ((GstGLDisplay*)(obj))

/**
* GstGLDisplayThreadFunc:
* @display: a #GstGLDisplay
* @data: user data
*
* Represents a function to run in the GL thread
*/
typedef void (*GstGLDisplayThreadFunc) (GstGLDisplay * display, gpointer data);

/**
* GstGLDisplay:
*
Expand All @@ -60,8 +51,6 @@ struct _GstGLDisplay
GstGLContext *context;
GstGLAPI gl_api;

GstGLFuncs *gl_vtable;

GstGLDisplayPrivate *priv;
};

Expand All @@ -81,9 +70,6 @@ void gst_gl_display_set_context (GstGLDisplay * display, G
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);

#define GST_GL_DISPLAY_CONTEXT_TYPE "gst.gl.GLDisplay"
void gst_context_set_gl_display (GstContext * context, GstGLDisplay * display);
gboolean gst_context_get_gl_display (GstContext * context, GstGLDisplay ** display);
Expand Down

0 comments on commit 711ad48

Please sign in to comment.