Cocoa: Fix qmlscene flicker on startup.
[profile/ivi/qtbase.git] / src / plugins / platforms / cocoa / qcocoawindow.mm
index e594514..ef04fc4 100644 (file)
@@ -90,16 +90,6 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
 
     m_contentView = [[QNSView alloc] initWithQWindow:tlw];
 
-    if (tlw->surfaceType() == QWindow::OpenGLSurface) {
-        NSRect glFrame = globalGeometry(window()->geometry());
-        m_windowSurfaceView = [[NSOpenGLView alloc] initWithFrame : glFrame pixelFormat : QCocoaGLContext::createNSOpenGLPixelFormat() ];
-        [m_contentView setAutoresizesSubviews : YES];
-        [m_windowSurfaceView setAutoresizingMask : (NSViewWidthSizable | NSViewHeightSizable)];
-        [m_contentView addSubview : m_windowSurfaceView];
-    } else {
-        m_windowSurfaceView = m_contentView;
-    }
-
     setGeometry(tlw->geometry());
 
     [m_nsWindow setContentView:m_contentView];
@@ -131,8 +121,10 @@ void QCocoaWindow::setVisible(bool visible)
         if (window()->transientParent())
             setGeometry(window()->geometry());
 
+        // Make sure the QWindow has a frame ready before we show the NSWindow.
+        QWindowSystemInterface::handleSynchronousExposeEvent(window(), QRect(QPoint(), geometry().size()));
+
         [m_nsWindow makeKeyAndOrderFront:nil];
-        QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
     } else {
         [m_nsWindow orderOut:nil];
     }
@@ -166,11 +158,6 @@ NSView *QCocoaWindow::contentView() const
     return [m_nsWindow contentView];
 }
 
-NSView *QCocoaWindow::windowSurfaceView() const
-{
-    return m_windowSurfaceView;
-}
-
 void QCocoaWindow::windowDidMove()
 {
     if (m_glContext)
@@ -179,12 +166,12 @@ void QCocoaWindow::windowDidMove()
 
 void QCocoaWindow::windowDidResize()
 {
+    if (m_glContext)
+        m_glContext->update();
+
     NSRect rect = [[m_nsWindow contentView]frame];
     QRect geo(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
     QWindowSystemInterface::handleSynchronousGeometryChange(window(), geo);
-
-    if (m_glContext)
-        m_glContext->update();
 }
 
 
@@ -334,7 +321,7 @@ QNSWindow * QCocoaWindow::createWindow()
         panel = [[NSPanel alloc] initWithContentRect:frame
                                    styleMask:m_windowAttributes
                                    backing:NSBackingStoreBuffered
-                                   defer:YES];
+                                   defer:NO]; // see window case below
 //  ### crashes
 //        [panel setFloatingPanel:needFloating];
 //        [panel setWorksWhenModal:worksWhenModal];
@@ -345,7 +332,8 @@ QNSWindow * QCocoaWindow::createWindow()
         window  = [[QNSWindow alloc] initWithContentRect:frame
                                             styleMask:(NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask)
                                             backing:NSBackingStoreBuffered
-                                            defer:YES];
+                                            defer:NO]; // Deferring window creation breaks OpenGL (the GL context is set up
+                                                       // before the window is shown and needs a proper window.).
         break;
     }