Changeset View
Changeset View
Standalone View
Standalone View
src/server/remoteaccess_interface.cpp
- This file was added.
1 | /**************************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Oleg Chernovskiy <kanedias@xaker.ru> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | ****************************************************************************/ | ||||
20 | #include "remoteaccess_interface.h" | ||||
21 | #include "display.h" | ||||
22 | #include "global_p.h" | ||||
23 | #include "resource_p.h" | ||||
24 | | ||||
25 | #include <wayland-remoteaccess-server-protocol.h> | ||||
26 | | ||||
27 | namespace KWayland | ||||
28 | { | ||||
29 | namespace Server | ||||
30 | { | ||||
31 | | ||||
32 | class RemoteAccessInterface::Private : public Global::Private | ||||
33 | { | ||||
34 | public: | ||||
35 | Private(RemoteAccessInterface *q, Display *d); | ||||
36 | void passBuffer(qint32 gbmHandle, quint32 width, quint32 height, quint32 stride, quint32 format); | ||||
37 | bool bound = false; | ||||
38 | | ||||
39 | private: | ||||
40 | static void bufferNoLongerNeededCallback(wl_client *client, wl_resource *resource); | ||||
41 | static void unbind(wl_resource *resource); | ||||
42 | static Private *cast(wl_resource *r) { | ||||
43 | return reinterpret_cast<Private*>(wl_resource_get_user_data(r)); | ||||
44 | } | ||||
45 | void bind(wl_client *client, uint32_t version, uint32_t id) override; | ||||
46 | | ||||
47 | static const struct org_kde_kwin_remoteaccess_interface s_interface; | ||||
48 | static const quint32 s_version; | ||||
49 | RemoteAccessInterface *q; | ||||
50 | wl_resource *m_resource = nullptr; | ||||
51 | }; | ||||
52 | | ||||
53 | const quint32 RemoteAccessInterface::Private::s_version = 1; | ||||
54 | | ||||
55 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | ||||
56 | const struct org_kde_kwin_remoteaccess_interface RemoteAccessInterface::Private::s_interface = { | ||||
57 | bufferNoLongerNeededCallback | ||||
58 | }; | ||||
59 | #endif | ||||
60 | | ||||
61 | void RemoteAccessInterface::Private::bufferNoLongerNeededCallback(wl_client *client, wl_resource *resource) | ||||
62 | { | ||||
63 | Private *p = cast(resource); | ||||
64 | emit p->q->bufferNoLongerNeeded(); | ||||
65 | } | ||||
66 | | ||||
67 | RemoteAccessInterface::Private::Private(RemoteAccessInterface *q, Display *d) | ||||
68 | : Global::Private(d, &org_kde_kwin_remoteaccess_interface, s_version) | ||||
69 | , q(q) | ||||
70 | { | ||||
71 | } | ||||
72 | | ||||
73 | void RemoteAccessInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) | ||||
74 | { | ||||
75 | auto c = display->getConnection(client); | ||||
76 | wl_resource *resource = c->createResource(&org_kde_kwin_remoteaccess_interface, qMin(version, s_version), id); | ||||
77 | if (!resource) { | ||||
78 | wl_client_post_no_memory(client); | ||||
79 | return; | ||||
80 | } | ||||
81 | wl_resource_set_implementation(resource, &s_interface, this, unbind); | ||||
82 | m_resource = resource; | ||||
83 | bound = true; | ||||
84 | } | ||||
85 | | ||||
86 | void RemoteAccessInterface::Private::unbind(wl_resource *resource) | ||||
87 | { | ||||
88 | Private *p = cast(resource); | ||||
89 | p->bound = false; | ||||
90 | } | ||||
91 | | ||||
92 | void RemoteAccessInterface::Private::passBuffer(qint32 gbmHandle, quint32 width, quint32 height, quint32 stride, quint32 format) | ||||
93 | { | ||||
94 | org_kde_kwin_remoteaccess_send_bufferReady(m_resource, gbmHandle, width, height, stride, format); | ||||
95 | } | ||||
96 | | ||||
97 | | ||||
98 | RemoteAccessInterface::RemoteAccessInterface(Display *display, QObject *parent) | ||||
99 | : Global(new Private(this, display), parent) | ||||
100 | { | ||||
101 | } | ||||
102 | | ||||
103 | RemoteAccessInterface::~RemoteAccessInterface() = default; | ||||
104 | | ||||
105 | void RemoteAccessInterface::passBuffer(qint32 gbmHandle, quint32 width, quint32 height, quint32 stride, quint32 format) | ||||
106 | { | ||||
107 | Private *priv = reinterpret_cast<Private *>(d.data()); | ||||
108 | priv->passBuffer(gbmHandle, width, height, stride, format); | ||||
109 | } | ||||
110 | | ||||
111 | bool RemoteAccessInterface::isBound() { | ||||
112 | Private *priv = reinterpret_cast<Private *>(d.data()); | ||||
113 | return priv->bound; | ||||
114 | } | ||||
115 | | ||||
116 | } | ||||
117 | } | ||||
118 | |