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 <laszlo.agocs@digia.com>
bb10
Andras Becsi 2014-07-29 14:10:50 +02:00
parent 4010cfbf2d
commit 00b63b18ce
1 changed files with 43 additions and 7 deletions

View File

@ -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<QWindowsWindow *>(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<QWindowsOpenGLContext *>(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;