Commit 538b848f authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

backends: Split out a DmaBufParams class

Instead of using a DmaBufAttributes instance to communicate the settings
to create a new dmabuf, use a smaller DmaBufParams class that only
contains the information we need after destroying the BO.
parent 56ab74a1
......@@ -635,20 +635,19 @@ gbm_bo *DrmBackend::createBo(const QSize &size, quint32 format, const QVector<ui
return createGbmBo(primaryGpu()->gbmDevice(), size, format, modifiers);
}
std::optional<DmaBufAttributes> DrmBackend::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
std::optional<DmaBufParams> DrmBackend::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
gbm_bo *bo = createBo(size, format, modifiers);
if (!bo) {
return {};
}
auto ret = dmaBufAttributesForBo(bo);
gbm_bo_destroy(bo);
auto ret = dmaBufParamsForBo(bo);
// We are just testing to know it works and check the modifier, no need to keep the fd
for (int i = 0, c = ret.planeCount; i < c; ++i) {
close(ret.fd[i]);
for (int i = 0, c = gbm_bo_get_plane_count(bo); i < c; ++i) {
close(gbm_bo_get_fd_for_plane(bo, i));
}
gbm_bo_destroy(bo);
return ret;
}
......
......@@ -47,7 +47,7 @@ public:
QPainterBackend *createQPainterBackend() override;
OpenGLBackend *createOpenGLBackend() override;
std::optional<DmaBufAttributes> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers) override;
std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers) override;
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier) override;
Session *session() const override;
bool initialize() override;
......
......@@ -55,6 +55,17 @@ inline DmaBufAttributes dmaBufAttributesForBo(gbm_bo *bo)
return attributes;
}
inline DmaBufParams dmaBufParamsForBo(gbm_bo *bo)
{
DmaBufParams attributes;
attributes.planeCount = gbm_bo_get_plane_count(bo);
attributes.width = gbm_bo_get_width(bo);
attributes.height = gbm_bo_get_height(bo);
attributes.format = gbm_bo_get_format(bo);
attributes.modifier = gbm_bo_get_modifier(bo);
return attributes;
}
inline gbm_bo *createGbmBo(gbm_device *device, const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
const uint32_t flags = GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR;
......
......@@ -1028,20 +1028,19 @@ void WaylandBackend::removeVirtualOutput(Output *output)
}
}
std::optional<DmaBufAttributes> WaylandBackend::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
std::optional<DmaBufParams> WaylandBackend::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
gbm_bo *bo = createGbmBo(m_gbmDevice, size, format, modifiers);
if (!bo) {
return {};
}
auto ret = dmaBufAttributesForBo(bo);
gbm_bo_destroy(bo);
auto ret = dmaBufParamsForBo(bo);
// We are just testing to know it works and check the modifier, no need to keep the fd
for (int i = 0, c = ret.planeCount; i < c; ++i) {
close(ret.fd[i]);
for (int i = 0, c = gbm_bo_get_plane_count(bo); i < c; ++i) {
close(gbm_bo_get_fd_for_plane(bo, i));
}
gbm_bo_destroy(bo);
return ret;
}
......
......@@ -303,7 +303,7 @@ public:
Output *createVirtualOutput(const QString &name, const QSize &size, double scale) override;
void removeVirtualOutput(Output *output) override;
std::optional<DmaBufAttributes> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers) override;
std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers) override;
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, uint64_t modifier) override;
gbm_device *gbmDevice() const
......
......@@ -11,6 +11,15 @@
namespace KWin
{
struct DmaBufParams
{
int planeCount = 0;
int width = 0;
int height = 0;
uint32_t format = 0;
uint64_t modifier = 0;
};
struct DmaBufAttributes
{
int planeCount = 0;
......
......@@ -81,7 +81,7 @@ QPainterBackend *Platform::createQPainterBackend()
return nullptr;
}
std::optional<DmaBufAttributes> Platform::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
std::optional<DmaBufParams> Platform::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
Q_UNUSED(size)
Q_UNUSED(format)
......@@ -97,7 +97,7 @@ std::shared_ptr<DmaBufTexture> Platform::createDmaBufTexture(const QSize &size,
return {};
}
std::shared_ptr<DmaBufTexture> Platform::createDmaBufTexture(const DmaBufAttributes &attribs)
std::shared_ptr<DmaBufTexture> Platform::createDmaBufTexture(const DmaBufParams &attribs)
{
return createDmaBufTexture({attribs.width, attribs.height}, attribs.format, attribs.modifier);
}
......
......@@ -44,7 +44,7 @@ class Scene;
class ScreenEdges;
class Session;
class OutputConfiguration;
struct DmaBufAttributes;
struct DmaBufParams;
class KWIN_EXPORT Outputs : public QVector<Output *>
{
......@@ -69,9 +69,9 @@ public:
virtual InputBackend *createInputBackend();
virtual OpenGLBackend *createOpenGLBackend();
virtual QPainterBackend *createQPainterBackend();
virtual std::optional<DmaBufAttributes> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers);
virtual std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers);
virtual std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier);
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const DmaBufAttributes &attributes);
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const DmaBufParams &attributes);
/**
* Allows the platform to create a platform specific screen edge.
......
......@@ -164,8 +164,8 @@ void ScreenCastStream::onStreamAddBuffer(void *data, pw_buffer *buffer)
std::shared_ptr<DmaBufTexture> dmabuff;
if (spa_data[0].type != SPA_ID_INVALID && spa_data[0].type & (1 << SPA_DATA_DmaBuf)) {
Q_ASSERT(stream->m_attribs);
dmabuff = kwinApp()->platform()->createDmaBufTexture(*stream->m_attribs);
Q_ASSERT(stream->m_params);
dmabuff = kwinApp()->platform()->createDmaBufTexture(*stream->m_params);
}
if (dmabuff) {
......@@ -306,9 +306,9 @@ bool ScreenCastStream::createStream()
int n_params;
const auto format = m_source->hasAlphaChannel() ? SPA_VIDEO_FORMAT_BGRA : SPA_VIDEO_FORMAT_BGR;
m_attribs = kwinApp()->platform()->testCreateDmaBuf(m_resolution, spaVideoFormatToDrmFormat(format), {DRM_FORMAT_MOD_INVALID});
m_params = kwinApp()->platform()->testCreateDmaBuf(m_resolution, spaVideoFormatToDrmFormat(format), {DRM_FORMAT_MOD_INVALID});
if (m_attribs) {
if (m_params) {
params[0] = buildFormat(&podBuilder, SPA_VIDEO_FORMAT_BGRA, &resolution, &defaultFramerate, &minFramerate, &maxFramerate, &modifier, 1);
params[1] = buildFormat(&podBuilder, format, &resolution, &defaultFramerate, &minFramerate, &maxFramerate, nullptr, 0);
n_params = 2;
......
......@@ -121,7 +121,7 @@ private:
EGLNativeFence *m_pendingFence = nullptr;
std::optional<std::chrono::nanoseconds> m_start;
quint64 m_sequential = 0;
std::optional<DmaBufAttributes> m_attribs;
std::optional<DmaBufParams> m_params;
};
} // namespace KWin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment