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 | QT_BEGIN_NAMESPACE |
44 | |
45 | class QWaylandCompositor; |
46 | class QWaylandSurface; |
47 | class QWaylandView; |
48 | class QWaylandInputMethodControl; |
49 | |
50 | namespace QtWayland { |
51 | class FrameCallback; |
52 | } |
53 | |
54 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSurfacePrivate : public QObjectPrivate, public QtWaylandServer::wl_surface |
55 | { |
56 | public: |
57 | static QWaylandSurfacePrivate *get(QWaylandSurface *surface); |
58 | |
59 | QWaylandSurfacePrivate(); |
60 | ~QWaylandSurfacePrivate() override; |
61 | |
62 | void ref(); |
63 | void deref(); |
64 | |
65 | void refView(QWaylandView *view); |
66 | void derefView(QWaylandView *view); |
67 | |
68 | using QtWaylandServer::wl_surface::resource; |
69 | |
70 | void removeFrameCallback(QtWayland::FrameCallback *callback); |
71 | |
72 | void notifyViewsAboutDestruction(); |
73 | |
74 | #ifndef QT_NO_DEBUG |
75 | static void addUninitializedSurface(QWaylandSurfacePrivate *surface); |
76 | static void removeUninitializedSurface(QWaylandSurfacePrivate *surface); |
77 | static bool hasUninitializedSurface(); |
78 | #endif |
79 | |
80 | void initSubsurface(QWaylandSurface *parent, struct ::wl_client *client, int id, int version); |
81 | bool isSubsurface() const { return subsurface; } |
82 | QWaylandSurfacePrivate *parentSurface() const { return subsurface ? subsurface->parentSurface : nullptr; } |
83 | |
84 | protected: |
85 | void surface_destroy_resource(Resource *resource) override; |
86 | |
87 | void surface_destroy(Resource *resource) override; |
88 | void surface_attach(Resource *resource, |
89 | struct wl_resource *buffer, int x, int y) override; |
90 | void surface_damage(Resource *resource, |
91 | int32_t x, int32_t y, int32_t width, int32_t height) override; |
92 | void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; |
93 | void surface_frame(Resource *resource, |
94 | uint32_t callback) override; |
95 | void surface_set_opaque_region(Resource *resource, |
96 | struct wl_resource *region) override; |
97 | void surface_set_input_region(Resource *resource, |
98 | struct wl_resource *region) override; |
99 | void surface_commit(Resource *resource) override; |
100 | void surface_set_buffer_transform(Resource *resource, int32_t transform) override; |
101 | void surface_set_buffer_scale(Resource *resource, int32_t bufferScale) override; |
102 | |
103 | QtWayland::ClientBuffer *getBuffer(struct ::wl_resource *buffer); |
104 | |
105 | public: //member variables |
106 | QWaylandCompositor *compositor = nullptr; |
107 | int refCount = 1; |
108 | QWaylandClient *client = nullptr; |
109 | QList<QWaylandView *> views; |
110 | QRegion damage; |
111 | QWaylandBufferRef bufferRef; |
112 | QWaylandSurfaceRole *role = nullptr; |
113 | QWaylandViewporterPrivate::Viewport *viewport = nullptr; |
114 | |
115 | struct { |
116 | QWaylandBufferRef buffer; |
117 | QRegion surfaceDamage; |
118 | QRegion bufferDamage; |
119 | QPoint offset; |
120 | bool newlyAttached = false; |
121 | QRegion inputRegion; |
122 | int bufferScale = 1; |
123 | QRectF sourceGeometry; |
124 | QSize destinationSize; |
125 | QRegion opaqueRegion; |
126 | } pending; |
127 | |
128 | QPoint lastLocalMousePos; |
129 | QPoint lastGlobalMousePos; |
130 | |
131 | QList<QtWayland::FrameCallback *> pendingFrameCallbacks; |
132 | QList<QtWayland::FrameCallback *> frameCallbacks; |
133 | |
134 | QList<QPointer<QWaylandSurface>> subsurfaceChildren; |
135 | |
136 | QList<QWaylandIdleInhibitManagerV1Private::Inhibitor *> idleInhibitors; |
137 | |
138 | QRegion inputRegion; |
139 | QRegion opaqueRegion; |
140 | |
141 | QRectF sourceGeometry; |
142 | QSize destinationSize; |
143 | QSize bufferSize; |
144 | int bufferScale = 1; |
145 | bool isCursorSurface = false; |
146 | bool destroyed = false; |
147 | bool hasContent = false; |
148 | bool isInitialized = false; |
149 | bool isOpaque = false; |
150 | Qt::ScreenOrientation contentOrientation = Qt::PrimaryOrientation; |
151 | QWindow::Visibility visibility; |
152 | #if QT_CONFIG(im) |
153 | QWaylandInputMethodControl *inputMethodControl = nullptr; |
154 | #endif |
155 | |
156 | class Subsurface : public QtWaylandServer::wl_subsurface |
157 | { |
158 | public: |
159 | Subsurface(QWaylandSurfacePrivate *s) : surface(s) {} |
160 | QWaylandSurfacePrivate *surfaceFromResource(); |
161 | |
162 | protected: |
163 | void subsurface_set_position(wl_subsurface::Resource *resource, int32_t x, int32_t y) override; |
164 | void subsurface_place_above(wl_subsurface::Resource *resource, struct wl_resource *sibling) override; |
165 | void subsurface_place_below(wl_subsurface::Resource *resource, struct wl_resource *sibling) override; |
166 | void subsurface_set_sync(wl_subsurface::Resource *resource) override; |
167 | void subsurface_set_desync(wl_subsurface::Resource *resource) override; |
168 | |
169 | private: |
170 | friend class QWaylandSurfacePrivate; |
171 | QWaylandSurfacePrivate *surface = nullptr; |
172 | QWaylandSurfacePrivate *parentSurface = nullptr; |
173 | QPoint position; |
174 | }; |
175 | |
176 | Subsurface *subsurface = nullptr; |
177 | |
178 | #ifndef QT_NO_DEBUG |
179 | static QList<QWaylandSurfacePrivate *> uninitializedSurfaces; |
180 | #endif |
181 | Q_DECLARE_PUBLIC(QWaylandSurface) |
182 | Q_DISABLE_COPY(QWaylandSurfacePrivate) |
183 | }; |
184 | |
185 | QT_END_NAMESPACE |
186 | |
187 | #endif |
188 | |