eglfs/kms: Re-enable drm/gbm format overrides in the config file

Follow up to 091a386eaf

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 <johan.helsing@qt.io>
This commit is contained in:
Laszlo Agocs 2019-08-01 15:29:01 +02:00
parent a547404c12
commit 80e7120feb
3 changed files with 35 additions and 13 deletions

View File

@ -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;

View File

@ -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<QKmsPlane> available_planes;
struct QKmsPlane *eglfs_plane = nullptr;

View File

@ -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<QEglFSKmsGbmDevice *>(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 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 (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(),