mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-30 02:58:24 +00:00
[368/906] Cocoa backend: fix crash when resizing
Default implementation of NSOpenglView::update is not safe because it just calls update on the opengl context whereas we are not in the gl thread. Also fix the white flickering when resizing, because now we need to call the draw callback manually when resizing.
This commit is contained in:
parent
e467ea29e9
commit
2e22bb4560
1 changed files with 36 additions and 24 deletions
|
@ -56,10 +56,10 @@
|
|||
|
||||
@interface GstGLNSOpenGLView: NSOpenGLView {
|
||||
GstGLWindowPrivate *m_priv;
|
||||
gint m_resizeCount;
|
||||
}
|
||||
- (id) initWithFrame:(NSRect)contentRect pixelFormat:(NSOpenGLPixelFormat *)fmt
|
||||
private: (GstGLWindowPrivate *) priv;
|
||||
- (void) reshape;
|
||||
@end
|
||||
|
||||
|
||||
|
@ -396,7 +396,7 @@ gst_gl_window_run_loop (GstGLWindow * window)
|
|||
|
||||
if (priv->internal_win_id != nil) {
|
||||
while(priv->running)
|
||||
[run_loop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
|
||||
[run_loop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
||||
|
||||
[priv->internal_win_id release];
|
||||
priv->internal_win_id = nil;
|
||||
|
@ -604,12 +604,19 @@ gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
|||
self = [super initWithFrame: contentRect pixelFormat: fmt];
|
||||
|
||||
m_priv = priv;
|
||||
m_resizeCount = 0;
|
||||
|
||||
[self setWantsLayer:NO];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)reshape {
|
||||
|
||||
|
||||
if (m_resizeCount % 5 == 0) {
|
||||
m_resizeCount = 0;
|
||||
if (m_priv->resize_cb) {
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
@ -619,10 +626,15 @@ gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
|||
toSize:bounds.size private:m_priv];
|
||||
|
||||
[app_thread_performer performSelector:@selector(resizeWindow) onThread:m_priv->thread
|
||||
withObject:nil waitUntilDone:NO];
|
||||
withObject:nil waitUntilDone:YES];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
m_resizeCount++;
|
||||
}
|
||||
|
||||
- (void) update {
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -683,13 +695,10 @@ gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
|||
if (![m_priv->internal_win_id isClosed]) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
if ([[m_priv->internal_win_id contentView] lockFocusIfCanDraw]) {
|
||||
/* draw opengl scene in the back buffer */
|
||||
m_priv->draw_cb (m_priv->draw_data);
|
||||
/* Copy the back buffer to the front buffer */
|
||||
[[[m_priv->internal_win_id contentView] openGLContext] flushBuffer];
|
||||
[[m_priv->internal_win_id contentView] unlockFocus];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
@ -699,6 +708,9 @@ gst_gl_window_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
|||
- (void) resizeWindow {
|
||||
if (m_priv->running && ![m_priv->internal_win_id isClosed]) {
|
||||
m_callback2 (m_data, m_width, m_height);
|
||||
[[[m_priv->internal_win_id contentView] openGLContext] update];
|
||||
m_priv->draw_cb (m_priv->draw_data);
|
||||
[[[m_priv->internal_win_id contentView] openGLContext] flushBuffer];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue