macOS: Handle backing property changes in a single place

Change-Id: I70d57632a1756f74249f64d4d4c405cb3120a179
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-09-19 18:09:52 +02:00
parent 6db83e2584
commit 04dcc902eb
3 changed files with 12 additions and 20 deletions

View File

@ -161,7 +161,6 @@ 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();

View File

@ -1262,17 +1262,6 @@ 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()
{

View File

@ -211,17 +211,21 @@
- (void)viewDidChangeBackingProperties
{
CALayer *layer = self.layer;
if (!layer)
return;
qCDebug(lcQpaDrawing) << "Backing properties changed for" << self;
layer.contentsScale = self.window.backingScaleFactor;
if (CALayer *layer = self.layer) {
layer.contentsScale = self.window.backingScaleFactor;
// Metal layers must be manually updated on e.g. screen change
if ([layer isKindOfClass:CAMetalLayer.class]) {
[self updateMetalLayerDrawableSize:static_cast<CAMetalLayer* >(layer)];
[self setNeedsDisplay:YES];
// Metal layers must be manually updated on e.g. screen change
if ([layer isKindOfClass:CAMetalLayer.class])
[self updateMetalLayerDrawableSize:static_cast<CAMetalLayer* >(layer)];
}
// Ideally we would plumb this situation through QPA in a way that lets
// clients invalidate their own caches, recreate QBackingStore, etc.
// For now we trigger an expose, and let QCocoaBackingStore deal with
// buffer invalidation internally.
[self setNeedsDisplay:YES];
}
@end