2009-02-26 00:06:58 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2014-09-26 10:05:27 +00:00
|
|
|
* Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
|
2009-02-26 00:06:58 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-07-17 14:47:41 +00:00
|
|
|
* modify it un der the terms of the GNU Library General Public
|
2009-02-26 00:06:58 +00:00
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-02-26 00:06:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2021-04-23 18:05:45 +00:00
|
|
|
#if !defined(MAC_OS_X_VERSION_MAX_ALLOWED) || MAC_OS_X_VERSION_MAX_ALLOWED >= 1014
|
|
|
|
# define GL_SILENCE_DEPRECATION
|
|
|
|
#endif
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2015-02-03 00:07:58 +00:00
|
|
|
#include <QuartzCore/QuartzCore.h>
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
#include "gstgl_cocoa_private.h"
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2017-10-01 17:04:15 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
|
2017-05-20 10:16:50 +00:00
|
|
|
#define NSWindowStyleMaskTitled NSTitledWindowMask
|
|
|
|
#define NSWindowStyleMaskClosable NSClosableWindowMask
|
|
|
|
#define NSWindowStyleMaskResizable NSResizableWindowMask
|
|
|
|
#define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
|
|
|
|
#endif
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLNSWindow declaration */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-11-13 11:01:25 +00:00
|
|
|
@interface GstGLNSWindow: NSWindow {
|
2009-02-26 00:06:58 +00:00
|
|
|
BOOL m_isClosed;
|
2014-09-26 10:05:27 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
- (id)initWithContentRect:(NSRect)contentRect
|
2009-07-17 14:47:41 +00:00
|
|
|
styleMask: (unsigned int) styleMask
|
|
|
|
backing: (NSBackingStoreType) bufferingType
|
|
|
|
defer: (BOOL) flag screen: (NSScreen *) aScreen
|
2012-11-16 06:13:03 +00:00
|
|
|
gstWin: (GstGLWindowCocoa *) window;
|
2009-07-24 08:12:07 +00:00
|
|
|
- (void) setClosed;
|
2009-07-17 14:47:41 +00:00
|
|
|
- (BOOL) isClosed;
|
2009-07-24 08:12:07 +00:00
|
|
|
- (BOOL) canBecomeMainWindow;
|
|
|
|
- (BOOL) canBecomeKeyWindow;
|
2009-02-26 00:06:58 +00:00
|
|
|
@end
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLWindow */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_cocoa_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2015-03-06 04:31:18 +00:00
|
|
|
static void gst_gl_window_cocoa_finalize (GObject * object);
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static gboolean gst_gl_window_cocoa_open (GstGLWindow *window, GError **err);
|
|
|
|
static void gst_gl_window_cocoa_close (GstGLWindow *window);
|
2020-03-26 02:51:24 +00:00
|
|
|
static void gst_gl_window_cocoa_quit (GstGLWindow *window);
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr gst_gl_window_cocoa_get_window_handle (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_cocoa_set_window_handle (GstGLWindow * window,
|
2012-11-16 06:13:03 +00:00
|
|
|
guintptr handle);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_cocoa_draw (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_cocoa_set_preferred_size (GstGLWindow * window,
|
|
|
|
gint width, gint height);
|
2015-01-29 11:25:00 +00:00
|
|
|
static void gst_gl_window_cocoa_show (GstGLWindow * window);
|
2015-09-17 07:06:37 +00:00
|
|
|
static void gst_gl_window_cocoa_queue_resize (GstGLWindow * window);
|
2016-04-10 22:34:00 +00:00
|
|
|
static void gst_gl_window_cocoa_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy);
|
2017-12-30 12:29:13 +00:00
|
|
|
static gboolean gst_gl_window_cocoa_set_render_rectangle (GstGLWindow * window,
|
|
|
|
gint x, gint y, gint width, gint height);
|
2019-03-05 05:13:15 +00:00
|
|
|
static gboolean gst_gl_window_cocoa_controls_viewport (GstGLWindow * window);
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
|
|
|
|
struct _GstGLWindowCocoaPrivate
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2017-02-03 13:46:39 +00:00
|
|
|
gpointer internal_win_id;
|
2022-07-08 18:49:21 +00:00
|
|
|
gpointer internal_view;
|
2017-02-03 13:46:39 +00:00
|
|
|
gpointer external_view;
|
2009-02-26 00:06:58 +00:00
|
|
|
gboolean visible;
|
2015-01-23 03:11:48 +00:00
|
|
|
gint preferred_width;
|
|
|
|
gint preferred_height;
|
2014-09-29 06:33:42 +00:00
|
|
|
|
2015-03-03 07:05:04 +00:00
|
|
|
/* atomic set when the internal NSView has been created */
|
|
|
|
int view_ready;
|
2016-04-10 22:34:00 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
gpointer gl_queue;
|
2020-03-26 02:51:24 +00:00
|
|
|
|
|
|
|
gboolean shutting_down;
|
|
|
|
GstGLContext *last_context;
|
2009-02-26 00:06:58 +00:00
|
|
|
};
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
|
|
|
|
|
|
|
|
#define gst_gl_window_cocoa_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLWindowCocoa, gst_gl_window_cocoa, GST_TYPE_GL_WINDOW,
|
|
|
|
G_ADD_PRIVATE (GstGLWindowCocoa)
|
|
|
|
DEBUG_INIT);
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
static void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_class_init (GstGLWindowCocoaClass * klass)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2015-03-06 04:31:18 +00:00
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_open);
|
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_close);
|
2020-03-26 02:51:24 +00:00
|
|
|
window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_quit);
|
2013-08-15 07:09:04 +00:00
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_get_window_handle);
|
2012-11-16 06:13:03 +00:00
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_set_window_handle);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_draw);
|
2015-01-23 03:11:48 +00:00
|
|
|
window_class->set_preferred_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_set_preferred_size);
|
2015-01-29 11:25:00 +00:00
|
|
|
window_class->show = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_show);
|
2015-09-17 07:06:37 +00:00
|
|
|
window_class->queue_resize = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_queue_resize);
|
2016-04-10 22:34:00 +00:00
|
|
|
window_class->send_message_async =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_send_message_async);
|
2017-12-26 13:23:11 +00:00
|
|
|
window_class->set_render_rectangle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_set_render_rectangle);
|
2019-03-05 05:13:15 +00:00
|
|
|
window_class->controls_viewport =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_controls_viewport);
|
2015-03-06 04:31:18 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_gl_window_cocoa_finalize;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_init (GstGLWindowCocoa * window)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
window->priv = gst_gl_window_cocoa_get_instance_private (window);
|
2015-01-23 03:11:48 +00:00
|
|
|
|
|
|
|
window->priv->preferred_width = 320;
|
|
|
|
window->priv->preferred_height = 240;
|
2018-04-24 22:33:43 +00:00
|
|
|
#if OS_OBJECT_USE_OBJC
|
2017-02-03 13:46:39 +00:00
|
|
|
window->priv->gl_queue = (__bridge_retained gpointer)
|
|
|
|
(dispatch_queue_create ("org.freedesktop.gstreamer.glwindow", NULL));
|
2018-04-24 22:33:43 +00:00
|
|
|
#else
|
|
|
|
window->priv->gl_queue = (gpointer)
|
|
|
|
(dispatch_queue_create ("org.freedesktop.gstreamer.glwindow", NULL));
|
|
|
|
#endif
|
2015-03-06 04:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_finalize (GObject * object)
|
|
|
|
{
|
2016-04-10 22:34:00 +00:00
|
|
|
GstGLWindowCocoa *window = GST_GL_WINDOW_COCOA (object);
|
2018-04-24 22:33:43 +00:00
|
|
|
|
|
|
|
#if OS_OBJECT_USE_OBJC
|
|
|
|
/* Let ARC clean up our queue */
|
|
|
|
dispatch_queue_t queue = (__bridge_transfer dispatch_queue_t) window->priv->gl_queue;
|
2019-08-30 03:00:14 +00:00
|
|
|
(void) queue;
|
2018-04-24 22:33:43 +00:00
|
|
|
#else
|
|
|
|
dispatch_release (window->priv->gl_queue);
|
|
|
|
#endif
|
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
window->priv->gl_queue = NULL;
|
2015-03-06 04:31:18 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *
|
2015-07-24 07:00:27 +00:00
|
|
|
gst_gl_window_cocoa_new (GstGLDisplay * display)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2017-05-15 17:31:31 +00:00
|
|
|
GstGLWindowCocoa *window;
|
|
|
|
|
2015-07-24 07:00:27 +00:00
|
|
|
if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_COCOA) == 0)
|
|
|
|
/* we require an cocoa display to create CGL windows */
|
|
|
|
return NULL;
|
2013-02-12 12:48:36 +00:00
|
|
|
|
2017-05-15 17:31:31 +00:00
|
|
|
window = g_object_new (GST_TYPE_GL_WINDOW_COCOA, NULL);
|
|
|
|
gst_object_ref_sink (window);
|
|
|
|
|
|
|
|
return window;
|
2013-02-12 12:48:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
/* Must be called from the main thread */
|
2013-02-12 12:48:36 +00:00
|
|
|
gboolean
|
2015-02-17 05:39:56 +00:00
|
|
|
gst_gl_window_cocoa_create_window (GstGLWindowCocoa *window_cocoa)
|
2013-02-12 12:48:36 +00:00
|
|
|
{
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2015-02-17 05:39:56 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_cocoa);
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLNSWindow *internal_win_id;
|
2015-02-17 05:39:56 +00:00
|
|
|
NSRect mainRect = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
gint h = priv->preferred_height;
|
|
|
|
gint y = mainRect.size.height > h ? (mainRect.size.height - h) * 0.5 : 0;
|
|
|
|
NSRect rect = NSMakeRect (0, y, priv->preferred_width, priv->preferred_height);
|
|
|
|
NSRect windowRect = NSMakeRect (0, y, priv->preferred_width, priv->preferred_height);
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
2017-07-15 15:17:04 +00:00
|
|
|
GstGLCAOpenGLLayer *layer;
|
|
|
|
GstGLNSView *glView;
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-01-14 10:46:39 +00:00
|
|
|
layer = [[GstGLCAOpenGLLayer alloc] initWithGstGLWindow:window];
|
2017-12-26 13:23:11 +00:00
|
|
|
layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
|
|
|
|
layer.needsDisplayOnBoundsChange = YES;
|
2017-07-15 15:17:04 +00:00
|
|
|
glView = [[GstGLNSView alloc] initWithFrameLayer:window_cocoa rect:windowRect layer:layer];
|
2015-02-17 05:39:56 +00:00
|
|
|
|
|
|
|
gst_object_unref (context);
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2017-12-12 07:31:47 +00:00
|
|
|
internal_win_id = [[GstGLNSWindow alloc] initWithContentRect:rect styleMask:
|
2017-05-20 10:16:50 +00:00
|
|
|
(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
|
|
|
NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable)
|
2014-09-26 11:21:46 +00:00
|
|
|
backing: NSBackingStoreBuffered defer: NO screen: nil gstWin: window_cocoa];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
priv->internal_win_id = (__bridge_retained gpointer)internal_win_id;
|
2022-07-08 18:49:21 +00:00
|
|
|
priv->internal_view = (__bridge gpointer)glView;
|
2017-02-03 13:46:39 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("NSWindow id: %"G_GUINTPTR_FORMAT, (guintptr) priv->internal_win_id);
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
[internal_win_id setContentView:glView];
|
2015-03-03 07:05:04 +00:00
|
|
|
|
|
|
|
g_atomic_int_set (&window_cocoa->priv->view_ready, 1);
|
2015-02-17 05:39:56 +00:00
|
|
|
|
2017-07-15 16:25:36 +00:00
|
|
|
/* Set the window handle for real now that the NSWindow has been created. */
|
|
|
|
if (priv->external_view)
|
|
|
|
gst_gl_window_cocoa_set_window_handle (window,
|
|
|
|
(guintptr) priv->external_view);
|
|
|
|
|
2023-05-11 18:01:45 +00:00
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
return TRUE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_window_cocoa_open (GstGLWindow *window, GError **err)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-20 11:44:12 +00:00
|
|
|
_close_window (gpointer * data)
|
2014-09-25 13:13:19 +00:00
|
|
|
{
|
2019-03-20 11:44:12 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (data);
|
2022-07-08 18:49:21 +00:00
|
|
|
GstGLNSView *view =
|
|
|
|
(__bridge GstGLNSView *) window_cocoa->priv->internal_view;
|
|
|
|
|
|
|
|
[view removeFromSuperview];
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2019-03-20 11:44:12 +00:00
|
|
|
CFBridgingRelease (window_cocoa->priv->internal_win_id);
|
2022-07-08 18:49:21 +00:00
|
|
|
CFBridgingRelease (window_cocoa->priv->internal_view);
|
2017-02-03 13:46:39 +00:00
|
|
|
window_cocoa->priv->internal_win_id = NULL;
|
2022-07-08 18:49:21 +00:00
|
|
|
window_cocoa->priv->internal_view = NULL;
|
2014-09-25 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 11:44:12 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_close (GstGLWindow * window)
|
|
|
|
{
|
2022-10-21 16:20:01 +00:00
|
|
|
_gst_gl_invoke_on_main ((GstGLWindowCB) _close_window,
|
|
|
|
gst_object_ref (window), (GDestroyNotify) gst_object_unref);
|
2019-03-20 11:44:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr
|
|
|
|
gst_gl_window_cocoa_get_window_handle (GstGLWindow *window)
|
2009-10-26 10:44:35 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
return (guintptr) GST_GL_WINDOW_COCOA (window)->priv->internal_win_id;
|
2009-10-26 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_set_window_handle (GstGLWindow * window, guintptr handle)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstGLWindowCocoaPrivate *priv;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
priv = window_cocoa->priv;
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2013-07-11 19:22:57 +00:00
|
|
|
if (priv->internal_win_id) {
|
2013-11-30 16:38:13 +00:00
|
|
|
if (handle) {
|
2017-02-03 13:46:39 +00:00
|
|
|
priv->external_view = (gpointer)handle;
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = TRUE;
|
|
|
|
} else {
|
|
|
|
/* bring back our internal window */
|
2014-04-24 09:37:00 +00:00
|
|
|
priv->external_view = 0;
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = FALSE;
|
|
|
|
}
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
dispatch_async (dispatch_get_main_queue (), ^{
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLNSWindow *internal_win_id =
|
|
|
|
(__bridge GstGLNSWindow *)window_cocoa->priv->internal_win_id;
|
|
|
|
NSView *external_view =
|
|
|
|
(__bridge NSView *)window_cocoa->priv->external_view;
|
2022-07-08 18:49:21 +00:00
|
|
|
NSView *view = (__bridge NSView *)window_cocoa->priv->internal_view;
|
2014-09-26 11:21:46 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
[internal_win_id orderOut:internal_win_id];
|
2014-09-26 11:21:46 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
[external_view addSubview: view];
|
|
|
|
|
2017-12-26 13:23:11 +00:00
|
|
|
[external_view setAutoresizesSubviews: YES];
|
2017-02-03 13:46:39 +00:00
|
|
|
[view setFrame: [external_view bounds]];
|
2014-09-26 11:21:46 +00:00
|
|
|
[view setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
});
|
2013-11-30 16:38:13 +00:00
|
|
|
} else {
|
2014-09-25 13:13:19 +00:00
|
|
|
/* no internal window yet so delay it to the next drawing */
|
2017-02-03 13:46:39 +00:00
|
|
|
priv->external_view = (gpointer)handle;
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = FALSE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 07:17:59 +00:00
|
|
|
static void
|
|
|
|
_show_window (gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (data);
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
|
2015-02-17 07:17:59 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (window_cocoa, "make the window available\n");
|
2017-02-03 13:46:39 +00:00
|
|
|
[internal_win_id makeMainWindow];
|
|
|
|
[internal_win_id orderFrontRegardless];
|
|
|
|
[internal_win_id setViewsNeedDisplay:YES];
|
2015-02-17 07:17:59 +00:00
|
|
|
|
|
|
|
priv->visible = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-01-29 11:25:00 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_show (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
|
|
|
|
|
|
|
if (!priv->visible) {
|
|
|
|
/* useful when set_window_handle is called before
|
|
|
|
* the internal NSWindow */
|
|
|
|
if (priv->external_view) {
|
|
|
|
gst_gl_window_cocoa_set_window_handle (window, (guintptr) priv->external_view);
|
|
|
|
priv->visible = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-17 07:17:59 +00:00
|
|
|
if (!priv->external_view && !priv->visible)
|
2022-10-21 16:20:01 +00:00
|
|
|
_gst_gl_invoke_on_main ((GstGLWindowCB) _show_window,
|
|
|
|
gst_object_ref (window), (GDestroyNotify) gst_object_unref);
|
2015-01-29 11:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2015-09-17 07:06:37 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_queue_resize (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2022-07-08 18:49:21 +00:00
|
|
|
GstGLNSView *view = (__bridge GstGLNSView *)priv->internal_view;
|
2015-09-17 07:06:37 +00:00
|
|
|
|
|
|
|
if (!g_atomic_int_get (&window_cocoa->priv->view_ready))
|
|
|
|
return;
|
|
|
|
|
|
|
|
[view->layer queueResize];
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
2015-01-23 03:11:48 +00:00
|
|
|
gst_gl_window_cocoa_draw (GstGLWindow * window)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2015-01-20 11:01:39 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2022-07-08 18:49:21 +00:00
|
|
|
GstGLNSView *view = (__bridge GstGLNSView *)priv->internal_view;
|
2015-03-03 07:05:04 +00:00
|
|
|
|
|
|
|
/* As the view is created asynchronously in the main thread we cannot know
|
|
|
|
* exactly when it will be ready to draw to */
|
|
|
|
if (!g_atomic_int_get (&window_cocoa->priv->view_ready))
|
|
|
|
return;
|
|
|
|
|
2015-01-20 11:01:39 +00:00
|
|
|
/* this redraws the GstGLCAOpenGLLayer which calls
|
2015-02-03 00:07:58 +00:00
|
|
|
* gst_gl_window_cocoa_draw_thread(). Use an explicit CATransaction since we
|
|
|
|
* don't know how often the main runloop is running.
|
2015-01-20 11:01:39 +00:00
|
|
|
*/
|
2015-02-03 00:07:58 +00:00
|
|
|
[CATransaction begin];
|
|
|
|
[view setNeedsDisplay:YES];
|
|
|
|
[CATransaction commit];
|
2014-09-25 13:13:19 +00:00
|
|
|
}
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2015-01-23 03:11:48 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_set_preferred_size (GstGLWindow * window, gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
|
|
|
|
window_cocoa->priv->preferred_width = width;
|
|
|
|
window_cocoa->priv->preferred_height = height;
|
|
|
|
}
|
|
|
|
|
2015-01-29 06:31:09 +00:00
|
|
|
static void
|
|
|
|
gst_gl_cocoa_draw_cb (GstGLWindowCocoa *window_cocoa)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
|
2015-01-29 06:31:09 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
if (internal_win_id && ![internal_win_id isClosed]) {
|
2019-03-05 05:13:15 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_cocoa);
|
2015-01-29 06:31:09 +00:00
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
/* draw opengl scene in the back buffer */
|
2019-03-05 05:13:15 +00:00
|
|
|
/* We do not need to change viewports like in other window implementations
|
|
|
|
* as the caopengllayer will take care of that for us. */
|
2016-10-26 05:30:43 +00:00
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
2015-01-29 06:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_cocoa_resize_cb (GstGLNSView * view, guint width, guint height)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = view->window_cocoa;
|
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_cocoa);
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
|
|
|
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
|
2015-01-29 06:31:09 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
if (internal_win_id && ![internal_win_id isClosed]) {
|
2015-01-29 06:31:09 +00:00
|
|
|
const GstGLFuncs *gl;
|
|
|
|
NSRect bounds = [view bounds];
|
|
|
|
NSRect visibleRect = [view visibleRect];
|
|
|
|
gint viewport_dim[4];
|
2019-03-05 05:13:15 +00:00
|
|
|
GstVideoRectangle viewport;
|
2015-01-29 06:31:09 +00:00
|
|
|
|
|
|
|
gl = context->gl_vtable;
|
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
|
|
|
bounds = [view convertRectToBacking:bounds];
|
|
|
|
visibleRect = [view convertRectToBacking:visibleRect];
|
|
|
|
#endif
|
|
|
|
|
2019-03-05 05:13:15 +00:00
|
|
|
/* don't use the default gst_gl_window_resize() as that will marshal through
|
|
|
|
* the GL thread. We are being called from the main thread by the
|
|
|
|
* caopengllayer */
|
|
|
|
if (window->resize)
|
|
|
|
window->resize (window->resize_data, width, height);
|
|
|
|
|
|
|
|
gl->GetIntegerv (GL_VIEWPORT, viewport_dim);
|
|
|
|
|
2015-01-29 06:31:09 +00:00
|
|
|
GST_DEBUG_OBJECT (window, "Window resized: bounds %lf %lf %lf %lf "
|
2019-03-05 05:13:15 +00:00
|
|
|
"visibleRect %lf %lf %lf %lf, "
|
|
|
|
"viewport dimensions %i %i %i %i",
|
2015-01-29 06:31:09 +00:00
|
|
|
bounds.origin.x, bounds.origin.y,
|
|
|
|
bounds.size.width, bounds.size.height,
|
|
|
|
visibleRect.origin.x, visibleRect.origin.y,
|
2019-03-05 05:13:15 +00:00
|
|
|
visibleRect.size.width, visibleRect.size.height,
|
|
|
|
viewport_dim[0], viewport_dim[1], viewport_dim[2],
|
|
|
|
viewport_dim[3]);
|
2015-01-29 06:31:09 +00:00
|
|
|
|
2019-03-05 05:13:15 +00:00
|
|
|
viewport.x = viewport_dim[0] - visibleRect.origin.x;
|
|
|
|
viewport.x = viewport_dim[1] - visibleRect.origin.y;
|
|
|
|
viewport.w = viewport_dim[2];
|
|
|
|
viewport.h = viewport_dim[3];
|
2015-01-29 06:31:09 +00:00
|
|
|
|
2019-03-05 05:13:15 +00:00
|
|
|
gl->Viewport (viewport.x, viewport.y, viewport.w, viewport.h);
|
2015-01-29 06:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (context);
|
|
|
|
}
|
|
|
|
|
2016-04-10 22:34:00 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = (GstGLWindowCocoa *) window;
|
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
2020-03-26 02:51:24 +00:00
|
|
|
GstGLContext *unref_context = NULL;
|
|
|
|
GThread *thread = NULL;
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2018-04-24 22:33:43 +00:00
|
|
|
#if OS_OBJECT_USE_OBJC
|
2017-02-03 13:46:39 +00:00
|
|
|
dispatch_queue_t gl_queue = (__bridge dispatch_queue_t)priv->gl_queue;
|
2018-04-24 22:33:43 +00:00
|
|
|
#else
|
|
|
|
dispatch_queue_t gl_queue = (dispatch_queue_t)priv->gl_queue;
|
|
|
|
#endif
|
2016-04-10 22:34:00 +00:00
|
|
|
|
2020-03-26 02:51:24 +00:00
|
|
|
if (context)
|
|
|
|
window_cocoa->priv->last_context = unref_context = context;
|
|
|
|
|
|
|
|
/* we may not have a context if we are shutting down */
|
|
|
|
if (!context && window_cocoa->priv->shutting_down) {
|
|
|
|
context = window_cocoa->priv->last_context;
|
|
|
|
window_cocoa->priv->shutting_down = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
|
|
|
|
thread = gst_gl_context_get_thread (context);
|
|
|
|
|
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);
|
2020-03-26 02:51:24 +00:00
|
|
|
if (unref_context)
|
|
|
|
gst_object_unref (unref_context);
|
2016-04-10 22:34:00 +00:00
|
|
|
} else {
|
2017-02-03 13:46:39 +00:00
|
|
|
dispatch_async (gl_queue, ^{
|
2016-04-10 22:34:00 +00:00
|
|
|
gst_gl_context_activate (context, TRUE);
|
2020-03-26 02:51:24 +00:00
|
|
|
if (unref_context)
|
|
|
|
gst_object_unref (unref_context);
|
2016-04-10 22:34:00 +00:00
|
|
|
callback (data);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-03-26 02:51:24 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_quit (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = (GstGLWindowCocoa *) window;
|
|
|
|
|
|
|
|
window_cocoa->priv->shutting_down = TRUE;
|
|
|
|
|
|
|
|
GST_GL_WINDOW_CLASS (parent_class)->quit (window);
|
|
|
|
}
|
|
|
|
|
2017-12-26 13:23:11 +00:00
|
|
|
struct SetRenderRectangle
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstVideoRectangle rect;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_free_set_render_rectangle (struct SetRenderRectangle *render)
|
|
|
|
{
|
|
|
|
if (render) {
|
|
|
|
if (render->window_cocoa) {
|
|
|
|
gst_object_unref (render->window_cocoa);
|
|
|
|
}
|
|
|
|
g_free (render);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_set_render_rectangle (gpointer data)
|
|
|
|
{
|
|
|
|
struct SetRenderRectangle *render = data;
|
|
|
|
GstGLWindowCocoaPrivate *priv = render->window_cocoa->priv;
|
2022-07-08 18:49:21 +00:00
|
|
|
GstGLNSView *view = (__bridge GstGLNSView *)priv->internal_view;
|
2017-12-26 13:23:11 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (render->window_cocoa, "setting render rectangle %i,%i+%ix%i",
|
|
|
|
render->rect.x, render->rect.y, render->rect.w, render->rect.h);
|
|
|
|
if (!g_atomic_int_get (&render->window_cocoa->priv->view_ready)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:08:58 +00:00
|
|
|
NSRect newMainViewFrame = NSMakeRect(render->rect.x,
|
2017-12-26 13:23:11 +00:00
|
|
|
render->rect.y,
|
|
|
|
render->rect.w,
|
|
|
|
render->rect.h);
|
|
|
|
|
|
|
|
[view.superview setFrame:newMainViewFrame];
|
|
|
|
[view setFrame: view.superview.bounds];
|
|
|
|
|
|
|
|
[CATransaction begin];
|
|
|
|
[view setNeedsDisplay:YES];
|
|
|
|
[CATransaction commit];
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_window_cocoa_set_render_rectangle (GstGLWindow * window, gint x, gint y, gint width, gint height)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = (GstGLWindowCocoa *) window;
|
|
|
|
struct SetRenderRectangle *render;
|
|
|
|
|
|
|
|
render = g_new0 (struct SetRenderRectangle, 1);
|
|
|
|
render->window_cocoa = gst_object_ref (window_cocoa);
|
|
|
|
render->rect.x = x;
|
|
|
|
render->rect.y = y;
|
|
|
|
render->rect.w = width;
|
|
|
|
render->rect.h = height;
|
|
|
|
|
2022-10-21 16:20:01 +00:00
|
|
|
_gst_gl_invoke_on_main ((GstGLWindowCB) _set_render_rectangle, render,
|
|
|
|
(GDestroyNotify) _free_set_render_rectangle);
|
2017-12-26 13:23:11 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:13:15 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_window_cocoa_controls_viewport (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLNSWindow implementation */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
/* Must be called from the main thread */
|
2009-02-26 00:06:58 +00:00
|
|
|
@implementation GstGLNSWindow
|
|
|
|
|
|
|
|
- (id) initWithContentRect: (NSRect) contentRect
|
2009-07-17 14:47:41 +00:00
|
|
|
styleMask: (unsigned int) styleMask
|
2009-02-26 00:06:58 +00:00
|
|
|
backing: (NSBackingStoreType) bufferingType
|
|
|
|
defer: (BOOL) flag screen: (NSScreen *) aScreen
|
2012-11-16 06:13:03 +00:00
|
|
|
gstWin: (GstGLWindowCocoa *) cocoa {
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2009-04-13 05:24:06 +00:00
|
|
|
m_isClosed = NO;
|
2014-09-26 10:05:27 +00:00
|
|
|
window_cocoa = cocoa;
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
|
|
|
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
|
2009-04-13 05:24:06 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
self = [super initWithContentRect: contentRect
|
2009-07-17 14:47:41 +00:00
|
|
|
styleMask: styleMask backing: bufferingType
|
|
|
|
defer: flag screen:aScreen];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[self setReleasedWhenClosed:NO];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("initializing GstGLNSWindow\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[self setTitle:@"OpenGL renderer"];
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2015-01-20 11:01:39 +00:00
|
|
|
[self setBackgroundColor:[NSColor blackColor]];
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
[self orderOut:internal_win_id];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:12:07 +00:00
|
|
|
- (void) setClosed {
|
|
|
|
m_isClosed = YES;
|
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
- (BOOL) isClosed {
|
|
|
|
return m_isClosed;
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:12:07 +00:00
|
|
|
- (BOOL) canBecomeMainWindow {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canBecomeKeyWindow {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static void
|
|
|
|
close_window_cb (gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = data;
|
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
window = GST_GL_WINDOW (window_cocoa);
|
|
|
|
|
|
|
|
if (window->close) {
|
|
|
|
window->close (window->close_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:12:07 +00:00
|
|
|
/* Called in the main thread which is never the gl thread */
|
2009-02-26 00:06:58 +00:00
|
|
|
- (BOOL) windowShouldClose:(id)sender {
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2017-02-03 13:46:39 +00:00
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
|
|
|
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("user clicked the close button\n");
|
2017-02-03 13:46:39 +00:00
|
|
|
[internal_win_id setClosed];
|
2015-01-28 06:59:42 +00:00
|
|
|
gst_gl_window_send_message_async (GST_GL_WINDOW (window_cocoa),
|
|
|
|
(GstGLWindowCB) close_window_cb, gst_object_ref (window_cocoa),
|
|
|
|
(GDestroyNotify) gst_object_unref);
|
2009-02-26 00:06:58 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
2014-09-26 10:05:27 +00:00
|
|
|
/* GstGLNSView implementation */
|
2009-07-17 14:47:41 +00:00
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
@implementation GstGLNSView
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
/* Must be called from the application main thread */
|
2015-01-20 11:01:39 +00:00
|
|
|
- (id)initWithFrameLayer:(GstGLWindowCocoa *)window rect:(NSRect)contentRect layer:(CALayer *)layerContent {
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
self = [super initWithFrame: contentRect];
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
window_cocoa = window;
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2015-01-20 11:01:39 +00:00
|
|
|
/* The order of the next two calls matters. This creates a layer-hosted
|
|
|
|
* NSView. Calling setWantsLayer before setLayer will create a
|
|
|
|
* layer-backed NSView. See the apple developer documentation on the
|
|
|
|
* difference.
|
|
|
|
*/
|
|
|
|
[self setLayer:layerContent];
|
|
|
|
[self setWantsLayer:YES];
|
|
|
|
self->layer = (GstGLCAOpenGLLayer *)layerContent;
|
2015-01-29 06:31:09 +00:00
|
|
|
[self->layer setDrawCallback:(GstGLWindowCB)gst_gl_cocoa_draw_cb
|
|
|
|
data:window notify:NULL];
|
|
|
|
[self->layer setResizeCallback:(GstGLWindowResizeCB)gst_gl_cocoa_resize_cb
|
2017-02-03 13:46:39 +00:00
|
|
|
data:(__bridge_retained gpointer)self notify:(GDestroyNotify)CFRelease];
|
2015-01-20 11:01:39 +00:00
|
|
|
|
|
|
|
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay];
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-10-09 07:54:35 +00:00
|
|
|
[self setWantsBestResolutionOpenGLSurface:YES];
|
2014-09-26 10:05:27 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
return self;
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
- (void) dealloc {
|
2017-02-03 13:46:39 +00:00
|
|
|
self->layer = nil;
|
2014-09-26 10:05:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 08:55:13 +00:00
|
|
|
- (void)renewGState {
|
|
|
|
/* Don't update the screen until we redraw, this
|
|
|
|
* prevents flickering during scrolling, clipping,
|
|
|
|
* resizing, etc
|
|
|
|
*/
|
|
|
|
[[self window] disableScreenUpdatesUntilFlush];
|
|
|
|
|
|
|
|
[super renewGState];
|
|
|
|
}
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
- (BOOL) isOpaque {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isFlipped {
|
2014-09-29 06:33:42 +00:00
|
|
|
return NO;
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
@end
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2015-02-17 07:17:59 +00:00
|
|
|
void
|
2022-10-21 16:20:01 +00:00
|
|
|
_gst_gl_invoke_on_main (GstGLWindowCB func, gpointer data, GDestroyNotify notify)
|
2015-02-17 07:17:59 +00:00
|
|
|
{
|
|
|
|
if ([NSThread isMainThread]) {
|
|
|
|
func (data);
|
2017-07-15 15:17:04 +00:00
|
|
|
if (notify)
|
|
|
|
notify (data);
|
2015-02-17 07:17:59 +00:00
|
|
|
} else {
|
2015-03-03 07:05:04 +00:00
|
|
|
dispatch_async (dispatch_get_main_queue (), ^{
|
2015-02-17 07:17:59 +00:00
|
|
|
func (data);
|
2017-07-15 15:17:04 +00:00
|
|
|
if (notify)
|
|
|
|
notify (data);
|
2015-02-17 07:17:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|