KWayland

remote_access.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Oleg Chernovskiy <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "remote_access.h"
7 #include "event_queue.h"
8 #include "logging.h"
9 #include "wayland_pointer_p.h"
10 // Wayland
11 #include <wayland-remote-access-client-protocol.h>
12 
13 namespace KWayland
14 {
15 namespace Client
16 {
17 class RemoteAccessManager::Private
18 {
19 public:
20  explicit Private(RemoteAccessManager *ram);
21  void setup(org_kde_kwin_remote_access_manager *k);
22 
23  WaylandPointer<org_kde_kwin_remote_access_manager, org_kde_kwin_remote_access_manager_release> ram;
24  EventQueue *queue = nullptr;
25 
26 private:
27  static const struct org_kde_kwin_remote_access_manager_listener s_listener;
28  static void bufferReadyCallback(void *data, org_kde_kwin_remote_access_manager *interface, qint32 buffer_id, wl_output *output);
29 
31 };
32 
33 RemoteAccessManager::Private::Private(RemoteAccessManager *q)
34  : q(q)
35 {
36 }
37 
38 const org_kde_kwin_remote_access_manager_listener RemoteAccessManager::Private::s_listener = {bufferReadyCallback};
39 
40 void RemoteAccessManager::Private::bufferReadyCallback(void *data, org_kde_kwin_remote_access_manager *interface, qint32 buffer_id, wl_output *output)
41 {
42  auto ramp = reinterpret_cast<RemoteAccessManager::Private *>(data);
43  Q_ASSERT(ramp->ram == interface);
44 
45  // handle it fully internally, get the buffer immediately
46  auto requested = org_kde_kwin_remote_access_manager_get_buffer(ramp->ram, buffer_id);
47  auto rbuf = new RemoteBuffer(ramp->q);
48  rbuf->setup(requested);
49  qCDebug(KWAYLAND_CLIENT) << "Got buffer, server fd:" << buffer_id;
50 
51  Q_EMIT ramp->q->bufferReady(output, rbuf);
52 }
53 
54 void RemoteAccessManager::Private::setup(org_kde_kwin_remote_access_manager *k)
55 {
56  Q_ASSERT(k);
57  Q_ASSERT(!ram);
58  ram.setup(k);
59  org_kde_kwin_remote_access_manager_add_listener(k, &s_listener, this);
60 }
61 
62 RemoteAccessManager::RemoteAccessManager(QObject *parent)
63  : QObject(parent)
64  , d(new Private(this))
65 {
66 }
67 
68 RemoteAccessManager::~RemoteAccessManager()
69 {
70  release();
71 }
72 
73 void RemoteAccessManager::setup(org_kde_kwin_remote_access_manager *ram)
74 {
75  d->setup(ram);
76 }
77 
79 {
80  d->ram.release();
81 }
82 
84 {
85  d->ram.destroy();
86 }
87 
89 {
90  d->queue = queue;
91 }
92 
94 {
95  return d->queue;
96 }
97 
98 RemoteAccessManager::operator org_kde_kwin_remote_access_manager *()
99 {
100  return d->ram;
101 }
102 
103 RemoteAccessManager::operator org_kde_kwin_remote_access_manager *() const
104 {
105  return d->ram;
106 }
107 
109 {
110  return d->ram.isValid();
111 }
112 
113 class RemoteBuffer::Private
114 {
115 public:
116  Private(RemoteBuffer *q);
117  void setup(org_kde_kwin_remote_buffer *buffer);
118 
119  static struct org_kde_kwin_remote_buffer_listener s_listener;
120  static void paramsCallback(void *data, org_kde_kwin_remote_buffer *rbuf, qint32 fd, quint32 width, quint32 height, quint32 stride, quint32 format);
121 
122  WaylandPointer<org_kde_kwin_remote_buffer, org_kde_kwin_remote_buffer_release> remotebuffer;
123  RemoteBuffer *q;
124 
125  qint32 fd = 0;
126  quint32 width = 0;
127  quint32 height = 0;
128  quint32 stride = 0;
129  quint32 format = 0;
130 };
131 
132 RemoteBuffer::Private::Private(RemoteBuffer *q)
133  : q(q)
134 {
135 }
136 
137 void RemoteBuffer::Private::paramsCallback(void *data,
138  org_kde_kwin_remote_buffer *rbuf,
139  qint32 fd,
140  quint32 width,
141  quint32 height,
142  quint32 stride,
143  quint32 format)
144 {
145  Q_UNUSED(rbuf)
146  Private *p = reinterpret_cast<Private *>(data);
147  p->fd = fd;
148  p->width = width;
149  p->height = height;
150  p->stride = stride;
151  p->format = format;
152  Q_EMIT p->q->parametersObtained();
153 }
154 
155 #ifndef K_DOXYGEN
156 org_kde_kwin_remote_buffer_listener RemoteBuffer::Private::s_listener = {paramsCallback};
157 #endif
158 
159 void RemoteBuffer::Private::setup(org_kde_kwin_remote_buffer *rbuffer)
160 {
161  remotebuffer.setup(rbuffer);
162  org_kde_kwin_remote_buffer_add_listener(rbuffer, &s_listener, this);
163 }
164 
165 RemoteBuffer::RemoteBuffer(QObject *parent)
166  : QObject(parent)
167  , d(new Private(this))
168 {
169 }
170 
171 RemoteBuffer::~RemoteBuffer()
172 {
173  release();
174  qCDebug(KWAYLAND_CLIENT) << "Buffer released";
175 }
176 
177 void RemoteBuffer::setup(org_kde_kwin_remote_buffer *remotebuffer)
178 {
179  Q_ASSERT(remotebuffer);
180  Q_ASSERT(!d->remotebuffer);
181  d->setup(remotebuffer);
182 }
183 
185 {
186  d->remotebuffer.release();
187 }
188 
190 {
191  d->remotebuffer.destroy();
192 }
193 
194 RemoteBuffer::operator org_kde_kwin_remote_buffer *()
195 {
196  return d->remotebuffer;
197 }
198 
199 RemoteBuffer::operator org_kde_kwin_remote_buffer *() const
200 {
201  return d->remotebuffer;
202 }
203 
205 {
206  return d->remotebuffer.isValid();
207 }
208 
209 qint32 RemoteBuffer::fd() const
210 {
211  return d->fd;
212 }
213 
214 quint32 RemoteBuffer::width() const
215 {
216  return d->width;
217 }
218 
219 quint32 RemoteBuffer::height() const
220 {
221  return d->height;
222 }
223 
224 quint32 RemoteBuffer::stride() const
225 {
226  return d->stride;
227 }
228 
229 quint32 RemoteBuffer::format() const
230 {
231  return d->format;
232 }
233 
234 }
235 }
void setup(org_kde_kwin_remote_access_manager *remoteaccessmanager)
Setup this RemoteAccessManager to manage the remoteaccessmanager.
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this RemoteAccessManager.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
RemoteAccessManager(QObject *parent=nullptr)
Creates a new RemoteAccessManager.
void release()
Releases the org_kde_kwin_remote_buffer interface.
void destroy()
Destroys the data held by this RemoteAccessManager.
void destroy()
Destroys the data held by this RemoteBuffer.
Wrapper for org_kde_kwin_remote_buffer interface.
QObject(QObject *parent)
void setup(org_kde_kwin_remote_buffer *remotebuffer)
Setup this RemoteBuffer to manage the remotebuffer.
QObject * parent() const const
void release()
Releases the org_kde_kwin_remote_access_manager interface.
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Sep 26 2021 22:51:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.