2014-04-12 19:43:50 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it un der 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#import <OpenGLES/EAGL.h>
|
2014-04-13 14:53:58 +00:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2014-04-12 19:43:50 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
|
|
|
#include "gstglwindow_eagl.h"
|
|
|
|
#include "gstglcontext_eagl.h"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_eagl_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2016-04-10 22:34:00 +00:00
|
|
|
static void gst_gl_window_eagl_finalize (GObject * object);
|
2014-04-12 19:43:50 +00:00
|
|
|
|
|
|
|
static guintptr gst_gl_window_eagl_get_display (GstGLWindow * window);
|
|
|
|
static guintptr gst_gl_window_eagl_get_window_handle (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_eagl_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_eagl_set_preferred_size (GstGLWindow * window,
|
2015-01-23 05:52:25 +00:00
|
|
|
gint width, gint height);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_eagl_draw (GstGLWindow * window);
|
2016-04-10 22:34:00 +00:00
|
|
|
static void gst_gl_window_eagl_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy);
|
2014-04-12 19:43:50 +00:00
|
|
|
|
|
|
|
struct _GstGLWindowEaglPrivate
|
|
|
|
{
|
2017-02-03 13:46:39 +00:00
|
|
|
gpointer view;
|
2014-04-13 17:20:32 +00:00
|
|
|
gint window_width, window_height;
|
2015-01-23 03:11:48 +00:00
|
|
|
gint preferred_width, preferred_height;
|
2017-02-03 13:46:39 +00:00
|
|
|
gpointer gl_queue;
|
2014-04-12 19:43:50 +00:00
|
|
|
};
|
|
|
|
|
2018-06-24 11:35:20 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
|
|
|
|
#define gst_gl_window_eagl_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLWindowEagl, gst_gl_window_eagl,
|
|
|
|
GST_TYPE_GL_WINDOW, G_ADD_PRIVATE (GstGLWindowEagl) DEBUG_INIT);
|
|
|
|
|
2014-04-12 19:43:50 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_eagl_class_init (GstGLWindowEaglClass * klass)
|
|
|
|
{
|
2016-04-10 22:34:00 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2015-03-06 04:31:18 +00:00
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
2014-04-12 19:43:50 +00:00
|
|
|
|
2016-04-10 22:34:00 +00:00
|
|
|
gobject_class->finalize = gst_gl_window_eagl_finalize;
|
|
|
|
|
2014-04-12 19:43:50 +00:00
|
|
|
window_class->get_display =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_get_display);
|
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_get_window_handle);
|
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_set_window_handle);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_eagl_draw);
|
2015-01-23 03:11:48 +00:00
|
|
|
window_class->set_preferred_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_set_preferred_size);
|
2016-04-10 22:34:00 +00:00
|
|
|
window_class->send_message_async =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_send_message_async);
|
2014-04-12 19:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_eagl_init (GstGLWindowEagl * window)
|
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
window->priv = gst_gl_window_eagl_get_instance_private (window);
|
2016-04-10 22:34:00 +00:00
|
|
|
window->priv->gl_queue =
|
2017-02-03 13:46:39 +00:00
|
|
|
(__bridge_retained gpointer)dispatch_queue_create ("org.freedesktop.gstreamer.glwindow", NULL);
|
2016-04-10 22:34:00 +00:00
|
|
|
}
|
2015-03-06 04:31:18 +00:00
|
|
|
|
2016-04-10 22:34:00 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_eagl_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLWindowEagl *window = GST_GL_WINDOW_EAGL (object);
|
2017-02-03 13:46:39 +00:00
|
|
|
CFRelease(window->priv->gl_queue);
|
2016-04-10 22:34:00 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2014-04-12 19:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
|
|
|
GstGLWindowEagl *
|
2015-07-24 07:00:27 +00:00
|
|
|
gst_gl_window_eagl_new (GstGLDisplay * display)
|
2014-04-12 19:43:50 +00:00
|
|
|
{
|
2017-05-15 17:31:31 +00:00
|
|
|
GstGLWindowEagl *window;
|
|
|
|
|
2015-07-24 07:00:27 +00:00
|
|
|
/* there isn't an eagl display type */
|
2017-05-15 17:31:31 +00:00
|
|
|
window = g_object_new (GST_TYPE_GL_WINDOW_EAGL, NULL);
|
|
|
|
gst_object_ref_sink (window);
|
|
|
|
|
|
|
|
return window;
|
2014-04-12 19:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_window_eagl_get_display (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_window_eagl_get_window_handle (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return (guintptr) GST_GL_WINDOW_EAGL (window)->priv->view;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_eagl_set_window_handle (GstGLWindow * window, guintptr handle)
|
|
|
|
{
|
|
|
|
GstGLWindowEagl *window_eagl;
|
2015-04-02 07:05:55 +00:00
|
|
|
GstGLContext *context;
|
2014-04-12 19:43:50 +00:00
|
|
|
|
|
|
|
window_eagl = GST_GL_WINDOW_EAGL (window);
|
2015-04-02 07:05:55 +00:00
|
|
|
context = gst_gl_window_get_context (window);
|
2014-04-12 19:43:50 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
window_eagl->priv->view = (gpointer)handle;
|
2015-04-02 07:05:55 +00:00
|
|
|
GST_INFO_OBJECT (context, "handle set, updating layer");
|
|
|
|
gst_gl_context_eagl_update_layer (context);
|
2015-08-25 07:09:14 +00:00
|
|
|
|
|
|
|
gst_object_unref (context);
|
2014-04-12 19:43:50 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 03:11:48 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_eagl_set_preferred_size (GstGLWindow * window, gint width, gint height)
|
2014-04-12 19:43:50 +00:00
|
|
|
{
|
2015-01-23 05:52:25 +00:00
|
|
|
GstGLWindowEagl *window_eagl = GST_GL_WINDOW_EAGL (window);
|
2015-01-23 03:11:48 +00:00
|
|
|
|
|
|
|
window_eagl->priv->preferred_width = width;
|
|
|
|
window_eagl->priv->preferred_height = height;
|
|
|
|
}
|
2014-04-12 19:43:50 +00:00
|
|
|
|
2016-04-10 22:34:00 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_eagl_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GstGLWindowEagl *window_eagl = (GstGLWindowEagl *) window;
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
2016-04-12 14:43:18 +00:00
|
|
|
GThread *thread = gst_gl_context_get_thread (context);
|
2016-04-10 22:34:00 +00:00
|
|
|
|
2016-04-12 14:43:18 +00:00
|
|
|
if (thread == g_thread_self()) {
|
2016-04-10 22:34:00 +00:00
|
|
|
/* this case happens for nested calls happening from inside the GCD queue */
|
|
|
|
callback (data);
|
|
|
|
if (destroy)
|
|
|
|
destroy (data);
|
|
|
|
gst_object_unref (context);
|
|
|
|
} else {
|
2017-02-03 13:46:39 +00:00
|
|
|
dispatch_async ((__bridge dispatch_queue_t)(window_eagl->priv->gl_queue), ^{
|
2016-04-10 22:34:00 +00:00
|
|
|
gst_gl_context_activate (context, TRUE);
|
|
|
|
callback (data);
|
2017-02-03 13:46:39 +00:00
|
|
|
gst_object_unref (context);
|
2016-04-10 22:34:00 +00:00
|
|
|
if (destroy)
|
|
|
|
destroy (data);
|
|
|
|
});
|
|
|
|
}
|
2016-04-12 14:43:18 +00:00
|
|
|
if (thread)
|
|
|
|
g_thread_unref (thread);
|
2016-04-10 22:34:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-12 19:43:50 +00:00
|
|
|
static void
|
|
|
|
draw_cb (gpointer data)
|
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
GstGLWindowEagl *window_eagl = data;
|
2014-04-12 19:43:50 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_eagl);
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
|
|
|
GstGLContextEagl *eagl_context = GST_GL_CONTEXT_EAGL (context);
|
|
|
|
|
2014-04-13 17:20:32 +00:00
|
|
|
if (window_eagl->priv->view) {
|
2014-04-13 14:53:58 +00:00
|
|
|
CGSize size;
|
|
|
|
CAEAGLLayer *eagl_layer;
|
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
eagl_layer = (CAEAGLLayer *)[GS_GL_WINDOW_EAGL_VIEW(window_eagl) layer];
|
2014-04-13 14:53:58 +00:00
|
|
|
size = eagl_layer.frame.size;
|
|
|
|
|
2018-03-16 07:57:36 +00:00
|
|
|
size = CGSizeMake (size.width * eagl_layer.contentsScale, size.height * eagl_layer.contentsScale);
|
|
|
|
|
2015-09-17 07:06:37 +00:00
|
|
|
if (window->queue_resize || window_eagl->priv->window_width != size.width ||
|
2015-02-24 03:23:49 +00:00
|
|
|
window_eagl->priv->window_height != size.height) {
|
|
|
|
|
|
|
|
window_eagl->priv->window_width = size.width;
|
|
|
|
window_eagl->priv->window_height = size.height;
|
|
|
|
|
|
|
|
gst_gl_context_eagl_resize (eagl_context);
|
2014-04-13 14:53:58 +00:00
|
|
|
|
2015-09-17 07:06:37 +00:00
|
|
|
gst_gl_window_resize (window, window_eagl->priv->window_width,
|
2015-02-24 03:23:49 +00:00
|
|
|
window_eagl->priv->window_height);
|
2014-04-13 14:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-12 19:43:50 +00:00
|
|
|
gst_gl_context_eagl_prepare_draw (eagl_context);
|
|
|
|
|
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
|
|
|
|
2017-05-21 10:03:01 +00:00
|
|
|
gst_gl_context_swap_buffers (context);
|
2014-04-12 19:43:50 +00:00
|
|
|
|
|
|
|
gst_gl_context_eagl_finish_draw (eagl_context);
|
|
|
|
|
|
|
|
gst_object_unref (context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_eagl_draw (GstGLWindow * window)
|
2014-04-12 19:43:50 +00:00
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, window);
|
2014-04-12 19:43:50 +00:00
|
|
|
}
|