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 "qeglfshooks_p.h" |
5 | #include <QLoggingCategory> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | Q_DECLARE_LOGGING_CATEGORY(qLcEglDevDebug) |
10 | |
11 | #ifdef EGLFS_PLATFORM_HOOKS |
12 | |
13 | QEglFSDeviceIntegration *qt_egl_device_integration() |
14 | { |
15 | extern QEglFSHooks *platformHooks; |
16 | return platformHooks; |
17 | } |
18 | |
19 | #else |
20 | |
21 | namespace { |
22 | class DeviceIntegration |
23 | { |
24 | public: |
25 | DeviceIntegration(); |
26 | ~DeviceIntegration() { delete m_integration; } |
27 | QEglFSDeviceIntegration *integration() { return m_integration; } |
28 | private: |
29 | QEglFSDeviceIntegration *m_integration; |
30 | }; |
31 | } |
32 | |
33 | Q_GLOBAL_STATIC(DeviceIntegration, deviceIntegration) |
34 | |
35 | DeviceIntegration::DeviceIntegration() |
36 | : m_integration(nullptr) |
37 | { |
38 | QStringList pluginKeys = QEglFSDeviceIntegrationFactory::keys(); |
39 | if (!pluginKeys.isEmpty()) { |
40 | // Some built-in logic: Prioritize either X11 or KMS/DRM. |
41 | if (qEnvironmentVariableIsSet(varName: "DISPLAY")) { |
42 | const QString x11key = QStringLiteral("eglfs_x11"); |
43 | if (pluginKeys.contains(str: x11key)) { |
44 | pluginKeys.removeOne(t: x11key); |
45 | pluginKeys.prepend(t: x11key); |
46 | } |
47 | } else { |
48 | const QString kmskey = QStringLiteral("eglfs_kms"); |
49 | if (pluginKeys.contains(str: kmskey)) { |
50 | pluginKeys.removeOne(t: kmskey); |
51 | pluginKeys.prepend(t: kmskey); |
52 | } |
53 | } |
54 | |
55 | QByteArray requested; |
56 | |
57 | // The environment variable can override everything. |
58 | if (qEnvironmentVariableIsSet(varName: "QT_QPA_EGLFS_INTEGRATION")) { |
59 | requested = qgetenv(varName: "QT_QPA_EGLFS_INTEGRATION"); |
60 | } else { |
61 | // Device-specific makespecs may define a preferred plugin. |
62 | #ifdef EGLFS_PREFERRED_PLUGIN |
63 | #define DEFAULT_PLUGIN EGLFS_PREFERRED_PLUGIN |
64 | #define STR(s) #s |
65 | #define STRQ(s) STR(s) |
66 | requested = STRQ(DEFAULT_PLUGIN); |
67 | #endif |
68 | } |
69 | |
70 | // Treat "none" as special. There has to be a way to indicate |
71 | // that plugins must be ignored when the device is known to be |
72 | // functional with the default, non-specialized integration. |
73 | if (requested != QByteArrayLiteral("none")) { |
74 | if (!requested.isEmpty()) { |
75 | QString reqStr = QString::fromLocal8Bit(ba: requested); |
76 | pluginKeys.removeOne(t: reqStr); |
77 | pluginKeys.prepend(t: reqStr); |
78 | } |
79 | qCDebug(qLcEglDevDebug) << "EGL device integration plugin keys (sorted):"<< pluginKeys; |
80 | while (!m_integration && !pluginKeys.isEmpty()) { |
81 | QString key = pluginKeys.takeFirst(); |
82 | qCDebug(qLcEglDevDebug) << "Trying to load device EGL integration"<< key; |
83 | m_integration = QEglFSDeviceIntegrationFactory::create(name: key); |
84 | } |
85 | } |
86 | } |
87 | |
88 | if (!m_integration) { |
89 | // Use a default, non-specialized device integration when no plugin is available. |
90 | // For some systems this is sufficient. |
91 | qCDebug(qLcEglDevDebug) << "Using base device integration"; |
92 | m_integration = new QEglFSDeviceIntegration; |
93 | } |
94 | } |
95 | |
96 | QEglFSDeviceIntegration *qt_egl_device_integration() |
97 | { |
98 | return deviceIntegration()->integration(); |
99 | } |
100 | |
101 | #endif // EGLFS_PLATFORM_HOOKS |
102 | |
103 | QT_END_NAMESPACE |
104 |