KWin
Loading...
Searching...
No Matches
graphicsbuffer.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kwin_export.h"
11
12#include <QObject>
13#include <QSize>
14#include <utility>
15
16namespace KWin
17{
18
20{
21 int planeCount = 0;
22 int width = 0;
23 int height = 0;
24 uint32_t format = 0;
25 uint64_t modifier = 0;
26
27 std::array<FileDescriptor, 4> fd;
28 std::array<uint32_t, 4> offset{0, 0, 0, 0};
29 std::array<uint32_t, 4> pitch{0, 0, 0, 0};
30};
31
33{
35 int stride;
36 off_t offset;
37 QSize size;
38 uint32_t format;
39};
40
45 TopLeft,
47};
48
56class KWIN_EXPORT GraphicsBuffer : public QObject
57{
58 Q_OBJECT
59
60public:
61 explicit GraphicsBuffer(QObject *parent = nullptr);
62
63 bool isReferenced() const;
64 bool isDropped() const;
65
66 void ref();
67 void unref();
68 void drop();
69
70 enum MapFlag {
71 Read = 0x1,
72 Write = 0x2,
73 };
74 Q_DECLARE_FLAGS(MapFlags, MapFlag)
75
76 struct Map
77 {
78 void *data = nullptr;
79 uint32_t stride = 0;
80 };
81 virtual Map map(MapFlags flags);
82 virtual void unmap();
83
84 virtual QSize size() const = 0;
85 virtual bool hasAlphaChannel() const = 0;
86
87 virtual const DmaBufAttributes *dmabufAttributes() const;
88 virtual const ShmAttributes *shmAttributes() const;
89
90 static bool alphaChannelFromDrmFormat(uint32_t format);
91
92Q_SIGNALS:
93 void released();
94
95protected:
96 int m_refCount = 0;
97 bool m_dropped = false;
98};
99
105{
106public:
108 : m_buffer(nullptr)
109 {
110 }
111
113 : m_buffer(buffer)
114 {
115 if (m_buffer) {
116 m_buffer->ref();
117 }
118 }
119
121 : m_buffer(other.m_buffer)
122 {
123 if (m_buffer) {
124 m_buffer->unref();
125 }
126 }
127
129 : m_buffer(std::exchange(other.m_buffer, nullptr))
130 {
131 }
132
134 {
135 if (m_buffer) {
136 m_buffer->unref();
137 }
138 }
139
141 {
142 if (other.m_buffer) {
143 other.m_buffer->ref();
144 }
145 if (m_buffer) {
146 m_buffer->unref();
147 }
148 m_buffer = other.m_buffer;
149 return *this;
150 }
151
153 {
154 if (m_buffer) {
155 m_buffer->unref();
156 }
157 m_buffer = std::exchange(other.m_buffer, nullptr);
158 return *this;
159 }
160
162 {
163 if (m_buffer != buffer) {
164 if (m_buffer) {
165 m_buffer->unref();
166 }
167 if (buffer) {
168 buffer->ref();
169 }
170 m_buffer = buffer;
171 }
172 return *this;
173 }
174
175 inline GraphicsBuffer *buffer() const
176 {
177 return m_buffer;
178 }
179
180 inline GraphicsBuffer *operator*() const
181 {
182 return m_buffer;
183 }
184
186 {
187 return m_buffer;
188 }
189
190 inline operator bool() const
191 {
192 return m_buffer;
193 }
194
195private:
196 GraphicsBuffer *m_buffer;
197};
198
199} // namespace KWin
200
201Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::GraphicsBuffer::MapFlags)
virtual bool hasAlphaChannel() const =0
virtual QSize size() const =0
GraphicsBufferRef & operator=(const GraphicsBufferRef &other)
GraphicsBufferRef(const GraphicsBufferRef &other)
GraphicsBuffer * operator->() const
GraphicsBufferRef(GraphicsBuffer *buffer)
GraphicsBuffer * operator*() const
GraphicsBufferRef & operator=(GraphicsBufferRef &&other)
GraphicsBufferRef & operator=(GraphicsBuffer *buffer)
GraphicsBufferRef(GraphicsBufferRef &&other)
GraphicsBuffer * buffer() const
GraphicsBufferOrigin
std::array< uint32_t, 4 > offset
std::array< uint32_t, 4 > pitch
std::array< FileDescriptor, 4 > fd
FileDescriptor fd