1 /********************************************************************
2 Copyright © 2020 Roman Gilg <subdiff@gmail.com>
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 #pragma once
21 
22 #include "output.h"
23 
24 #include <QObject>
25 #include <QPointer>
26 #include <QRegion>
27 
28 #include <Wrapland/Server/wraplandserver_export.h>
29 
30 struct wl_resource;
31 
32 namespace Wrapland::Server
33 {
34 class BlurManager;
35 class Blur;
36 class Buffer;
37 class Client;
38 class ConfinedPointerV1;
39 class Contrast;
40 class ContrastManager;
41 class Compositor;
42 class IdleInhibitManagerV1;
43 class IdleInhibitor;
44 class LockedPointerV1;
45 class PointerConstraintsV1;
46 class PresentationFeedback;
47 class ShadowManager;
48 class Shadow;
49 class Slide;
50 class Subsurface;
51 class Viewport;
52 class Viewporter;
53 
54 enum class surface_change {
55     none = 0,
56     mapped = 1 << 0,
57     buffer = 1 << 1,
58     size = 1 << 2,
59     opaque = 1 << 3,
60     scale = 1 << 4,
61     transform = 1 << 5,
62     offset = 1 << 6,
63     source_rectangle = 1 << 7,
64     input = 1 << 8,
65     children = 1 << 9,
66     shadow = 1 << 10,
67     blur = 1 << 11,
68     slide = 1 << 12,
69     contrast = 1 << 13,
70     frame = 1 << 14,
71 };
72 Q_DECLARE_FLAGS(surface_changes, surface_change)
73 
74 struct surface_state {
75     std::shared_ptr<Buffer> buffer;
76 
77     QRegion damage;
78     QRegion opaque;
79 
80     int32_t scale{1};
81     Output::Transform transform{Output::Transform::Normal};
82     QPoint offset;
83 
84     QRectF source_rectangle;
85 
86     QRegion input;
87     bool input_is_infinite{true};
88 
89     // Stacking order: bottom (first) -> top (last).
90     std::vector<Subsurface*> children;
91 
92     QPointer<Shadow> shadow;
93     QPointer<Blur> blur;
94     QPointer<Slide> slide;
95     QPointer<Contrast> contrast;
96 
97     surface_changes updates{surface_change::none};
98 };
99 
100 class WRAPLANDSERVER_EXPORT Surface : public QObject
101 {
102     Q_OBJECT
103 public:
104     enum class PresentationKind {
105         None = 0,
106         Vsync = 1 << 0,
107         HwClock = 1 << 1,
108         HwCompletion = 1 << 2,
109         ZeroCopy = 1 << 3
110     };
111     Q_DECLARE_FLAGS(PresentationKinds, PresentationKind)
112 
113     surface_state const& state() const;
114 
115     void frameRendered(quint32 msec);
116 
117     QSize size() const;
118 
119     /**
120      * Bounds of the surface and all subsurfaces. Origin is the top-left corner of the surface.
121      */
122     QRect expanse() const;
123 
124     Subsurface* subsurface() const;
125 
126     bool isMapped() const;
127     QRegion trackedDamage() const;
128     void resetTrackedDamage();
129 
130     void setOutputs(std::vector<Output*> const& outputs);
131     void setOutputs(std::vector<WlOutput*> const& outputs);
132     std::vector<WlOutput*> outputs() const;
133 
134     QPointer<ConfinedPointerV1> confinedPointer() const;
135     QPointer<LockedPointerV1> lockedPointer() const;
136 
137     bool inhibitsIdle() const;
138 
139     uint32_t id() const;
140     Client* client() const;
141 
142     void setDataProxy(Surface* surface);
143     Surface* dataProxy() const;
144 
145     uint32_t lockPresentation(Output* output);
146     void presentationFeedback(uint32_t presentationId,
147                               uint32_t tvSecHi,
148                               uint32_t tvSecLo,
149                               uint32_t tvNsec,
150                               uint32_t refresh,
151                               uint32_t seqHi,
152                               uint32_t seqLo,
153                               PresentationKinds kinds);
154     void presentationDiscarded(uint32_t presentationId);
155 
156     wl_resource* resource() const;
157 
158 Q_SIGNALS:
159     void subsurfaceTreeChanged();
160     void pointerConstraintsChanged();
161     void inhibitsIdleChanged();
162     void committed();
163     void resourceDestroyed();
164 
165 private:
166     friend class AppMenuManager;
167     friend class BlurManager;
168     friend class ContrastManager;
169     friend class Compositor;
170     friend class DataDevice;
171     friend class Keyboard;
172     friend class IdleInhibitManagerV1;
173     friend class input_method_v2;
174     friend class LayerShellV1;
175     friend class LayerSurfaceV1;
176     friend class PlasmaShell;
177     friend class Pointer;
178     friend class PointerConstraintsV1;
179     friend class PointerPinchGestureV1;
180     friend class PointerSwipeGestureV1;
181     friend class PresentationManager;
182     friend class Seat;
183     friend class ShadowManager;
184     friend class SlideManager;
185     friend class Subsurface;
186     friend class TextInputV2;
187     friend class text_input_v3;
188     friend class Viewporter;
189     friend class XdgShell;
190     friend class XdgShellSurface;
191 
192     explicit Surface(Client* client, uint32_t version, uint32_t id);
193 
194     class Private;
195     Private* d_ptr;
196 };
197 
198 }
199 
200 Q_DECLARE_METATYPE(Wrapland::Server::Surface*)
201 Q_DECLARE_OPERATORS_FOR_FLAGS(Wrapland::Server::surface_changes)
202 Q_DECLARE_OPERATORS_FOR_FLAGS(Wrapland::Server::Surface::PresentationKinds)
203