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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6185>
This commit is contained in:
Piotr Brzeziński 2024-02-22 16:36:40 +01:00 committed by GStreamer Marge Bot
parent cca0bc31a7
commit ca0d4dd6cc

View file

@ -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;
}