1 | // Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> |
2 | // Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QWAYLANDSURFACE_P_H |
6 | #define QWAYLANDSURFACE_P_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> |
20 | #include <private/qobject_p.h> |
21 | |
22 | #include <private/qwlclientbuffer_p.h> |
23 | #include <QtWaylandCompositor/qwaylandsurface.h> |
24 | #include <QtWaylandCompositor/qwaylandbufferref.h> |
25 | |
26 | #include <QtWaylandCompositor/private/qwlregion_p.h> |
27 | |
28 | #include <QtCore/QList> |
29 | #include <QtCore/QRect> |
30 | #include <QtGui/QRegion> |
31 | #include <QtGui/QImage> |
32 | #include <QtGui/QWindow> |
33 | |
34 | #include <QtCore/QTextStream> |
35 | #include <QtCore/QMetaType> |
36 | |
37 | #include <wayland-util.h> |
38 | |
39 | #include <QtWaylandCompositor/private/qwayland-server-wayland.h> |
40 | #include <QtWaylandCompositor/private/qwaylandviewporter_p.h> |
41 | #include <QtWaylandCompositor/private/qwaylandidleinhibitv1_p.h> |
42 | |
43 | #include <QtCore/qpointer.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | class QWaylandCompositor; |
48 | class QWaylandSurface; |
49 | class QWaylandView; |
50 | class QWaylandInputMethodControl; |
51 | |
52 | namespace QtWayland { |
53 | class FrameCallback; |
54 | } |
55 | |
56 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSurfacePrivate : public QObjectPrivate, public QtWaylandServer::wl_surface |
57 | { |
58 | public: |
59 | static QWaylandSurfacePrivate *get(QWaylandSurface *surface); |
60 | |
61 | QWaylandSurfacePrivate(); |
62 | ~QWaylandSurfacePrivate() override; |
63 | |
64 | void ref(); |
65 | void deref(); |
66 | |
67 | void refView(QWaylandView *view); |
68 | void derefView(QWaylandView *view); |
69 | |
70 | using QtWaylandServer::wl_surface::resource; |
71 | |
72 | void removeFrameCallback(QtWayland::FrameCallback *callback); |
73 | |
74 | void notifyViewsAboutDestruction(); |
75 | |
76 | #ifndef QT_NO_DEBUG |
77 | static void addUninitializedSurface(QWaylandSurfacePrivate *surface); |
78 | static void removeUninitializedSurface(QWaylandSurfacePrivate *surface); |
79 | static bool hasUninitializedSurface(); |
80 | #endif |
81 | |
82 | void initSubsurface(QWaylandSurface *parent, struct ::wl_client *client, int id, int version); |
83 | bool isSubsurface() const { return subsurface; } |
84 | QWaylandSurfacePrivate *parentSurface() const { return subsurface ? subsurface->parentSurface : nullptr; } |
85 | |
86 | protected: |
87 | void surface_destroy_resource(Resource *resource) override; |
88 | |
89 | void surface_destroy(Resource *resource) override; |
90 | void surface_attach(Resource *resource, |
91 | struct wl_resource *buffer, int x, int y) override; |
92 | void surface_damage(Resource *resource, |
93 | int32_t x, int32_t y, int32_t width, int32_t height) override; |
94 | void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; |
95 | void surface_frame(Resource *resource, |
96 | uint32_t callback) override; |
97 | void surface_set_opaque_region(Resource *resource, |
98 | struct wl_resource *region) override; |
99 | void surface_set_input_region(Resource *resource, |
100 | struct wl_resource *region) override; |
101 | void surface_commit(Resource *resource) override; |
102 | void surface_set_buffer_transform(Resource *resource, int32_t transform) override; |
103 | void surface_set_buffer_scale(Resource *resource, int32_t bufferScale) override; |
104 | |
105 | QtWayland::ClientBuffer *getBuffer(struct ::wl_resource *buffer); |
106 | |
107 | public: //member variables |
108 | QWaylandCompositor *compositor = nullptr; |
109 | int refCount = 1; |
110 | QWaylandClient *client = nullptr; |
111 | QList<QWaylandView *> views; |
112 | QRegion damage; |
113 | QWaylandBufferRef bufferRef; |
114 | QWaylandSurfaceRole *role = nullptr; |
115 | QWaylandViewporterPrivate::Viewport *viewport = nullptr; |
116 | |
117 | struct { |
118 | QWaylandBufferRef buffer; |
119 | QRegion surfaceDamage; |
120 | QRegion bufferDamage; |
121 | QPoint offset; |
122 | bool newlyAttached = false; |
123 | QRegion inputRegion; |
124 | int bufferScale = 1; |
125 | QRectF sourceGeometry; |
126 | QSize destinationSize; |
127 | QRegion opaqueRegion; |
128 | } pending; |
129 | |
130 | QPoint lastLocalMousePos; |
131 | QPoint lastGlobalMousePos; |
132 | |
133 | QList<QtWayland::FrameCallback *> pendingFrameCallbacks; |
134 | QList<QtWayland::FrameCallback *> frameCallbacks; |
135 | |
136 | QList<QPointer<QWaylandSurface>> subsurfaceChildren; |
137 | |
138 | QList<QWaylandIdleInhibitManagerV1Private::Inhibitor *> idleInhibitors; |
139 | |
140 | QRegion inputRegion; |
141 | QRegion opaqueRegion; |
142 | |
143 | QRectF sourceGeometry; |
144 | QSize destinationSize; |
145 | QSize bufferSize; |
146 | int bufferScale = 1; |
147 | bool isCursorSurface = false; |
148 | bool destroyed = false; |
149 | bool hasContent = false; |
150 | bool isInitialized = false; |
151 | bool isOpaque = false; |
152 | Qt::ScreenOrientation contentOrientation = Qt::PrimaryOrientation; |
153 | QWindow::Visibility visibility; |
154 | #if QT_CONFIG(im) |
155 | QWaylandInputMethodControl *inputMethodControl = nullptr; |
156 | #endif |
157 | |
158 | class Subsurface : public QtWaylandServer::wl_subsurface |
159 | { |
160 | public: |
161 | Subsurface(QWaylandSurfacePrivate *s) : surface(s) {} |
162 | QWaylandSurfacePrivate *surfaceFromResource(); |
163 | |
164 | protected: |
165 | void subsurface_set_position(wl_subsurface::Resource *resource, int32_t x, int32_t y) override; |
166 | void subsurface_place_above(wl_subsurface::Resource *resource, struct wl_resource *sibling) override; |
167 | void subsurface_place_below(wl_subsurface::Resource *resource, struct wl_resource *sibling) override; |
168 | void subsurface_set_sync(wl_subsurface::Resource *resource) override; |
169 | void subsurface_set_desync(wl_subsurface::Resource *resource) override; |
170 | |
171 | private: |
172 | friend class QWaylandSurfacePrivate; |
173 | QWaylandSurfacePrivate *surface = nullptr; |
174 | QWaylandSurfacePrivate *parentSurface = nullptr; |
175 | QPoint position; |
176 | }; |
177 | |
178 | Subsurface *subsurface = nullptr; |
179 | |
180 | #ifndef QT_NO_DEBUG |
181 | static QList<QWaylandSurfacePrivate *> uninitializedSurfaces; |
182 | #endif |
183 | Q_DECLARE_PUBLIC(QWaylandSurface) |
184 | Q_DISABLE_COPY(QWaylandSurfacePrivate) |
185 | }; |
186 | |
187 | QT_END_NAMESPACE |
188 | |
189 | #endif |
190 | |