From c410163173f7f4e4afe4823b56a71aa20a954ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 7 Jun 2024 14:34:28 +0200 Subject: [PATCH] Report 2.x scale factor for UIView on visionOS The docs claim that this is the default, but in practice it's not the case. Change-Id: I5f6184cbfded2efedbac88023644d3c1e80e9901 Reviewed-by: Timur Pocheptsov (cherry picked from commit a05f5457ca033214c1efcf528b85a09a9c758920) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/ios/qiosscreen.mm | 5 ++++- src/plugins/platforms/ios/quiview.mm | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 7559979f330..8f3081e276c 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -322,7 +322,10 @@ QDpi QIOSScreen::logicalBaseDpi() const qreal QIOSScreen::devicePixelRatio() const { #if defined(Q_OS_VISIONOS) - return 2.0; // Based on what iPad app reports + // Based on what iPad app reports, and what Apple + // documents to be the default scale factor on + // visionOS, and the minimum scale for assets. + return 2.0; #else return [m_uiScreen scale]; #endif diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index 932b4eca603..cc4b92b92b2 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -139,6 +139,14 @@ inline ulong getTimeStamp(UIEvent *event) }; } #endif + +#if defined(Q_OS_VISIONOS) + // Although the "Drawing sharp layer-based content in visionOS" docs + // claim that by default a CALayer rasterizes at a 2x scale this does + // not seem to be the case in practice. So we explicitly set the view's + // scale factor based on the screen, where we hard-code it to 2.0. + self.contentScaleFactor = self.platformWindow->screen()->devicePixelRatio(); +#endif } return self;