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.
This commit is contained in:
Xaver Hugl 2023-12-05 15:58:34 +01:00
parent 33e971cc09
commit 9e70c2a21c
6 changed files with 11 additions and 28 deletions

View file

@ -172,13 +172,6 @@ std::pair<std::shared_ptr<KWin::GLTexture>, 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<DrmPipelineLayer> EglGbmBackend::createPrimaryLayer(DrmPipeline *pipeline)
{
return std::make_shared<EglGbmLayer>(this, pipeline);

View file

@ -51,7 +51,6 @@ public:
OutputLayer *cursorLayer(Output *output) override;
void init() override;
bool prefer10bpc() const override;
std::shared_ptr<DrmPipelineLayer> createPrimaryLayer(DrmPipeline *pipeline) override;
std::shared_ptr<DrmPipelineLayer> createCursorLayer(DrmPipeline *pipeline) override;
std::shared_ptr<DrmOutputLayer> createLayer(DrmVirtualOutput *output) override;

View file

@ -342,11 +342,11 @@ std::unique_ptr<EglGbmLayerSurface::Surface> 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 {

View file

@ -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<EglGbmBackend *>(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()));

View file

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

View file

@ -42,7 +42,6 @@ public:
QList<LinuxDmaBufV1Feedback::Tranche> tranches() const;
dev_t deviceId() const;
virtual bool prefer10bpc() const;
std::shared_ptr<GLTexture> importDmaBufAsTexture(const DmaBufAttributes &attributes) const;
EGLImageKHR importDmaBufAsImage(const DmaBufAttributes &attributes) const;