macOS: Invalidate backingstore and trigger expose on color space changes
Fixes: QTBUG-77749 Change-Id: I677a71152e4a218c08d8863d4f886d158a79e809 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
ee82f86615
commit
e688e28ee5
@ -54,6 +54,8 @@ class QCocoaBackingStore : public QRasterBackingStore
|
||||
protected:
|
||||
QCocoaBackingStore(QWindow *window);
|
||||
QCFType<CGColorSpaceRef> colorSpace() const;
|
||||
QMacNotificationObserver m_backingPropertiesObserver;
|
||||
virtual void backingPropertiesChanged() = 0;
|
||||
};
|
||||
|
||||
class QNSWindowBackingStore : public QCocoaBackingStore
|
||||
@ -69,6 +71,7 @@ private:
|
||||
bool windowHasUnifiedToolbar() const;
|
||||
QImage::Format format() const override;
|
||||
void redrawRoundedBottomCorners(CGRect) const;
|
||||
void backingPropertiesChanged() override;
|
||||
};
|
||||
|
||||
class QCALayerBackingStore : public QCocoaBackingStore
|
||||
@ -115,6 +118,8 @@ private:
|
||||
bool recreateBackBufferIfNeeded();
|
||||
bool prepareForFlush();
|
||||
|
||||
void backingPropertiesChanged() override;
|
||||
|
||||
std::list<std::unique_ptr<GraphicsBuffer>> m_buffers;
|
||||
};
|
||||
|
||||
|
@ -51,6 +51,17 @@ QT_BEGIN_NAMESPACE
|
||||
QCocoaBackingStore::QCocoaBackingStore(QWindow *window)
|
||||
: QRasterBackingStore(window)
|
||||
{
|
||||
// Ideally this would be plumbed from the platform layer to QtGui, and
|
||||
// the QBackingStore would be recreated, but we don't have that code yet,
|
||||
// so at least make sure we invalidate our backingstore when the backing
|
||||
// properties (color space e.g.) are changed.
|
||||
NSView *view = static_cast<QCocoaWindow *>(window->handle())->view();
|
||||
m_backingPropertiesObserver = QMacNotificationObserver(view.window,
|
||||
NSWindowDidChangeBackingPropertiesNotification, [this]() {
|
||||
qCDebug(lcQpaBackingStore) << "Backing properties for"
|
||||
<< this->window() << "did change";
|
||||
backingPropertiesChanged();
|
||||
});
|
||||
}
|
||||
|
||||
QCFType<CGColorSpaceRef> QCocoaBackingStore::colorSpace() const
|
||||
@ -299,6 +310,11 @@ void QNSWindowBackingStore::redrawRoundedBottomCorners(CGRect windowRect) const
|
||||
#endif
|
||||
}
|
||||
|
||||
void QNSWindowBackingStore::backingPropertiesChanged()
|
||||
{
|
||||
m_image = QImage();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// https://stackoverflow.com/a/52722575/2761869
|
||||
@ -574,6 +590,12 @@ QImage QCALayerBackingStore::toImage() const
|
||||
return imageCopy;
|
||||
}
|
||||
|
||||
void QCALayerBackingStore::backingPropertiesChanged()
|
||||
{
|
||||
m_buffers.clear();
|
||||
m_buffers.resize(1);
|
||||
}
|
||||
|
||||
QPlatformGraphicsBuffer *QCALayerBackingStore::graphicsBuffer() const
|
||||
{
|
||||
return m_buffers.back().get();
|
||||
|
@ -161,6 +161,7 @@ public:
|
||||
Q_NOTIFICATION_HANDLER(NSWindowDidOrderOffScreenNotification) void windowDidOrderOffScreen();
|
||||
Q_NOTIFICATION_HANDLER(NSWindowDidChangeOcclusionStateNotification) void windowDidChangeOcclusionState();
|
||||
Q_NOTIFICATION_HANDLER(NSWindowDidChangeScreenNotification) void windowDidChangeScreen();
|
||||
Q_NOTIFICATION_HANDLER(NSWindowDidChangeBackingPropertiesNotification) void windowDidChangeBackingProperties();
|
||||
Q_NOTIFICATION_HANDLER(NSWindowWillCloseNotification) void windowWillClose();
|
||||
|
||||
bool windowShouldClose();
|
||||
|
@ -1261,6 +1261,17 @@ void QCocoaWindow::windowDidChangeScreen()
|
||||
currentScreen->requestUpdate();
|
||||
}
|
||||
}
|
||||
/*
|
||||
The window's backing scale factor or color space has changed.
|
||||
*/
|
||||
void QCocoaWindow::windowDidChangeBackingProperties()
|
||||
{
|
||||
// Ideally we would plumb this thought QPA in a way that lets clients
|
||||
// invalidate their own caches, and recreate QBackingStore. For now we
|
||||
// trigger an expose, and let QCocoaBackingStore deal with its own
|
||||
// buffer invalidation.
|
||||
[m_view setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
void QCocoaWindow::windowWillClose()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user