-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCoordinatedPlatformLayer.h
More file actions
350 lines (308 loc) · 13 KB
/
CoordinatedPlatformLayer.h
File metadata and controls
350 lines (308 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
* Copyright (C) 2024 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if USE(COORDINATED_GRAPHICS)
#include "CoordinatedCompositionReason.h"
#include "Damage.h"
#include "FloatPoint.h"
#include "FloatPoint3D.h"
#include "FloatSize.h"
#include "PlatformLayerIdentifier.h"
#include "TextureMapperAnimation.h"
#include "TransformationMatrix.h"
#include <wtf/EnumSet.h>
#include <wtf/Lock.h>
#include <wtf/ThreadSafeRefCounted.h>
namespace WebCore {
class CoordinatedAnimatedBackingStoreClient;
class CoordinatedBackingStore;
class CoordinatedBackingStoreProxy;
class CoordinatedImageBackingStore;
class CoordinatedPlatformLayer;
class CoordinatedPlatformLayerBuffer;
class CoordinatedTileBuffer;
class GraphicsLayerCoordinated;
class NativeImage;
class TextureMapperLayer;
#if USE(SKIA)
class SkiaCompositingLayer;
class SkiaPaintingEngine;
class SkiaRecordingResult;
#endif
#if USE(CAIRO)
namespace Cairo {
class PaintingEngine;
}
#endif
class CoordinatedPlatformLayer : public ThreadSafeRefCounted<CoordinatedPlatformLayer> {
public:
// FIXME: remove this client when a subclass is added for the WebProcess.
class Client {
public:
virtual void attachLayer(CoordinatedPlatformLayer&) = 0;
virtual void detachLayer(CoordinatedPlatformLayer&) = 0;
#if USE(CAIRO)
virtual Cairo::PaintingEngine& paintingEngine() = 0;
#elif USE(SKIA)
virtual SkiaPaintingEngine& paintingEngine() const = 0;
#endif
virtual Ref<CoordinatedImageBackingStore> imageBackingStore(Ref<NativeImage>&&) = 0;
virtual void notifyCompositionRequired() = 0;
virtual bool isCompositionRequiredOrOngoing() const = 0;
virtual void requestComposition(CompositionReason) = 0;
virtual RunLoop* compositingRunLoop() const = 0;
virtual int maxTextureSize() const = 0;
virtual void willPaintTile() = 0;
virtual void didPaintTile() = 0;
};
static Ref<CoordinatedPlatformLayer> create();
static Ref<CoordinatedPlatformLayer> create(Client&);
virtual ~CoordinatedPlatformLayer();
PlatformLayerIdentifier id() const { return m_id; }
Lock& lock() LIFETIME_BOUND { return m_lock; }
Client& client() const { ASSERT(m_client); return *m_client; }
void invalidateClient();
void setOwner(GraphicsLayerCoordinated*);
GraphicsLayerCoordinated* owner() const;
TextureMapperLayer& ensureTarget();
#if USE(SKIA)
SkiaCompositingLayer& ensureSkiaTarget();
#endif
void invalidateTarget();
#if ENABLE(DAMAGE_TRACKING)
void setDamagePropagationEnabled(bool enabled) { m_damagePropagationEnabled = enabled; }
void setDamageInGlobalCoordinateSpace(std::shared_ptr<Damage> damage) { m_damageInGlobalCoordinateSpace = WTF::move(damage); }
#endif
void setPosition(FloatPoint&&);
enum class ForcePositionSync : bool { No, Yes };
void setPositionForScrolling(const FloatPoint&, ForcePositionSync = ForcePositionSync::No);
const FloatPoint& position() const;
void setTopLeftPositionForScrolling(const FloatPoint&, ForcePositionSync = ForcePositionSync::No);
FloatPoint topLeftPositionForScrolling();
void setBoundsOrigin(const FloatPoint&);
void setBoundsOriginForScrolling(const FloatPoint&);
const FloatPoint& boundsOrigin() const;
void setAnchorPoint(FloatPoint3D&&);
const FloatPoint3D& anchorPoint() const;
void setSize(FloatSize&&);
const FloatSize& size() const;
FloatRect bounds() const;
void setTransform(const TransformationMatrix&);
const TransformationMatrix& transform() const;
void setChildrenTransform(const TransformationMatrix&);
const TransformationMatrix& childrenTransform() const;
void didUpdateLayerTransform();
void setVisibleRect(const FloatRect&);
const FloatRect& visibleRect() const;
void setTransformedVisibleRect(IntRect&& visibleRect, IntRect&& visibleRectIncludingFuture);
#if ENABLE(SCROLLING_THREAD)
void setScrollingNodeID(std::optional<ScrollingNodeID>);
const Markable<ScrollingNodeID>& scrollingNodeID() const;
#endif
void setDrawsContent(bool);
void setMasksToBounds(bool);
void setPreserves3D(bool);
void setBackfaceVisibility(bool);
void setOpacity(float);
void setBlendMode(BlendMode);
void setContentsVisible(bool);
bool contentsVisible() const;
void setContentsOpaque(bool);
void setContentsRect(const FloatRect&);
void setContentsRectClipsDescendants(bool);
void setContentsClippingRect(const FloatRoundedRect&);
void setContentsScale(float);
enum class RequireComposition : bool { No, Yes };
void setContentsBuffer(std::unique_ptr<CoordinatedPlatformLayerBuffer>&&, std::optional<Damage>&& = std::nullopt, RequireComposition = RequireComposition::Yes);
#if ENABLE(VIDEO) && USE(GSTREAMER)
void replaceCurrentContentsBufferWithCopy();
#endif
void setContentsBufferNeedsDisplay();
void setContentsImage(NativeImage*);
void setContentsColor(const Color&);
void setContentsTileSize(const FloatSize&);
void setContentsTilePhase(const FloatSize&);
void setDirtyRegion(Damage&&);
void setFilters(const FilterOperations&);
void setMask(CoordinatedPlatformLayer*);
void setReplica(CoordinatedPlatformLayer*);
void setBackdrop(CoordinatedPlatformLayer*);
void notifyBackdropFiltersChanged();
void setBackdropRect(const FloatRoundedRect&);
void setIsBackdropRoot(bool);
void setAnimations(const TextureMapperAnimations&);
void setChildren(Vector<Ref<CoordinatedPlatformLayer>>&&);
const Vector<Ref<CoordinatedPlatformLayer>>& children() const;
void setEventRegion(const EventRegion&);
const EventRegion& eventRegion() const;
void setClipPath(const Path&, WindRule);
void setDebugBorder(Color&&, float);
void setShowRepaintCounter(bool);
void updateContents(bool affectedByTransformAnimation);
void updateBackingStore();
void flushCompositingState(const OptionSet<CompositionReason>&, bool = false);
bool hasPendingTilesCreation() const { return m_pendingTilesCreation; }
bool isCompositionRequiredOrOngoing() const;
void requestComposition(CompositionReason);
RunLoop* compositingRunLoop() const;
int maxTextureSize() const;
Ref<CoordinatedTileBuffer> paint(const IntRect&);
#if USE(SKIA)
Ref<SkiaRecordingResult> record(const IntRect&);
Ref<CoordinatedTileBuffer> replay(const RefPtr<SkiaRecordingResult>&, const IntRect&);
#endif
void willPaintTile();
void didPaintTile();
void waitUntilPaintingComplete();
private:
explicit CoordinatedPlatformLayer(Client*);
void notifyCompositionRequired();
bool needsBackingStore() const;
void purgeBackingStores();
bool hasCommittedContentsBuffer() const;
#if ENABLE(DAMAGE_TRACKING)
void addDamage(Damage&&);
#endif
void flushCompositingStateOnTarget(const OptionSet<CompositionReason>&, TextureMapperLayer&);
#if USE(SKIA)
void flushCompositingStateOnSkiaTarget(const OptionSet<CompositionReason>&, SkiaCompositingLayer&);
#endif
enum class Change : uint8_t {
AnchorPoint,
Animations,
Backdrop,
BackdropRect,
BackdropRoot,
BackfaceVisibility,
BackingStore,
BlendMode,
BoundsOrigin,
Children,
ChildrenTransform,
ClipPath,
ContentsBuffer,
ContentsClippingRect,
ContentsColor,
ContentsImage,
ContentsOpaque,
ContentsRect,
ContentsRectClipsDescendants,
ContentsTiling,
ContentsVisible,
#if ENABLE(DAMAGE_TRACKING)
Damage,
#endif
DebugIndicators,
DrawsContent,
Filters,
Mask,
MasksToBounds,
Opacity,
Position,
Preserves3D,
Replica,
#if ENABLE(SCROLLING_THREAD)
ScrollingNode,
#endif
Size,
Transform,
};
// FIXME: remove the client when a subclass is added for the WebProcess.
Client* m_client { nullptr };
const PlatformLayerIdentifier m_id;
GraphicsLayerCoordinated* m_owner { nullptr };
std::unique_ptr<TextureMapperLayer> m_target;
#if USE(SKIA)
RefPtr<SkiaCompositingLayer> m_skiaTarget;
#endif
bool m_pendingTilesCreation { false };
bool m_needsTilesUpdate { false };
#if ENABLE(DAMAGE_TRACKING)
bool m_damagePropagationEnabled { false };
std::shared_ptr<Damage> m_damageInGlobalCoordinateSpace;
#endif
Lock m_lock;
EnumSet<Change> m_pendingChanges WTF_GUARDED_BY_LOCK(m_lock);
FloatPoint m_position WTF_GUARDED_BY_LOCK(m_lock);
FloatPoint3D m_anchorPoint WTF_GUARDED_BY_LOCK(m_lock) { 0.5f, 0.5f, 0 };
FloatSize m_size WTF_GUARDED_BY_LOCK(m_lock);
FloatPoint m_boundsOrigin WTF_GUARDED_BY_LOCK(m_lock);
TransformationMatrix m_transform WTF_GUARDED_BY_LOCK(m_lock);
TransformationMatrix m_childrenTransform WTF_GUARDED_BY_LOCK(m_lock);
FloatRect m_visibleRect WTF_GUARDED_BY_LOCK(m_lock);
IntRect m_transformedVisibleRect WTF_GUARDED_BY_LOCK(m_lock);
IntRect m_transformedVisibleRectIncludingFuture WTF_GUARDED_BY_LOCK(m_lock);
bool m_drawsContent WTF_GUARDED_BY_LOCK(m_lock) { false };
bool m_masksToBounds WTF_GUARDED_BY_LOCK(m_lock) { false };
bool m_preserves3D WTF_GUARDED_BY_LOCK(m_lock) { false };
bool m_backfaceVisibility WTF_GUARDED_BY_LOCK(m_lock) { true };
float m_opacity WTF_GUARDED_BY_LOCK(m_lock) { 1. };
BlendMode m_blendMode WTF_GUARDED_BY_LOCK(m_lock) { BlendMode::Normal };
bool m_contentsVisible WTF_GUARDED_BY_LOCK(m_lock) { true };
bool m_contentsOpaque WTF_GUARDED_BY_LOCK(m_lock) { false };
FloatRect m_contentsRect WTF_GUARDED_BY_LOCK(m_lock);
bool m_contentsRectClipsDescendants WTF_GUARDED_BY_LOCK(m_lock) { false };
FloatRoundedRect m_contentsClippingRect WTF_GUARDED_BY_LOCK(m_lock);
Color m_contentsColor WTF_GUARDED_BY_LOCK(m_lock);
FloatSize m_contentsTileSize WTF_GUARDED_BY_LOCK(m_lock);
FloatSize m_contentsTilePhase WTF_GUARDED_BY_LOCK(m_lock);
float m_contentsScale WTF_GUARDED_BY_LOCK(m_lock) { 1. };
RefPtr<CoordinatedBackingStoreProxy> m_backingStoreProxy WTF_GUARDED_BY_LOCK(m_lock);
RefPtr<CoordinatedBackingStore> m_backingStore WTF_GUARDED_BY_LOCK(m_lock);
RefPtr<CoordinatedAnimatedBackingStoreClient> m_animatedBackingStoreClient WTF_GUARDED_BY_LOCK(m_lock);
struct {
RefPtr<CoordinatedImageBackingStore> current;
RefPtr<CoordinatedImageBackingStore> committed;
} m_imageBackingStore WTF_GUARDED_BY_LOCK(m_lock);
struct {
std::unique_ptr<CoordinatedPlatformLayerBuffer> pending;
std::unique_ptr<CoordinatedPlatformLayerBuffer> committed;
} m_contentsBuffer WTF_GUARDED_BY_LOCK(m_lock);
struct {
Path path;
WindRule windRule;
} m_clipPath WTF_GUARDED_BY_LOCK(m_lock);
Vector<IntRect, 1> m_dirtyRegion WTF_GUARDED_BY_LOCK(m_lock);
FilterOperations m_filters WTF_GUARDED_BY_LOCK(m_lock);
RefPtr<CoordinatedPlatformLayer> m_mask WTF_GUARDED_BY_LOCK(m_lock);
RefPtr<CoordinatedPlatformLayer> m_replica WTF_GUARDED_BY_LOCK(m_lock);
RefPtr<CoordinatedPlatformLayer> m_backdrop WTF_GUARDED_BY_LOCK(m_lock);
FloatRoundedRect m_backdropRect WTF_GUARDED_BY_LOCK(m_lock);
bool m_isBackdropRoot WTF_GUARDED_BY_LOCK(m_lock) { false };
TextureMapperAnimations m_animations WTF_GUARDED_BY_LOCK(m_lock);
Vector<Ref<CoordinatedPlatformLayer>> m_children WTF_GUARDED_BY_LOCK(m_lock);
EventRegion m_eventRegion WTF_GUARDED_BY_LOCK(m_lock);
Color m_debugBorderColor WTF_GUARDED_BY_LOCK(m_lock);
float m_debugBorderWidth WTF_GUARDED_BY_LOCK(m_lock) { 0 };
int m_repaintCount WTF_GUARDED_BY_LOCK(m_lock) { -1 };
#if ENABLE(DAMAGE_TRACKING)
std::optional<Damage> m_damage WTF_GUARDED_BY_LOCK(m_lock);
#endif
#if ENABLE(SCROLLING_THREAD)
Markable<ScrollingNodeID> m_scrollingNodeID WTF_GUARDED_BY_LOCK(m_lock);
#endif
};
} // namespace WebCore
#endif // USE(COORDINATED_GRAPHICS)