KWayland

buffer.h
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
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 <QSize>
10 #include <QScopedPointer>
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 
22 class ShmPool;
23 
24 /**
25  * @short Wrapper class for wl_buffer interface.
26  *
27  * The Buffer is provided by ShmPool and is owned by ShmPool.
28  *
29  * @see ShmPool
30  **/
31 class KWAYLANDCLIENT_EXPORT Buffer
32 {
33 public:
34  /**
35  * All image formats supported by the implementation.
36  **/
37  enum class Format {
38  ARGB32, ///< 32-bit ARGB format, can be used for QImage::Format_ARGB32 and QImage::Format_ARGB32_Premultiplied
39  RGB32 ///< 32-bit RGB format, can be used for QImage::Format_RGB32
40  };
41 
42  ~Buffer();
43  /**
44  * Copies the data from @p src into the Buffer.
45  **/
46  void copy(const void *src);
47  /**
48  * Sets the Buffer as @p released.
49  * This is automatically invoked when the Wayland server sends the release event.
50  * @param released Whether the Buffer got released by the Wayland server.
51  * @see isReleased
52  **/
53  void setReleased(bool released);
54  /**
55  * Sets whether the Buffer is used.
56  * If the Buffer may not be reused when it gets released, the user of a Buffer should
57  * mark the Buffer as used. This is needed for example when the memory is shared with
58  * a QImage. As soon as the Buffer can be reused again one should call this method with
59  * @c false again.
60  *
61  * By default a Buffer is not used.
62  *
63  * @param used Whether the Bufer should be marked as used.
64  * @see isUsed
65  **/
66  void setUsed(bool used);
67 
68  wl_buffer *buffer() const;
69  /**
70  * @returns The size of this Buffer.
71  **/
72  QSize size() const;
73  /**
74  * @returns The stride (bytes per line) of this Buffer.
75  **/
76  int32_t stride() const;
77  /**
78  * @returns @c true if the Wayland server doesn't need the Buffer anymore.
79  **/
80  bool isReleased() const;
81  /**
82  * @returns @c true if the Buffer's user is still needing the Buffer.
83  **/
84  bool isUsed() const;
85  /**
86  * @returns the memory address of this Buffer.
87  **/
88  uchar *address();
89  /**
90  * @returns The image format used by this Buffer.
91  **/
92  Format format() const;
93 
94  operator wl_buffer*();
95  operator wl_buffer*() const;
96 
97  typedef QWeakPointer<Buffer> Ptr;
98 
99  /**
100  * Helper method to get the id for a provided native buffer.
101  * @since 5.3
102  **/
103  static quint32 getId(wl_buffer *b);
104 
105 private:
106  friend class ShmPool;
107  explicit Buffer(ShmPool *parent, wl_buffer *buffer, const QSize &size, int32_t stride, size_t offset, Format format);
108  class Private;
110 };
111 
112 }
113 }
114 
115 #endif
Wrapper class for wl_shm interface.
Definition: shm_pool.h:116
Wrapper class for wl_buffer interface.
Definition: buffer.h:31
Format
All image formats supported by the implementation.
Definition: buffer.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Mar 8 2021 22:50:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.