Skip to content

Commit

Permalink
eglfs/kms: Re-enable drm/gbm format overrides in the config file
Browse files Browse the repository at this point in the history
Follow up to 091a386

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 <[email protected]>
  • Loading branch information
alpqr committed Aug 15, 2019
1 parent a547404 commit 80e7120
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/platformsupport/kmsconvenience/qkmsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/platformsupport/kmsconvenience/qkmsdevice_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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(),
Expand Down

0 comments on commit 80e7120

Please sign in to comment.