| 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 |
#ifdef EGLFS_PLATFORM_HOOKS |
| 10 |
|
| 11 |
QEglFSDeviceIntegration *qt_egl_device_integration() |
| 12 |
{ |
| 13 |
extern QEglFSHooks *platformHooks; |
| 14 |
return platformHooks; |
| 15 |
} |
| 16 |
|
| 17 |
#else |
| 18 |
|
| 19 |
namespace { |
| 20 |
class DeviceIntegration |
| 21 |
{ |
| 22 |
public: |
| 23 |
DeviceIntegration(); |
| 24 |
~DeviceIntegration() { delete m_integration; } |
| 25 |
QEglFSDeviceIntegration *integration() { return m_integration; } |
| 26 |
private: |
| 27 |
QEglFSDeviceIntegration *m_integration; |
| 28 |
}; |
| 29 |
} |
| 30 |
|
| 31 |
Q_GLOBAL_STATIC(DeviceIntegration, deviceIntegration) |
| 32 |
|
| 33 |
DeviceIntegration::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("DISPLAY")) { |
| 40 |
const QString x11key = QStringLiteral("eglfs_x11"); |
| 41 |
if (pluginKeys.contains(x11key)) { |
| 42 |
pluginKeys.removeOne(x11key); |
| 43 |
pluginKeys.prepend(x11key); |
| 44 |
} |
| 45 |
} else { |
| 46 |
const QString kmskey = QStringLiteral("eglfs_kms"); |
| 47 |
if (pluginKeys.contains(kmskey)) { |
| 48 |
pluginKeys.removeOne(kmskey); |
| 49 |
pluginKeys.prepend(kmskey); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
// The environment variable can override everything. |
| 54 |
QString requested = qEnvironmentVariable("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(requested); |
| 71 |
pluginKeys.prepend(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(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 |
|
| 90 |
QEglFSDeviceIntegration *qt_egl_device_integration() |
| 91 |
{ |
| 92 |
return deviceIntegration()->integration(); |
| 93 |
} |
| 94 |
|
| 95 |
#endif // EGLFS_PLATFORM_HOOKS |
| 96 |
|
| 97 |
QT_END_NAMESPACE |