Use native visual ID when creating GBM surfaces for KMS

According to the Khronos documentation, gbm_surface_create() will give
a BAD_MATCH error if the format does not match the EGL_NATIVE_VISUAL_ID.
Newer drivers have started to enforce this.

Change-Id: I61360b0f52965ad8057e7de8f824ffca64fea904
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
This commit is contained in:
Paul Olav Tvete 2018-10-09 11:01:37 +02:00
parent 4dc251879c
commit 091a386eaf
3 changed files with 22 additions and 6 deletions

View File

@ -148,16 +148,32 @@ QPlatformCursor *QEglFSKmsGbmScreen::cursor() const
}
}
gbm_surface *QEglFSKmsGbmScreen::createSurface()
gbm_surface *QEglFSKmsGbmScreen::createSurface(EGLConfig eglConfig)
{
if (!m_gbm_surface) {
uint32_t gbmFormat = drmFormatToGbmFormat(m_output.drm_format);
qCDebug(qLcEglfsKmsDebug, "Creating gbm_surface for screen %s with format 0x%x", qPrintable(name()), gbmFormat);
m_gbm_surface = gbm_surface_create(static_cast<QEglFSKmsGbmDevice *>(device())->gbmDevice(),
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 (!m_gbm_surface) { // fallback for older drivers
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);
m_gbm_surface = gbm_surface_create(gbmDevice,
rawGeometry().width(),
rawGeometry().height(),
gbmFormat,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
}
}
return m_gbm_surface; // not owned, gets destroyed in QEglFSKmsGbmIntegration::destroyNativeWindow() via QEglFSKmsGbmWindow::invalidateSurface()
}

View File

@ -59,7 +59,7 @@ public:
QPlatformCursor *cursor() const override;
gbm_surface *createSurface();
gbm_surface *createSurface(EGLConfig eglConfig);
void resetSurface();
void initCloning(QPlatformScreen *screenThisScreenClones,

View File

@ -53,7 +53,7 @@ void QEglFSKmsGbmWindow::resetSurface()
m_config = QEglFSDeviceIntegration::chooseConfig(display, platformFormat);
m_format = q_glFormatFromConfig(display, m_config, platformFormat);
// One fullscreen window per screen -> the native window is simply the gbm_surface the screen created.
m_window = reinterpret_cast<EGLNativeWindowType>(gbmScreen->createSurface());
m_window = reinterpret_cast<EGLNativeWindowType>(gbmScreen->createSurface(m_config));
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC createPlatformWindowSurface = nullptr;
const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);