Changeset View
Changeset View
Standalone View
Standalone View
src/client/remoteaccess.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.h" | ||||
21 | #include "event_queue.h" | ||||
22 | #include "wayland_pointer_p.h" | ||||
23 | | ||||
24 | #include <wayland-remoteaccess-client-protocol.h> | ||||
25 | | ||||
26 | namespace KWayland | ||||
27 | { | ||||
28 | namespace Client | ||||
29 | { | ||||
30 | | ||||
31 | class RemoteAccess::Private | ||||
32 | { | ||||
33 | public: | ||||
34 | explicit Private(RemoteAccess *q); | ||||
35 | void setup(org_kde_kwin_remoteaccess *k); | ||||
36 | | ||||
37 | WaylandPointer<org_kde_kwin_remoteaccess, org_kde_kwin_remoteaccess_destroy> remoteAccess; | ||||
38 | EventQueue *queue = nullptr; | ||||
39 | | ||||
40 | private: | ||||
41 | static const struct org_kde_kwin_remoteaccess_listener s_listener; | ||||
42 | static void bufferReadyCallback(void *data, org_kde_kwin_remoteaccess *org_kde_kwin_remoteaccess, qint32 gbmHandle, quint32 width, quint32 height, quint32 stride, quint32 format); | ||||
43 | | ||||
44 | RemoteAccess *q; | ||||
45 | }; | ||||
46 | | ||||
47 | RemoteAccess::RemoteAccess(QObject *parent) | ||||
48 | : QObject(parent) | ||||
49 | , d(new Private(this)) | ||||
50 | { | ||||
51 | } | ||||
52 | | ||||
53 | RemoteAccess::~RemoteAccess() | ||||
54 | { | ||||
55 | release(); | ||||
56 | } | ||||
57 | | ||||
58 | void RemoteAccess::setup(org_kde_kwin_remoteaccess *remoteAccess) | ||||
59 | { | ||||
60 | d->setup(remoteAccess); | ||||
61 | } | ||||
62 | | ||||
63 | void RemoteAccess::release() | ||||
64 | { | ||||
65 | d->remoteAccess.release(); | ||||
66 | } | ||||
67 | | ||||
68 | void RemoteAccess::destroy() | ||||
69 | { | ||||
70 | d->remoteAccess.destroy(); | ||||
71 | } | ||||
72 | | ||||
73 | void RemoteAccess::setEventQueue(EventQueue *queue) | ||||
74 | { | ||||
75 | d->queue = queue; | ||||
76 | } | ||||
77 | | ||||
78 | EventQueue *RemoteAccess::eventQueue() | ||||
79 | { | ||||
80 | return d->queue; | ||||
81 | } | ||||
82 | | ||||
83 | RemoteAccess::operator org_kde_kwin_remoteaccess*() { | ||||
84 | return d->remoteAccess; | ||||
85 | } | ||||
86 | | ||||
87 | RemoteAccess::operator org_kde_kwin_remoteaccess*() const { | ||||
88 | return d->remoteAccess; | ||||
89 | } | ||||
90 | | ||||
91 | bool RemoteAccess::isValid() const | ||||
92 | { | ||||
93 | return d->remoteAccess.isValid(); | ||||
94 | } | ||||
95 | | ||||
96 | const org_kde_kwin_remoteaccess_listener RemoteAccess::Private::s_listener = { | ||||
97 | bufferReadyCallback | ||||
98 | }; | ||||
99 | | ||||
100 | void RemoteAccess::Private::bufferReadyCallback(void *data, org_kde_kwin_remoteaccess *org_kde_kwin_remoteaccess, qint32 gbmHandle, quint32 width, quint32 height, quint32 stride, quint32 format) | ||||
101 | { | ||||
102 | Q_UNUSED(org_kde_kwin_remoteaccess) | ||||
103 | emit reinterpret_cast<Private*>(data)->q->bufferReady(gbmHandle, width, height, stride, format); | ||||
104 | } | ||||
105 | | ||||
106 | RemoteAccess::Private::Private(RemoteAccess *q) | ||||
107 | : q(q) | ||||
108 | { | ||||
109 | } | ||||
110 | | ||||
111 | void RemoteAccess::Private::setup(org_kde_kwin_remoteaccess *k) | ||||
112 | { | ||||
113 | Q_ASSERT(k); | ||||
114 | Q_ASSERT(!remoteAccess); | ||||
115 | remoteAccess.setup(k); | ||||
116 | org_kde_kwin_remoteaccess_add_listener(k, &s_listener, this); | ||||
117 | } | ||||
118 | | ||||
119 | void RemoteAccess::bufferNoLongerNeeded() | ||||
120 | { | ||||
121 | org_kde_kwin_remoteaccess_bufferNoLongerNeeded(d->remoteAccess); | ||||
122 | } | ||||
123 | | ||||
124 | | ||||
125 | } | ||||
126 | } |