Skip to content

Commit

Permalink
Make AnimationPropertyID an enum class
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=250520

Reviewed by Alex Christensen.

* Source/WebCore/platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::animationNameForTransition):
(WebCore::GraphicsLayer::validateFilterOperations):
* Source/WebCore/platform/graphics/GraphicsLayer.h:
(WebCore::KeyframeValueList::KeyframeValueList):
(WebCore::KeyframeValueList::property const):
* Source/WebCore/platform/graphics/GraphicsLayerClient.h:
(WebCore::GraphicsLayerClient::transformMatrixForProperty const):
(WebCore::animatedPropertyIsTransformOrRelated): Deleted.
* Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::propertyIdToString):
(WebCore::animatedPropertyIsTransformOrRelated):
(WebCore::GraphicsLayerCA::moveOrCopyAnimations):
(WebCore::GraphicsLayerCA::addAnimation):
(WebCore::GraphicsLayerCA::updateAnimations):
(WebCore::GraphicsLayerCA::createAnimationFromKeyframes):
(WebCore::GraphicsLayerCA::createFilterAnimationsFromKeyframes):
(WebCore::GraphicsLayerCA::setAnimationEndpoints):
(WebCore::GraphicsLayerCA::setAnimationKeyframes):
(WebCore::GraphicsLayerCA::animatedLayer const):
(WebCore::GraphicsLayerCA::animatedLayerClones const):
(WebCore::operator<<):
* Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h:
(WebCore::GraphicsLayerCA::LayerPropertyAnimation::LayerPropertyAnimation):
* Source/WebCore/platform/graphics/nicosia/NicosiaAnimation.cpp:
(Nicosia::createThreadsafeKeyFrames):
(Nicosia::Animation::applyInternal):
(Nicosia::Animations::remove):
(Nicosia::Animations::hasActiveAnimationsOfType const):
* Source/WebCore/platform/graphics/nicosia/NicosiaAnimation.h:
(Nicosia::Animation::Animation):
* Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
(WebCore::GraphicsLayerTextureMapper::addAnimation):
* Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
(WebCore::CoordinatedGraphicsLayer::shouldHaveBackingStore const):
(WebCore::CoordinatedGraphicsLayer::selfOrAncestorHasActiveTransformAnimation const):
(WebCore::CoordinatedGraphicsLayer::addAnimation):
* Source/WebCore/rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::startAnimation):
(WebCore::RenderLayerBacking::graphicsLayerToCSSProperty):
(WebCore::RenderLayerBacking::cssToGraphicsLayerProperty):
(WebCore::RenderLayerBacking::transformMatrixForProperty const):
* Source/WebCore/rendering/RenderLayerBacking.h:
* Source/WebKit/WebProcess/Inspector/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::showPaintRect):

Canonical link: https://commits.webkit.org/258865@main
  • Loading branch information
graouts committed Jan 13, 2023
1 parent dffcbbe commit 8299608
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 149 deletions.
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/GraphicsLayer.cpp
Expand Up @@ -612,7 +612,7 @@ FloatRect GraphicsLayer::adjustCoverageRectForMovement(const FloatRect& coverage
return unionRect(coverageRect, expandedRect);
}

