Skip to content

Commit

Permalink
macOS: Treat default swapInterval (-1) as vsync-enabled display-link
Browse files Browse the repository at this point in the history
Change-Id: I6d3d241d3813bfac36155ad219d4a338cb1ef6f7
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
torarnv committed Feb 11, 2019
1 parent 21e25ff commit 17e5158
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/plugins/platforms/cocoa/qcocoascreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void flushOutput() {
auto windows = QGuiApplication::allWindows();
for (int i = 0; i < windows.size(); ++i) {
QWindow *window = windows.at(i);
QPlatformWindow *platformWindow = window->handle();
auto *platformWindow = static_cast<QCocoaWindow*>(window->handle());
if (!platformWindow)
continue;

Expand All @@ -341,7 +341,7 @@ void flushOutput() {
continue;

// Skip windows that are not doing update requests via display link
if (!(window->format().swapInterval() > 0))
if (!platformWindow->updatesWithDisplayLink())
continue;

platformWindow->deliverUpdateRequest();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/platforms/cocoa/qcocoawindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class QCocoaWindow : public QObject, public QPlatformWindow
bool isForeignWindow() const override;

void requestUpdate() override;
bool updatesWithDisplayLink() const;
void deliverUpdateRequest() override;

void requestActivateWindow() override;
Expand Down
13 changes: 9 additions & 4 deletions src/plugins/platforms/cocoa/qcocoawindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1473,18 +1473,23 @@ Posted whenever an NSView object that has attached surfaces (that is,

void QCocoaWindow::requestUpdate()
{
const int swapInterval = format().swapInterval();
qCDebug(lcQpaDrawing) << "QCocoaWindow::requestUpdate" << window() << "swapInterval" << swapInterval;
qCDebug(lcQpaDrawing) << "QCocoaWindow::requestUpdate" << window()
<< "using" << (updatesWithDisplayLink() ? "display-link" : "timer");

if (swapInterval > 0) {
// Vsync is enabled, deliver via CVDisplayLink
if (updatesWithDisplayLink()) {
static_cast<QCocoaScreen *>(screen())->requestUpdate();
} else {
// Fall back to the un-throttled timer-based callback
QPlatformWindow::requestUpdate();
}
}

bool QCocoaWindow::updatesWithDisplayLink() const
{
// Update via CVDisplayLink if Vsync is enabled
return format().swapInterval() != 0;
}

void QCocoaWindow::deliverUpdateRequest()
{
// Don't send update requests for views that need display, as the update
Expand Down

0 comments on commit 17e5158

Please sign in to comment.