diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-07-02 23:10:13 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-07-07 14:40:57 +0000 |
commit | 85472b6b02b42ea624e1c00a5fd38c0d2889a731 (patch) | |
tree | a968d6b1e7df234dad747faee36390880656e3bc /src/plugins/platforms/cocoa/qcocoawindow.mm | |
parent | b3dc96ef4c0d6387bed819e614b20285b48bcfb7 (diff) |
macOS: Deliver update request via CVDisplayLink if swapInterval > 0
We use GCD for marshaling the display link update over to the main
thread, as Qt requires that the update request is delivered there.
Change-Id: I318a5b8f27dc5094ce71244401308a4044c41b39
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 5702d01cb3..47e13a9e8c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1070,8 +1070,12 @@ void QCocoaWindow::windowDidChangeScreen() if (!window()) return; - if (QCocoaScreen *cocoaScreen = QCocoaIntegration::instance()->screenForNSScreen(m_view.window.screen)) + if (QCocoaScreen *cocoaScreen = QCocoaIntegration::instance()->screenForNSScreen(m_view.window.screen)) { QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(window(), cocoaScreen->screen()); + + if (hasPendingUpdateRequest() && cocoaScreen->isRunningDisplayLink()) + requestUpdate(); // Restart display-link on new screen + } } void QCocoaWindow::windowWillClose() @@ -1330,8 +1334,16 @@ void QCocoaWindow::recreateWindowIfNeeded() void QCocoaWindow::requestUpdate() { - qCDebug(lcQpaDrawing) << "QCocoaWindow::requestUpdate" << window(); - QPlatformWindow::requestUpdate(); + const int swapInterval = format().swapInterval(); + qCDebug(lcQpaDrawing) << "QCocoaWindow::requestUpdate" << window() << "swapInterval" << swapInterval; + + if (swapInterval > 0) { + // Vsync is enabled, deliver via CVDisplayLink + static_cast<QCocoaScreen *>(screen())->requestUpdate(); + } else { + // Fall back to the un-throttled timer-based callback + QPlatformWindow::requestUpdate(); + } } void QCocoaWindow::deliverUpdateRequest() |