KWayland

linuxdmabuf_v1_interface.h
1 /*
2  SPDX-FileCopyrightText: 2019 Roman Gilg <[email protected]>
3  SPDX-FileCopyrightText: 2018 Fredrik Höglund <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 #ifndef WAYLAND_SERVER_LINUXDMABUF_INTERFACE_H
8 #define WAYLAND_SERVER_LINUXDMABUF_INTERFACE_H
9 
10 #include "global.h"
11 #include "resource.h"
12 
13 #include <KWayland/Server/kwaylandserver_export.h>
14 
15 #include <QHash>
16 #include <QSet>
17 #include <QSize>
18 
19 struct wl_buffer_interface;
20 
21 namespace KWayland
22 {
23 namespace Server
24 {
25 class BufferInterface;
26 
27 /**
28  * The base class for linux-dmabuf buffers
29  *
30  * Compositors should reimplement this class to store objects specific
31  * to the underlying graphics stack.
32  */
33 class KWAYLANDSERVER_EXPORT LinuxDmabufBuffer
34 {
35 public:
37  virtual ~LinuxDmabufBuffer() = default;
38 
39  /**
40  * Returns the DRM format code for the buffer.
41  */
42  uint32_t format() const;
43  /**
44  * Returns the size of the buffer.
45  */
46  QSize size() const;
47 
48 private:
49  class Private;
50  Private *d;
51 
52  friend class LinuxDmabufUnstableV1Buffer;
53 };
54 
55 class KWAYLANDSERVER_EXPORT LinuxDmabufUnstableV1Buffer : public LinuxDmabufBuffer
56 {
57 public:
58  /**
59  * Creates a new Buffer.
60  */
61  LinuxDmabufUnstableV1Buffer(uint32_t format, const QSize &size);
62 
63  /**
64  * Destroys the Buffer.
65  */
66  virtual ~LinuxDmabufUnstableV1Buffer() = default;
67 
68 private:
69  class Private;
70  Private *d;
71 };
72 
73 /**
74  * Represents the global zpw_linux_dmabuf_v1 interface.
75  *
76  * This interface provides a way for clients to create generic dmabuf based wl_buffers.
77  */
78 class KWAYLANDSERVER_EXPORT LinuxDmabufUnstableV1Interface : public Global
79 {
80  Q_OBJECT
81 public:
82  enum Flag {
83  YInverted = (1 << 0), /// Contents are y-inverted
84  Interlaced = (1 << 1), /// Content is interlaced
85  BottomFieldFirst = (1 << 2), /// Bottom field first
86  };
87 
88  Q_DECLARE_FLAGS(Flags, Flag)
89 
90  /**
91  * Represents a plane in a buffer
92  */
93  struct Plane {
94  int fd; /// The dmabuf file descriptor
95  uint32_t offset; /// The offset from the start of buffer
96  uint32_t stride; /// The distance from the start of a row to the next row in bytes
97  uint64_t modifier; /// The layout modifier
98  };
99 
100  /**
101  * The Iface class provides an interface from the LinuxDmabufInterface into the compositor
102  */
103  class Impl
104  {
105  public:
106  Impl() = default;
107  virtual ~Impl() = default;
108 
109  /**
110  * Imports a linux-dmabuf buffer into the compositor.
111  *
112  * The parent LinuxDmabufUnstableV1Interface class takes ownership of returned
113  * buffer objects.
114  *
115  * In return the returned buffer takes ownership of the file descriptor for each
116  * plane.
117  *
118  * Note that it is the responsibility of the caller to close the file descriptors
119  * when the import fails.
120  *
121  * @return The imported buffer on success, and nullptr otherwise.
122  */
123  virtual LinuxDmabufUnstableV1Buffer *importBuffer(const QVector<Plane> &planes, uint32_t format, const QSize &size, Flags flags) = 0;
124  };
125 
126  /**
127  * Destroys the LinuxDmabufUnstableV1Interface.
128  */
130 
131  /**
132  * Sets the compositor implementation for the dmabuf interface.
133  *
134  * The ownership is not transferred by this call.
135  */
136  void setImpl(Impl *impl);
137 
138  void setSupportedFormatsWithModifiers(QHash<uint32_t, QSet<uint64_t>> set);
139 
140  /**
141  * Returns the LinuxDmabufInterface for the given resource.
142  **/
143  static LinuxDmabufUnstableV1Interface *get(wl_resource *native);
144 
145 private:
146  /**
147  * @internal
148  */
149  explicit LinuxDmabufUnstableV1Interface(Display *display, QObject *parent = nullptr);
150 
151  /**
152  * Returns a pointer to the wl_buffer implementation for imported dmabufs.
153  */
154  static const struct wl_buffer_interface *bufferImplementation();
155 
156  friend class Display;
157  friend class BufferInterface;
158 
159  class Private;
160  Private *d_func() const;
161 };
162 
163 Q_DECLARE_OPERATORS_FOR_FLAGS(LinuxDmabufUnstableV1Interface::Flags)
164 
165 }
166 }
167 
169 
170 #endif // WAYLAND_SERVER_LINUXDMABUF_INTERFACE_H
uint32_t stride
The offset from the start of buffer.
uint64_t modifier
The distance from the start of a row to the next row in bytes.
Represents the global zpw_linux_dmabuf_v1 interface.
Class holding the Wayland server display loop.
Definition: display.h:86
Reference counted representation of a Wayland buffer on Server side.
The Iface class provides an interface from the LinuxDmabufInterface into the compositor.
Base class for all Globals.
Definition: global.h:46
The base class for linux-dmabuf buffers.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Sep 23 2021 22:51:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.