2012-11-13 11:12:20 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstglwindow
|
|
|
|
* @short_description: window/surface abstraction
|
|
|
|
* @title: GstGLWindow
|
|
|
|
* @see_also: #GstGLContext, #GstGLDisplay
|
|
|
|
*
|
|
|
|
* GstGLWindow represents a window that elements can render into. A window can
|
|
|
|
* either be a user visible window (onscreen) or hidden (offscreen).
|
|
|
|
*/
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-01-08 06:40:39 +00:00
|
|
|
#include <gmodule.h>
|
2013-06-12 13:17:30 +00:00
|
|
|
#include <stdio.h>
|
2013-01-08 06:40:39 +00:00
|
|
|
|
2013-07-10 15:03:04 +00:00
|
|
|
#include "gl.h"
|
2012-11-13 11:12:20 +00:00
|
|
|
#include "gstglwindow.h"
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
/* FIXME make this work with windowless contexts */
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
2012-11-19 11:54:19 +00:00
|
|
|
#include "x11/gstglwindow_x11.h"
|
2012-11-13 11:12:20 +00:00
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WIN32
|
2012-11-19 11:54:19 +00:00
|
|
|
#include "win32/gstglwindow_win32.h"
|
2012-11-13 11:12:20 +00:00
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_COCOA
|
2012-11-19 11:54:19 +00:00
|
|
|
#include "cocoa/gstglwindow_cocoa.h"
|
2012-11-13 11:12:20 +00:00
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WAYLAND
|
2012-11-28 14:01:59 +00:00
|
|
|
#include "wayland/gstglwindow_wayland_egl.h"
|
|
|
|
#endif
|
2013-07-10 09:31:17 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_ANDROID
|
|
|
|
#include "android/gstglwindow_android_egl.h"
|
|
|
|
#endif
|
2014-04-12 19:43:50 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_EAGL
|
|
|
|
#include "eagl/gstglwindow_eagl.h"
|
|
|
|
#endif
|
2013-08-30 13:12:37 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_DISPMANX
|
|
|
|
#include "dispmanx/gstglwindow_dispmanx_egl.h"
|
|
|
|
#endif
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2014-05-30 00:27:14 +00:00
|
|
|
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
|
|
|
|
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
|
|
|
|
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
|
|
|
|
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
|
|
|
|
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_debug
|
2012-11-28 14:01:59 +00:00
|
|
|
GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
#define gst_gl_window_parent_class parent_class
|
2014-05-08 05:30:49 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GstGLWindow, gst_gl_window, GST_TYPE_OBJECT);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
#define GST_GL_WINDOW_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW, GstGLWindowPrivate))
|
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
static void gst_gl_window_default_send_message (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
struct _GstGLWindowPrivate
|
|
|
|
{
|
|
|
|
GThread *gl_thread;
|
|
|
|
|
|
|
|
gboolean alive;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gst_gl_window_finalize (GObject * object);
|
|
|
|
|
2014-03-17 09:44:32 +00:00
|
|
|
typedef struct _GstGLDummyWindow
|
|
|
|
{
|
|
|
|
GstGLWindow parent;
|
|
|
|
|
|
|
|
guintptr handle;
|
|
|
|
|
|
|
|
GMainContext *main_context;
|
|
|
|
GMainLoop *loop;
|
|
|
|
} GstGLDummyWindow;
|
|
|
|
|
|
|
|
typedef struct _GstGLDummyWindowCass
|
|
|
|
{
|
|
|
|
GstGLWindowClass parent;
|
|
|
|
} GstGLDummyWindowClass;
|
|
|
|
|
|
|
|
GstGLDummyWindow *gst_gl_dummy_window_new (void);
|
|
|
|
|
2014-07-06 20:39:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
EVENT_MOUSE_SIGNAL,
|
|
|
|
EVENT_KEY_SIGNAL,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_gl_window_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2012-12-08 22:30:48 +00:00
|
|
|
GQuark
|
|
|
|
gst_gl_window_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("gst-gl-window-error-quark");
|
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_init (GstGLWindow * window)
|
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
window->priv = GST_GL_WINDOW_GET_PRIVATE (window);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
g_mutex_init (&window->lock);
|
2013-11-06 21:55:49 +00:00
|
|
|
window->is_drawing = FALSE;
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
g_weak_ref_init (&window->context_ref, NULL);
|
2012-11-13 11:12:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_class_init (GstGLWindowClass * klass)
|
|
|
|
{
|
2013-06-12 13:17:30 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLWindowPrivate));
|
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
klass->send_message = GST_DEBUG_FUNCPTR (gst_gl_window_default_send_message);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_window_finalize;
|
2014-07-06 20:39:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstGLWindow::mouse-event:
|
|
|
|
* @object: the #GstGLWindow
|
|
|
|
* @id: the name of the event
|
|
|
|
* @button: the id of the button
|
|
|
|
* @x: the x coordinate of the mouse event
|
|
|
|
* @y: the y coordinate of the mouse event
|
|
|
|
*
|
|
|
|
* Will be emitted when a mouse event is received by the GstGLwindow.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
gst_gl_window_signals[EVENT_MOUSE_SIGNAL] =
|
|
|
|
g_signal_new ("mouse-event", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
|
|
|
G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstGLWindow::key-event:
|
|
|
|
* @object: the #GstGLWindow
|
|
|
|
* @id: the name of the event
|
|
|
|
* @key: the id of the key pressed
|
|
|
|
*
|
|
|
|
* Will be emitted when a key event is received by the GstGLwindow.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
gst_gl_window_signals[EVENT_KEY_SIGNAL] =
|
|
|
|
g_signal_new ("key-event", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
|
|
|
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
|
2012-11-13 11:12:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_new:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstGLWindow using @display's connection
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindow *
|
2013-06-12 13:17:30 +00:00
|
|
|
gst_gl_window_new (GstGLDisplay * display)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
|
|
|
GstGLWindow *window = NULL;
|
|
|
|
const gchar *user_choice;
|
2012-11-28 14:01:59 +00:00
|
|
|
static volatile gsize _init = 0;
|
|
|
|
|
2013-11-25 22:32:32 +00:00
|
|
|
g_return_val_if_fail (display != NULL, NULL);
|
|
|
|
|
2012-11-28 14:01:59 +00:00
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_window_debug, "glwindow", 0,
|
|
|
|
"glwindow element");
|
|
|
|
g_once_init_leave (&_init, 1);
|
|
|
|
}
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
user_choice = g_getenv ("GST_GL_WINDOW");
|
2012-11-28 14:01:59 +00:00
|
|
|
GST_INFO ("creating a window, user choice:%s", user_choice);
|
|
|
|
|
2013-11-30 09:51:49 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_COCOA
|
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 5, "cocoa")))
|
|
|
|
window = GST_GL_WINDOW (gst_gl_window_cocoa_new ());
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
2012-11-13 11:12:20 +00:00
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
|
2013-11-27 06:52:46 +00:00
|
|
|
window = GST_GL_WINDOW (gst_gl_window_x11_new (display));
|
2012-11-13 11:12:20 +00:00
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WIN32
|
2012-11-13 11:12:20 +00:00
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 5, "win32")))
|
2013-02-12 12:48:36 +00:00
|
|
|
window = GST_GL_WINDOW (gst_gl_window_win32_new ());
|
2012-11-13 11:12:20 +00:00
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WAYLAND
|
2012-11-28 14:01:59 +00:00
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
|
2013-02-12 12:48:36 +00:00
|
|
|
window = GST_GL_WINDOW (gst_gl_window_wayland_egl_new ());
|
2013-07-10 09:31:17 +00:00
|
|
|
#endif
|
2013-10-01 11:27:07 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_DISPMANX
|
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 8, "dispmanx")))
|
|
|
|
window = GST_GL_WINDOW (gst_gl_window_dispmanx_egl_new ());
|
|
|
|
#endif
|
2013-07-10 09:31:17 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_ANDROID
|
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 7, "android")))
|
|
|
|
window = GST_GL_WINDOW (gst_gl_window_android_egl_new ());
|
2014-04-12 19:43:50 +00:00
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_WINDOW_EAGL
|
2014-05-06 06:39:55 +00:00
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 4, "eagl")))
|
2014-04-12 19:43:50 +00:00
|
|
|
window = GST_GL_WINDOW (gst_gl_window_eagl_new ());
|
2012-11-13 11:12:20 +00:00
|
|
|
#endif
|
|
|
|
if (!window) {
|
2013-02-12 12:48:36 +00:00
|
|
|
/* subclass returned a NULL window */
|
2014-03-17 09:44:32 +00:00
|
|
|
GST_WARNING ("Could not create window. user specified %s, creating dummy"
|
|
|
|
" window", user_choice ? user_choice : "(null)");
|
2013-02-12 12:48:36 +00:00
|
|
|
|
2014-03-17 09:44:32 +00:00
|
|
|
window = GST_GL_WINDOW (gst_gl_dummy_window_new ());
|
2012-11-13 11:12:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 22:32:32 +00:00
|
|
|
window->display = gst_object_ref (display);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLWindow *window = GST_GL_WINDOW (object);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
g_weak_ref_clear (&window->context_ref);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2013-11-06 22:13:20 +00:00
|
|
|
g_mutex_clear (&window->lock);
|
2013-11-25 22:32:32 +00:00
|
|
|
gst_object_unref (window->display);
|
2013-11-06 22:13:20 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_window_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_set_window_handle:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @handle: handle to the window
|
|
|
|
*
|
|
|
|
* Sets the window that this @window should render into. Some implementations
|
|
|
|
* require this to be called with a valid handle before drawing can commence.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_set_window_handle (GstGLWindow * window, guintptr handle)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
g_return_if_fail (handle != 0);
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->set_window_handle != NULL);
|
|
|
|
|
|
|
|
window_class->set_window_handle (window, handle);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_draw_unlocked:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @width: requested width of the window
|
|
|
|
* @height: requested height of the window
|
|
|
|
*
|
|
|
|
* Redraw the window contents. Implementations should invoke the draw callback.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_draw_unlocked (GstGLWindow * window, guint width, guint height)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->draw_unlocked != NULL);
|
|
|
|
|
|
|
|
window_class->draw_unlocked (window, width, height);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_draw:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @width: requested width of the window
|
|
|
|
* @height: requested height of the window
|
|
|
|
*
|
|
|
|
* Redraw the window contents. Implementations should invoke the draw callback.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_draw (GstGLWindow * window, guint width, guint height)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->draw != NULL);
|
|
|
|
|
2013-11-06 21:55:49 +00:00
|
|
|
/* avoid to overload the drawer */
|
|
|
|
if (window->is_drawing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_class->draw (window, width, height);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_run:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Start the execution of the runloop.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_run (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->run != NULL);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
window->priv->alive = TRUE;
|
2012-11-13 11:12:20 +00:00
|
|
|
window_class->run (window);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_quit:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Quit the runloop's execution.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
2013-07-15 13:58:04 +00:00
|
|
|
gst_gl_window_quit (GstGLWindow * window)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->quit != NULL);
|
|
|
|
|
|
|
|
GST_GL_WINDOW_LOCK (window);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
window->priv->alive = FALSE;
|
|
|
|
|
2013-07-15 13:58:04 +00:00
|
|
|
window_class->quit (window);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
GST_INFO ("quit sent to gl window loop");
|
|
|
|
|
2013-06-13 04:36:41 +00:00
|
|
|
GST_GL_WINDOW_UNLOCK (window);
|
2012-11-13 11:12:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
typedef struct _GstGLSyncMessage
|
|
|
|
{
|
|
|
|
GMutex lock;
|
|
|
|
GCond cond;
|
|
|
|
gboolean fired;
|
|
|
|
|
|
|
|
GstGLWindowCB callback;
|
|
|
|
gpointer data;
|
|
|
|
} GstGLSyncMessage;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_run_message_sync (GstGLSyncMessage * message)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&message->lock);
|
|
|
|
|
|
|
|
if (message->callback)
|
|
|
|
message->callback (message->data);
|
|
|
|
|
|
|
|
message->fired = TRUE;
|
|
|
|
g_cond_signal (&message->cond);
|
|
|
|
g_mutex_unlock (&message->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_default_send_message (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLSyncMessage message;
|
|
|
|
|
|
|
|
message.callback = callback;
|
|
|
|
message.data = data;
|
|
|
|
message.fired = FALSE;
|
|
|
|
g_mutex_init (&message.lock);
|
|
|
|
g_cond_init (&message.cond);
|
|
|
|
|
|
|
|
gst_gl_window_send_message_async (window, (GstGLWindowCB) _run_message_sync,
|
|
|
|
&message, NULL);
|
|
|
|
|
|
|
|
g_mutex_lock (&message.lock);
|
|
|
|
|
|
|
|
/* block until opengl calls have been executed in the gl thread */
|
|
|
|
while (!message.fired)
|
|
|
|
g_cond_wait (&message.cond, &message.lock);
|
|
|
|
g_mutex_unlock (&message.lock);
|
|
|
|
|
|
|
|
g_mutex_clear (&message.lock);
|
|
|
|
g_cond_clear (&message.cond);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_send_message:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @callback: (scope async): function to invoke
|
|
|
|
* @data: (closure): data to invoke @callback with
|
|
|
|
*
|
|
|
|
* Invoke @callback with data on the window thread. @callback is guarenteed to
|
|
|
|
* have executed when this function returns.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
2013-09-25 02:26:57 +00:00
|
|
|
g_return_if_fail (window_class->send_message != NULL);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
window_class->send_message (window, callback, data);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_send_message_async:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @callback: (scope async): function to invoke
|
|
|
|
* @data: (closure): data to invoke @callback with
|
|
|
|
* @destroy: (destroy): called when @data is not needed anymore
|
|
|
|
*
|
|
|
|
* Invoke @callback with @data on the window thread. The callback may not
|
|
|
|
* have been executed when this function returns.
|
|
|
|
*/
|
2013-09-25 02:26:57 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_send_message_async (GstGLWindow * window, GstGLWindowCB callback,
|
|
|
|
gpointer data, GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->send_message_async != NULL);
|
|
|
|
|
|
|
|
window_class->send_message_async (window, callback, data, destroy);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_set_draw_callback:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @callback: (scope notified): function to invoke
|
|
|
|
* @data: (closure): data to invoke @callback with
|
|
|
|
* @destroy_notify: (destroy): called when @data is not needed any more
|
|
|
|
*
|
|
|
|
* Sets the draw callback called everytime gst_gl_window_draw() is called
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_set_draw_callback (GstGLWindow * window, GstGLWindowCB callback,
|
2013-07-15 13:58:04 +00:00
|
|
|
gpointer data, GDestroyNotify destroy_notify)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
|
|
|
|
GST_GL_WINDOW_LOCK (window);
|
|
|
|
|
2013-07-15 13:58:04 +00:00
|
|
|
if (window->draw_notify)
|
|
|
|
window->draw_notify (window->draw_data);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window->draw = callback;
|
|
|
|
window->draw_data = data;
|
2013-07-15 13:58:04 +00:00
|
|
|
window->draw_notify = destroy_notify;
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
GST_GL_WINDOW_UNLOCK (window);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_set_resize_callback:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @callback: (scope notified): function to invoke
|
|
|
|
* @data: (closure): data to invoke @callback with
|
|
|
|
* @destroy_notify: (destroy): called when @data is not needed any more
|
|
|
|
*
|
|
|
|
* Sets the resize callback called everytime a resize of the window occurs.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_set_resize_callback (GstGLWindow * window,
|
2013-07-15 13:58:04 +00:00
|
|
|
GstGLWindowResizeCB callback, gpointer data, GDestroyNotify destroy_notify)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
|
|
|
|
GST_GL_WINDOW_LOCK (window);
|
|
|
|
|
2013-07-15 13:58:04 +00:00
|
|
|
if (window->resize_notify)
|
|
|
|
window->resize_notify (window->resize_data);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window->resize = callback;
|
|
|
|
window->resize_data = data;
|
2013-07-15 13:58:04 +00:00
|
|
|
window->resize_notify = destroy_notify;
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
GST_GL_WINDOW_UNLOCK (window);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_set_close_callback:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @callback: (scope notified): function to invoke
|
|
|
|
* @data: (closure): data to invoke @callback with
|
|
|
|
* @destroy_notify: (destroy): called when @data is not needed any more
|
|
|
|
*
|
|
|
|
* Sets the callback called when the window is about to close.
|
|
|
|
*/
|
2012-11-13 11:12:20 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_set_close_callback (GstGLWindow * window, GstGLWindowCB callback,
|
2013-07-15 13:58:04 +00:00
|
|
|
gpointer data, GDestroyNotify destroy_notify)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
|
|
|
|
GST_GL_WINDOW_LOCK (window);
|
|
|
|
|
2013-07-15 13:58:04 +00:00
|
|
|
if (window->close_notify)
|
|
|
|
window->close_notify (window->close_data);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window->close = callback;
|
|
|
|
window->close_data = data;
|
2013-07-15 13:58:04 +00:00
|
|
|
window->close_notify = destroy_notify;
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
GST_GL_WINDOW_UNLOCK (window);
|
|
|
|
}
|
2012-12-03 04:04:49 +00:00
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_is_running:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Whether the runloop is running
|
|
|
|
*/
|
2013-08-15 07:09:04 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_window_is_running (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return window->priv->alive;
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_get_display:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Returns: the windowing system display handle for this @window
|
|
|
|
*/
|
2013-08-15 07:09:04 +00:00
|
|
|
guintptr
|
|
|
|
gst_gl_window_get_display (GstGLWindow * window)
|
2012-12-03 04:04:49 +00:00
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
g_return_val_if_fail (GST_GL_IS_WINDOW (window), 0);
|
2012-12-03 04:04:49 +00:00
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
2013-08-15 07:09:04 +00:00
|
|
|
g_return_val_if_fail (window_class->get_display != NULL, 0);
|
|
|
|
|
2013-11-25 09:34:06 +00:00
|
|
|
return window_class->get_display (window);
|
2012-12-03 04:04:49 +00:00
|
|
|
}
|
2013-01-08 06:40:39 +00:00
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_get_window_handle:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Returns: the window handle we are currently rendering into
|
|
|
|
*/
|
2013-08-15 07:09:04 +00:00
|
|
|
guintptr
|
|
|
|
gst_gl_window_get_window_handle (GstGLWindow * window)
|
2013-01-08 06:40:39 +00:00
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
g_return_val_if_fail (GST_GL_IS_WINDOW (window), 0);
|
2013-01-08 06:40:39 +00:00
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
2013-08-15 07:09:04 +00:00
|
|
|
g_return_val_if_fail (window_class->get_window_handle != NULL, 0);
|
2013-01-08 06:40:39 +00:00
|
|
|
|
2013-11-25 09:34:06 +00:00
|
|
|
return window_class->get_window_handle (window);
|
2013-01-08 06:40:39 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 11:57:49 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_get_context:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GstGLContext associated with this @window
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLContext *
|
|
|
|
gst_gl_window_get_context (GstGLWindow * window)
|
2013-06-12 13:17:30 +00:00
|
|
|
{
|
2013-08-14 00:44:19 +00:00
|
|
|
g_return_val_if_fail (GST_GL_IS_WINDOW (window), NULL);
|
2013-06-12 13:17:30 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
return (GstGLContext *) g_weak_ref_get (&window->context_ref);
|
2013-06-12 13:17:30 +00:00
|
|
|
}
|
2014-03-17 09:44:32 +00:00
|
|
|
|
2014-08-06 13:48:03 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_window_get_surface_dimensions:
|
|
|
|
* @window: a #GstGLWindow
|
|
|
|
* @width: (out): resulting surface width
|
|
|
|
* @height: (out): resulting surface height
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_get_surface_dimensions (GstGLWindow * window, guint * width,
|
|
|
|
guint * height)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (window));
|
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (window);
|
|
|
|
g_return_if_fail (window_class->get_surface_dimensions != NULL);
|
|
|
|
window_class->get_surface_dimensions (window, width, height);
|
|
|
|
}
|
|
|
|
|
2014-03-17 09:44:32 +00:00
|
|
|
GType gst_gl_dummy_window_get_type (void);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstGLDummyWindow, gst_gl_dummy_window, GST_GL_TYPE_WINDOW);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_dummy_window_open (GstGLWindow * window, GError ** error)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy = (GstGLDummyWindow *) window;
|
|
|
|
|
|
|
|
dummy->main_context = g_main_context_new ();
|
|
|
|
dummy->loop = g_main_loop_new (dummy->main_context, FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_close (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy = (GstGLDummyWindow *) window;
|
|
|
|
|
|
|
|
g_main_loop_unref (dummy->loop);
|
|
|
|
g_main_context_unref (dummy->main_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_quit (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy = (GstGLDummyWindow *) window;
|
|
|
|
|
|
|
|
g_main_loop_quit (dummy->loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_run (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy = (GstGLDummyWindow *) window;
|
|
|
|
|
|
|
|
g_main_loop_run (dummy->loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _GstGLMessage
|
|
|
|
{
|
|
|
|
GstGLWindowCB callback;
|
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify destroy;
|
|
|
|
} GstGLMessage;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_run_message (GstGLMessage * message)
|
|
|
|
{
|
|
|
|
if (message->callback)
|
|
|
|
message->callback (message->data);
|
|
|
|
|
|
|
|
if (message->destroy)
|
|
|
|
message->destroy (message->data);
|
|
|
|
|
|
|
|
g_slice_free (GstGLMessage, message);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy;
|
|
|
|
GstGLMessage *message;
|
|
|
|
|
|
|
|
dummy = (GstGLDummyWindow *) window;
|
|
|
|
message = g_slice_new (GstGLMessage);
|
|
|
|
|
|
|
|
message->callback = callback;
|
|
|
|
message->data = data;
|
|
|
|
message->destroy = destroy;
|
|
|
|
|
|
|
|
g_main_context_invoke (dummy->main_context, (GSourceFunc) _run_message,
|
|
|
|
message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_set_window_handle (GstGLWindow * window, guintptr handle)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy = (GstGLDummyWindow *) window;
|
|
|
|
|
|
|
|
dummy->handle = handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_dummy_window_get_window_handle (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *dummy = (GstGLDummyWindow *) window;
|
|
|
|
|
|
|
|
return (guintptr) dummy->handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct draw
|
|
|
|
{
|
|
|
|
GstGLDummyWindow *window;
|
|
|
|
guint width, height;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_cb (gpointer data)
|
|
|
|
{
|
|
|
|
struct draw *draw_data = data;
|
|
|
|
GstGLDummyWindow *dummy = draw_data->window;
|
|
|
|
GstGLWindow *window = GST_GL_WINDOW (dummy);
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
|
|
|
GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
|
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
|
|
|
|
|
|
|
context_class->swap_buffers (context);
|
|
|
|
|
|
|
|
gst_object_unref (context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_draw (GstGLWindow * window, guint width, guint height)
|
|
|
|
{
|
|
|
|
struct draw draw_data;
|
|
|
|
|
|
|
|
draw_data.window = (GstGLDummyWindow *) window;
|
|
|
|
draw_data.width = width;
|
|
|
|
draw_data.height = height;
|
|
|
|
|
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, &draw_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_dummy_window_get_display (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-06 13:48:03 +00:00
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_get_surface_dimensions (GstGLWindow * window, guint * width,
|
|
|
|
guint * height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-17 09:44:32 +00:00
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_class_init (GstGLDummyWindowClass * klass)
|
|
|
|
{
|
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
|
|
|
|
|
|
|
window_class->get_display =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_dummy_window_get_display);
|
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_dummy_window_get_window_handle);
|
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_dummy_window_set_window_handle);
|
|
|
|
window_class->draw_unlocked = GST_DEBUG_FUNCPTR (gst_gl_dummy_window_draw);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_dummy_window_draw);
|
|
|
|
window_class->run = GST_DEBUG_FUNCPTR (gst_gl_dummy_window_run);
|
|
|
|
window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_dummy_window_quit);
|
|
|
|
window_class->send_message_async =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_dummy_window_send_message_async);
|
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_dummy_window_open);
|
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_dummy_window_close);
|
2014-08-06 13:48:03 +00:00
|
|
|
window_class->get_surface_dimensions =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_dummy_window_get_surface_dimensions);
|
2014-03-17 09:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_dummy_window_init (GstGLDummyWindow * dummy)
|
|
|
|
{
|
|
|
|
dummy->handle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstGLDummyWindow *
|
|
|
|
gst_gl_dummy_window_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (gst_gl_dummy_window_get_type (), NULL);
|
|
|
|
}
|
2014-07-06 20:39:47 +00:00
|
|
|
|
|
|
|
void
|
2014-07-24 10:23:03 +00:00
|
|
|
gst_gl_window_send_key_event (GstGLWindow * window, const char *event_type,
|
|
|
|
const char *key_str)
|
2014-07-06 20:39:47 +00:00
|
|
|
{
|
|
|
|
g_signal_emit (window, gst_gl_window_signals[EVENT_KEY_SIGNAL], 0,
|
|
|
|
event_type, key_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-24 10:23:03 +00:00
|
|
|
gst_gl_window_send_mouse_event (GstGLWindow * window, const char *event_type,
|
2014-07-06 20:39:47 +00:00
|
|
|
int button, double posx, double posy)
|
|
|
|
{
|
|
|
|
g_signal_emit (window, gst_gl_window_signals[EVENT_MOUSE_SIGNAL], 0,
|
|
|
|
event_type, button, posx, posy);
|
|
|
|
}
|