From c112bb5c56cc2cac07893dcf58dfa8b008afe317 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 14 Jun 2023 12:59:29 +0200 Subject: [PATCH] backends/drm: fix color management with sRGB output We need to target the linear EOTF for rendering, even if the output EOTF is sRGB --- src/backends/drm/drm_egl_layer_surface.cpp | 7 ++++--- src/backends/drm/drm_egl_layer_surface.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backends/drm/drm_egl_layer_surface.cpp b/src/backends/drm/drm_egl_layer_surface.cpp index e6e23d02b7..4a9f09ba0b 100644 --- a/src/backends/drm/drm_egl_layer_surface.cpp +++ b/src/backends/drm/drm_egl_layer_surface.cpp @@ -89,12 +89,13 @@ std::optional EglGbmLayerSurface::startRendering(cons } m_surface.currentBuffer = buffer; - if (m_surface.targetColorDescription != colorDescription || m_surface.channelFactors != channelFactors) { + if (m_surface.targetColorDescription != colorDescription || m_surface.channelFactors != channelFactors || m_surface.colormanagementEnabled != enableColormanagement) { m_surface.gbmSwapchain->resetDamage(); repaint = infiniteRegion(); + m_surface.colormanagementEnabled = enableColormanagement; m_surface.targetColorDescription = colorDescription; m_surface.channelFactors = channelFactors; - if (colorDescription != ColorDescription::sRGB) { + if (enableColormanagement) { m_surface.intermediaryColorDescription = ColorDescription(colorDescription.colorimetry(), NamedTransferFunction::linear, colorDescription.sdrBrightness(), colorDescription.minHdrBrightness(), colorDescription.maxHdrBrightness(), colorDescription.maxHdrHighlightBrightness()); @@ -126,7 +127,7 @@ std::optional EglGbmLayerSurface::startRendering(cons bool EglGbmLayerSurface::endRendering(const QRegion &damagedRegion) { - if (m_surface.shadowTexture) { + if (m_surface.colormanagementEnabled) { const auto &[texture, fbo] = m_surface.textureCache[m_surface.currentBuffer->bo()]; GLFramebuffer::pushFramebuffer(fbo.get()); ShaderBinder binder(ShaderTrait::MapTexture | ShaderTrait::TransformColorspace); diff --git a/src/backends/drm/drm_egl_layer_surface.h b/src/backends/drm/drm_egl_layer_surface.h index ef09b76256..97ddd267b8 100644 --- a/src/backends/drm/drm_egl_layer_surface.h +++ b/src/backends/drm/drm_egl_layer_surface.h @@ -69,6 +69,7 @@ private: }; struct Surface { + bool colormanagementEnabled = false; std::shared_ptr shadowTexture; std::shared_ptr shadowBuffer; ColorDescription targetColorDescription = ColorDescription::sRGB;