From 8aa14a84a91d3f8116e04cbe68bfcdb0207c2a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 18 Jul 2018 18:35:29 +0200 Subject: macOS: Correctly scale CALayer contentsRect for child NSViews MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When flushing parts of a QBackingStore onto child QWindows, and we're in layer-backed mode, we need to set the contentsRect of the layer so that the layer will only show the part of the top-level-owned backingstore image that's relevant for the child window. Since the contentsRect is in unit coordinate system, we need to apply a transform, but this must be based on the top level view's size, not the image size, as the latter will be twice as big on a retina screen, giving the wrong unit rect. Change-Id: I7d6f378ed46a98272efb13406a2878ec1efe734e Reviewed-by: Simon Hausmann Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 639851e855..23a9edfa49 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -127,10 +127,11 @@ void QCocoaBackingStore::flush(QWindow *window, const QRegion ®ion, const QPo // FIXME: Figure out if there's a way to do partial updates view.layer.contents = (__bridge id)static_cast(cgImage); if (view != topLevelView) { + const CGSize topLevelSize = topLevelView.bounds.size; view.layer.contentsRect = CGRectApplyAffineTransform( [view convertRect:view.bounds toView:topLevelView], // The contentsRect is in unit coordinate system - CGAffineTransformMakeScale(1.0 / m_image.width(), 1.0 / m_image.height())); + CGAffineTransformMakeScale(1.0 / topLevelSize.width, 1.0 / topLevelSize.height)); } } else { // Normally a NSView is drawn via drawRect, as part of the display cycle in the -- cgit v1.2.3