core: Move DmaBufAttributes getter to GraphicsBuffer
LinuxDmaBufV1ClientBuffer contains properties (formats, and flags) that are not available in the base GraphicsBuffer type and there's no reason to move it there. In order to get rid of those properties (and eventually hide the LinuxDmaBufV1ClientBuffer type from the public api), this change adds a DmaBufAttributes getter in the GraphicsBuffer.
This commit is contained in:
parent
27b27696e8
commit
99af2aa726
12 changed files with 66 additions and 71 deletions
|
@ -158,28 +158,28 @@ void GbmBuffer::createFds()
|
|||
|
||||
std::shared_ptr<GbmBuffer> GbmBuffer::importBuffer(DrmGpu *gpu, KWaylandServer::LinuxDmaBufV1ClientBuffer *clientBuffer)
|
||||
{
|
||||
const auto &attrs = clientBuffer->attributes();
|
||||
const auto *attrs = clientBuffer->dmabufAttributes();
|
||||
gbm_bo *bo;
|
||||
if (attrs.modifier != DRM_FORMAT_MOD_INVALID || attrs.offset[0] > 0 || attrs.planeCount > 1) {
|
||||
if (attrs->modifier != DRM_FORMAT_MOD_INVALID || attrs->offset[0] > 0 || attrs->planeCount > 1) {
|
||||
gbm_import_fd_modifier_data data = {};
|
||||
data.format = attrs.format;
|
||||
data.width = static_cast<uint32_t>(attrs.width);
|
||||
data.height = static_cast<uint32_t>(attrs.height);
|
||||
data.num_fds = attrs.planeCount;
|
||||
data.modifier = attrs.modifier;
|
||||
for (int i = 0; i < attrs.planeCount; i++) {
|
||||
data.fds[i] = attrs.fd[i].get();
|
||||
data.offsets[i] = attrs.offset[i];
|
||||
data.strides[i] = attrs.pitch[i];
|
||||
data.format = attrs->format;
|
||||
data.width = static_cast<uint32_t>(attrs->width);
|
||||
data.height = static_cast<uint32_t>(attrs->height);
|
||||
data.num_fds = attrs->planeCount;
|
||||
data.modifier = attrs->modifier;
|
||||
for (int i = 0; i < attrs->planeCount; i++) {
|
||||
data.fds[i] = attrs->fd[i].get();
|
||||
data.offsets[i] = attrs->offset[i];
|
||||
data.strides[i] = attrs->pitch[i];
|
||||
}
|
||||
bo = gbm_bo_import(gpu->gbmDevice(), GBM_BO_IMPORT_FD_MODIFIER, &data, GBM_BO_USE_SCANOUT);
|
||||
} else {
|
||||
gbm_import_fd_data data = {};
|
||||
data.fd = attrs.fd[0].get();
|
||||
data.width = static_cast<uint32_t>(attrs.width);
|
||||
data.height = static_cast<uint32_t>(attrs.height);
|
||||
data.stride = attrs.pitch[0];
|
||||
data.format = attrs.format;
|
||||
data.fd = attrs->fd[0].get();
|
||||
data.width = static_cast<uint32_t>(attrs->width);
|
||||
data.height = static_cast<uint32_t>(attrs->height);
|
||||
data.stride = attrs->pitch[0];
|
||||
data.format = attrs->format;
|
||||
bo = gbm_bo_import(gpu->gbmDevice(), GBM_BO_IMPORT_FD, &data, GBM_BO_USE_SCANOUT);
|
||||
}
|
||||
if (bo) {
|
||||
|
|
|
@ -57,9 +57,9 @@ void DmabufFeedback::scanoutFailed(KWaylandServer::SurfaceInterface *surface, co
|
|||
if (const auto &feedback = m_surface->dmabufFeedbackV1()) {
|
||||
const auto buffer = qobject_cast<KWaylandServer::LinuxDmaBufV1ClientBuffer *>(surface->buffer());
|
||||
Q_ASSERT(buffer);
|
||||
const DmaBufAttributes &dmabufAttrs = buffer->attributes();
|
||||
if (!m_attemptedFormats[dmabufAttrs.format].contains(dmabufAttrs.modifier)) {
|
||||
m_attemptedFormats[dmabufAttrs.format] << dmabufAttrs.modifier;
|
||||
const DmaBufAttributes *dmabufAttrs = buffer->dmabufAttributes();
|
||||
if (!m_attemptedFormats[dmabufAttrs->format].contains(dmabufAttrs->modifier)) {
|
||||
m_attemptedFormats[dmabufAttrs->format] << dmabufAttrs->modifier;
|
||||
QVector<KWaylandServer::LinuxDmaBufV1Feedback::Tranche> scanoutTranches;
|
||||
const auto tranches = m_eglBackend->tranches();
|
||||
for (const auto &tranche : tranches) {
|
||||
|
|
|
@ -143,16 +143,18 @@ bool EglGbmLayer::scanout(SurfaceItem *surfaceItem)
|
|||
return false;
|
||||
}
|
||||
|
||||
const DmaBufAttributes *dmabufAttributes = buffer->dmabufAttributes();
|
||||
|
||||
const auto formats = m_pipeline->formats();
|
||||
if (!formats.contains(buffer->format())) {
|
||||
if (!formats.contains(dmabufAttributes->format)) {
|
||||
m_dmabufFeedback.scanoutFailed(surface, formats);
|
||||
return false;
|
||||
}
|
||||
if (buffer->attributes().modifier == DRM_FORMAT_MOD_INVALID && m_pipeline->gpu()->platform()->gpuCount() > 1) {
|
||||
if (dmabufAttributes->modifier == DRM_FORMAT_MOD_INVALID && m_pipeline->gpu()->platform()->gpuCount() > 1) {
|
||||
// importing a buffer from another GPU without an explicit modifier can mess up the buffer format
|
||||
return false;
|
||||
}
|
||||
if (!formats[buffer->format()].contains(buffer->attributes().modifier)) {
|
||||
if (!formats[dmabufAttributes->format].contains(dmabufAttributes->modifier)) {
|
||||
return false;
|
||||
}
|
||||
const auto gbmBuffer = GbmBuffer::importBuffer(m_pipeline->gpu(), buffer);
|
||||
|
|
|
@ -36,23 +36,23 @@ namespace Wayland
|
|||
WaylandEglLayerBuffer::WaylandEglLayerBuffer(GbmGraphicsBuffer *buffer, WaylandEglBackend *backend)
|
||||
: m_graphicsBuffer(buffer)
|
||||
{
|
||||
const DmaBufAttributes &attributes = buffer->dmabufAttributes();
|
||||
const DmaBufAttributes *attributes = buffer->dmabufAttributes();
|
||||
|
||||
zwp_linux_buffer_params_v1 *params = zwp_linux_dmabuf_v1_create_params(backend->backend()->display()->linuxDmabuf()->handle());
|
||||
for (int i = 0; i < attributes.planeCount; ++i) {
|
||||
for (int i = 0; i < attributes->planeCount; ++i) {
|
||||
zwp_linux_buffer_params_v1_add(params,
|
||||
attributes.fd[i].get(),
|
||||
attributes->fd[i].get(),
|
||||
i,
|
||||
attributes.offset[i],
|
||||
attributes.pitch[i],
|
||||
attributes.modifier >> 32,
|
||||
attributes.modifier & 0xffffffff);
|
||||
attributes->offset[i],
|
||||
attributes->pitch[i],
|
||||
attributes->modifier >> 32,
|
||||
attributes->modifier & 0xffffffff);
|
||||
}
|
||||
|
||||
m_buffer = zwp_linux_buffer_params_v1_create_immed(params, attributes.width, attributes.height, attributes.format, 0);
|
||||
m_buffer = zwp_linux_buffer_params_v1_create_immed(params, attributes->width, attributes->height, attributes->format, 0);
|
||||
zwp_linux_buffer_params_v1_destroy(params);
|
||||
|
||||
m_texture = backend->importDmaBufAsTexture(attributes);
|
||||
m_texture = backend->importDmaBufAsTexture(*attributes);
|
||||
m_framebuffer = std::make_unique<GLFramebuffer>(m_texture.get());
|
||||
}
|
||||
|
||||
|
@ -258,12 +258,12 @@ bool WaylandEglCursorLayer::endFrame(const QRegion &renderedRegion, const QRegio
|
|||
|
||||
quint32 WaylandEglCursorLayer::format() const
|
||||
{
|
||||
return m_buffer->graphicsBuffer()->dmabufAttributes().format;
|
||||
return m_buffer->graphicsBuffer()->dmabufAttributes()->format;
|
||||
}
|
||||
|
||||
quint32 WaylandEglPrimaryLayer::format() const
|
||||
{
|
||||
return m_buffer->graphicsBuffer()->dmabufAttributes().format;
|
||||
return m_buffer->graphicsBuffer()->dmabufAttributes()->format;
|
||||
}
|
||||
|
||||
WaylandEglBackend::WaylandEglBackend(WaylandBackend *b)
|
||||
|
|
|
@ -25,32 +25,32 @@ X11WindowedEglLayerBuffer::X11WindowedEglLayerBuffer(GbmGraphicsBuffer *graphics
|
|||
, m_graphicsBuffer(graphicsBuffer)
|
||||
{
|
||||
X11WindowedBackend *x11Backend = backend->backend();
|
||||
const DmaBufAttributes &attributes = graphicsBuffer->dmabufAttributes();
|
||||
const DmaBufAttributes *attributes = graphicsBuffer->dmabufAttributes();
|
||||
|
||||
m_pixmap = xcb_generate_id(x11Backend->connection());
|
||||
if (x11Backend->driMajorVersion() >= 1 || x11Backend->driMinorVersion() >= 2) {
|
||||
// xcb_dri3_pixmap_from_buffers() takes the ownership of the file descriptors.
|
||||
int fds[4] = {
|
||||
attributes.fd[0].duplicate().take(),
|
||||
attributes.fd[1].duplicate().take(),
|
||||
attributes.fd[2].duplicate().take(),
|
||||
attributes.fd[3].duplicate().take(),
|
||||
attributes->fd[0].duplicate().take(),
|
||||
attributes->fd[1].duplicate().take(),
|
||||
attributes->fd[2].duplicate().take(),
|
||||
attributes->fd[3].duplicate().take(),
|
||||
};
|
||||
xcb_dri3_pixmap_from_buffers(x11Backend->connection(), m_pixmap, drawable, attributes.planeCount,
|
||||
attributes.width, attributes.height,
|
||||
attributes.pitch[0], attributes.offset[0],
|
||||
attributes.pitch[1], attributes.offset[1],
|
||||
attributes.pitch[2], attributes.offset[2],
|
||||
attributes.pitch[3], attributes.offset[3],
|
||||
depth, bpp, attributes.modifier, fds);
|
||||
xcb_dri3_pixmap_from_buffers(x11Backend->connection(), m_pixmap, drawable, attributes->planeCount,
|
||||
attributes->width, attributes->height,
|
||||
attributes->pitch[0], attributes->offset[0],
|
||||
attributes->pitch[1], attributes->offset[1],
|
||||
attributes->pitch[2], attributes->offset[2],
|
||||
attributes->pitch[3], attributes->offset[3],
|
||||
depth, bpp, attributes->modifier, fds);
|
||||
} else {
|
||||
// xcb_dri3_pixmap_from_buffer() takes the ownership of the file descriptor.
|
||||
xcb_dri3_pixmap_from_buffer(x11Backend->connection(), m_pixmap, drawable,
|
||||
attributes.height * attributes.pitch[0], attributes.width, attributes.height,
|
||||
attributes.pitch[0], depth, bpp, attributes.fd[0].duplicate().take());
|
||||
attributes->height * attributes->pitch[0], attributes->width, attributes->height,
|
||||
attributes->pitch[0], depth, bpp, attributes->fd[0].duplicate().take());
|
||||
}
|
||||
|
||||
m_texture = backend->importDmaBufAsTexture(attributes);
|
||||
m_texture = backend->importDmaBufAsTexture(*attributes);
|
||||
m_framebuffer = std::make_unique<GLFramebuffer>(m_texture.get());
|
||||
}
|
||||
|
||||
|
|
|
@ -115,9 +115,9 @@ GraphicsBuffer::Origin GbmGraphicsBuffer::origin() const
|
|||
return Origin::TopLeft;
|
||||
}
|
||||
|
||||
const DmaBufAttributes &GbmGraphicsBuffer::dmabufAttributes() const
|
||||
const DmaBufAttributes *GbmGraphicsBuffer::dmabufAttributes() const
|
||||
{
|
||||
return m_dmabufAttributes;
|
||||
return &m_dmabufAttributes;
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -27,8 +27,7 @@ public:
|
|||
QSize size() const override;
|
||||
bool hasAlphaChannel() const override;
|
||||
Origin origin() const override;
|
||||
|
||||
const DmaBufAttributes &dmabufAttributes() const;
|
||||
const DmaBufAttributes *dmabufAttributes() const override;
|
||||
|
||||
private:
|
||||
gbm_bo *m_bo;
|
||||
|
|
|
@ -52,4 +52,9 @@ void GraphicsBuffer::drop()
|
|||
}
|
||||
}
|
||||
|
||||
const DmaBufAttributes *GraphicsBuffer::dmabufAttributes() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
struct DmaBufAttributes;
|
||||
|
||||
/**
|
||||
* The GraphicsBuffer class represents a chunk of memory containing graphics data.
|
||||
*
|
||||
|
@ -47,6 +49,8 @@ public:
|
|||
virtual bool hasAlphaChannel() const = 0;
|
||||
virtual Origin origin() const = 0;
|
||||
|
||||
virtual const DmaBufAttributes *dmabufAttributes() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void released();
|
||||
void dropped();
|
||||
|
|
|
@ -287,7 +287,7 @@ EGLImageKHR AbstractEglBackend::importBufferAsImage(KWaylandServer::LinuxDmaBufV
|
|||
return *it;
|
||||
}
|
||||
|
||||
EGLImageKHR image = importDmaBufAsImage(buffer->attributes());
|
||||
EGLImageKHR image = importDmaBufAsImage(*buffer->dmabufAttributes());
|
||||
if (image != EGL_NO_IMAGE_KHR) {
|
||||
m_importedBuffers[buffer] = image;
|
||||
connect(buffer, &QObject::destroyed, this, [this, buffer]() {
|
||||
|
|
|
@ -379,22 +379,10 @@ void LinuxDmaBufV1ClientBuffer::initialize(wl_resource *resource)
|
|||
ClientBuffer::initialize(resource);
|
||||
}
|
||||
|
||||
quint32 LinuxDmaBufV1ClientBuffer::format() const
|
||||
const KWin::DmaBufAttributes *LinuxDmaBufV1ClientBuffer::dmabufAttributes() const
|
||||
{
|
||||
Q_D(const LinuxDmaBufV1ClientBuffer);
|
||||
return d->attrs.format;
|
||||
}
|
||||
|
||||
quint32 LinuxDmaBufV1ClientBuffer::flags() const
|
||||
{
|
||||
Q_D(const LinuxDmaBufV1ClientBuffer);
|
||||
return d->flags;
|
||||
}
|
||||
|
||||
const KWin::DmaBufAttributes &LinuxDmaBufV1ClientBuffer::attributes() const
|
||||
{
|
||||
Q_D(const LinuxDmaBufV1ClientBuffer);
|
||||
return d->attrs;
|
||||
return &d->attrs;
|
||||
}
|
||||
|
||||
QSize LinuxDmaBufV1ClientBuffer::size() const
|
||||
|
|
|
@ -43,13 +43,10 @@ public:
|
|||
LinuxDmaBufV1ClientBuffer(KWin::DmaBufAttributes &&attrs, quint32 flags);
|
||||
~LinuxDmaBufV1ClientBuffer() override;
|
||||
|
||||
quint32 format() const;
|
||||
quint32 flags() const;
|
||||
const KWin::DmaBufAttributes &attributes() const;
|
||||
|
||||
QSize size() const override;
|
||||
bool hasAlphaChannel() const override;
|
||||
Origin origin() const override;
|
||||
const KWin::DmaBufAttributes *dmabufAttributes() const override;
|
||||
|
||||
private:
|
||||
void initialize(wl_resource *resource);
|
||||
|
|
Loading…
Reference in a new issue