String GraphicsLayer::animationNameForTransition(AnimatedPropertyID property)
String GraphicsLayer::animationNameForTransition(AnimatedProperty property)
{
// | is not a valid identifier character in CSS, so this can never conflict with a keyframe identifier.
return makeString("-|transition", static_cast<int>(property), '-');
Expand Down Expand Up @@ -694,9 +694,9 @@ static inline const FilterOperations& filterOperationsAt(const KeyframeValueList
int GraphicsLayer::validateFilterOperations(const KeyframeValueList& valueList)
{
#if ENABLE(FILTERS_LEVEL_2)
ASSERT(valueList.property() == AnimatedPropertyFilter || valueList.property() == AnimatedPropertyWebkitBackdropFilter);
ASSERT(valueList.property() == AnimatedProperty::Filter || valueList.property() == AnimatedProperty::WebkitBackdropFilter);
#else
ASSERT(valueList.property() == AnimatedPropertyFilter);
ASSERT(valueList.property() == AnimatedProperty::Filter);
#endif

if (valueList.size() < 2)
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/graphics/GraphicsLayer.h
Expand Up @@ -201,7 +201,7 @@ class FilterAnimationValue : public AnimationValue {
// FIXME: Should be moved to its own header file.
class KeyframeValueList {
public:
explicit KeyframeValueList(AnimatedPropertyID property)
explicit KeyframeValueList(AnimatedProperty property)
: m_property(property)
{
}
Expand Down Expand Up @@ -231,7 +231,7 @@ class KeyframeValueList {
m_values.swap(other.m_values);
}

AnimatedPropertyID property() const { return m_property; }
AnimatedProperty property() const { return m_property; }

size_t size() const { return m_values.size(); }
const AnimationValue& at(size_t i) const { return *m_values.at(i); }
Expand All @@ -241,7 +241,7 @@ class KeyframeValueList {

protected:
Vector<std::unique_ptr<const AnimationValue>> m_values;
AnimatedPropertyID m_property;
AnimatedProperty m_property;
};

// GraphicsLayer is an abstraction for a rendering surface with backing store,
Expand Down Expand Up @@ -488,7 +488,7 @@ class GraphicsLayer : public RefCounted<GraphicsLayer> {
WEBCORE_EXPORT virtual void setEventRegion(EventRegion&&);

// Transitions are identified by a special animation name that cannot clash with a keyframe identifier.
static String animationNameForTransition(AnimatedPropertyID);
static String animationNameForTransition(AnimatedProperty);

// Return true if the animation is handled by the compositing system.
virtual bool addAnimation(const KeyframeValueList&, const FloatSize& /*boxSize*/, const Animation*, const String& /*animationName*/, double /*timeOffset*/) { return false; }
Expand Down
35 changes: 15 additions & 20 deletions Source/WebCore/platform/graphics/GraphicsLayerClient.h
Expand Up @@ -40,6 +40,20 @@ class GraphicsLayer;
class IntPoint;
class IntRect;

enum class AnimatedProperty : uint8_t {
Invalid,
Translate,
Scale,
Rotate,
Transform,
Opacity,
BackgroundColor,
Filter,
#if ENABLE(FILTERS_LEVEL_2)
WebkitBackdropFilter,
#endif
};

enum class GraphicsLayerPaintingPhase {
Background = 1 << 0,
Foreground = 1 << 1,
Expand All @@ -50,25 +64,6 @@ enum class GraphicsLayerPaintingPhase {
ChildClippingMask = 1 << 6,
};

enum AnimatedPropertyID {
AnimatedPropertyInvalid,
AnimatedPropertyTranslate,
AnimatedPropertyScale,
AnimatedPropertyRotate,
AnimatedPropertyTransform,
AnimatedPropertyOpacity,
AnimatedPropertyBackgroundColor,
AnimatedPropertyFilter,
#if ENABLE(FILTERS_LEVEL_2)
AnimatedPropertyWebkitBackdropFilter,
#endif
};

inline bool animatedPropertyIsTransformOrRelated(AnimatedPropertyID property)
{
return property == AnimatedPropertyTransform || property == AnimatedPropertyTranslate || property == AnimatedPropertyScale || property == AnimatedPropertyRotate;
}

enum class PlatformLayerTreeAsTextFlags : uint8_t {
Debug = 1 << 0,
IgnoreChildren = 1 << 1,
Expand Down Expand Up @@ -136,7 +131,7 @@ class GraphicsLayerClient {

virtual void logFilledVisibleFreshTile(unsigned) { };

virtual TransformationMatrix transformMatrixForProperty(AnimatedPropertyID) const { return { }; }
virtual TransformationMatrix transformMatrixForProperty(AnimatedProperty) const { return { }; }

#ifndef NDEBUG
// RenderLayerBacking overrides this to verify that it is not
Expand Down
131 changes: 68 additions & 63 deletions Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
Expand Up @@ -263,14 +263,14 @@ class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
PlatformCALayer* primaryLayer() const { return m_structuralLayer.get() ? m_structuralLayer.get() : m_layer.get(); }
PlatformCALayer* hostLayerForSublayers() const;
PlatformCALayer* layerForSuperlayer() const;
PlatformCALayer* animatedLayer(AnimatedPropertyID) const;
PlatformCALayer* animatedLayer(AnimatedProperty) const;

typedef String CloneID; // Identifier for a given clone, based on original/replica branching down the tree.
static bool isReplicatedRootClone(const CloneID& cloneID) { return cloneID[0U] & 1; }

typedef HashMap<CloneID, RefPtr<PlatformCALayer>> LayerMap;
LayerMap* primaryLayerClones() const;
LayerMap* animatedLayerClones(AnimatedPropertyID) const;
LayerMap* animatedLayerClones(AnimatedProperty) const;
static void clearClones(LayerMap&);

bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset, bool keyframesShouldUseAnimationWideTimingFunction);
Expand Down Expand Up @@ -490,7 +490,7 @@ class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
// a single transition or keyframe animation, so index is used to distinguish these.
enum class PlayState { Playing, PlayPending, Paused, PausePending };
struct LayerPropertyAnimation {
LayerPropertyAnimation(Ref<PlatformCAAnimation>&& caAnimation, const String& animationName, AnimatedPropertyID property, int index, Seconds timeOffset)
LayerPropertyAnimation(Ref<PlatformCAAnimation>&& caAnimation, const String& animationName, AnimatedProperty property, int index, Seconds timeOffset)
: m_animation(WTFMove(caAnimation))
, m_name(animationName)
, m_property(property)
Expand All @@ -508,7 +508,7 @@ class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {

RefPtr<PlatformCAAnimation> m_animation;
String m_name;
AnimatedPropertyID m_property;
AnimatedProperty m_property;
int m_index;
Seconds m_timeOffset { 0_s };
std::optional<Seconds> m_beginTime;
Expand Down
14 changes: 7 additions & 7 deletions Source/WebCore/platform/graphics/nicosia/NicosiaAnimation.cpp
Expand Up @@ -141,7 +141,7 @@ static const TimingFunction& timingFunctionForAnimationValue(const AnimationValu

static KeyframeValueList createThreadsafeKeyFrames(const KeyframeValueList& originalKeyframes, const FloatSize& boxSize)
{
if (originalKeyframes.property() != AnimatedPropertyTransform)
if (originalKeyframes.property() != AnimatedProperty::Transform)
return originalKeyframes;

// Currently translation operations are the only transform operations that store a non-fixed
Expand Down Expand Up @@ -306,15 +306,15 @@ Seconds Animation::computeTotalRunningTime(MonotonicTime time)
void Animation::applyInternal(ApplicationResult& applicationResults, const AnimationValue& from, const AnimationValue& to, float progress)
{
switch (m_keyframes.property()) {
case AnimatedPropertyTransform:
case AnimatedProperty::Transform:
applicationResults.transform = applyTransformAnimation(static_cast<const TransformAnimationValue&>(from).value(), static_cast<const TransformAnimationValue&>(to).value(), progress, m_boxSize);
return;
case AnimatedPropertyOpacity:
case AnimatedProperty::Opacity:
applicationResults.opacity = applyOpacityAnimation((static_cast<const FloatAnimationValue&>(from).value()), (static_cast<const FloatAnimationValue&>(to).value()), progress);
return;
case AnimatedPropertyFilter:
case AnimatedProperty::Filter:
#if ENABLE(FILTERS_LEVEL_2)
case AnimatedPropertyWebkitBackdropFilter:
case AnimatedProperty::WebkitBackdropFilter:
#endif
applicationResults.filters = applyFilterAnimation(static_cast<const FilterAnimationValue&>(from).value(), static_cast<const FilterAnimationValue&>(to).value(), progress, m_boxSize);
return;
Expand All @@ -338,7 +338,7 @@ void Animations::remove(const String& name)
});
}

void Animations::remove(const String& name, AnimatedPropertyID property)
void Animations::remove(const String& name, AnimatedProperty property)
{
m_animations.removeAllMatching([&name, property] (const Animation& animation) {
return animation.name() == name && animation.keyframes().property() == property;
Expand Down Expand Up @@ -379,7 +379,7 @@ void Animations::applyKeepingInternalState(Animation::ApplicationResult& applica
animation.applyKeepingInternalState(applicationResults, time);
}

bool Animations::hasActiveAnimationsOfType(AnimatedPropertyID type) const
bool Animations::hasActiveAnimationsOfType(AnimatedProperty type) const
{
return std::any_of(m_animations.begin(), m_animations.end(),
[&type](const Animation& animation) {
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/nicosia/NicosiaAnimation.h
Expand Up @@ -40,7 +40,7 @@ class Animation {
};

Animation()
: m_keyframes(WebCore::AnimatedPropertyInvalid)
: m_keyframes(WebCore::AnimatedProperty::Invalid)
{ }
Animation(const String&, const WebCore::KeyframeValueList&, const WebCore::FloatSize&, const WebCore::Animation&, MonotonicTime, Seconds, AnimationState);

Expand Down Expand Up @@ -84,7 +84,7 @@ class Animations {

void add(const Animation&);
void remove(const String& name);
void remove(const String& name, WebCore::AnimatedPropertyID);
void remove(const String& name, WebCore::AnimatedProperty);
void pause(const String&, Seconds);
void suspend(MonotonicTime);
void resume();
Expand All @@ -98,7 +98,7 @@ class Animations {
Vector<Animation>& animations() { return m_animations; }

bool hasRunningAnimations() const;
bool hasActiveAnimationsOfType(WebCore::AnimatedPropertyID type) const;
bool hasActiveAnimationsOfType(WebCore::AnimatedProperty type) const;

private:
Vector<Animation> m_animations;
Expand Down
Expand Up @@ -609,10 +609,10 @@ bool GraphicsLayerTextureMapper::addAnimation(const KeyframeValueList& valueList
{
ASSERT(!keyframesName.isEmpty());

if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyTransform && valueList.property() != AnimatedPropertyOpacity))
if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedProperty::Transform && valueList.property() != AnimatedProperty::Opacity))
return false;

if (valueList.property() == AnimatedPropertyFilter) {
if (valueList.property() == AnimatedProperty::Filter) {
int listIndex = validateFilterOperations(valueList);
if (listIndex < 0)
return false;
Expand Down
Expand Up @@ -1388,22 +1388,22 @@ void CoordinatedGraphicsLayer::computeTransformedVisibleRect()
bool CoordinatedGraphicsLayer::shouldHaveBackingStore() const
{
// If the CSS opacity value is 0 and there's no animation over the opacity property, the layer is invisible.
bool isInvisibleBecauseOpacityZero = !opacity() && !m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity);
bool isInvisibleBecauseOpacityZero = !opacity() && !m_animations.hasActiveAnimationsOfType(AnimatedProperty::Opacity);

// Check if there's a filter that sets the opacity to zero.
bool hasOpacityZeroFilter = notFound != filters().operations().findIf([&](const auto& operation) {
return operation->type() == FilterOperation::Type::Opacity && !downcast<BasicComponentTransferFilterOperation>(*operation).amount();
});

// If there's a filter that sets opacity to 0 and the filters are not being animated, the layer is invisible.
isInvisibleBecauseOpacityZero |= hasOpacityZeroFilter && !m_animations.hasActiveAnimationsOfType(AnimatedPropertyFilter);
isInvisibleBecauseOpacityZero |= hasOpacityZeroFilter && !m_animations.hasActiveAnimationsOfType(AnimatedProperty::Filter);

return drawsContent() && contentsAreVisible() && !m_size.isEmpty() && !isInvisibleBecauseOpacityZero;
}

bool CoordinatedGraphicsLayer::selfOrAncestorHasActiveTransformAnimation() const
{
if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyTransform))
if (m_animations.hasActiveAnimationsOfType(AnimatedProperty::Transform))
return true;

if (!parent())
Expand Down Expand Up @@ -1432,9 +1432,9 @@ bool CoordinatedGraphicsLayer::addAnimation(const KeyframeValueList& valueList,

switch (valueList.property()) {
#if ENABLE(FILTERS_LEVEL_2)
case AnimatedPropertyWebkitBackdropFilter:
case AnimatedProperty::WebkitBackdropFilter:
#endif
case AnimatedPropertyFilter: {
case AnimatedProperty::Filter: {
int listIndex = validateFilterOperations(valueList);
if (listIndex < 0)
return false;
Expand All @@ -1444,8 +1444,8 @@ bool CoordinatedGraphicsLayer::addAnimation(const KeyframeValueList& valueList,
return false;
break;
}
case AnimatedPropertyOpacity:
case AnimatedPropertyTransform:
case AnimatedProperty::Opacity:
case AnimatedProperty::Transform:
break;
default:
return false;
Expand Down

0 comments on commit 8299608

Please sign in to comment.