From d9c34e9cdd24937a3c487d0f525a8b8b38ee1ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 26 Aug 2013 10:49:48 +0200 Subject: [PATCH] Repaint widgets on screen change. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a screenChanged handler slot to QWidgetWindow, which calls markDirty() on the backing store with the BufferInvalid and UpdateNow flags set. Update CocoaBackingStore to create a new buffer on window devicePixelRatio change. Use the QCocoaWindow::devicePixelRatio() implementation instead of a duplicate implementation in the backing store. The plan is to replace this implementation with one based on QUpdateWindowRequestEvent for Qt 5.4 Change-Id: I8e521c53df4ac90815613e730fe821996334721f Reviewed-by: Jørgen Lind --- .../platforms/cocoa/qcocoabackingstore.mm | 23 ++++++++----------- src/widgets/kernel/qwidgetwindow.cpp | 14 +++++++++++ src/widgets/kernel/qwidgetwindow_qpa_p.h | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 3ca611b537..2222b51a42 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -59,25 +59,20 @@ QCocoaBackingStore::~QCocoaBackingStore() QPaintDevice *QCocoaBackingStore::paintDevice() { - if (m_qImage.size() / m_qImage.devicePixelRatio() != m_requestedSize) { + QCocoaWindow *cocoaWindow = static_cast(window()->handle()); + int windowDevicePixelRatio = int(cocoaWindow->devicePixelRatio()); + + // Receate the backing store buffer if the effective buffer size has changed, + // either due to a window resize or devicePixelRatio change. + QSize effectiveBufferSize = m_requestedSize * windowDevicePixelRatio; + if (m_qImage.size() != effectiveBufferSize) { CGImageRelease(m_cgImage); m_cgImage = 0; - int scaleFactor = 1; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) { - QCocoaWindow *cocoaWindow = static_cast(window()->handle()); - if (cocoaWindow && cocoaWindow->m_contentView && [cocoaWindow->m_contentView window]) { - scaleFactor = int([[cocoaWindow->m_contentView window] backingScaleFactor]); - } - } -#endif - - QCocoaWindow *cocoaWindow = static_cast(window()->handle()); QImage::Format format = (window()->format().hasAlpha() || cocoaWindow->m_drawContentBorderGradient) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; - m_qImage = QImage(m_requestedSize * scaleFactor, format); - m_qImage.setDevicePixelRatio(scaleFactor); + m_qImage = QImage(effectiveBufferSize, format); + m_qImage.setDevicePixelRatio(windowDevicePixelRatio); if (format == QImage::Format_ARGB32_Premultiplied) m_qImage.fill(Qt::transparent); } diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index e50736d6b8..ef138267bb 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -100,6 +100,7 @@ QWidgetWindow::QWidgetWindow(QWidget *widget) setSurfaceType(QSurface::RasterGLSurface); } connect(m_widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName); + connect(this, SIGNAL(screenChanged(QScreen*)), this, SLOT(repaintWindow())); } QWidgetWindow::~QWidgetWindow() @@ -560,6 +561,19 @@ void QWidgetWindow::updateGeometry() m_widget->data->fstrut_dirty = false; } +// Invalidates the backing store buffer and repaints immediately. +// ### Qt 5.4: replace with QUpdateWindowRequestEvent. +void QWidgetWindow::repaintWindow() +{ + if (!m_widget->isVisible() || !m_widget->updatesEnabled()) + return; + + QTLWExtra *tlwExtra = m_widget->window()->d_func()->maybeTopData(); + if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) + tlwExtra->backingStoreTracker->markDirty(m_widget->rect(), m_widget, + QWidgetBackingStore::UpdateNow, QWidgetBackingStore::BufferInvalid); +} + Qt::WindowState effectiveState(Qt::WindowStates state); // Store normal geometry used for saving application settings. diff --git a/src/widgets/kernel/qwidgetwindow_qpa_p.h b/src/widgets/kernel/qwidgetwindow_qpa_p.h index 8d6f14a669..06ba8ea646 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa_p.h +++ b/src/widgets/kernel/qwidgetwindow_qpa_p.h @@ -101,6 +101,7 @@ protected: private slots: void updateObjectName(); + void repaintWindow(); private: void updateGeometry();