glwindow_cocoa: fix a leak of the GstNSView

This leak is also causing a leak of the GstGLCAOpenGLLayer
which leaks the GstGLWrappedContext and the GstGLDisplay

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2744>
This commit is contained in:
Andoni Morales Alastruey 2022-07-08 20:49:21 +02:00 committed by Tim-Philipp Müller
parent 5541717374
commit 9d9ecfc837

View file

@ -92,6 +92,7 @@ static gboolean gst_gl_window_cocoa_controls_viewport (GstGLWindow * window);
struct _GstGLWindowCocoaPrivate
{
gpointer internal_win_id;
gpointer internal_view;
gpointer external_view;
gboolean visible;
gint preferred_width;
@ -224,6 +225,7 @@ gst_gl_window_cocoa_create_window (GstGLWindowCocoa *window_cocoa)
backing: NSBackingStoreBuffered defer: NO screen: nil gstWin: window_cocoa];
priv->internal_win_id = (__bridge_retained gpointer)internal_win_id;
priv->internal_view = (__bridge gpointer)glView;
GST_DEBUG ("NSWindow id: %"G_GUINTPTR_FORMAT, (guintptr) priv->internal_win_id);
@ -253,12 +255,15 @@ static void
_close_window (gpointer * data)
{
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (data);
GstGLNSWindow *internal_win_id =
(__bridge GstGLNSWindow *) window_cocoa->priv->internal_win_id;
GstGLNSView *view =
(__bridge GstGLNSView *) window_cocoa->priv->internal_view;
[view removeFromSuperview];
[[internal_win_id contentView] removeFromSuperview];
CFBridgingRelease (window_cocoa->priv->internal_win_id);
CFBridgingRelease (window_cocoa->priv->internal_view);
window_cocoa->priv->internal_win_id = NULL;
window_cocoa->priv->internal_view = NULL;
}
static void
@ -299,8 +304,8 @@ gst_gl_window_cocoa_set_window_handle (GstGLWindow * window, guintptr handle)
(__bridge GstGLNSWindow *)window_cocoa->priv->internal_win_id;
NSView *external_view =
(__bridge NSView *)window_cocoa->priv->external_view;
NSView *view = (__bridge NSView *)window_cocoa->priv->internal_view;
NSView *view = [internal_win_id contentView];
[internal_win_id orderOut:internal_win_id];
[external_view addSubview: view];
@ -356,15 +361,12 @@ static void
gst_gl_window_cocoa_queue_resize (GstGLWindow * window)
{
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
GstGLNSView *view;
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
GstGLNSView *view = (__bridge GstGLNSView *)priv->internal_view;
if (!g_atomic_int_get (&window_cocoa->priv->view_ready))
return;
view = (GstGLNSView *)[internal_win_id contentView];
[view->layer queueResize];
}
@ -372,17 +374,14 @@ static void
gst_gl_window_cocoa_draw (GstGLWindow * window)
{
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
GstGLNSView *view;
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
GstGLNSView *view = (__bridge GstGLNSView *)priv->internal_view;
/* 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;
view = (GstGLNSView *)[internal_win_id contentView];
/* this redraws the GstGLCAOpenGLLayer which calls
* gst_gl_window_cocoa_draw_thread(). Use an explicit CATransaction since we
* don't know how often the main runloop is running.
@ -551,9 +550,8 @@ static void
_set_render_rectangle (gpointer data)
{
struct SetRenderRectangle *render = data;
NSView *view;
GstGLWindowCocoaPrivate *priv = render->window_cocoa->priv;
GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id;
GstGLNSView *view = (__bridge GstGLNSView *)priv->internal_view;
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);
@ -561,7 +559,6 @@ _set_render_rectangle (gpointer data)
return;
}
view = [internal_win_id contentView];
NSRect newMainViewFrame = NSMakeRect(render->rect.x,
render->rect.y,
render->rect.w,