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 <gabriel.dedietrich@digia.com>
This commit is contained in:
Morten Johan Sørvig 2014-10-06 14:36:06 +02:00
parent a1d66c9aee
commit a7f1eb4ab3

View File

@ -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
{