Repaint widgets on screen change.

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 <jorgen.lind@digia.com>
This commit is contained in:
Morten Johan Sørvig 2013-08-26 10:49:48 +02:00 committed by The Qt Project
parent 6d858a0fdb
commit d9c34e9cdd
3 changed files with 24 additions and 14 deletions

View File

@ -59,25 +59,20 @@ QCocoaBackingStore::~QCocoaBackingStore()
QPaintDevice *QCocoaBackingStore::paintDevice()
{
if (m_qImage.size() / m_qImage.devicePixelRatio() != m_requestedSize) {
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(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<QCocoaWindow *>(window()->handle());
if (cocoaWindow && cocoaWindow->m_contentView && [cocoaWindow->m_contentView window]) {
scaleFactor = int([[cocoaWindow->m_contentView window] backingScaleFactor]);
}
}
#endif
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(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);
}

View File

@ -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.

View File

@ -101,6 +101,7 @@ protected:
private slots:
void updateObjectName();
void repaintWindow();
private:
void updateGeometry();