File indexing completed on 2025-03-16 11:21:47
0001 /* 0002 SPDX-FileCopyrightText: 2018 Fredrik Höglund <fredrik@kde.org> 0003 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com> 0004 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0005 SPDX-FileCopyrightText: 2021 Xaver Hugl <xaver.hugl@gmail.com> 0006 0007 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0008 */ 0009 #pragma once 0010 0011 #include "clientbuffer.h" 0012 #include "clientbufferintegration.h" 0013 0014 #include "core/dmabufattributes.h" 0015 0016 #include <QHash> 0017 #include <QSet> 0018 #include <sys/types.h> 0019 0020 namespace KWaylandServer 0021 { 0022 class LinuxDmaBufV1ClientBufferPrivate; 0023 class LinuxDmaBufV1ClientBufferIntegrationPrivate; 0024 class LinuxDmaBufV1FeedbackPrivate; 0025 0026 /** 0027 * The LinuxDmaBufV1ClientBuffer class represents a linux dma-buf client buffer. 0028 * 0029 * The LinuxDmaBufV1ClientBuffer can be used even after the underlying wl_buffer object 0030 * is destroyed by the client. 0031 */ 0032 class KWIN_EXPORT LinuxDmaBufV1ClientBuffer : public ClientBuffer 0033 { 0034 Q_OBJECT 0035 Q_DECLARE_PRIVATE(LinuxDmaBufV1ClientBuffer) 0036 0037 public: 0038 LinuxDmaBufV1ClientBuffer(KWin::DmaBufAttributes &&attrs, quint32 flags); 0039 ~LinuxDmaBufV1ClientBuffer() override; 0040 0041 quint32 format() const; 0042 quint32 flags() const; 0043 const KWin::DmaBufAttributes &attributes() const; 0044 0045 QSize size() const override; 0046 bool hasAlphaChannel() const override; 0047 Origin origin() const override; 0048 0049 private: 0050 void initialize(wl_resource *resource); 0051 friend class LinuxDmaBufParamsV1; 0052 }; 0053 0054 class KWIN_EXPORT LinuxDmaBufV1Feedback : public QObject 0055 { 0056 Q_OBJECT 0057 public: 0058 ~LinuxDmaBufV1Feedback() override; 0059 0060 enum class TrancheFlag : uint32_t { 0061 Scanout = 1, 0062 }; 0063 Q_DECLARE_FLAGS(TrancheFlags, TrancheFlag) 0064 0065 struct Tranche 0066 { 0067 dev_t device; 0068 TrancheFlags flags; 0069 QHash<uint32_t, QVector<uint64_t>> formatTable; 0070 }; 0071 /** 0072 * Sets the list of tranches for this feedback object, with lower indices 0073 * indicating a higher priority / a more optimal configuration. 0074 * The main device does not need to be included 0075 */ 0076 void setTranches(const QVector<Tranche> &tranches); 0077 0078 private: 0079 LinuxDmaBufV1Feedback(LinuxDmaBufV1ClientBufferIntegrationPrivate *integration); 0080 friend class LinuxDmaBufV1ClientBufferIntegrationPrivate; 0081 friend class LinuxDmaBufV1FeedbackPrivate; 0082 std::unique_ptr<LinuxDmaBufV1FeedbackPrivate> d; 0083 }; 0084 0085 /** 0086 * The LinuxDmaBufV1ClientBufferIntegration class provides support for linux dma-buf buffers. 0087 */ 0088 class KWIN_EXPORT LinuxDmaBufV1ClientBufferIntegration : public ClientBufferIntegration 0089 { 0090 Q_OBJECT 0091 0092 public: 0093 explicit LinuxDmaBufV1ClientBufferIntegration(Display *display); 0094 ~LinuxDmaBufV1ClientBufferIntegration() override; 0095 0096 /** 0097 * The Iface class provides an interface from the LinuxDmabufInterface into the compositor 0098 */ 0099 class RendererInterface 0100 { 0101 public: 0102 virtual ~RendererInterface() = default; 0103 0104 /** 0105 * Imports a linux-dmabuf buffer into the compositor. 0106 * 0107 * The parent LinuxDmabufUnstableV1Interface class takes ownership of returned 0108 * buffer objects. 0109 * 0110 * In return the returned buffer takes ownership of the file descriptor for each 0111 * plane. 0112 * 0113 * Note that it is the responsibility of the caller to close the file descriptors 0114 * when the import fails. 0115 * 0116 * @return The imported buffer on success, and nullptr otherwise. 0117 */ 0118 virtual LinuxDmaBufV1ClientBuffer *importBuffer(KWin::DmaBufAttributes &&attrs, quint32 flags) = 0; 0119 }; 0120 0121 RendererInterface *rendererInterface() const; 0122 0123 /** 0124 * Sets the compositor implementation for the dmabuf interface. 0125 * 0126 * The ownership is not transferred by this call. 0127 */ 0128 void setRendererInterface(RendererInterface *rendererInterface); 0129 0130 void setSupportedFormatsWithModifiers(const QVector<LinuxDmaBufV1Feedback::Tranche> &tranches); 0131 0132 private: 0133 friend class LinuxDmaBufV1ClientBufferIntegrationPrivate; 0134 std::unique_ptr<LinuxDmaBufV1ClientBufferIntegrationPrivate> d; 0135 }; 0136 0137 } // namespace KWaylandServer