From 9507edddf239eb3130535a4d3e0d74b6502ed555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 30 Aug 2017 19:22:40 +0200 Subject: [PATCH] macOS: Implement QWindow::requestUpdate() in terms of setNeedsDisplay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is preferable to the timer-based default implementation of QPlatformWindow, as it gives AppKit more control of when to schedule the update, and makes sure the update is scheduled along with other views in the normal display-cycle, reducing the number of push flushes we do. QtWidgets still need to plumb the update() method to updateRequest for that to have any real effect though. In the future we may consider scheduling the update via a display link, if the window surface is set up for GL, for example. Ideally we'd also have a platform hook for the repaint() method, so that we could funnel it through display and get synchronous painting with AppKit still taking care of drawing and compositing child views. Change-Id: I136a9afa087b922aad69086548c2aa190ce75b6b Reviewed-by: Morten Johan Sørvig Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index e20f033a43..052d8f838c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -123,6 +123,7 @@ public: bool isForeignWindow() const Q_DECL_OVERRIDE; + void requestUpdate() override; void requestActivateWindow() Q_DECL_OVERRIDE; WId winId() const Q_DECL_OVERRIDE; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index f37c95aa77..aaa7a8798f 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1069,6 +1069,15 @@ void QCocoaWindow::handleExposeEvent(const QRegion ®ion) && !region.isEmpty() && !m_view.hiddenOrHasHiddenAncestor; + + QWindowPrivate *windowPrivate = qt_window_private(window()); + if (m_isExposed && windowPrivate->updateRequestPending) { + // FIXME: Should this logic for expose events be in QGuiApplication? + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::handleExposeEvent" << window() << region << "as update request"; + windowPrivate->deliverUpdateRequest(); + return; + } + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::handleExposeEvent" << window() << region << "isExposed" << isExposed(); QWindowSystemInterface::handleExposeEvent(window(), region); } @@ -1239,6 +1248,12 @@ void QCocoaWindow::recreateWindowIfNeeded() updateNSToolbar(); } +void QCocoaWindow::requestUpdate() +{ + qCDebug(lcQpaCocoaWindow) << "QCocoaWindow::requestUpdate" << window(); + [m_view setNeedsDisplay:YES]; +} + void QCocoaWindow::requestActivateWindow() { NSWindow *window = [m_view window];