From 80e7120feb5ddf9d5f0c9ed12bb8580898b18db8 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 1 Aug 2019 15:29:01 +0200 Subject: eglfs/kms: Re-enable drm/gbm format overrides in the config file Follow up to 091a386eaf91ad8932332a8aefc2df793de59f6c Defaulting to querying from the egl config is fine, but dropping support for the "format" key in the output list in the json config file is not ideal. Task-number: QTBUG-76748 Change-Id: I25dc99369d118c300cdef25b464426f6be85453b Reviewed-by: Johan Helsing --- src/platformsupport/kmsconvenience/qkmsdevice.cpp | 12 +++++-- src/platformsupport/kmsconvenience/qkmsdevice_p.h | 1 + .../eglfs_kms/qeglfskmsgbmscreen.cpp | 37 +++++++++++++++------- 3 files changed, 36 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/platformsupport/kmsconvenience/qkmsdevice.cpp b/src/platformsupport/kmsconvenience/qkmsdevice.cpp index 7e3a870421..fec59cfc7b 100644 --- a/src/platformsupport/kmsconvenience/qkmsdevice.cpp +++ b/src/platformsupport/kmsconvenience/qkmsdevice.cpp @@ -342,10 +342,14 @@ QPlatformScreen *QKmsDevice::createScreenForConnector(drmModeResPtr resources, } qCDebug(qLcKmsDebug) << "Physical size is" << physSize << "mm" << "for output" << connectorName; - const QByteArray formatStr = userConnectorConfig.value(QStringLiteral("format"), QStringLiteral("xrgb8888")) + const QByteArray formatStr = userConnectorConfig.value(QStringLiteral("format"), QString()) .toByteArray().toLower(); uint32_t drmFormat; - if (formatStr == "xrgb8888") { + bool drmFormatExplicit = true; + if (formatStr.isEmpty()) { + drmFormat = DRM_FORMAT_XRGB8888; + drmFormatExplicit = false; + } else if (formatStr == "xrgb8888") { drmFormat = DRM_FORMAT_XRGB8888; } else if (formatStr == "xbgr8888") { drmFormat = DRM_FORMAT_XBGR8888; @@ -368,7 +372,10 @@ QPlatformScreen *QKmsDevice::createScreenForConnector(drmModeResPtr resources, } else { qWarning("Invalid pixel format \"%s\" for output %s", formatStr.constData(), connectorName.constData()); drmFormat = DRM_FORMAT_XRGB8888; + drmFormatExplicit = false; } + qCDebug(qLcKmsDebug) << "Format is" << hex << drmFormat << dec << "requested_by_user =" << drmFormatExplicit + << "for output" << connectorName; const QString cloneSource = userConnectorConfig.value(QStringLiteral("clones")).toString(); if (!cloneSource.isEmpty()) @@ -411,6 +418,7 @@ QPlatformScreen *QKmsDevice::createScreenForConnector(drmModeResPtr resources, output.forced_plane_id = 0; output.forced_plane_set = false; output.drm_format = drmFormat; + output.drm_format_requested_by_user = drmFormatExplicit; output.clone_source = cloneSource; output.size = framebufferSize; diff --git a/src/platformsupport/kmsconvenience/qkmsdevice_p.h b/src/platformsupport/kmsconvenience/qkmsdevice_p.h index 403972fbb8..14da6bb947 100644 --- a/src/platformsupport/kmsconvenience/qkmsdevice_p.h +++ b/src/platformsupport/kmsconvenience/qkmsdevice_p.h @@ -201,6 +201,7 @@ struct QKmsOutput uint32_t forced_plane_id = 0; bool forced_plane_set = false; uint32_t drm_format = DRM_FORMAT_XRGB8888; + bool drm_format_requested_by_user = false; QString clone_source; QVector available_planes; struct QKmsPlane *eglfs_plane = nullptr; diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp index 24f82e7843..3a2951efbd 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp @@ -155,20 +155,33 @@ gbm_surface *QEglFSKmsGbmScreen::createSurface(EGLConfig eglConfig) qCDebug(qLcEglfsKmsDebug, "Creating gbm_surface for screen %s", qPrintable(name())); const auto gbmDevice = static_cast(device())->gbmDevice(); - EGLint native_format = -1; - EGLBoolean success = eglGetConfigAttrib(display(), eglConfig, EGL_NATIVE_VISUAL_ID, &native_format); - qCDebug(qLcEglfsKmsDebug) << "Got native format" << hex << native_format << dec << "from eglGetConfigAttrib() with return code" << bool(success); - - if (success) - m_gbm_surface = gbm_surface_create(gbmDevice, - rawGeometry().width(), - rawGeometry().height(), - native_format, - GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + // If there was no format override given in the config file, + // query the native (here, gbm) format from the EGL config. + const bool queryFromEgl = !m_output.drm_format_requested_by_user; + if (queryFromEgl) { + EGLint native_format = -1; + EGLBoolean success = eglGetConfigAttrib(display(), eglConfig, EGL_NATIVE_VISUAL_ID, &native_format); + qCDebug(qLcEglfsKmsDebug) << "Got native format" << hex << native_format << dec + << "from eglGetConfigAttrib() with return code" << bool(success); + + if (success) { + m_gbm_surface = gbm_surface_create(gbmDevice, + rawGeometry().width(), + rawGeometry().height(), + native_format, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + if (m_gbm_surface) + m_output.drm_format = gbmFormatToDrmFormat(native_format); + } + } - if (!m_gbm_surface) { // fallback for older drivers + // Fallback for older drivers, and when "format" is explicitly specified + // in the output config. (not guaranteed that the requested format works + // of course, but do what we are told to) + if (!m_gbm_surface) { uint32_t gbmFormat = drmFormatToGbmFormat(m_output.drm_format); - qCDebug(qLcEglfsKmsDebug, "Could not create surface with EGL_NATIVE_VISUAL_ID, falling back to format %x", gbmFormat); + if (queryFromEgl) + qCDebug(qLcEglfsKmsDebug, "Could not create surface with EGL_NATIVE_VISUAL_ID, falling back to format %x", gbmFormat); m_gbm_surface = gbm_surface_create(gbmDevice, rawGeometry().width(), rawGeometry().height(), -- cgit v1.2.3