| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 |
// Qt-Security score:significant reason:default |
| 4 |
|
| 5 |
#include "qxcbeglnativeinterfacehandler.h" |
| 6 |
|
| 7 |
#include <QtGui/private/qguiapplication_p.h> |
| 8 |
#include "qxcbeglwindow.h" |
| 9 |
#include "qxcbintegration.h" |
| 10 |
#include "qxcbeglintegration.h" |
| 11 |
#include "qxcbeglcontext.h" |
| 12 |
|
| 13 |
QT_BEGIN_NAMESPACE |
| 14 |
|
| 15 |
static int resourceType(const QByteArray &key) |
| 16 |
{ |
| 17 |
static const QByteArray names[] = { // match QXcbEglNativeInterfaceHandler::ResourceType |
| 18 |
QByteArrayLiteral("egldisplay"), |
| 19 |
QByteArrayLiteral("eglcontext"), |
| 20 |
QByteArrayLiteral("eglconfig") |
| 21 |
}; |
| 22 |
for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) { |
| 23 |
if (key == names[i]) |
| 24 |
return i; |
| 25 |
} |
| 26 |
|
| 27 |
if (key == QByteArrayLiteral("get_egl_context")) |
| 28 |
return QXcbEglNativeInterfaceHandler::EglContext; |
| 29 |
|
| 30 |
return sizeof(names) / sizeof(names[0]); |
| 31 |
} |
| 32 |
|
| 33 |
QXcbEglNativeInterfaceHandler::QXcbEglNativeInterfaceHandler(QXcbNativeInterface *nativeInterface) |
| 34 |
: QXcbNativeInterfaceHandler(nativeInterface) |
| 35 |
{ |
| 36 |
} |
| 37 |
|
| 38 |
QPlatformNativeInterface::NativeResourceForIntegrationFunction QXcbEglNativeInterfaceHandler::nativeResourceFunctionForIntegration(const QByteArray &resource) const{ |
| 39 |
switch (resourceType(resource)) { |
| 40 |
case EglDisplay: |
| 41 |
return eglDisplay; |
| 42 |
default: |
| 43 |
break; |
| 44 |
} |
| 45 |
return nullptr; |
| 46 |
} |
| 47 |
|
| 48 |
QPlatformNativeInterface::NativeResourceForContextFunction QXcbEglNativeInterfaceHandler::nativeResourceFunctionForContext(const QByteArray &resource) const |
| 49 |
{ |
| 50 |
switch (resourceType(resource)) { |
| 51 |
case EglContext: |
| 52 |
return eglContextForContext; |
| 53 |
case EglConfig: |
| 54 |
return eglConfigForContext; |
| 55 |
default: |
| 56 |
break; |
| 57 |
} |
| 58 |
return nullptr; |
| 59 |
} |
| 60 |
|
| 61 |
QPlatformNativeInterface::NativeResourceForWindowFunction QXcbEglNativeInterfaceHandler::nativeResourceFunctionForWindow(const QByteArray &resource) const |
| 62 |
{ |
| 63 |
switch (resourceType(resource)) { |
| 64 |
case EglDisplay: |
| 65 |
return eglDisplayForWindow; |
| 66 |
default: |
| 67 |
break; |
| 68 |
} |
| 69 |
return nullptr; |
| 70 |
} |
| 71 |
|
| 72 |
void *QXcbEglNativeInterfaceHandler::eglDisplay() |
| 73 |
{ |
| 74 |
QXcbIntegration *integration = QXcbIntegration::instance(); |
| 75 |
QXcbEglIntegration *eglIntegration = static_cast<QXcbEglIntegration *>(integration->connection()->glIntegration()); |
| 76 |
return eglIntegration->eglDisplay(); |
| 77 |
} |
| 78 |
|
| 79 |
void *QXcbEglNativeInterfaceHandler::eglDisplayForWindow(QWindow *window) |
| 80 |
{ |
| 81 |
Q_ASSERT(window); |
| 82 |
if (window->supportsOpenGL() && window->handle() == nullptr) |
| 83 |
return eglDisplay(); |
| 84 |
else if (window->supportsOpenGL()) |
| 85 |
return static_cast<QXcbEglWindow *>(window->handle())->glIntegration()->eglDisplay(); |
| 86 |
return nullptr; |
| 87 |
} |
| 88 |
|
| 89 |
void *QXcbEglNativeInterfaceHandler::eglContextForContext(QOpenGLContext *context) |
| 90 |
{ |
| 91 |
Q_ASSERT(context); |
| 92 |
Q_ASSERT(context->handle()); |
| 93 |
return static_cast<QXcbEglContext *>(context->handle())->eglContext(); |
| 94 |
} |
| 95 |
|
| 96 |
void *QXcbEglNativeInterfaceHandler::eglConfigForContext(QOpenGLContext *context) |
| 97 |
{ |
| 98 |
Q_ASSERT(context); |
| 99 |
Q_ASSERT(context->handle()); |
| 100 |
return static_cast<QXcbEglContext *>(context->handle())->eglConfig(); |
| 101 |
} |
| 102 |
|
| 103 |
QT_END_NAMESPACE |