2 * Copyright (C) 2009-2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "Animation.h"
30 #include "FilterOperations.h"
31 #include "FloatPoint.h"
32 #include "FloatPoint3D.h"
33 #include "FloatRoundedRect.h"
34 #include "FloatSize.h"
35 #include "GraphicsLayerClient.h"
37 #include "PlatformLayer.h"
38 #include "TransformOperations.h"
40 #include <wtf/Function.h>
41 #include <wtf/TypeCasts.h>
43 #if ENABLE(CSS_COMPOSITING)
44 #include "GraphicsTypes.h"
53 class GraphicsContext;
54 class GraphicsLayerFactory;
58 class TransformationMatrix;
60 namespace DisplayList {
61 typedef unsigned AsTextFlags;
64 // Base class for animation values (also used for transitions). Here to
65 // represent values for properties being animated via the GraphicsLayer,
66 // without pulling in style-related data from outside of the platform directory.
67 // FIXME: Should be moved to its own header file.
68 class AnimationValue {
69 WTF_MAKE_FAST_ALLOCATED;
71 virtual ~AnimationValue() = default;
73 double keyTime() const { return m_keyTime; }
74 const TimingFunction* timingFunction() const { return m_timingFunction.get(); }
75 virtual std::unique_ptr<AnimationValue> clone() const = 0;
78 AnimationValue(double keyTime, TimingFunction* timingFunction = nullptr)
80 , m_timingFunction(timingFunction)
84 AnimationValue(const AnimationValue& other)
85 : m_keyTime(other.m_keyTime)
86 , m_timingFunction(other.m_timingFunction ? RefPtr<TimingFunction> { other.m_timingFunction->clone() } : nullptr)
90 AnimationValue(AnimationValue&&) = default;
93 void operator=(const AnimationValue&) = delete;
96 RefPtr<TimingFunction> m_timingFunction;
99 // Used to store one float value of an animation.
100 // FIXME: Should be moved to its own header file.
101 class FloatAnimationValue : public AnimationValue {
103 FloatAnimationValue(double keyTime, float value, TimingFunction* timingFunction = nullptr)
104 : AnimationValue(keyTime, timingFunction)
109 std::unique_ptr<AnimationValue> clone() const override
111 return std::make_unique<FloatAnimationValue>(*this);
114 float value() const { return m_value; }
120 // Used to store one transform value in a keyframe list.
121 // FIXME: Should be moved to its own header file.
122 class TransformAnimationValue : public AnimationValue {
124 TransformAnimationValue(double keyTime, const TransformOperations& value, TimingFunction* timingFunction = nullptr)
125 : AnimationValue(keyTime, timingFunction)
130 std::unique_ptr<AnimationValue> clone() const override
132 return std::make_unique<TransformAnimationValue>(*this);
135 TransformAnimationValue(const TransformAnimationValue& other)
136 : AnimationValue(other)
138 m_value.operations().reserveInitialCapacity(other.m_value.operations().size());
139 for (auto& operation : other.m_value.operations())
140 m_value.operations().uncheckedAppend(operation->clone());
143 TransformAnimationValue(TransformAnimationValue&&) = default;
145 const TransformOperations& value() const { return m_value; }
148 TransformOperations m_value;
151 // Used to store one filter value in a keyframe list.
152 // FIXME: Should be moved to its own header file.
153 class FilterAnimationValue : public AnimationValue {
155 FilterAnimationValue(double keyTime, const FilterOperations& value, TimingFunction* timingFunction = nullptr)
156 : AnimationValue(keyTime, timingFunction)
161 std::unique_ptr<AnimationValue> clone() const override
163 return std::make_unique<FilterAnimationValue>(*this);
166 FilterAnimationValue(const FilterAnimationValue& other)
167 : AnimationValue(other)
169 m_value.operations().reserveInitialCapacity(other.m_value.operations().size());
170 for (auto& operation : other.m_value.operations())
171 m_value.operations().uncheckedAppend(operation->clone());
174 FilterAnimationValue(FilterAnimationValue&&) = default;
176 const FilterOperations& value() const { return m_value; }
179 FilterOperations m_value;
182 // Used to store a series of values in a keyframe list.
183 // Values will all be of the same type, which can be inferred from the property.
184 // FIXME: Should be moved to its own header file.
185 class KeyframeValueList {
187 explicit KeyframeValueList(AnimatedPropertyID property)
188 : m_property(property)
192 KeyframeValueList(const KeyframeValueList& other)
193 : m_property(other.property())
195 m_values.reserveInitialCapacity(other.m_values.size());
196 for (auto& value : other.m_values)
197 m_values.uncheckedAppend(value->clone());
200 KeyframeValueList(KeyframeValueList&&) = default;
202 KeyframeValueList& operator=(const KeyframeValueList& other)
204 KeyframeValueList copy(other);
209 KeyframeValueList& operator=(KeyframeValueList&&) = default;
211 void swap(KeyframeValueList& other)
213 std::swap(m_property, other.m_property);
214 m_values.swap(other.m_values);
217 AnimatedPropertyID property() const { return m_property; }
219 size_t size() const { return m_values.size(); }
220 const AnimationValue& at(size_t i) const { return *m_values.at(i); }
222 // Insert, sorted by keyTime.
223 WEBCORE_EXPORT void insert(std::unique_ptr<const AnimationValue>);
226 Vector<std::unique_ptr<const AnimationValue>> m_values;
227 AnimatedPropertyID m_property;
230 // GraphicsLayer is an abstraction for a rendering surface with backing store,
231 // which may have associated transformation and animations.
233 class GraphicsLayer : public RefCounted<GraphicsLayer> {
234 WTF_MAKE_FAST_ALLOCATED;
236 enum class Type : uint8_t {
243 WEBCORE_EXPORT static Ref<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient&, Type = Type::Normal);
245 WEBCORE_EXPORT virtual ~GraphicsLayer();
247 Type type() const { return m_type; }
249 virtual void initialize(Type) { }
251 using PlatformLayerID = uint64_t;
252 virtual PlatformLayerID primaryLayerID() const { return 0; }
254 GraphicsLayerClient& client() const { return m_client; }
256 // Layer name. Only used to identify layers in debug output
257 const String& name() const { return m_name; }
258 virtual void setName(const String& name) { m_name = name; }
260 GraphicsLayer* parent() const { return m_parent; };
261 void setParent(GraphicsLayer*); // Internal use only.
263 // Returns true if the layer has the given layer as an ancestor (excluding self).
264 bool hasAncestor(GraphicsLayer*) const;
266 const Vector<Ref<GraphicsLayer>>& children() const { return m_children; }
267 Vector<Ref<GraphicsLayer>>& children() { return m_children; }
269 // Returns true if the child list changed.
270 WEBCORE_EXPORT virtual bool setChildren(Vector<Ref<GraphicsLayer>>&&);
272 // Add child layers. If the child is already parented, it will be removed from its old parent.
273 WEBCORE_EXPORT virtual void addChild(Ref<GraphicsLayer>&&);
274 WEBCORE_EXPORT virtual void addChildAtIndex(Ref<GraphicsLayer>&&, int index);
275 WEBCORE_EXPORT virtual void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling);
276 WEBCORE_EXPORT virtual void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling);
277 WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild);
279 WEBCORE_EXPORT void removeAllChildren();
280 WEBCORE_EXPORT virtual void removeFromParent();
282 // The parent() of a maskLayer is set to the layer being masked.
283 GraphicsLayer* maskLayer() const { return m_maskLayer.get(); }
284 virtual void setMaskLayer(RefPtr<GraphicsLayer>&&);
286 void setIsMaskLayer(bool isMask) { m_isMaskLayer = isMask; }
287 bool isMaskLayer() const { return m_isMaskLayer; }
289 // The given layer will replicate this layer and its children; the replica renders behind this layer.
290 WEBCORE_EXPORT virtual void setReplicatedByLayer(GraphicsLayer*);
291 // Whether this layer is being replicated by another layer.
292 bool isReplicated() const { return m_replicaLayer; }
293 // The layer that replicates this layer (if any).
294 GraphicsLayer* replicaLayer() const { return m_replicaLayer.get(); }
296 const FloatPoint& replicatedLayerPosition() const { return m_replicatedLayerPosition; }
297 void setReplicatedLayerPosition(const FloatPoint& p) { m_replicatedLayerPosition = p; }
299 enum ShouldSetNeedsDisplay {
304 // Offset is origin of the renderer minus origin of the graphics layer.
305 FloatSize offsetFromRenderer() const { return m_offsetFromRenderer; }
306 void setOffsetFromRenderer(const FloatSize&, ShouldSetNeedsDisplay = SetNeedsDisplay);
308 // The position of the layer (the location of its top-left corner in its parent)
309 const FloatPoint& position() const { return m_position; }
310 virtual void setPosition(const FloatPoint& p) { m_approximatePosition = std::nullopt; m_position = p; }
312 // approximatePosition, if set, overrides position() and is used during coverage rect computation.
313 FloatPoint approximatePosition() const { return m_approximatePosition ? m_approximatePosition.value() : m_position; }
314 virtual void setApproximatePosition(const FloatPoint& p) { m_approximatePosition = p; }
316 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.
317 virtual void syncPosition(const FloatPoint& p) { m_position = p; }
319 // Anchor point: (0, 0) is top left, (1, 1) is bottom right. The anchor point
320 // affects the origin of the transforms.
321 const FloatPoint3D& anchorPoint() const { return m_anchorPoint; }
322 virtual void setAnchorPoint(const FloatPoint3D& p) { m_anchorPoint = p; }
324 // The size of the layer.
325 const FloatSize& size() const { return m_size; }
326 WEBCORE_EXPORT virtual void setSize(const FloatSize&);
328 // The boundOrigin affects the offset at which content is rendered, and sublayers are positioned.
329 const FloatPoint& boundsOrigin() const { return m_boundsOrigin; }
330 virtual void setBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
332 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.
333 virtual void syncBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
335 const TransformationMatrix& transform() const;
336 virtual void setTransform(const TransformationMatrix&);
337 bool hasNonIdentityTransform() const { return m_transform && !m_transform->isIdentity(); }
339 const TransformationMatrix& childrenTransform() const;
340 virtual void setChildrenTransform(const TransformationMatrix&);
341 bool hasNonIdentityChildrenTransform() const { return m_childrenTransform && !m_childrenTransform->isIdentity(); }
343 bool preserves3D() const { return m_preserves3D; }
344 virtual void setPreserves3D(bool b) { m_preserves3D = b; }
346 bool masksToBounds() const { return m_masksToBounds; }
347 virtual void setMasksToBounds(bool b) { m_masksToBounds = b; }
349 bool drawsContent() const { return m_drawsContent; }
350 virtual void setDrawsContent(bool b) { m_drawsContent = b; }
352 bool contentsAreVisible() const { return m_contentsVisible; }
353 virtual void setContentsVisible(bool b) { m_contentsVisible = b; }
355 bool userInteractionEnabled() const { return m_userInteractionEnabled; }
356 virtual void setUserInteractionEnabled(bool b) { m_userInteractionEnabled = b; }
358 bool acceleratesDrawing() const { return m_acceleratesDrawing; }
359 virtual void setAcceleratesDrawing(bool b) { m_acceleratesDrawing = b; }
361 bool usesDisplayListDrawing() const { return m_usesDisplayListDrawing; }
362 virtual void setUsesDisplayListDrawing(bool b) { m_usesDisplayListDrawing = b; }
364 bool needsBackdrop() const { return !m_backdropFilters.isEmpty(); }
366 // The color used to paint the layer background. Pass an invalid color to remove it.
367 // Note that this covers the entire layer. Use setContentsToSolidColor() if the color should
368 // only cover the contentsRect.
369 const Color& backgroundColor() const { return m_backgroundColor; }
370 WEBCORE_EXPORT virtual void setBackgroundColor(const Color&);
372 // opaque means that we know the layer contents have no alpha
373 bool contentsOpaque() const { return m_contentsOpaque; }
374 virtual void setContentsOpaque(bool b) { m_contentsOpaque = b; }
376 bool supportsSubpixelAntialiasedText() const { return m_supportsSubpixelAntialiasedText; }
377 virtual void setSupportsSubpixelAntialiasedText(bool b) { m_supportsSubpixelAntialiasedText = b; }
379 bool backfaceVisibility() const { return m_backfaceVisibility; }
380 virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; }
382 float opacity() const { return m_opacity; }
383 virtual void setOpacity(float opacity) { m_opacity = opacity; }
385 const FilterOperations& filters() const { return m_filters; }
386 // Returns true if filter can be rendered by the compositor.
387 virtual bool setFilters(const FilterOperations& filters) { m_filters = filters; return true; }
389 const FilterOperations& backdropFilters() const { return m_backdropFilters; }
390 virtual bool setBackdropFilters(const FilterOperations& filters) { m_backdropFilters = filters; return true; }
392 virtual void setBackdropFiltersRect(const FloatRoundedRect& backdropFiltersRect) { m_backdropFiltersRect = backdropFiltersRect; }
393 const FloatRoundedRect& backdropFiltersRect() const { return m_backdropFiltersRect; }
395 #if ENABLE(CSS_COMPOSITING)
396 BlendMode blendMode() const { return m_blendMode; }
397 virtual void setBlendMode(BlendMode blendMode) { m_blendMode = blendMode; }
400 // Some GraphicsLayers paint only the foreground or the background content
401 GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; }
402 void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; }
404 enum ShouldClipToLayer {
409 virtual void setNeedsDisplay() = 0;
410 // mark the given rect (in layer coords) as needing dispay. Never goes deep.
411 virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) = 0;
413 virtual void setContentsNeedsDisplay() { };
415 // The tile phase is relative to the GraphicsLayer bounds.
416 virtual void setContentsTilePhase(const FloatSize& p) { m_contentsTilePhase = p; }
417 FloatSize contentsTilePhase() const { return m_contentsTilePhase; }
419 virtual void setContentsTileSize(const FloatSize& s) { m_contentsTileSize = s; }
420 FloatSize contentsTileSize() const { return m_contentsTileSize; }
421 bool hasContentsTiling() const { return !m_contentsTileSize.isEmpty(); }
423 // Set that the position/size of the contents (image or video).
424 FloatRect contentsRect() const { return m_contentsRect; }
425 virtual void setContentsRect(const FloatRect& r) { m_contentsRect = r; }
427 // Set a rounded rect that will be used to clip the layer contents.
428 FloatRoundedRect contentsClippingRect() const { return m_contentsClippingRect; }
429 virtual void setContentsClippingRect(const FloatRoundedRect& roundedRect) { m_contentsClippingRect = roundedRect; }
431 // Set a rounded rect that is used to clip this layer and its descendants (implies setting masksToBounds).
432 // Returns false if the platform can't support this rounded clip, and we should fall back to painting a mask.
433 FloatRoundedRect maskToBoundsRect() const { return m_masksToBoundsRect; };
434 virtual bool setMasksToBoundsRect(const FloatRoundedRect& roundedRect) { m_masksToBoundsRect = roundedRect; return false; }
436 Path shapeLayerPath() const;
437 virtual void setShapeLayerPath(const Path&);
439 WindRule shapeLayerWindRule() const;
440 virtual void setShapeLayerWindRule(WindRule);
442 // Transitions are identified by a special animation name that cannot clash with a keyframe identifier.
443 static String animationNameForTransition(AnimatedPropertyID);
445 // Return true if the animation is handled by the compositing system. If this returns
446 // false, the animation will be run by CSSAnimationController.
447 // These methods handle both transitions and keyframe animations.
448 virtual bool addAnimation(const KeyframeValueList&, const FloatSize& /*boxSize*/, const Animation*, const String& /*animationName*/, double /*timeOffset*/) { return false; }
449 virtual void pauseAnimation(const String& /*animationName*/, double /*timeOffset*/) { }
450 virtual void seekAnimation(const String& /*animationName*/, double /*timeOffset*/) { }
451 virtual void removeAnimation(const String& /*animationName*/) { }
453 WEBCORE_EXPORT virtual void suspendAnimations(MonotonicTime);
454 WEBCORE_EXPORT virtual void resumeAnimations();
457 virtual void setContentsToImage(Image*) { }
458 virtual bool shouldDirectlyCompositeImage(Image*) const { return true; }
460 virtual PlatformLayer* contentsLayerForMedia() const { return 0; }
463 enum class ContentsLayerPurpose : uint8_t {
472 // Pass an invalid color to remove the contents layer.
473 virtual void setContentsToSolidColor(const Color&) { }
474 virtual void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) { }
475 virtual bool usesContentsLayer() const { return false; }
477 // Callback from the underlying graphics system to draw layer contents.
478 void paintGraphicsLayerContents(GraphicsContext&, const FloatRect& clip, GraphicsLayerPaintBehavior = GraphicsLayerPaintNormal);
480 // For hosting this GraphicsLayer in a native layer hierarchy.
481 virtual PlatformLayer* platformLayer() const { return 0; }
483 enum class CompositingCoordinatesOrientation : uint8_t { TopDown, BottomUp };
485 // Flippedness of the contents of this layer. Does not affect sublayer geometry.
486 virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; }
487 CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
489 void dumpLayer(WTF::TextStream&, LayerTreeAsTextBehavior = LayerTreeAsTextBehaviorNormal) const;
491 virtual void setShowDebugBorder(bool show) { m_showDebugBorder = show; }
492 bool isShowingDebugBorder() const { return m_showDebugBorder; }
494 virtual void setShowRepaintCounter(bool show) { m_showRepaintCounter = show; }
495 bool isShowingRepaintCounter() const { return m_showRepaintCounter; }
497 // FIXME: this is really a paint count.
498 int repaintCount() const { return m_repaintCount; }
499 int incrementRepaintCount() { return ++m_repaintCount; }
501 virtual void setDebugBackgroundColor(const Color&) { }
502 virtual void setDebugBorder(const Color&, float /*borderWidth*/) { }
504 enum class CustomAppearance : uint8_t {
511 virtual void setCustomAppearance(CustomAppearance customAppearance) { m_customAppearance = customAppearance; }
512 CustomAppearance customAppearance() const { return m_customAppearance; }
514 // z-position is the z-equivalent of position(). It's only used for debugging purposes.
515 virtual float zPosition() const { return m_zPosition; }
516 WEBCORE_EXPORT virtual void setZPosition(float);
518 WEBCORE_EXPORT virtual void distributeOpacity(float);
519 WEBCORE_EXPORT virtual float accumulatedOpacity() const;
521 virtual FloatSize pixelAlignmentOffset() const { return FloatSize(); }
523 virtual void setAppliesPageScale(bool appliesScale = true) { m_appliesPageScale = appliesScale; }
524 virtual bool appliesPageScale() const { return m_appliesPageScale; }
526 float pageScaleFactor() const { return m_client.pageScaleFactor(); }
527 float deviceScaleFactor() const { return m_client.deviceScaleFactor(); }
529 // Whether this layer is viewport constrained, implying that it's moved around externally from GraphicsLayer (e.g. by the scrolling tree).
530 virtual void setIsViewportConstrained(bool) { }
531 virtual bool isViewportConstrained() const { return false; }
533 virtual void deviceOrPageScaleFactorChanged() { }
534 WEBCORE_EXPORT void noteDeviceOrPageScaleFactorChangedIncludingDescendants();
536 void setIsInWindow(bool);
538 // Some compositing systems may do internal batching to synchronize compositing updates
539 // with updates drawn into the window. These methods flush internal batched state on this layer
540 // and descendant layers, and this layer only.
541 virtual void flushCompositingState(const FloatRect& /* clipRect */) { }
542 virtual void flushCompositingStateForThisLayerOnly() { }
544 // If the exposed rect of this layer changes, returns true if this or descendant layers need a flush,
545 // for example to allocate new tiles.
546 virtual bool visibleRectChangeRequiresFlush(const FloatRect& /* clipRect */) const { return false; }
548 // Return a string with a human readable form of the layer tree, If debug is true
549 // pointers for the layers and timing data will be included in the returned string.
550 WEBCORE_EXPORT String layerTreeAsText(LayerTreeAsTextBehavior = LayerTreeAsTextBehaviorNormal) const;
553 virtual String displayListAsText(DisplayList::AsTextFlags) const { return String(); }
555 virtual void setIsTrackingDisplayListReplay(bool isTracking) { m_isTrackingDisplayListReplay = isTracking; }
556 virtual bool isTrackingDisplayListReplay() const { return m_isTrackingDisplayListReplay; }
557 virtual String replayDisplayListAsText(DisplayList::AsTextFlags) const { return String(); }
559 // Return an estimate of the backing store memory cost (in bytes). May be incorrect for tiled layers.
560 WEBCORE_EXPORT virtual double backingStoreMemoryEstimate() const;
562 virtual bool backingStoreAttached() const { return true; }
563 virtual bool backingStoreAttachedForTesting() const { return backingStoreAttached(); }
565 void setCanDetachBackingStore(bool b) { m_canDetachBackingStore = b; }
566 bool canDetachBackingStore() const { return m_canDetachBackingStore; }
568 virtual TiledBacking* tiledBacking() const { return 0; }
570 void resetTrackedRepaints();
571 void addRepaintRect(const FloatRect&);
573 static bool supportsBackgroundColorContent();
574 static bool supportsLayerType(Type);
575 static bool supportsContentsTiling();
576 static bool supportsSubpixelAntialiasedLayerText();
578 void updateDebugIndicators();
580 virtual bool canThrottleLayerFlush() const { return false; }
582 virtual bool isGraphicsLayerCA() const { return false; }
583 virtual bool isGraphicsLayerCARemote() const { return false; }
584 virtual bool isGraphicsLayerTextureMapper() const { return false; }
585 virtual bool isCoordinatedGraphicsLayer() const { return false; }
587 const std::optional<FloatRect>& animationExtent() const { return m_animationExtent; }
588 void setAnimationExtent(std::optional<FloatRect> animationExtent) { m_animationExtent = animationExtent; }
590 static void traverse(GraphicsLayer&, const WTF::Function<void (GraphicsLayer&)>&);
593 WEBCORE_EXPORT explicit GraphicsLayer(Type, GraphicsLayerClient&);
595 // Should be called from derived class destructors. Should call willBeDestroyed() on super.
596 WEBCORE_EXPORT virtual void willBeDestroyed();
597 bool beingDestroyed() const { return m_beingDestroyed; }
599 // This method is used by platform GraphicsLayer classes to clear the filters
600 // when compositing is not done in hardware. It is not virtual, so the caller
601 // needs to notifiy the change to the platform layer as needed.
602 void clearFilters() { m_filters.clear(); }
603 void clearBackdropFilters() { m_backdropFilters.clear(); }
605 // Given a KeyframeValueList containing filterOperations, return true if the operations are valid.
606 static int validateFilterOperations(const KeyframeValueList&);
608 // Given a list of TransformAnimationValues, see if all the operations for each keyframe match. If so
609 // return the index of the KeyframeValueList entry that has that list of operations (it may not be
610 // the first entry because some keyframes might have an empty transform and those match any list).
611 // If the lists don't match return -1. On return, if hasBigRotation is true, functions contain
612 // rotations of >= 180 degrees
613 static int validateTransformOperations(const KeyframeValueList&, bool& hasBigRotation);
615 virtual bool shouldRepaintOnSizeChange() const { return drawsContent(); }
617 virtual void setOpacityInternal(float) { }
619 // The layer being replicated.
620 GraphicsLayer* replicatedLayer() const { return m_replicatedLayer; }
621 virtual void setReplicatedLayer(GraphicsLayer* layer) { m_replicatedLayer = layer; }
623 void dumpProperties(WTF::TextStream&, LayerTreeAsTextBehavior) const;
624 virtual void dumpAdditionalProperties(WTF::TextStream&, LayerTreeAsTextBehavior) const { }
626 WEBCORE_EXPORT virtual void getDebugBorderInfo(Color&, float& width) const;
628 GraphicsLayerClient& m_client;
631 // Offset from the owning renderer
632 FloatSize m_offsetFromRenderer;
634 // Position is relative to the parent GraphicsLayer
635 FloatPoint m_position;
637 // If set, overrides m_position. Only used for coverage computation.
638 std::optional<FloatPoint> m_approximatePosition;
640 FloatPoint3D m_anchorPoint { 0.5f, 0.5f, 0 };
642 FloatPoint m_boundsOrigin;
644 std::unique_ptr<TransformationMatrix> m_transform;
645 std::unique_ptr<TransformationMatrix> m_childrenTransform;
647 Color m_backgroundColor;
648 float m_opacity { 1 };
649 float m_zPosition { 0 };
651 FilterOperations m_filters;
652 FilterOperations m_backdropFilters;
654 #if ENABLE(CSS_COMPOSITING)
655 BlendMode m_blendMode { BlendMode::Normal };
659 CustomAppearance m_customAppearance { CustomAppearance::None };
660 GraphicsLayerPaintingPhase m_paintingPhase { GraphicsLayerPaintAllWithOverflowClip };
661 CompositingCoordinatesOrientation m_contentsOrientation { CompositingCoordinatesOrientation::TopDown }; // affects orientation of layer contents
663 bool m_beingDestroyed : 1;
664 bool m_contentsOpaque : 1;
665 bool m_supportsSubpixelAntialiasedText : 1;
666 bool m_preserves3D: 1;
667 bool m_backfaceVisibility : 1;
668 bool m_masksToBounds : 1;
669 bool m_drawsContent : 1;
670 bool m_contentsVisible : 1;
671 bool m_acceleratesDrawing : 1;
672 bool m_usesDisplayListDrawing : 1;
673 bool m_appliesPageScale : 1; // Set for the layer which has the page scale applied to it.
674 bool m_showDebugBorder : 1;
675 bool m_showRepaintCounter : 1;
676 bool m_isMaskLayer : 1;
677 bool m_isTrackingDisplayListReplay : 1;
678 bool m_userInteractionEnabled : 1;
679 bool m_canDetachBackingStore : 1;
681 int m_repaintCount { 0 };
683 Vector<Ref<GraphicsLayer>> m_children;
684 GraphicsLayer* m_parent { nullptr };
686 RefPtr<GraphicsLayer> m_maskLayer { nullptr }; // Reference to mask layer.
688 RefPtr<GraphicsLayer> m_replicaLayer { nullptr }; // A layer that replicates this layer. We only allow one, for now.
689 // The replica is not parented; this is the primary reference to it.
690 GraphicsLayer* m_replicatedLayer { nullptr }; // For a replica layer, a reference to the original layer.
691 FloatPoint m_replicatedLayerPosition; // For a replica layer, the position of the replica.
693 FloatRect m_contentsRect;
694 FloatRoundedRect m_contentsClippingRect;
695 FloatRoundedRect m_masksToBoundsRect;
696 FloatSize m_contentsTilePhase;
697 FloatSize m_contentsTileSize;
698 FloatRoundedRect m_backdropFiltersRect;
699 std::optional<FloatRect> m_animationExtent;
702 WindRule m_shapeLayerWindRule { WindRule::NonZero };
703 Path m_shapeLayerPath;
707 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const Vector<GraphicsLayer::PlatformLayerID>&);
708 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const GraphicsLayer::CustomAppearance&);
710 } // namespace WebCore
712 #define SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(ToValueTypeName, predicate) \
713 SPECIALIZE_TYPE_TRAITS_BEGIN(ToValueTypeName) \
714 static bool isType(const WebCore::GraphicsLayer& layer) { return layer.predicate; } \
715 SPECIALIZE_TYPE_TRAITS_END()
717 #if ENABLE(TREE_DEBUGGING)
718 // Outside the WebCore namespace for ease of invocation from the debugger.
719 void showGraphicsLayerTree(const WebCore::GraphicsLayer* layer);