From adfefceea5224ad9142f516e8b05607bca25b6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Brzezi=C5=84ski?= Date: Thu, 22 Feb 2024 16:36:40 +0100 Subject: [PATCH] macos: Fix glimagesink not respecting preferred size Cocoa version of glwindow only checks the preferred size upon window creation. glimagesink sets the size right before calling gst_gl_window_show(), which might be way after the window is created in some cases. If the size was set too late, glimagesink on macOS would remain 320x240 unless manually resized. This change makes sure to resize the existing window when _show() is called. Curiously, this has always been an issue, but went from manifesting every once in a while to being almost completely broken once old event loop workarounds were removed and gst_macos_main() was introduced. Part-of: --- .../gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m b/subprojects/gst-plugins-base/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m index 3a0371588f..3be6c88b01 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/cocoa/gstglwindow_cocoa.m @@ -54,6 +54,7 @@ backing: (NSBackingStoreType) bufferingType defer: (BOOL) flag screen: (NSScreen *) aScreen gstWin: (GstGLWindowCocoa *) window; +- (void) resize: (int) width height: (int) height; - (void) setClosed; - (BOOL) isClosed; - (BOOL) canBecomeMainWindow; @@ -325,6 +326,10 @@ _show_window (gpointer data) GstGLNSWindow *internal_win_id = (__bridge GstGLNSWindow *)priv->internal_win_id; GST_DEBUG_OBJECT (window_cocoa, "make the window available\n"); + + /* Preferred size might not yet be set when create_window is called, + * so we need to resize the window here to be sure. */ + [internal_win_id resize: priv->preferred_width height: priv->preferred_height]; [internal_win_id makeMainWindow]; [internal_win_id orderFrontRegardless]; [internal_win_id setViewsNeedDisplay:YES]; @@ -630,6 +635,15 @@ gst_gl_window_cocoa_controls_viewport (GstGLWindow * window) return self; } +- (void) resize: (gint) width height: (gint) height { + NSRect frame = [super frame]; + if (frame.size.width == width && frame.size.height == height) + return; + + frame.size = NSMakeSize (width, height); + [super setFrame:frame display:YES]; +} + - (void) setClosed { m_isClosed = YES; }