1 | /* |
2 | SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #ifndef WAYLAND_BUFFER_H |
7 | #define WAYLAND_BUFFER_H |
8 | |
9 | #include <QScopedPointer> |
10 | #include <QSize> |
11 | #include <QWeakPointer> |
12 | |
13 | #include "KWayland/Client/kwaylandclient_export.h" |
14 | |
15 | struct wl_buffer; |
16 | |
17 | namespace KWayland |
18 | { |
19 | namespace Client |
20 | { |
21 | class ShmPool; |
22 | |
23 | /** |
24 | * @short Wrapper class for wl_buffer interface. |
25 | * |
26 | * The Buffer is provided by ShmPool and is owned by ShmPool. |
27 | * |
28 | * @see ShmPool |
29 | **/ |
30 | class KWAYLANDCLIENT_EXPORT Buffer |
31 | { |
32 | public: |
33 | /** |
34 | * All image formats supported by the implementation. |
35 | **/ |
36 | enum class Format { |
37 | ARGB32, ///< 32-bit ARGB format, can be used for QImage::Format_ARGB32 and QImage::Format_ARGB32_Premultiplied |
38 | RGB32, ///< 32-bit RGB format, can be used for QImage::Format_RGB32 |
39 | }; |
40 | |
41 | ~Buffer(); |
42 | /** |
43 | * Copies the data from @p src into the Buffer. |
44 | **/ |
45 | void copy(const void *src); |
46 | /** |
47 | * Sets the Buffer as @p released. |
48 | * This is automatically invoked when the Wayland server sends the release event. |
49 | * @param released Whether the Buffer got released by the Wayland server. |
50 | * @see isReleased |
51 | **/ |
52 | void setReleased(bool released); |
53 | /** |
54 | * Sets whether the Buffer is used. |
55 | * If the Buffer may not be reused when it gets released, the user of a Buffer should |
56 | * mark the Buffer as used. This is needed for example when the memory is shared with |
57 | * a QImage. As soon as the Buffer can be reused again one should call this method with |
58 | * @c false again. |
59 | * |
60 | * By default a Buffer is not used. |
61 | * |
62 | * @param used Whether the Buffer should be marked as used. |
63 | * @see isUsed |
64 | **/ |
65 | void setUsed(bool used); |
66 | |
67 | wl_buffer *buffer() const; |
68 | /** |
69 | * @returns The size of this Buffer. |
70 | **/ |
71 | QSize size() const; |
72 | /** |
73 | * @returns The stride (bytes per line) of this Buffer. |
74 | **/ |
75 | int32_t stride() const; |
76 | /** |
77 | * @returns @c true if the Wayland server doesn't need the Buffer anymore. |
78 | **/ |
79 | bool isReleased() const; |
80 | /** |
81 | * @returns @c true if the Buffer's user is still needing the Buffer. |
82 | **/ |
83 | bool isUsed() const; |
84 | /** |
85 | * @returns the memory address of this Buffer. |
86 | **/ |
87 | uchar *address(); |
88 | /** |
89 | * @returns The image format used by this Buffer. |
90 | **/ |
91 | Format format() const; |
92 | |
93 | operator wl_buffer *(); |
94 | operator wl_buffer *() const; |
95 | |
96 | typedef QWeakPointer<Buffer> Ptr; |
97 | |
98 | /** |
99 | * Helper method to get the id for a provided native buffer. |
100 | * @since 5.3 |
101 | **/ |
102 | static quint32 getId(wl_buffer *b); |
103 | |
104 | private: |
105 | friend class ShmPool; |
106 | explicit Buffer(ShmPool *parent, wl_buffer *buffer, const QSize &size, int32_t stride, size_t offset, Format format); |
107 | class Private; |
108 | QScopedPointer<Private> d; |
109 | }; |
110 | |
111 | } |
112 | } |
113 | |
114 | #endif |
115 | |