diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/qeglfsintegration.cpp index 14b839c2dd..ff06ac223b 100644 --- a/src/plugins/platforms/eglfs/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/qeglfsintegration.cpp @@ -194,43 +194,77 @@ QPlatformNativeInterface *QEglFSIntegration::nativeInterface() const return const_cast(this); } +enum ResourceType { + EglDisplay, + EglWindow, + EglContext +}; + +static int resourceType(const QByteArray &key) +{ + static const QByteArray names[] = { // match ResourceType + QByteArrayLiteral("egldisplay"), + QByteArrayLiteral("eglwindow"), + QByteArrayLiteral("eglcontext") + }; + 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 *QEglFSIntegration::nativeResourceForIntegration(const QByteArray &resource) { - QByteArray lowerCaseResource = resource.toLower(); + void *result = 0; - if (lowerCaseResource == "egldisplay") - return mScreen->display(); + switch (resourceType(resource)) { + case EglDisplay: + result = mScreen->display(); + break; + default: + break; + } - return 0; + return result; } void *QEglFSIntegration::nativeResourceForWindow(const QByteArray &resource, QWindow *window) { - QByteArray lowerCaseResource = resource.toLower(); + void *result = 0; - if (lowerCaseResource == "egldisplay") { + switch (resourceType(resource)) { + case EglDisplay: if (window && window->handle()) - return static_cast(window->handle()->screen())->display(); + result = static_cast(window->handle()->screen())->display(); else - return mScreen->display(); + result = mScreen->display(); + break; + case EglWindow: + if (window && window->handle()) + result = reinterpret_cast(static_cast(window->handle())->eglWindow()); + break; + default: + break; } - return 0; + return result; } void *QEglFSIntegration::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) { - QByteArray lowerCaseResource = resource.toLower(); + void *result = 0; - QEGLPlatformContext *handle = static_cast(context->handle()); + switch (resourceType(resource)) { + case EglContext: + if (context->handle()) + result = static_cast(context->handle())->eglContext(); + break; + default: + break; + } - if (!handle) - return 0; - - if (lowerCaseResource == "eglcontext") - return handle->eglContext(); - - return 0; + return result; } QPlatformNativeInterface::NativeResourceForContextFunction QEglFSIntegration::nativeResourceFunctionForContext(const QByteArray &resource) diff --git a/src/plugins/platforms/eglfs/qeglfswindow.cpp b/src/plugins/platforms/eglfs/qeglfswindow.cpp index 888de058ad..ac2e7e72fb 100644 --- a/src/plugins/platforms/eglfs/qeglfswindow.cpp +++ b/src/plugins/platforms/eglfs/qeglfswindow.cpp @@ -238,6 +238,11 @@ QSurfaceFormat QEglFSWindow::format() const return m_format; } +EGLNativeWindowType QEglFSWindow::eglWindow() const +{ + return m_window; +} + QEglFSScreen *QEglFSWindow::screen() const { return static_cast(QPlatformWindow::screen()); diff --git a/src/plugins/platforms/eglfs/qeglfswindow.h b/src/plugins/platforms/eglfs/qeglfswindow.h index 783ae414d6..a5a25409b2 100644 --- a/src/plugins/platforms/eglfs/qeglfswindow.h +++ b/src/plugins/platforms/eglfs/qeglfswindow.h @@ -64,6 +64,7 @@ public: EGLSurface surface() const; QSurfaceFormat format() const; + EGLNativeWindowType eglWindow() const; QEglFSScreen *screen() const;