diff options
Diffstat (limited to 'src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp')
-rw-r--r-- | src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp | 120 |
1 files changed, 94 insertions, 26 deletions
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp index f4ffee569d..f6b58d1ba6 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsdevice.cpp @@ -42,7 +42,7 @@ #include "qeglfskmsdevice.h" #include "qeglfskmsscreen.h" -#include "qeglfsintegration.h" +#include "qeglfsintegration_p.h" #include <QtCore/QLoggingCategory> #include <QtCore/private/qcore_unix_p.h> @@ -86,7 +86,7 @@ int QEglFSKmsDevice::crtcForConnector(drmModeResPtr resources, drmModeConnectorP return -1; } -static const char * const connector_type_names[] = { +static const char * const connector_type_names[] = { // must match DRM_MODE_CONNECTOR_* "None", "VGA", "DVI", @@ -102,6 +102,8 @@ static const char * const connector_type_names[] = { "HDMI", "TV", "eDP", + "Virtual", + "DSI" }; static QByteArray nameForConnector(const drmModeConnectorPtr connector) @@ -159,7 +161,9 @@ static bool parseModeline(const QByteArray &text, drmModeModeInfoPtr mode) return true; } -QEglFSKmsScreen *QEglFSKmsDevice::screenForConnector(drmModeResPtr resources, drmModeConnectorPtr connector, QPoint pos) +QEglFSKmsScreen *QEglFSKmsDevice::createScreenForConnector(drmModeResPtr resources, + drmModeConnectorPtr connector, + VirtualDesktopInfo *vinfo) { const QByteArray connectorName = nameForConnector(connector); @@ -173,8 +177,11 @@ QEglFSKmsScreen *QEglFSKmsDevice::screenForConnector(drmModeResPtr resources, dr QSize configurationSize; drmModeModeInfo configurationModeline; - const QByteArray mode = m_integration->outputSettings().value(QString::fromUtf8(connectorName)) - .value(QStringLiteral("mode"), QStringLiteral("preferred")).toByteArray().toLower(); + auto userConfig = m_integration->outputSettings(); + auto userConnectorConfig = userConfig.value(QString::fromUtf8(connectorName)); + // default to the preferred mode unless overridden in the config + const QByteArray mode = userConnectorConfig.value(QStringLiteral("mode"), QStringLiteral("preferred")) + .toByteArray().toLower(); if (mode == "off") { configuration = OutputConfigOff; } else if (mode == "preferred") { @@ -189,6 +196,16 @@ QEglFSKmsScreen *QEglFSKmsDevice::screenForConnector(drmModeResPtr resources, dr qWarning("Invalid mode \"%s\" for output %s", mode.constData(), connectorName.constData()); configuration = OutputConfigPreferred; } + if (vinfo) { + *vinfo = VirtualDesktopInfo(); + vinfo->virtualIndex = userConnectorConfig.value(QStringLiteral("virtualIndex"), INT_MAX).toInt(); + if (userConnectorConfig.contains(QStringLiteral("virtualPos"))) { + const QByteArray vpos = userConnectorConfig.value(QStringLiteral("virtualPos")).toByteArray(); + const QByteArrayList vposComp = vpos.split(','); + if (vposComp.count() == 2) + vinfo->virtualPos = QPoint(vposComp[0].trimmed().toInt(), vposComp[1].trimmed().toInt()); + } + } const uint32_t crtc_id = resources->crtcs[crtc]; @@ -287,18 +304,26 @@ QEglFSKmsScreen *QEglFSKmsDevice::screenForConnector(drmModeResPtr resources, dr qCDebug(qLcEglfsKmsDebug) << "Selected mode" << selected_mode << ":" << width << "x" << height << '@' << refresh << "hz for output" << connectorName; } + + // physical size from connector < config values < env vars static const int width = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_WIDTH"); static const int height = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_HEIGHT"); - QSizeF size(width, height); - if (size.isEmpty()) { - size.setWidth(connector->mmWidth); - size.setHeight(connector->mmHeight); + QSizeF physSize(width, height); + if (physSize.isEmpty()) { + physSize = QSize(userConnectorConfig.value(QStringLiteral("physicalWidth")).toInt(), + userConnectorConfig.value(QStringLiteral("physicalHeight")).toInt()); + if (physSize.isEmpty()) { + physSize.setWidth(connector->mmWidth); + physSize.setHeight(connector->mmHeight); + } } + qCDebug(qLcEglfsKmsDebug) << "Physical size is" << physSize << "mm" << "for output" << connectorName; + QEglFSKmsOutput output = { QString::fromUtf8(connectorName), connector->connector_id, crtc_id, - size, + physSize, selected_mode, false, drmModeGetCrtc(m_dri_fd, crtc_id), @@ -310,7 +335,7 @@ QEglFSKmsScreen *QEglFSKmsDevice::screenForConnector(drmModeResPtr resources, dr m_crtc_allocator |= (1 << output.crtc_id); m_connector_allocator |= (1 << output.connector_id); - return createScreen(m_integration, this, output, pos); + return createScreen(m_integration, this, output); } drmModePropertyPtr QEglFSKmsDevice::connectorProperty(drmModeConnectorPtr connector, const QByteArray &name) @@ -342,6 +367,28 @@ QEglFSKmsDevice::~QEglFSKmsDevice() { } +struct OrderedScreen +{ + OrderedScreen() : screen(nullptr) { } + OrderedScreen(QEglFSKmsScreen *screen, const QEglFSKmsDevice::VirtualDesktopInfo &vinfo) + : screen(screen), vinfo(vinfo) { } + QEglFSKmsScreen *screen; + QEglFSKmsDevice::VirtualDesktopInfo vinfo; +}; + +QDebug operator<<(QDebug dbg, const OrderedScreen &s) +{ + QDebugStateSaver saver(dbg); + dbg.nospace() << "OrderedScreen(" << s.screen << " : " << s.vinfo.virtualIndex + << " / " << s.vinfo.virtualPos << ")"; + return dbg; +} + +static bool orderedScreenLessThan(const OrderedScreen &a, const OrderedScreen &b) +{ + return a.vinfo.virtualIndex < b.vinfo.virtualIndex; +} + void QEglFSKmsDevice::createScreens() { drmModeResPtr resources = drmModeGetResources(m_dri_fd); @@ -350,32 +397,53 @@ void QEglFSKmsDevice::createScreens() return; } - QEglFSKmsScreen *primaryScreen = Q_NULLPTR; - QList<QPlatformScreen *> siblings; - QPoint pos(0, 0); - QEglFSIntegration *integration = static_cast<QEglFSIntegration *>(QGuiApplicationPrivate::platformIntegration()); + QVector<OrderedScreen> screens; for (int i = 0; i < resources->count_connectors; i++) { drmModeConnectorPtr connector = drmModeGetConnector(m_dri_fd, resources->connectors[i]); if (!connector) continue; - QEglFSKmsScreen *screen = screenForConnector(resources, connector, pos); - if (screen) { - integration->addScreen(screen); - pos.rx() += screen->geometry().width(); - siblings << screen; - - if (!primaryScreen) - primaryScreen = screen; - } + VirtualDesktopInfo vinfo; + QEglFSKmsScreen *screen = createScreenForConnector(resources, connector, &vinfo); + if (screen) + screens.append(OrderedScreen(screen, vinfo)); drmModeFreeConnector(connector); } drmModeFreeResources(resources); + // Use stable sort to preserve the original order for outputs with unspecified indices. + std::stable_sort(screens.begin(), screens.end(), orderedScreenLessThan); + qCDebug(qLcEglfsKmsDebug) << "Sorted screen list:" << screens; + + QPoint pos(0, 0); + QList<QPlatformScreen *> siblings; + QEglFSIntegration *qpaIntegration = static_cast<QEglFSIntegration *>(QGuiApplicationPrivate::platformIntegration()); + + for (const OrderedScreen &orderedScreen : screens) { + QEglFSKmsScreen *s = orderedScreen.screen; + // set up a horizontal or vertical virtual desktop + if (orderedScreen.vinfo.virtualPos.isNull()) { + s->setVirtualPosition(pos); + if (m_integration->virtualDesktopLayout() == QEglFSKmsIntegration::VirtualDesktopLayoutVertical) + pos.ry() += s->geometry().height(); + else + pos.rx() += s->geometry().width(); + } else { + s->setVirtualPosition(orderedScreen.vinfo.virtualPos); + } + qCDebug(qLcEglfsKmsDebug) << "Adding screen" << s << "to QPA with geometry" << s->geometry(); + // The order in qguiapp's screens list will match the order set by + // virtualIndex. This is not only handy but also required since for instance + // evdevtouch relies on it when performing touch device - screen mapping. + qpaIntegration->addScreen(s); + siblings << s; + } + if (!m_integration->separateScreens()) { + // enable the virtual desktop Q_FOREACH (QPlatformScreen *screen, siblings) static_cast<QEglFSKmsScreen *>(screen)->setVirtualSiblings(siblings); } @@ -391,9 +459,9 @@ QString QEglFSKmsDevice::devicePath() const return m_path; } -QEglFSKmsScreen *QEglFSKmsDevice::createScreen(QEglFSKmsIntegration *integration, QEglFSKmsDevice *device, QEglFSKmsOutput output, QPoint position) +QEglFSKmsScreen *QEglFSKmsDevice::createScreen(QEglFSKmsIntegration *integration, QEglFSKmsDevice *device, QEglFSKmsOutput output) { - return new QEglFSKmsScreen(integration, device, output, position); + return new QEglFSKmsScreen(integration, device, output); } void QEglFSKmsDevice::setFd(int fd) |