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