Commit 56ab74a1 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

backends: Share gbm create implementations between drm and wayland

parent f50f5193
......@@ -624,18 +624,6 @@ void DrmBackend::removeVirtualOutput(Output *output)
primaryGpu()->removeVirtualOutput(virtualOutput);
}
#if !GBM_CREATE_WITH_MODIFIERS2
struct gbm_bo *
gbm_bo_create_with_modifiers2(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count, quint32 flags)
{
return gbm_bo_create_with_modifiers(gbm, width, height, format, modifiers, count);
}
#endif
gbm_bo *DrmBackend::createBo(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
const auto eglBackend = dynamic_cast<EglGbmBackend *>(m_renderBackend);
......@@ -644,26 +632,7 @@ gbm_bo *DrmBackend::createBo(const QSize &size, quint32 format, const QVector<ui
}
eglBackend->makeCurrent();
const uint32_t flags = GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR;
gbm_bo *bo = nullptr;
if (modifiers.count() > 0 && !(modifiers.count() == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) {
bo = gbm_bo_create_with_modifiers2(primaryGpu()->gbmDevice(),
size.width(),
size.height(),
format,
modifiers.constData(), modifiers.count(), 0);
}
if (!bo && (modifiers.isEmpty() || modifiers.contains(DRM_FORMAT_MOD_INVALID))) {
bo = gbm_bo_create(primaryGpu()->gbmDevice(),
size.width(),
size.height(),
format,
flags);
Q_ASSERT(!bo || gbm_bo_get_modifier(bo) == DRM_FORMAT_MOD_INVALID);
}
return bo;
return createGbmBo(primaryGpu()->gbmDevice(), size, format, modifiers);
}
std::optional<DmaBufAttributes> DrmBackend::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
......
......@@ -8,9 +8,22 @@
#include "config-kwin.h"
#include "dmabuftexture.h"
#include <libdrm/drm_fourcc.h>
#include <gbm.h>
#if !GBM_CREATE_WITH_MODIFIERS2
struct gbm_bo *
gbm_bo_create_with_modifiers2(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count, quint32 flags)
{
return gbm_bo_create_with_modifiers(gbm, width, height, format, modifiers, count);
}
#endif
namespace KWin
{
......@@ -42,4 +55,27 @@ inline DmaBufAttributes dmaBufAttributesForBo(gbm_bo *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;
gbm_bo *bo = nullptr;
if (modifiers.count() > 0 && !(modifiers.count() == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) {
bo = gbm_bo_create_with_modifiers2(device,
size.width(),
size.height(),
format,
modifiers.constData(), modifiers.count(), 0);
}
if (!bo && (modifiers.isEmpty() || modifiers.contains(DRM_FORMAT_MOD_INVALID))) {
bo = gbm_bo_create(device,
size.width(),
size.height(),
format,
flags);
Q_ASSERT(!bo || gbm_bo_get_modifier(bo) == DRM_FORMAT_MOD_INVALID);
}
return bo;
}
} // namespace KWin
......@@ -1030,7 +1030,7 @@ void WaylandBackend::removeVirtualOutput(Output *output)
std::optional<DmaBufAttributes> WaylandBackend::testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
gbm_bo *bo = createBo(size, format, modifiers);
gbm_bo *bo = createGbmBo(m_gbmDevice, size, format, modifiers);
if (!bo) {
return {};
}
......@@ -1047,7 +1047,7 @@ std::optional<DmaBufAttributes> WaylandBackend::testCreateDmaBuf(const QSize &si
std::shared_ptr<DmaBufTexture> WaylandBackend::createDmaBufTexture(const QSize &size, quint32 format, uint64_t modifier)
{
gbm_bo *bo = createBo(size, format, {modifier});
gbm_bo *bo = createGbmBo(m_gbmDevice, size, format, {modifier});
if (!bo) {
return {};
}
......@@ -1058,42 +1058,6 @@ std::shared_ptr<DmaBufTexture> WaylandBackend::createDmaBufTexture(const QSize &
return std::make_shared<DmaBufTexture>(m_eglBackend->importDmaBufAsTexture(attributes), attributes);
}
#if !GBM_CREATE_WITH_MODIFIERS2
struct gbm_bo *
gbm_bo_create_with_modifiers2(struct gbm_device *gbm,
uint32_t width, uint32_t height,
uint32_t format,
const uint64_t *modifiers,
const unsigned int count, quint32 flags)
{
return gbm_bo_create_with_modifiers(gbm, width, height, format, modifiers, count);
}
#endif
gbm_bo *WaylandBackend::createBo(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers)
{
Q_ASSERT(!modifiers.isEmpty());
const uint32_t flags = GBM_BO_USE_RENDERING;
gbm_bo *bo = nullptr;
if (!modifiers.isEmpty() && !(modifiers.count() == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) {
bo = gbm_bo_create_with_modifiers2(m_gbmDevice,
size.width(),
size.height(),
format,
modifiers.constData(), modifiers.count(), 0);
}
if (!bo && modifiers.contains(DRM_FORMAT_MOD_INVALID)) {
bo = gbm_bo_create(m_gbmDevice,
size.width(),
size.height(),
format,
flags | GBM_BO_USE_LINEAR);
Q_ASSERT(!bo || gbm_bo_get_modifier(bo) == DRM_FORMAT_MOD_INVALID);
}
return bo;
}
}
} // KWin
......@@ -331,7 +331,6 @@ private:
void updateScreenSize(WaylandOutput *output);
WaylandOutput *createOutput(const QPoint &position, const QSize &size);
gbm_bo *createBo(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers);
Session *m_session;
wl_display *m_display;
......
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