From a7f1eb4ab35a74e401c41d77e5fad13193c25c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 6 Oct 2014 14:36:06 +0200 Subject: [PATCH] Correct devicePixelRatio for software OpenGL [NSView setWantsBestResulutionOpenGLSurface] is a hint and the driver may ignore it, for example when using software OpenGL on a virtual machine. In these cases devicePixelRatio() must return a value corresponding to the actual OpenGL surface size. Use [NSView convertSizeToBacking] which is one of the recommended methods. Task-number: QTBUG-41767 Change-Id: Ia79242219908a2454a83b44b6eb7463372764162 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoawindow.mm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index a0e02501de..9259c2c772 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1746,12 +1746,13 @@ qreal QCocoaWindow::devicePixelRatio() const { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) { - NSWindow* window = [m_contentView window]; - if (window) { - return qreal([window backingScaleFactor]); - } else { - return 1.0; - } + // The documented way to observe the relationship between device-independent + // and device pixels is to use one for the convertToBacking functions. Other + // methods such as [NSWindow backingScaleFacor] might not give the correct + // result, for example if setWantsBestResolutionOpenGLSurface is not set or + // or ignored by the OpenGL driver. + NSSize backingSize = [m_contentView convertSizeToBacking:NSMakeSize(1.0, 1.0)]; + return backingSize.height; } else #endif {