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 // Unparent, clear the client, and clear the RefPtr.
248 WEBCORE_EXPORT static void unparentAndClear(RefPtr<GraphicsLayer>&);
249 // Clear the client, and clear the RefPtr, but leave parented.
250 WEBCORE_EXPORT static void clear(RefPtr<GraphicsLayer>&);
252 WEBCORE_EXPORT void clearClient();
253 WEBCORE_EXPORT void setClient(GraphicsLayerClient&);
255 Type type() const { return m_type; }
257 virtual void initialize(Type) { }
259 using PlatformLayerID = uint64_t;
260 virtual PlatformLayerID primaryLayerID() const { return 0; }
262 GraphicsLayerClient& client() const { return *m_client; }
264 // Layer name. Only used to identify layers in debug output
265 const String& name() const { return m_name; }
266 virtual void setName(const String& name) { m_name = name; }
268 GraphicsLayer* parent() const { return m_parent; };
269 void setParent(GraphicsLayer*); // Internal use only.
271 // Returns true if the layer has the given layer as an ancestor (excluding self).
272 bool hasAncestor(GraphicsLayer*) const;
274 const Vector<Ref<GraphicsLayer>>& children() const { return m_children; }
275 Vector<Ref<GraphicsLayer>>& children() { return m_children; }
277 // Returns true if the child list changed.
278 WEBCORE_EXPORT virtual bool setChildren(Vector<Ref<GraphicsLayer>>&&);
280 // Add child layers. If the child is already parented, it will be removed from its old parent.
281 WEBCORE_EXPORT virtual void addChild(Ref<GraphicsLayer>&&);
282 WEBCORE_EXPORT virtual void addChildAtIndex(Ref<GraphicsLayer>&&, int index);
283 WEBCORE_EXPORT virtual void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling);
284 WEBCORE_EXPORT virtual void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling);
285 WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild);
287 WEBCORE_EXPORT void removeAllChildren();
288 WEBCORE_EXPORT virtual void removeFromParent();
290 // The parent() of a maskLayer is set to the layer being masked.
291 GraphicsLayer* maskLayer() const { return m_maskLayer.get(); }
292 virtual void setMaskLayer(RefPtr<GraphicsLayer>&&);
294 void setIsMaskLayer(bool isMask) { m_isMaskLayer = isMask; }
295 bool isMaskLayer() const { return m_isMaskLayer; }
297 // The given layer will replicate this layer and its children; the replica renders behind this layer.
298 WEBCORE_EXPORT virtual void setReplicatedByLayer(RefPtr<GraphicsLayer>&&);
299 // Whether this layer is being replicated by another layer.
300 bool isReplicated() const { return m_replicaLayer; }
301 // The layer that replicates this layer (if any).
302 GraphicsLayer* replicaLayer() const { return m_replicaLayer.get(); }
304 const FloatPoint& replicatedLayerPosition() const { return m_replicatedLayerPosition; }
305 void setReplicatedLayerPosition(const FloatPoint& p) { m_replicatedLayerPosition = p; }
307 enum ShouldSetNeedsDisplay {
312 // Offset is origin of the renderer minus origin of the graphics layer.
313 FloatSize offsetFromRenderer() const { return m_offsetFromRenderer; }
314 void setOffsetFromRenderer(const FloatSize&, ShouldSetNeedsDisplay = SetNeedsDisplay);
316 // The position of the layer (the location of its top-left corner in its parent)
317 const FloatPoint& position() const { return m_position; }
318 virtual void setPosition(const FloatPoint& p) { m_approximatePosition = std::nullopt; m_position = p; }
320 // approximatePosition, if set, overrides position() and is used during coverage rect computation.
321 FloatPoint approximatePosition() const { return m_approximatePosition ? m_approximatePosition.value() : m_position; }
322 virtual void setApproximatePosition(const FloatPoint& p) { m_approximatePosition = p; }
324 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.
325 virtual void syncPosition(const FloatPoint& p) { m_position = p; }
327 // Anchor point: (0, 0) is top left, (1, 1) is bottom right. The anchor point
328 // affects the origin of the transforms.
329 const FloatPoint3D& anchorPoint() const { return m_anchorPoint; }
330 virtual void setAnchorPoint(const FloatPoint3D& p) { m_anchorPoint = p; }
332 // The size of the layer.
333 const FloatSize& size() const { return m_size; }
334 WEBCORE_EXPORT virtual void setSize(const FloatSize&);
336 // The boundOrigin affects the offset at which content is rendered, and sublayers are positioned.
337 const FloatPoint& boundsOrigin() const { return m_boundsOrigin; }
338 virtual void setBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
340 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.
341 virtual void syncBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
343 const TransformationMatrix& transform() const;
344 virtual void setTransform(const TransformationMatrix&);
345 bool hasNonIdentityTransform() const { return m_transform && !m_transform->isIdentity(); }
347 const TransformationMatrix& childrenTransform() const;
348 virtual void setChildrenTransform(const TransformationMatrix&);
349 bool hasNonIdentityChildrenTransform() const { return m_childrenTransform && !m_childrenTransform->isIdentity(); }
351 bool preserves3D() const { return m_preserves3D; }
352 virtual void setPreserves3D(bool b) { m_preserves3D = b; }
354 bool masksToBounds() const { return m_masksToBounds; }
355 virtual void setMasksToBounds(bool b) { m_masksToBounds = b; }
357 bool drawsContent() const { return m_drawsContent; }
358 virtual void setDrawsContent(bool b) { m_drawsContent = b; }
360 bool contentsAreVisible() const { return m_contentsVisible; }
361 virtual void setContentsVisible(bool b) { m_contentsVisible = b; }
363 bool userInteractionEnabled() const { return m_userInteractionEnabled; }
364 virtual void setUserInteractionEnabled(bool b) { m_userInteractionEnabled = b; }
366 bool acceleratesDrawing() const { return m_acceleratesDrawing; }
367 virtual void setAcceleratesDrawing(bool b) { m_acceleratesDrawing = b; }
369 bool usesDisplayListDrawing() const { return m_usesDisplayListDrawing; }
370 virtual void setUsesDisplayListDrawing(bool b) { m_usesDisplayListDrawing = b; }
372 bool needsBackdrop() const { return !m_backdropFilters.isEmpty(); }
374 // The color used to paint the layer background. Pass an invalid color to remove it.
375 // Note that this covers the entire layer. Use setContentsToSolidColor() if the color should
376 // only cover the contentsRect.
377 const Color& backgroundColor() const { return m_backgroundColor; }
378 WEBCORE_EXPORT virtual void setBackgroundColor(const Color&);
380 // opaque means that we know the layer contents have no alpha
381 bool contentsOpaque() const { return m_contentsOpaque; }
382 virtual void setContentsOpaque(bool b) { m_contentsOpaque = b; }
384 bool supportsSubpixelAntialiasedText() const { return m_supportsSubpixelAntialiasedText; }
385 virtual void setSupportsSubpixelAntialiasedText(bool b) { m_supportsSubpixelAntialiasedText = b; }
387 bool backfaceVisibility() const { return m_backfaceVisibility; }
388 virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; }
390 float opacity() const { return m_opacity; }
391 virtual void setOpacity(float opacity) { m_opacity = opacity; }
393 const FilterOperations& filters() const { return m_filters; }
394 // Returns true if filter can be rendered by the compositor.
395 virtual bool setFilters(const FilterOperations& filters) { m_filters = filters; return true; }
397 const FilterOperations& backdropFilters() const { return m_backdropFilters; }
398 virtual bool setBackdropFilters(const FilterOperations& filters) { m_backdropFilters = filters; return true; }
400 virtual void setBackdropFiltersRect(const FloatRoundedRect& backdropFiltersRect) { m_backdropFiltersRect = backdropFiltersRect; }
401 const FloatRoundedRect& backdropFiltersRect() const { return m_backdropFiltersRect; }
403 #if ENABLE(CSS_COMPOSITING)
404 BlendMode blendMode() const { return m_blendMode; }
405 virtual void setBlendMode(BlendMode blendMode) { m_blendMode = blendMode; }
408 // Some GraphicsLayers paint only the foreground or the background content
409 GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; }
410 void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; }
412 enum ShouldClipToLayer {
417 virtual void setNeedsDisplay() = 0;
418 // mark the given rect (in layer coords) as needing dispay. Never goes deep.
419 virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) = 0;
421 virtual void setContentsNeedsDisplay() { };
423 // The tile phase is relative to the GraphicsLayer bounds.
424 virtual void setContentsTilePhase(const FloatSize& p) { m_contentsTilePhase = p; }
425 FloatSize contentsTilePhase() const { return m_contentsTilePhase; }
427 virtual void setContentsTileSize(const FloatSize& s) { m_contentsTileSize = s; }
428 FloatSize contentsTileSize() const { return m_contentsTileSize; }
429 bool hasContentsTiling() const { return !m_contentsTileSize.isEmpty(); }
431 // Set that the position/size of the contents (image or video).
432 FloatRect contentsRect() const { return m_contentsRect; }
433 virtual void setContentsRect(const FloatRect& r) { m_contentsRect = r; }
435 // Set a rounded rect that will be used to clip the layer contents.
436 FloatRoundedRect contentsClippingRect() const { return m_contentsClippingRect; }
437 virtual void setContentsClippingRect(const FloatRoundedRect& roundedRect) { m_contentsClippingRect = roundedRect; }
439 // Set a rounded rect that is used to clip this layer and its descendants (implies setting masksToBounds).
440 // Returns false if the platform can't support this rounded clip, and we should fall back to painting a mask.
441 FloatRoundedRect maskToBoundsRect() const { return m_masksToBoundsRect; };
442 virtual bool setMasksToBoundsRect(const FloatRoundedRect& roundedRect) { m_masksToBoundsRect = roundedRect; return false; }
444 Path shapeLayerPath() const;
445 virtual void setShapeLayerPath(const Path&);
447 WindRule shapeLayerWindRule() const;
448 virtual void setShapeLayerWindRule(WindRule);
450 // Transitions are identified by a special animation name that cannot clash with a keyframe identifier.
451 static String animationNameForTransition(AnimatedPropertyID);
453 // Return true if the animation is handled by the compositing system. If this returns
454 // false, the animation will be run by CSSAnimationController.
455 // These methods handle both transitions and keyframe animations.
456 virtual bool addAnimation(const KeyframeValueList&, const FloatSize& /*boxSize*/, const Animation*, const String& /*animationName*/, double /*timeOffset*/) { return false; }
457 virtual void pauseAnimation(const String& /*animationName*/, double /*timeOffset*/) { }
458 virtual void seekAnimation(const String& /*animationName*/, double /*timeOffset*/) { }
459 virtual void removeAnimation(const String& /*animationName*/) { }
461 WEBCORE_EXPORT virtual void suspendAnimations(MonotonicTime);
462 WEBCORE_EXPORT virtual void resumeAnimations();
465 virtual void setContentsToImage(Image*) { }
466 virtual bool shouldDirectlyCompositeImage(Image*) const { return true; }
468 virtual PlatformLayer* contentsLayerForMedia() const { return 0; }
471 enum class ContentsLayerPurpose : uint8_t {
480 // Pass an invalid color to remove the contents layer.
481 virtual void setContentsToSolidColor(const Color&) { }
482 virtual void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) { }
483 virtual bool usesContentsLayer() const { return false; }
485 // Callback from the underlying graphics system to draw layer contents.
486 void paintGraphicsLayerContents(GraphicsContext&, const FloatRect& clip, GraphicsLayerPaintBehavior = GraphicsLayerPaintNormal);
488 // For hosting this GraphicsLayer in a native layer hierarchy.
489 virtual PlatformLayer* platformLayer() const { return 0; }
491 enum class CompositingCoordinatesOrientation : uint8_t { TopDown, BottomUp };
493 // Flippedness of the contents of this layer. Does not affect sublayer geometry.
494 virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; }
495 CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
497 void dumpLayer(WTF::TextStream&, LayerTreeAsTextBehavior = LayerTreeAsTextBehaviorNormal) const;
499 virtual void setShowDebugBorder(bool show) { m_showDebugBorder = show; }
500 bool isShowingDebugBorder() const { return m_showDebugBorder; }
502 virtual void setShowRepaintCounter(bool show) { m_showRepaintCounter = show; }
503 bool isShowingRepaintCounter() const { return m_showRepaintCounter; }
505 // FIXME: this is really a paint count.
506 int repaintCount() const { return m_repaintCount; }
507 int incrementRepaintCount() { return ++m_repaintCount; }
509 virtual void setDebugBackgroundColor(const Color&) { }
510 virtual void setDebugBorder(const Color&, float /*borderWidth*/) { }
512 enum class CustomAppearance : uint8_t {
519 virtual void setCustomAppearance(CustomAppearance customAppearance) { m_customAppearance = customAppearance; }
520 CustomAppearance customAppearance() const { return m_customAppearance; }
522 // z-position is the z-equivalent of position(). It's only used for debugging purposes.
523 virtual float zPosition() const { return m_zPosition; }
524 WEBCORE_EXPORT virtual void setZPosition(float);
526 WEBCORE_EXPORT virtual void distributeOpacity(float);
527 WEBCORE_EXPORT virtual float accumulatedOpacity() const;
529 virtual FloatSize pixelAlignmentOffset() const { return FloatSize(); }
531 virtual void setAppliesPageScale(bool appliesScale = true) { m_appliesPageScale = appliesScale; }
532 virtual bool appliesPageScale() const { return m_appliesPageScale; }
534 float pageScaleFactor() const { return client().pageScaleFactor(); }
535 float deviceScaleFactor() const { return client().deviceScaleFactor(); }
537 // Whether this layer is viewport constrained, implying that it's moved around externally from GraphicsLayer (e.g. by the scrolling tree).
538 virtual void setIsViewportConstrained(bool) { }
539 virtual bool isViewportConstrained() const { return false; }
541 virtual void deviceOrPageScaleFactorChanged() { }
542 WEBCORE_EXPORT void noteDeviceOrPageScaleFactorChangedIncludingDescendants();
544 void setIsInWindow(bool);
546 // Some compositing systems may do internal batching to synchronize compositing updates
547 // with updates drawn into the window. These methods flush internal batched state on this layer
548 // and descendant layers, and this layer only.
549 virtual void flushCompositingState(const FloatRect& /* clipRect */) { }
550 virtual void flushCompositingStateForThisLayerOnly() { }
552 // If the exposed rect of this layer changes, returns true if this or descendant layers need a flush,
553 // for example to allocate new tiles.
554 virtual bool visibleRectChangeRequiresFlush(const FloatRect& /* clipRect */) const { return false; }
556 // Return a string with a human readable form of the layer tree, If debug is true
557 // pointers for the layers and timing data will be included in the returned string.
558 WEBCORE_EXPORT String layerTreeAsText(LayerTreeAsTextBehavior = LayerTreeAsTextBehaviorNormal) const;
561 virtual String displayListAsText(DisplayList::AsTextFlags) const { return String(); }
563 virtual void setIsTrackingDisplayListReplay(bool isTracking) { m_isTrackingDisplayListReplay = isTracking; }
564 virtual bool isTrackingDisplayListReplay() const { return m_isTrackingDisplayListReplay; }
565 virtual String replayDisplayListAsText(DisplayList::AsTextFlags) const { return String(); }
567 // Return an estimate of the backing store memory cost (in bytes). May be incorrect for tiled layers.
568 WEBCORE_EXPORT virtual double backingStoreMemoryEstimate() const;
570 virtual bool backingStoreAttached() const { return true; }
571 virtual bool backingStoreAttachedForTesting() const { return backingStoreAttached(); }
573 void setCanDetachBackingStore(bool b) { m_canDetachBackingStore = b; }
574 bool canDetachBackingStore() const { return m_canDetachBackingStore; }
576 virtual TiledBacking* tiledBacking() const { return 0; }
578 void resetTrackedRepaints();
579 void addRepaintRect(const FloatRect&);
581 static bool supportsBackgroundColorContent();
582 static bool supportsLayerType(Type);
583 static bool supportsContentsTiling();
584 static bool supportsSubpixelAntialiasedLayerText();
586 void updateDebugIndicators();
588 virtual bool canThrottleLayerFlush() const { return false; }
590 virtual bool isGraphicsLayerCA() const { return false; }
591 virtual bool isGraphicsLayerCARemote() const { return false; }
592 virtual bool isGraphicsLayerTextureMapper() const { return false; }
593 virtual bool isCoordinatedGraphicsLayer() const { return false; }
595 const std::optional<FloatRect>& animationExtent() const { return m_animationExtent; }
596 void setAnimationExtent(std::optional<FloatRect> animationExtent) { m_animationExtent = animationExtent; }
598 static void traverse(GraphicsLayer&, const WTF::Function<void (GraphicsLayer&)>&);
601 WEBCORE_EXPORT explicit GraphicsLayer(Type, GraphicsLayerClient&);
603 // Should be called from derived class destructors. Should call willBeDestroyed() on super.
604 WEBCORE_EXPORT virtual void willBeDestroyed();
605 bool beingDestroyed() const { return m_beingDestroyed; }
607 // This method is used by platform GraphicsLayer classes to clear the filters
608 // when compositing is not done in hardware. It is not virtual, so the caller
609 // needs to notifiy the change to the platform layer as needed.
610 void clearFilters() { m_filters.clear(); }
611 void clearBackdropFilters() { m_backdropFilters.clear(); }
613 // Given a KeyframeValueList containing filterOperations, return true if the operations are valid.
614 static int validateFilterOperations(const KeyframeValueList&);
616 // Given a list of TransformAnimationValues, see if all the operations for each keyframe match. If so
617 // return the index of the KeyframeValueList entry that has that list of operations (it may not be
618 // the first entry because some keyframes might have an empty transform and those match any list).
619 // If the lists don't match return -1. On return, if hasBigRotation is true, functions contain
620 // rotations of >= 180 degrees
621 static int validateTransformOperations(const KeyframeValueList&, bool& hasBigRotation);
623 virtual bool shouldRepaintOnSizeChange() const { return drawsContent(); }
625 virtual void setOpacityInternal(float) { }
627 // The layer being replicated.
628 GraphicsLayer* replicatedLayer() const { return m_replicatedLayer; }
629 virtual void setReplicatedLayer(GraphicsLayer* layer) { m_replicatedLayer = layer; }
631 void dumpProperties(WTF::TextStream&, LayerTreeAsTextBehavior) const;
632 virtual void dumpAdditionalProperties(WTF::TextStream&, LayerTreeAsTextBehavior) const { }
634 WEBCORE_EXPORT virtual void getDebugBorderInfo(Color&, float& width) const;
636 GraphicsLayerClient* m_client; // Always non-null.
639 // Offset from the owning renderer
640 FloatSize m_offsetFromRenderer;
642 // Position is relative to the parent GraphicsLayer
643 FloatPoint m_position;
645 // If set, overrides m_position. Only used for coverage computation.
646 std::optional<FloatPoint> m_approximatePosition;
648 FloatPoint3D m_anchorPoint { 0.5f, 0.5f, 0 };
650 FloatPoint m_boundsOrigin;
652 std::unique_ptr<TransformationMatrix> m_transform;
653 std::unique_ptr<TransformationMatrix> m_childrenTransform;
655 Color m_backgroundColor;
656 float m_opacity { 1 };
657 float m_zPosition { 0 };
659 FilterOperations m_filters;
660 FilterOperations m_backdropFilters;
662 #if ENABLE(CSS_COMPOSITING)
663 BlendMode m_blendMode { BlendMode::Normal };
667 CustomAppearance m_customAppearance { CustomAppearance::None };
668 GraphicsLayerPaintingPhase m_paintingPhase { GraphicsLayerPaintAllWithOverflowClip };
669 CompositingCoordinatesOrientation m_contentsOrientation { CompositingCoordinatesOrientation::TopDown }; // affects orientation of layer contents
671 bool m_beingDestroyed : 1;
672 bool m_contentsOpaque : 1;
673 bool m_supportsSubpixelAntialiasedText : 1;
674 bool m_preserves3D: 1;
675 bool m_backfaceVisibility : 1;
676 bool m_masksToBounds : 1;
677 bool m_drawsContent : 1;
678 bool m_contentsVisible : 1;
679 bool m_acceleratesDrawing : 1;
680 bool m_usesDisplayListDrawing : 1;
681 bool m_appliesPageScale : 1; // Set for the layer which has the page scale applied to it.
682 bool m_showDebugBorder : 1;
683 bool m_showRepaintCounter : 1;
684 bool m_isMaskLayer : 1;
685 bool m_isTrackingDisplayListReplay : 1;
686 bool m_userInteractionEnabled : 1;
687 bool m_canDetachBackingStore : 1;
689 int m_repaintCount { 0 };
691 Vector<Ref<GraphicsLayer>> m_children;
692 GraphicsLayer* m_parent { nullptr };
694 RefPtr<GraphicsLayer> m_maskLayer { nullptr }; // Reference to mask layer.
696 RefPtr<GraphicsLayer> m_replicaLayer { nullptr }; // A layer that replicates this layer. We only allow one, for now.
697 // The replica is not parented; this is the primary reference to it.
698 GraphicsLayer* m_replicatedLayer { nullptr }; // For a replica layer, a reference to the original layer.
699 FloatPoint m_replicatedLayerPosition; // For a replica layer, the position of the replica.
701 FloatRect m_contentsRect;
702 FloatRoundedRect m_contentsClippingRect;
703 FloatRoundedRect m_masksToBoundsRect;
704 FloatSize m_contentsTilePhase;
705 FloatSize m_contentsTileSize;
706 FloatRoundedRect m_backdropFiltersRect;
707 std::optional<FloatRect> m_animationExtent;
710 WindRule m_shapeLayerWindRule { WindRule::NonZero };
711 Path m_shapeLayerPath;
715 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const Vector<GraphicsLayer::PlatformLayerID>&);
716 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const GraphicsLayer::CustomAppearance&);
718 } // namespace WebCore
720 #define SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(ToValueTypeName, predicate) \
721 SPECIALIZE_TYPE_TRAITS_BEGIN(ToValueTypeName) \
722 static bool isType(const WebCore::GraphicsLayer& layer) { return layer.predicate; } \
723 SPECIALIZE_TYPE_TRAITS_END()
725 #if ENABLE(TREE_DEBUGGING)
726 // Outside the WebCore namespace for ease of invocation from the debugger.
727 void showGraphicsLayerTree(const WebCore::GraphicsLayer* layer);