From 9e70c2a21cc147e4be06f1ff3e15185fb408e2d2 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 5 Dec 2023 15:58:34 +0100 Subject: [PATCH] backends/drm: always prefer 10bpc buffers when supported The environment variable is primarily meant as a workaround for displays and drivers that misbehave when more than 8 bits per color is used. To simplify the code, this commit makes the environment variable only control the bpc used for displays, instead of also controlling which buffer formats get used. --- src/backends/drm/drm_egl_backend.cpp | 7 ------- src/backends/drm/drm_egl_backend.h | 1 - src/backends/drm/drm_egl_layer_surface.cpp | 4 ++-- src/backends/drm/drm_pipeline.cpp | 9 ++++----- .../scenes/opengl/abstract_egl_backend.cpp | 17 +++++------------ .../scenes/opengl/abstract_egl_backend.h | 1 - 6 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/backends/drm/drm_egl_backend.cpp b/src/backends/drm/drm_egl_backend.cpp index cfb7a482a0..6573ff32fd 100644 --- a/src/backends/drm/drm_egl_backend.cpp +++ b/src/backends/drm/drm_egl_backend.cpp @@ -172,13 +172,6 @@ std::pair, ColorDescription> EglGbmBackend::tex return std::make_pair(layer->texture(), layer->colorDescription()); } -bool EglGbmBackend::prefer10bpc() const -{ - static bool ok = false; - static const int preferred = qEnvironmentVariableIntValue("KWIN_DRM_PREFER_COLOR_DEPTH", &ok); - return !ok || preferred == 30; -} - std::shared_ptr EglGbmBackend::createPrimaryLayer(DrmPipeline *pipeline) { return std::make_shared(this, pipeline); diff --git a/src/backends/drm/drm_egl_backend.h b/src/backends/drm/drm_egl_backend.h index 43c431f07b..32132f50bf 100644 --- a/src/backends/drm/drm_egl_backend.h +++ b/src/backends/drm/drm_egl_backend.h @@ -51,7 +51,6 @@ public: OutputLayer *cursorLayer(Output *output) override; void init() override; - bool prefer10bpc() const override; std::shared_ptr createPrimaryLayer(DrmPipeline *pipeline) override; std::shared_ptr createCursorLayer(DrmPipeline *pipeline) override; std::shared_ptr createLayer(DrmVirtualOutput *output) override; diff --git a/src/backends/drm/drm_egl_layer_surface.cpp b/src/backends/drm/drm_egl_layer_surface.cpp index 5dac77761c..e8d955e9b7 100644 --- a/src/backends/drm/drm_egl_layer_surface.cpp +++ b/src/backends/drm/drm_egl_layer_surface.cpp @@ -342,11 +342,11 @@ std::unique_ptr EglGbmLayerSurface::createSurface(c } } - const auto sort = [this](const auto &lhs, const auto &rhs) { + const auto sort = [](const auto &lhs, const auto &rhs) { if (lhs.drmFormat == rhs.drmFormat) { // prefer having an alpha channel return lhs.alphaBits > rhs.alphaBits; - } else if (m_eglBackend->prefer10bpc() && ((lhs.bitsPerColor == 10) != (rhs.bitsPerColor == 10))) { + } else if ((lhs.bitsPerColor == 10) != (rhs.bitsPerColor == 10)) { // prefer 10bpc / 30bpp formats return lhs.bitsPerColor == 10; } else { diff --git a/src/backends/drm/drm_pipeline.cpp b/src/backends/drm/drm_pipeline.cpp index a29b1d7cb8..52036237d8 100644 --- a/src/backends/drm/drm_pipeline.cpp +++ b/src/backends/drm/drm_pipeline.cpp @@ -313,11 +313,10 @@ bool DrmPipeline::prepareAtomicModeset(DrmAtomicCommit *commit) commit->addProperty(m_connector->underscanHBorder, hborder); } if (m_connector->maxBpc.isValid()) { - uint64_t preferred = 8; - if (auto backend = dynamic_cast(gpu()->platform()->renderBackend()); backend && backend->prefer10bpc()) { - preferred = 10; - } - commit->addProperty(m_connector->maxBpc, preferred); + // TODO migrate this env var to a proper setting + static bool ok = false; + static const int preferred = qEnvironmentVariableIntValue("KWIN_DRM_PREFER_COLOR_DEPTH", &ok); + commit->addProperty(m_connector->maxBpc, ok && preferred == 24 ? 8 : 10); } if (m_connector->hdrMetadata.isValid()) { commit->addBlob(m_connector->hdrMetadata, createHdrMetadata(m_pending.colorDescription.transferFunction())); diff --git a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp index d955e2f559..5328ac4d5e 100644 --- a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp +++ b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp @@ -199,13 +199,11 @@ void AbstractEglBackend::initWayland() return formats; }; - if (prefer10bpc()) { - m_tranches.append({ - .device = deviceId(), - .flags = {}, - .formatTable = filterFormats(10, false), - }); - } + m_tranches.append({ + .device = deviceId(), + .flags = {}, + .formatTable = filterFormats(10, false), + }); m_tranches.append({ .device = deviceId(), .flags = {}, @@ -284,11 +282,6 @@ dev_t AbstractEglBackend::deviceId() const return m_deviceId; } -bool AbstractEglBackend::prefer10bpc() const -{ - return false; -} - EGLImageKHR AbstractEglBackend::importBufferAsImage(GraphicsBuffer *buffer, int plane, int format, const QSize &size) { std::pair key(buffer, plane); diff --git a/src/platformsupport/scenes/opengl/abstract_egl_backend.h b/src/platformsupport/scenes/opengl/abstract_egl_backend.h index 0abd331ed6..b8550f36f3 100644 --- a/src/platformsupport/scenes/opengl/abstract_egl_backend.h +++ b/src/platformsupport/scenes/opengl/abstract_egl_backend.h @@ -42,7 +42,6 @@ public: QList tranches() const; dev_t deviceId() const; - virtual bool prefer10bpc() const; std::shared_ptr importDmaBufAsTexture(const DmaBufAttributes &attributes) const; EGLImageKHR importDmaBufAsImage(const DmaBufAttributes &attributes) const;