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 "wayland_pointer_p.h"
9 #include "logging.h"
10 // Wayland
11 #include <wayland-remote-access-client-protocol.h>
12 
13 namespace KWayland
14 {
15 namespace Client
16 {
17 
18 class RemoteAccessManager::Private
19 {
20 public:
21  explicit Private(RemoteAccessManager *ram);
22  void setup(org_kde_kwin_remote_access_manager *k);
23 
24  WaylandPointer<org_kde_kwin_remote_access_manager, org_kde_kwin_remote_access_manager_release> ram;
25  EventQueue *queue = nullptr;
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 = {
39  bufferReadyCallback
40 };
41 
42 void RemoteAccessManager::Private::bufferReadyCallback(void *data, org_kde_kwin_remote_access_manager *interface, qint32 buffer_id, wl_output *output)
43 {
44  auto ramp = reinterpret_cast<RemoteAccessManager::Private*>(data);
45  Q_ASSERT(ramp->ram == interface);
46 
47  // handle it fully internally, get the buffer immediately
48  auto requested = org_kde_kwin_remote_access_manager_get_buffer(ramp->ram, buffer_id);
49  auto rbuf = new RemoteBuffer(ramp->q);
50  rbuf->setup(requested);
51  qCDebug(KWAYLAND_CLIENT) << "Got buffer, server fd:" << buffer_id;
52 
53  emit ramp->q->bufferReady(output, rbuf);
54 }
55 
56 void RemoteAccessManager::Private::setup(org_kde_kwin_remote_access_manager *k)
57 {
58  Q_ASSERT(k);
59  Q_ASSERT(!ram);
60  ram.setup(k);
61  org_kde_kwin_remote_access_manager_add_listener(k, &s_listener, this);
62 }
63 
64 RemoteAccessManager::RemoteAccessManager(QObject *parent)
65  : QObject(parent)
66  , d(new Private(this))
67 {
68 }
69 
70 RemoteAccessManager::~RemoteAccessManager()
71 {
72  release();
73 }
74 
75 void RemoteAccessManager::setup(org_kde_kwin_remote_access_manager *ram)
76 {
77  d->setup(ram);
78 }
79 
81 {
82  d->ram.release();
83 }
84 
86 {
87  d->ram.destroy();
88 }
89 
91 {
92  d->queue = queue;
93 }
94 
96 {
97  return d->queue;
98 }
99 
100 RemoteAccessManager::operator org_kde_kwin_remote_access_manager*() {
101  return d->ram;
102 }
103 
104 RemoteAccessManager::operator org_kde_kwin_remote_access_manager*() const {
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,
121  qint32 fd, quint32 width, quint32 height, quint32 stride, quint32 format);
122 
123  WaylandPointer<org_kde_kwin_remote_buffer, org_kde_kwin_remote_buffer_release> remotebuffer;
124  RemoteBuffer *q;
125 
126  qint32 fd = 0;
127  quint32 width = 0;
128  quint32 height = 0;
129  quint32 stride = 0;
130  quint32 format = 0;
131 };
132 
133 RemoteBuffer::Private::Private(RemoteBuffer *q)
134  : q(q)
135 {
136 }
137 
138 void RemoteBuffer::Private::paramsCallback(void *data, org_kde_kwin_remote_buffer *rbuf,
139  qint32 fd, quint32 width, quint32 height, quint32 stride, quint32 format)
140 {
141  Q_UNUSED(rbuf)
142  Private *p = reinterpret_cast<Private *>(data);
143  p->fd = fd;
144  p->width = width;
145  p->height = height;
146  p->stride = stride;
147  p->format = format;
148  emit p->q->parametersObtained();
149 }
150 
151 #ifndef K_DOXYGEN
152 org_kde_kwin_remote_buffer_listener RemoteBuffer::Private::s_listener = {
153  paramsCallback
154 };
155 #endif
156 
157 void RemoteBuffer::Private::setup(org_kde_kwin_remote_buffer *rbuffer)
158 {
159  remotebuffer.setup(rbuffer);
160  org_kde_kwin_remote_buffer_add_listener(rbuffer, &s_listener, this);
161 }
162 
163 RemoteBuffer::RemoteBuffer(QObject *parent)
164  : QObject(parent)
165  , d(new Private(this))
166 {
167 }
168 
169 RemoteBuffer::~RemoteBuffer()
170 {
171  release();
172  qCDebug(KWAYLAND_CLIENT) << "Buffer released";
173 }
174 
175 void RemoteBuffer::setup(org_kde_kwin_remote_buffer *remotebuffer)
176 {
177  Q_ASSERT(remotebuffer);
178  Q_ASSERT(!d->remotebuffer);
179  d->setup(remotebuffer);
180 }
181 
183 {
184  d->remotebuffer.release();
185 }
186 
188 {
189  d->remotebuffer.destroy();
190 }
191 
192 RemoteBuffer::operator org_kde_kwin_remote_buffer*() {
193  return d->remotebuffer;
194 }
195 
196 RemoteBuffer::operator org_kde_kwin_remote_buffer*() const {
197  return d->remotebuffer;
198 }
199 
201 {
202  return d->remotebuffer.isValid();
203 }
204 
205 qint32 RemoteBuffer::fd() const
206 {
207  return d->fd;
208 }
209 
210 quint32 RemoteBuffer::width() const
211 {
212  return d->width;
213 }
214 
215 quint32 RemoteBuffer::height() const
216 {
217  return d->height;
218 }
219 
220 quint32 RemoteBuffer::stride() const
221 {
222  return d->stride;
223 }
224 
225 quint32 RemoteBuffer::format() const
226 {
227  return d->format;
228 }
229 
230 
231 }
232 }
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:55
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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Aug 13 2020 22:50:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.