From 00b63b18ce62c6932a0b0fe566239649162be0d4 Mon Sep 17 00:00:00 2001 From: Andras Becsi Date: Tue, 29 Jul 2014 14:10:50 +0200 Subject: Allow lower case resource names in native interface on Windows The native interface implementation in QEGLPlatformIntegration lower-cases the resource key strings, where as in the Windows implementation we currently only check for camel-case resource names to retriece the same resources. Make it possible to use lower-case strings on Windows as well by using the same key look-up mechanism as used in the eglfs implementation. Change-Id: Id2a594310df610cadbe420409c090f0abb316474 Reviewed-by: Laszlo Agocs --- .../platforms/windows/qwindowsnativeinterface.cpp | 50 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp index 8ec1d8eb2f..ce28166e4f 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp @@ -51,6 +51,36 @@ QT_BEGIN_NAMESPACE +enum ResourceType { + RenderingContextType, + EglContextType, + EglDisplayType, + EglConfigType, + HandleType, + GlHandleType, + GetDCType, + ReleaseDCType +}; + +static int resourceType(const QByteArray &key) +{ + static const QByteArray names[] = { // match ResourceType + "renderingcontext", + "eglcontext", + "egldisplay", + "eglconfig", + "handle", + "glhandle", + "getdc", + "releasedc" + }; + const QByteArray *end = names + sizeof(names) / sizeof(names[0]); + const QByteArray *result = std::find(names, end, key); + if (result == end) + result = std::find(names, end, key.toLower()); + return int(result - names); +} + void *QWindowsNativeInterface::nativeResourceForWindow(const QByteArray &resource, QWindow *window) { if (!window || !window->handle()) { @@ -58,14 +88,15 @@ void *QWindowsNativeInterface::nativeResourceForWindow(const QByteArray &resourc return 0; } QWindowsWindow *bw = static_cast(window->handle()); - if (resource == "handle") + int type = resourceType(resource); + if (type == HandleType) return bw->handle(); switch (window->surfaceType()) { case QWindow::RasterSurface: case QWindow::RasterGLSurface: - if (resource == "getDC") + if (type == GetDCType) return bw->getDC(); - if (resource == "releaseDC") { + if (type == ReleaseDCType) { bw->releaseDC(); return 0; } @@ -111,7 +142,7 @@ QVariantMap QWindowsNativeInterface::windowProperties(QPlatformWindow *window) c void *QWindowsNativeInterface::nativeResourceForIntegration(const QByteArray &resource) { #ifndef QT_NO_OPENGL - if (resource == QByteArrayLiteral("glhandle")) + if (resourceType(resource) == GlHandleType) return QWindowsIntegration::staticOpenGLContext()->moduleHandle(); #endif @@ -127,12 +158,17 @@ void *QWindowsNativeInterface::nativeResourceForContext(const QByteArray &resour } QWindowsOpenGLContext *glcontext = static_cast(context->handle()); - if (resource == QByteArrayLiteral("renderingContext") || resource == QByteArrayLiteral("eglContext")) + switch (resourceType(resource)) { + case RenderingContextType: // Fall through. + case EglContextType: return glcontext->nativeContext(); - if (resource == QByteArrayLiteral("eglDisplay")) + case EglDisplayType: return glcontext->nativeDisplay(); - if (resource == QByteArrayLiteral("eglConfig")) + case EglConfigType: return glcontext->nativeConfig(); + default: + break; + } qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData()); return 0; -- cgit v1.2.3