diff --git a/src/backends/drm/drm_buffer_gbm.cpp b/src/backends/drm/drm_buffer_gbm.cpp index 5f559c1451..dd1618ae2e 100644 --- a/src/backends/drm/drm_buffer_gbm.cpp +++ b/src/backends/drm/drm_buffer_gbm.cpp @@ -158,28 +158,28 @@ void GbmBuffer::createFds() std::shared_ptr 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(attrs.width); - data.height = static_cast(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(attrs->width); + data.height = static_cast(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(attrs.width); - data.height = static_cast(attrs.height); - data.stride = attrs.pitch[0]; - data.format = attrs.format; + data.fd = attrs->fd[0].get(); + data.width = static_cast(attrs->width); + data.height = static_cast(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) { diff --git a/src/backends/drm/drm_dmabuf_feedback.cpp b/src/backends/drm/drm_dmabuf_feedback.cpp index 0792323f34..a87a3f3038 100644 --- a/src/backends/drm/drm_dmabuf_feedback.cpp +++ b/src/backends/drm/drm_dmabuf_feedback.cpp @@ -57,9 +57,9 @@ void DmabufFeedback::scanoutFailed(KWaylandServer::SurfaceInterface *surface, co if (const auto &feedback = m_surface->dmabufFeedbackV1()) { const auto buffer = qobject_cast(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 scanoutTranches; const auto tranches = m_eglBackend->tranches(); for (const auto &tranche : tranches) { diff --git a/src/backends/drm/drm_egl_layer.cpp b/src/backends/drm/drm_egl_layer.cpp index 2c8a927461..ae75e18cb6 100644 --- a/src/backends/drm/drm_egl_layer.cpp +++ b/src/backends/drm/drm_egl_layer.cpp @@ -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); diff --git a/src/backends/wayland/wayland_egl_backend.cpp b/src/backends/wayland/wayland_egl_backend.cpp index 2bbc28147a..a1d9e42dc2 100644 --- a/src/backends/wayland/wayland_egl_backend.cpp +++ b/src/backends/wayland/wayland_egl_backend.cpp @@ -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(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) diff --git a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp index 166b68043f..54af7f4ccf 100644 --- a/src/backends/x11/windowed/x11_windowed_egl_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_egl_backend.cpp @@ -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(m_texture.get()); } diff --git a/src/core/gbmgraphicsbufferallocator.cpp b/src/core/gbmgraphicsbufferallocator.cpp index eb467f230b..d8ef2c7ffc 100644 --- a/src/core/gbmgraphicsbufferallocator.cpp +++ b/src/core/gbmgraphicsbufferallocator.cpp @@ -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 diff --git a/src/core/gbmgraphicsbufferallocator.h b/src/core/gbmgraphicsbufferallocator.h index 22bec9da0a..2c05e75dcd 100644 --- a/src/core/gbmgraphicsbufferallocator.h +++ b/src/core/gbmgraphicsbufferallocator.h @@ -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; diff --git a/src/core/graphicsbuffer.cpp b/src/core/graphicsbuffer.cpp index 36d255073c..d4ec5d85b1 100644 --- a/src/core/graphicsbuffer.cpp +++ b/src/core/graphicsbuffer.cpp @@ -52,4 +52,9 @@ void GraphicsBuffer::drop() } } +const DmaBufAttributes *GraphicsBuffer::dmabufAttributes() const +{ + return nullptr; +} + } // namespace KWin diff --git a/src/core/graphicsbuffer.h b/src/core/graphicsbuffer.h index 2b7aee1977..9a04712b81 100644 --- a/src/core/graphicsbuffer.h +++ b/src/core/graphicsbuffer.h @@ -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(); diff --git a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp index 431c1fe388..1faa8215c3 100644 --- a/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp +++ b/src/platformsupport/scenes/opengl/abstract_egl_backend.cpp @@ -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]() { diff --git a/src/wayland/linuxdmabufv1clientbuffer.cpp b/src/wayland/linuxdmabufv1clientbuffer.cpp index 329e0ed240..fbab22f9fb 100644 --- a/src/wayland/linuxdmabufv1clientbuffer.cpp +++ b/src/wayland/linuxdmabufv1clientbuffer.cpp @@ -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 diff --git a/src/wayland/linuxdmabufv1clientbuffer.h b/src/wayland/linuxdmabufv1clientbuffer.h index 11564f73eb..0a6764b93b 100644 --- a/src/wayland/linuxdmabufv1clientbuffer.h +++ b/src/wayland/linuxdmabufv1clientbuffer.h @@ -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);