From e6eadd6f61ae38a49a6bb355c02532cad2aacf4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 11 Nov 2013 15:38:43 +0100 Subject: iOS: Flesh out device-pixel-ratio handling in QIOSWindow We don't need to cache the device-pixel-ratio, as we can ask the UIView directly. We do need to set it though, as the default behavior of matching the screen scale does not apply for EAGL-backed views, but the ratio needs to match the current screen the view is on. Change-Id: I29e4a4fa4f4b767d86265ec899fb43a355b5c3a3 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qioswindow.h | 1 - src/plugins/platforms/ios/qioswindow.mm | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/ios/qioswindow.h b/src/plugins/platforms/ios/qioswindow.h index b60290e479..9ab9a3a45e 100644 --- a/src/plugins/platforms/ios/qioswindow.h +++ b/src/plugins/platforms/ios/qioswindow.h @@ -87,7 +87,6 @@ private: QRect m_normalGeometry; int m_windowLevel; - qreal m_devicePixelRatio; void raiseOrLower(bool raise); void updateWindowLevel(); diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index f46616db1d..6d7b793f0b 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -127,6 +127,16 @@ return self; } +- (void)willMoveToWindow:(UIWindow *)newWindow +{ + // UIKIt will normally set the scale factor of a view to match the corresponding + // screen scale factor, but views backed by CAEAGLLayers need to do this manually. + self.contentScaleFactor = newWindow && newWindow.screen ? + newWindow.screen.scale : [[UIScreen mainScreen] scale]; + + // FIXME: Allow the scale factor to be customized through QSurfaceFormat. +} + - (void)layoutSubviews { // This method is the de facto way to know that view has been resized, @@ -331,19 +341,9 @@ QIOSWindow::QIOSWindow(QWindow *window) , m_view([[QUIView alloc] initWithQIOSWindow:this]) , m_normalGeometry(QPlatformWindow::geometry()) , m_windowLevel(0) - , m_devicePixelRatio(1.0) { setParent(parent()); setWindowState(window->windowState()); - - // Retina support: get screen scale factor and set it in the content view. - // This will make framebufferObject() create a 2x frame buffer on retina - // displays. Also set m_devicePixelRatio which is used for scaling the - // paint device. - if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES) { - m_devicePixelRatio = [[UIScreen mainScreen] scale]; - [m_view setContentScaleFactor: m_devicePixelRatio]; - } } QIOSWindow::~QIOSWindow() @@ -522,7 +522,7 @@ void QIOSWindow::handleContentOrientationChange(Qt::ScreenOrientation orientatio qreal QIOSWindow::devicePixelRatio() const { - return m_devicePixelRatio; + return m_view.contentScaleFactor; } QT_END_NAMESPACE -- cgit v1.2.3