From 2a6e372a490f6b539b5417b3275392ba6a041bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 3 Feb 2014 22:21:43 +0100 Subject: [PATCH] Cocoa: Option handling. Add qt_mac_resolveOption(). Support setting options using either an environment variable or a QWindow property, with a default fallback value. The options are resolved with precedence in the mentioned order. Adds options for the following: NSView setWantsBestResolutionOPenGLSurface NSVIew setWantsLayer NSOpenGLContext NSOpenGLCPSurfaceOrder The window properties use the _q_mac_camelCase format. The environment variables use the QT_MAC_ALL_CAPS format. Change-Id: I1978a02d62e107a2120d81ffdd0f7b32f7731644 Reviewed-by: Gabriel de Dietrich --- .../platforms/cocoa/qcocoaglcontext.mm | 6 ++++ src/plugins/platforms/cocoa/qcocoahelpers.h | 33 +++++++++++++++++++ src/plugins/platforms/cocoa/qcocoawindow.mm | 10 ++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index 4b637a707d..6f76892d93 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -42,6 +42,7 @@ #include "qcocoaglcontext.h" #include "qcocoawindow.h" #include "qcocoaautoreleasepool.h" +#include "qcocoahelpers.h" #include #include #include @@ -151,6 +152,11 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLCo [m_context setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity]; } + + // OpenGL surfaces can be ordered either above(default) or below the NSWindow. + const GLint order = qt_mac_resolveOption(1, "QT_MAC_OPENGL_SURFACE_ORDER"); + [m_context setValues:&order forParameter:NSOpenGLCPSurfaceOrder]; + updateSurfaceFormat(); } diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 64e1640a69..419bf631aa 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -162,6 +162,39 @@ CGContextRef qt_mac_cg_context(QPaintDevice *pdev); CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy); QImage qt_mac_toQImage(CGImageRef image); +template +T qt_mac_resolveOption(const T &fallback, const QByteArray &environment) +{ + // check for environment variable + if (!environment.isEmpty()) { + QByteArray env = qgetenv(environment); + if (!env.isEmpty()) + return T(env.toInt()); // works when T is bool, int. + } + + return fallback; +} + +template +T qt_mac_resolveOption(const T &fallback, QWindow *window, const QByteArray &property, const QByteArray &environment) +{ + // check for environment variable + if (!environment.isEmpty()) { + QByteArray env = qgetenv(environment); + if (!env.isEmpty()) + return T(env.toInt()); // works when T is bool, int. + } + + // check for window property + if (window && !property.isNull()) { + QVariant windowProperty = window->property(property); + if (windowProperty.isValid()) + return windowProperty.value(); + } + + // return default value. + return fallback; +} QT_END_NAMESPACE #endif //QCOCOAHELPERS_H diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index d13c6a8a3f..b1a230479e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -252,9 +252,15 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) // problem, except if the appilcation wants to have a "custom" viewport. // (like the hellogl example) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7 - && tlw->surfaceType() == QSurface::OpenGLSurface) - [m_contentView setWantsBestResolutionOpenGLSurface:YES]; + && tlw->surfaceType() == QSurface::OpenGLSurface) { + BOOL enable = qt_mac_resolveOption(YES, tlw, "_q_mac_wantsBestResolutionOpenGLSurface", + "QT_MAC_WANTS_BEST_RESOLUTION_OPENGL_SURFACE"); + [m_contentView setWantsBestResolutionOpenGLSurface:enable]; + } #endif + BOOL enable = qt_mac_resolveOption(NO, tlw, "_q_mac_wantsLayer", + "QT_MAC_WANTS_LAYER"); + [m_contentView setWantsLayer:enable]; } setGeometry(tlw->geometry()); recreateWindow(parent());