macOS: Resolve layer contents scale based on DPR
Change-Id: I32de4610a2aebbc7e0adcad9bb3440683cae5906 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
cefd214b1b
commit
4fade3c3b8
@ -174,9 +174,11 @@
|
|||||||
// layer on a view that's already in a view hierarchy we need to manually ensure
|
// layer on a view that's already in a view hierarchy we need to manually ensure
|
||||||
// the scale is up to date.
|
// the scale is up to date.
|
||||||
if (self.superview)
|
if (self.superview)
|
||||||
layer.contentsScale = self.window.backingScaleFactor;
|
[self updateLayerContentsScale];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------- Layer updates -----------------------
|
||||||
|
|
||||||
- (NSViewLayerContentsRedrawPolicy)layerContentsRedrawPolicy
|
- (NSViewLayerContentsRedrawPolicy)layerContentsRedrawPolicy
|
||||||
{
|
{
|
||||||
// We need to set this explicitly since the super implementation
|
// We need to set this explicitly since the super implementation
|
||||||
@ -198,7 +200,7 @@
|
|||||||
qCDebug(lcQpaDrawing) << "Backing properties changed for" << self;
|
qCDebug(lcQpaDrawing) << "Backing properties changed for" << self;
|
||||||
|
|
||||||
if (self.layer)
|
if (self.layer)
|
||||||
self.layer.contentsScale = self.window.backingScaleFactor;
|
[self updateLayerContentsScale];
|
||||||
|
|
||||||
// Ideally we would plumb this situation through QPA in a way that lets
|
// Ideally we would plumb this situation through QPA in a way that lets
|
||||||
// clients invalidate their own caches, recreate QBackingStore, etc.
|
// clients invalidate their own caches, recreate QBackingStore, etc.
|
||||||
@ -207,6 +209,32 @@
|
|||||||
[self setNeedsDisplay:YES];
|
[self setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateLayerContentsScale
|
||||||
|
{
|
||||||
|
// We expect clients to fill the layer with retina aware content,
|
||||||
|
// based on the devicePixelRatio of the QWindow, so we set the
|
||||||
|
// layer's content scale to match that. By going via devicePixelRatio
|
||||||
|
// instead of applying the NSWindow's backingScaleFactor, we also take
|
||||||
|
// into account OpenGL views with wantsBestResolutionOpenGLSurface set
|
||||||
|
// to NO. In this case the window will have a backingScaleFactor of 2,
|
||||||
|
// but the QWindow will have a devicePixelRatio of 1.
|
||||||
|
auto devicePixelRatio = m_platformWindow->devicePixelRatio();
|
||||||
|
qCDebug(lcQpaDrawing) << "Updating" << self.layer << "content scale to" << devicePixelRatio;
|
||||||
|
self.layer.contentsScale = devicePixelRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This method is called by AppKit to determine whether it should update
|
||||||
|
the contentScale of the layer to match the window backing scale.
|
||||||
|
|
||||||
|
We always return NO since we're updating the contents scale manually.
|
||||||
|
*/
|
||||||
|
- (BOOL)layer:(CALayer *)layer shouldInheritContentsScale:(CGFloat)scale fromWindow:(NSWindow *)window
|
||||||
|
{
|
||||||
|
Q_UNUSED(layer); Q_UNUSED(scale); Q_UNUSED(window);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------- Draw callbacks -----------------------
|
// ----------------------- Draw callbacks -----------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user