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

source code of qtbase/src/plugins/platforms/eglfs/api/qeglfshooks.cpp