plugins/screencast: centralize format querying into the RenderBackend

BUG: 460563
This commit is contained in:
Xaver Hugl 2022-10-20 14:20:48 +02:00
parent e73fedf2ae
commit 84635c71ec
7 changed files with 39 additions and 29 deletions

View file

@ -6,6 +6,8 @@
#include "renderbackend.h"
#include <drm_fourcc.h>
namespace KWin
{
@ -24,4 +26,9 @@ bool RenderBackend::checkGraphicsReset()
return false;
}
QHash<uint32_t, QVector<uint64_t>> RenderBackend::supportedFormats() const
{
return QHash<uint32_t, QVector<uint64_t>>{{DRM_FORMAT_XRGB8888, QVector<uint64_t>{DRM_FORMAT_MOD_LINEAR}}};
}
} // namespace KWin

View file

@ -35,6 +35,8 @@ public:
virtual OutputLayer *primaryLayer(Output *output) = 0;
virtual void present(Output *output) = 0;
virtual QHash<uint32_t, QVector<uint64_t>> supportedFormats() const;
};
} // namespace KWin

View file

@ -469,4 +469,12 @@ std::shared_ptr<GLTexture> AbstractEglBackend::importDmaBufAsTexture(const DmaBu
}
}
QHash<uint32_t, QVector<uint64_t>> AbstractEglBackend::supportedFormats() const
{
if (m_dmaBuf) {
return m_dmaBuf->supportedFormats();
} else {
return RenderBackend::supportedFormats();
}
}
}

View file

@ -64,6 +64,7 @@ public:
}
std::shared_ptr<GLTexture> textureForOutput(Output *output) const override;
QHash<uint32_t, QVector<uint64_t>> supportedFormats() const override;
dev_t deviceId() const;
virtual bool prefer10bpc() const;

View file

@ -319,7 +319,7 @@ void EglDmabuf::setSupportedFormatsAndModifiers()
filterFormatsWithMultiplePlanes(formats);
QHash<uint32_t, QVector<uint64_t>> supportedFormats;
m_supportedFormats.clear();
for (auto format : std::as_const(formats)) {
if (eglQueryDmaBufModifiersEXT != nullptr) {
EGLint count = 0;
@ -327,18 +327,18 @@ void EglDmabuf::setSupportedFormatsAndModifiers()
if (success && count > 0) {
QVector<uint64_t> modifiers(count);
if (eglQueryDmaBufModifiersEXT(eglDisplay, format, count, modifiers.data(), nullptr, &count)) {
supportedFormats.insert(format, modifiers);
m_supportedFormats.insert(format, modifiers);
continue;
}
}
}
supportedFormats.insert(format, {DRM_FORMAT_MOD_INVALID});
m_supportedFormats.insert(format, {DRM_FORMAT_MOD_INVALID});
}
qCDebug(KWIN_OPENGL) << "EGL driver advertises" << supportedFormats.count() << "supported dmabuf formats" << (eglQueryDmaBufModifiersEXT != nullptr ? "with" : "without") << "modifiers";
qCDebug(KWIN_OPENGL) << "EGL driver advertises" << m_supportedFormats.count() << "supported dmabuf formats" << (eglQueryDmaBufModifiersEXT != nullptr ? "with" : "without") << "modifiers";
auto filterFormats = [&supportedFormats](int bpc) {
auto filterFormats = [this](int bpc) {
QHash<uint32_t, QVector<uint64_t>> set;
for (auto it = supportedFormats.constBegin(); it != supportedFormats.constEnd(); it++) {
for (auto it = m_supportedFormats.constBegin(); it != m_supportedFormats.constEnd(); it++) {
if (bpcForFormat(it.key()) == bpc) {
set.insert(it.key(), it.value());
}
@ -365,4 +365,13 @@ void EglDmabuf::setSupportedFormatsAndModifiers()
LinuxDmaBufV1RendererInterface::setSupportedFormatsAndModifiers(m_tranches);
}
QVector<KWaylandServer::LinuxDmaBufV1Feedback::Tranche> EglDmabuf::tranches() const
{
return m_tranches;
}
QHash<uint32_t, QVector<uint64_t>> EglDmabuf::supportedFormats() const
{
return m_supportedFormats;
}
}

View file

@ -54,7 +54,7 @@ private:
ImportType m_importType;
};
class EglDmabuf : public LinuxDmaBufV1RendererInterface
class KWIN_EXPORT EglDmabuf : public LinuxDmaBufV1RendererInterface
{
public:
static EglDmabuf *factory(AbstractEglBackend *backend);
@ -64,10 +64,8 @@ public:
KWaylandServer::LinuxDmaBufV1ClientBuffer *importBuffer(DmaBufAttributes &&attrs, quint32 flags) override;
QVector<KWaylandServer::LinuxDmaBufV1Feedback::Tranche> tranches() const
{
return m_tranches;
}
QVector<KWaylandServer::LinuxDmaBufV1Feedback::Tranche> tranches() const;
QHash<uint32_t, QVector<uint64_t>> supportedFormats() const;
private:
KWaylandServer::LinuxDmaBufV1ClientBuffer *yuvImport(DmaBufAttributes &&attrs, quint32 flags);
@ -76,6 +74,7 @@ private:
AbstractEglBackend *m_backend;
QVector<KWaylandServer::LinuxDmaBufV1Feedback::Tranche> m_tranches;
QHash<uint32_t, QVector<uint64_t>> m_supportedFormats;
friend class EglDmabufBuffer;
};

View file

@ -9,6 +9,7 @@
#include "screencaststream.h"
#include "composite.h"
#include "core/platform.h"
#include "core/renderbackend.h"
#include "cursor.h"
#include "dmabuftexture.h"
#include "eglnativefence.h"
@ -315,23 +316,6 @@ uint ScreenCastStream::nodeId()
return pwNodeId;
}
static QVector<uint64_t> querySupportedModifiers(EGLDisplay eglDisplay, quint32 format)
{
QVector<uint64_t> modifiers;
if (eglQueryDmaBufModifiersEXT != nullptr) {
EGLint count = 0;
const EGLBoolean success = eglQueryDmaBufModifiersEXT(eglDisplay, format, 0, nullptr, nullptr, &count);
if (success && count > 0) {
modifiers.resize(count);
eglQueryDmaBufModifiersEXT(eglDisplay, format, count, modifiers.data(), nullptr, &count);
}
}
if (!modifiers.contains(DRM_FORMAT_MOD_INVALID)) {
modifiers.append(DRM_FORMAT_MOD_INVALID);
}
return modifiers;
}
bool ScreenCastStream::createStream()
{
const QByteArray objname = "kwin-screencast-" + objectName().toUtf8();
@ -341,7 +325,7 @@ bool ScreenCastStream::createStream()
const auto format = m_source->hasAlphaChannel() ? SPA_VIDEO_FORMAT_BGRA : SPA_VIDEO_FORMAT_BGR;
const int drmFormat = spaVideoFormatToDrmFormat(format);
m_hasDmaBuf = kwinApp()->platform()->testCreateDmaBuf(m_resolution, drmFormat, {DRM_FORMAT_MOD_INVALID}).has_value();
m_modifiers = querySupportedModifiers(kwinApp()->platform()->sceneEglDisplay(), drmFormat);
m_modifiers = Compositor::self()->backend()->supportedFormats().value(drmFormat);
char buffer[2048];
QVector<const spa_pod *> params = buildFormats(false, buffer);