Commit 51647047 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Improve performance of getting animation scales

- In ElementAnimations::UpdateClientAnimationState(), only get animation
  scales when there is transform animation. This fixes the main reason
  of the regression caused by crrev.com/c/1547131.

- Combine HasOnlyTranslationTransforms(), AnimationStartScale() and
  MaximumTargetScale() of KeyframeEffect into one function to avoid
  duplicated code/executation when called separately from one place.

- Remove unused HasOnlyTranslationTransforms() from AnimationHost
  and ElementAnimations.

Bug: 951912
Change-Id: I5cc858fb012f0b7c0280b9935d84bc2aa4cf4d7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580551
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654647}
parent 26c183d0
...@@ -578,15 +578,6 @@ bool AnimationHost::HasAnyAnimationTargetingProperty( ...@@ -578,15 +578,6 @@ bool AnimationHost::HasAnyAnimationTargetingProperty(
return element_animations->HasAnyAnimationTargetingProperty(property); return element_animations->HasAnyAnimationTargetingProperty(property);
} }
bool AnimationHost::HasOnlyTranslationTransforms(
ElementId element_id,
ElementListType list_type) const {
auto element_animations = GetElementAnimationsForElementId(element_id);
return element_animations
? element_animations->HasOnlyTranslationTransforms(list_type)
: true;
}
bool AnimationHost::AnimationsPreserveAxisAlignment( bool AnimationHost::AnimationsPreserveAxisAlignment(
ElementId element_id) const { ElementId element_id) const {
auto element_animations = GetElementAnimationsForElementId(element_id); auto element_animations = GetElementAnimationsForElementId(element_id);
...@@ -595,18 +586,17 @@ bool AnimationHost::AnimationsPreserveAxisAlignment( ...@@ -595,18 +586,17 @@ bool AnimationHost::AnimationsPreserveAxisAlignment(
: true; : true;
} }
float AnimationHost::MaximumTargetScale(ElementId element_id, void AnimationHost::GetAnimationScales(ElementId element_id,
ElementListType list_type) const { ElementListType list_type,
auto element_animations = GetElementAnimationsForElementId(element_id); float* maximum_scale,
return element_animations ? element_animations->MaximumTargetScale(list_type) float* starting_scale) const {
: kNotScaled; if (auto element_animations = GetElementAnimationsForElementId(element_id)) {
} element_animations->GetAnimationScales(list_type, maximum_scale,
starting_scale);
float AnimationHost::AnimationStartScale(ElementId element_id, return;
ElementListType list_type) const { }
auto element_animations = GetElementAnimationsForElementId(element_id); *maximum_scale = kNotScaled;
return element_animations ? element_animations->AnimationStartScale(list_type) *starting_scale = kNotScaled;
: kNotScaled;
} }
bool AnimationHost::IsElementAnimating(ElementId element_id) const { bool AnimationHost::IsElementAnimating(ElementId element_id) const {
......
...@@ -144,14 +144,12 @@ class CC_ANIMATION_EXPORT AnimationHost : public MutatorHost, ...@@ -144,14 +144,12 @@ class CC_ANIMATION_EXPORT AnimationHost : public MutatorHost,
ElementId element_id, ElementId element_id,
TargetProperty::Type property) const override; TargetProperty::Type property) const override;
bool HasOnlyTranslationTransforms(ElementId element_id,
ElementListType list_type) const override;
bool AnimationsPreserveAxisAlignment(ElementId element_id) const override; bool AnimationsPreserveAxisAlignment(ElementId element_id) const override;
float MaximumTargetScale(ElementId element_id, void GetAnimationScales(ElementId element_id,
ElementListType list_type) const override; ElementListType list_type,
float AnimationStartScale(ElementId element_id, float* maximum_scale,
ElementListType list_type) const override; float* starting_scale) const override;
bool IsElementAnimating(ElementId element_id) const override; bool IsElementAnimating(ElementId element_id) const override;
bool HasTickingKeyframeModelForTesting(ElementId element_id) const override; bool HasTickingKeyframeModelForTesting(ElementId element_id) const override;
......
...@@ -212,15 +212,6 @@ void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { ...@@ -212,15 +212,6 @@ void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) {
UpdateClientAnimationState(); UpdateClientAnimationState();
} }
bool ElementAnimations::HasOnlyTranslationTransforms(
ElementListType list_type) const {
for (auto& keyframe_effect : keyframe_effects_list_) {
if (!keyframe_effect.HasOnlyTranslationTransforms(list_type))
return false;
}
return true;
}
bool ElementAnimations::AnimationsPreserveAxisAlignment() const { bool ElementAnimations::AnimationsPreserveAxisAlignment() const {
for (auto& keyframe_effect : keyframe_effects_list_) { for (auto& keyframe_effect : keyframe_effects_list_) {
if (!keyframe_effect.AnimationsPreserveAxisAlignment()) if (!keyframe_effect.AnimationsPreserveAxisAlignment())
...@@ -229,40 +220,25 @@ bool ElementAnimations::AnimationsPreserveAxisAlignment() const { ...@@ -229,40 +220,25 @@ bool ElementAnimations::AnimationsPreserveAxisAlignment() const {
return true; return true;
} }
float ElementAnimations::AnimationStartScale(ElementListType list_type) const { void ElementAnimations::GetAnimationScales(ElementListType list_type,
float start_scale = kNotScaled; float* maximum_scale,
float* starting_scale) const {
*maximum_scale = kNotScaled;
*starting_scale = kNotScaled;
for (auto& keyframe_effect : keyframe_effects_list_) { for (auto& keyframe_effect : keyframe_effects_list_) {
if (keyframe_effect.HasOnlyTranslationTransforms(list_type)) float keyframe_effect_maximum_scale = kNotScaled;
continue; float keyframe_effect_starting_scale = kNotScaled;
float keyframe_effect_start_scale = kNotScaled; bool success = keyframe_effect.GetAnimationScales(
bool success = keyframe_effect.AnimationStartScale( list_type, &keyframe_effect_maximum_scale,
list_type, &keyframe_effect_start_scale); &keyframe_effect_starting_scale);
if (!success) if (!success) {
return kNotScaled; *maximum_scale = kNotScaled;
// Union: a maximum. *starting_scale = kNotScaled;
start_scale = std::max(start_scale, keyframe_effect_start_scale); return;
} }
*maximum_scale = std::max(*maximum_scale, keyframe_effect_maximum_scale);
return start_scale; *starting_scale = std::max(*starting_scale, keyframe_effect_starting_scale);
}
float ElementAnimations::MaximumTargetScale(ElementListType list_type) const {
float max_scale = kNotScaled;
for (auto& keyframe_effect : keyframe_effects_list_) {
if (keyframe_effect.HasOnlyTranslationTransforms(list_type))
continue;
float keyframe_effect_max_scale = kNotScaled;
bool success = keyframe_effect.MaximumTargetScale(
list_type, &keyframe_effect_max_scale);
if (!success)
return kNotScaled;
// Union: a maximum.
max_scale = std::max(max_scale, keyframe_effect_max_scale);
} }
return max_scale;
} }
bool ElementAnimations::ScrollOffsetAnimationWasInterrupted() const { bool ElementAnimations::ScrollOffsetAnimationWasInterrupted() const {
...@@ -369,8 +345,12 @@ void ElementAnimations::UpdateClientAnimationState() { ...@@ -369,8 +345,12 @@ void ElementAnimations::UpdateClientAnimationState() {
element_id_map, ElementListType::ACTIVE, diff_active, active_state_); element_id_map, ElementListType::ACTIVE, diff_active, active_state_);
} }
float maximum_scale = MaximumTargetScale(ElementListType::ACTIVE); float maximum_scale = kNotScaled;
float starting_scale = AnimationStartScale(ElementListType::ACTIVE); float starting_scale = kNotScaled;
if (transform_element_id) {
GetAnimationScales(ElementListType::ACTIVE, &maximum_scale,
&starting_scale);
}
if (maximum_scale != active_maximum_scale_ || if (maximum_scale != active_maximum_scale_ ||
starting_scale != active_starting_scale_) { starting_scale != active_starting_scale_) {
animation_host_->mutator_host_client()->AnimationScalesChanged( animation_host_->mutator_host_client()->AnimationScalesChanged(
...@@ -389,8 +369,12 @@ void ElementAnimations::UpdateClientAnimationState() { ...@@ -389,8 +369,12 @@ void ElementAnimations::UpdateClientAnimationState() {
pending_state_); pending_state_);
} }
float maximum_scale = MaximumTargetScale(ElementListType::PENDING); float maximum_scale = kNotScaled;
float starting_scale = AnimationStartScale(ElementListType::PENDING); float starting_scale = kNotScaled;
if (transform_element_id) {
GetAnimationScales(ElementListType::PENDING, &maximum_scale,
&starting_scale);
}
if (maximum_scale != pending_maximum_scale_ || if (maximum_scale != pending_maximum_scale_ ||
starting_scale != pending_starting_scale_) { starting_scale != pending_starting_scale_) {
animation_host_->mutator_host_client()->AnimationScalesChanged( animation_host_->mutator_host_client()->AnimationScalesChanged(
......
...@@ -107,19 +107,17 @@ class CC_ANIMATION_EXPORT ElementAnimations ...@@ -107,19 +107,17 @@ class CC_ANIMATION_EXPORT ElementAnimations
has_element_in_pending_list_ = has_element_in_pending_list; has_element_in_pending_list_ = has_element_in_pending_list;
} }
bool HasOnlyTranslationTransforms(ElementListType list_type) const;
bool AnimationsPreserveAxisAlignment() const; bool AnimationsPreserveAxisAlignment() const;
// Returns the maximum of starting animation scale along any dimension at any // Gets scales transform animations. On return, |maximum_scale| is the maximum
// destination in active scale animations, or kNotScaled if there is no active // scale along any dimension at any destination in active scale animations,
// scale animation or the starting scale cannot be computed. // and |starting_scale| is the maximum of starting animation scale along any
float AnimationStartScale(ElementListType list_type) const; // dimension at any destination in active scale animations. They are set to
// kNotScaled if there is no active scale animation or the scales cannot be
// Returns the maximum scale along any dimension at any destination in active // computed.
// scale animations, or kNotScaled if there is no active scale animation or void GetAnimationScales(ElementListType list_type,
// the maximum scale cannot be computed. float* maximum_scale,
float MaximumTargetScale(ElementListType list_type) const; float* starting_scale) const;
bool ScrollOffsetAnimationWasInterrupted() const; bool ScrollOffsetAnimationWasInterrupted() const;
......
This diff is collapsed.
...@@ -460,27 +460,6 @@ bool KeyframeEffect::HasNonDeletedKeyframeModel() const { ...@@ -460,27 +460,6 @@ bool KeyframeEffect::HasNonDeletedKeyframeModel() const {
return false; return false;
} }
bool KeyframeEffect::HasOnlyTranslationTransforms(
ElementListType list_type) const {
for (const auto& keyframe_model : keyframe_models_) {
if (keyframe_model->is_finished() ||
keyframe_model->target_property_id() != TargetProperty::TRANSFORM)
continue;
if ((list_type == ElementListType::ACTIVE &&
!keyframe_model->affects_active_elements()) ||
(list_type == ElementListType::PENDING &&
!keyframe_model->affects_pending_elements()))
continue;
const TransformAnimationCurve* transform_animation_curve =
keyframe_model->curve()->ToTransformAnimationCurve();
if (!transform_animation_curve->IsTranslation())
return false;
}
return true;
}
bool KeyframeEffect::AnimationsPreserveAxisAlignment() const { bool KeyframeEffect::AnimationsPreserveAxisAlignment() const {
for (const auto& keyframe_model : keyframe_models_) { for (const auto& keyframe_model : keyframe_models_) {
if (keyframe_model->is_finished() || if (keyframe_model->is_finished() ||
...@@ -495,9 +474,13 @@ bool KeyframeEffect::AnimationsPreserveAxisAlignment() const { ...@@ -495,9 +474,13 @@ bool KeyframeEffect::AnimationsPreserveAxisAlignment() const {
return true; return true;
} }
bool KeyframeEffect::AnimationStartScale(ElementListType list_type, bool KeyframeEffect::GetAnimationScales(ElementListType list_type,
float* start_scale) const { float* maximum_scale,
*start_scale = 0.f; float* starting_scale) const {
*maximum_scale = kNotScaled;
*starting_scale = kNotScaled;
bool maximum_scale_valid = true;
bool starting_scale_valid = true;
for (const auto& keyframe_model : keyframe_models_) { for (const auto& keyframe_model : keyframe_models_) {
if (keyframe_model->is_finished() || if (keyframe_model->is_finished() ||
keyframe_model->target_property_id() != TargetProperty::TRANSFORM) keyframe_model->target_property_id() != TargetProperty::TRANSFORM)
...@@ -509,41 +492,9 @@ bool KeyframeEffect::AnimationStartScale(ElementListType list_type, ...@@ -509,41 +492,9 @@ bool KeyframeEffect::AnimationStartScale(ElementListType list_type,
!keyframe_model->affects_pending_elements())) !keyframe_model->affects_pending_elements()))
continue; continue;
bool forward_direction = true;
switch (keyframe_model->direction()) {
case KeyframeModel::Direction::NORMAL:
case KeyframeModel::Direction::ALTERNATE_NORMAL:
forward_direction = keyframe_model->playback_rate() >= 0.0;
break;
case KeyframeModel::Direction::REVERSE:
case KeyframeModel::Direction::ALTERNATE_REVERSE:
forward_direction = keyframe_model->playback_rate() < 0.0;
break;
}
const TransformAnimationCurve* transform_animation_curve = const TransformAnimationCurve* transform_animation_curve =
keyframe_model->curve()->ToTransformAnimationCurve(); keyframe_model->curve()->ToTransformAnimationCurve();
float keyframe_model_start_scale = 0.f; if (transform_animation_curve->IsTranslation())
if (!transform_animation_curve->AnimationStartScale(
forward_direction, &keyframe_model_start_scale))
return false;
*start_scale = std::max(*start_scale, keyframe_model_start_scale);
}
return true;
}
bool KeyframeEffect::MaximumTargetScale(ElementListType list_type,
float* max_scale) const {
*max_scale = 0.f;
for (const auto& keyframe_model : keyframe_models_) {
if (keyframe_model->is_finished() ||
keyframe_model->target_property_id() != TargetProperty::TRANSFORM)
continue;
if ((list_type == ElementListType::ACTIVE &&
!keyframe_model->affects_active_elements()) ||
(list_type == ElementListType::PENDING &&
!keyframe_model->affects_pending_elements()))
continue; continue;
bool forward_direction = true; bool forward_direction = true;
...@@ -558,15 +509,32 @@ bool KeyframeEffect::MaximumTargetScale(ElementListType list_type, ...@@ -558,15 +509,32 @@ bool KeyframeEffect::MaximumTargetScale(ElementListType list_type,
break; break;
} }
const TransformAnimationCurve* transform_animation_curve = if (maximum_scale_valid) {
keyframe_model->curve()->ToTransformAnimationCurve(); float keyframe_model_maximum_scale = kNotScaled;
float keyframe_model_scale = 0.f; if (transform_animation_curve->MaximumTargetScale(
if (!transform_animation_curve->MaximumTargetScale(forward_direction, forward_direction, &keyframe_model_maximum_scale)) {
&keyframe_model_scale)) *maximum_scale = std::max(*maximum_scale, keyframe_model_maximum_scale);
return false; } else {
*max_scale = std::max(*max_scale, keyframe_model_scale); maximum_scale_valid = false;
*maximum_scale = kNotScaled;
}
} }
if (starting_scale_valid) {
float keyframe_model_starting_scale = kNotScaled;
if (transform_animation_curve->AnimationStartScale(
forward_direction, &keyframe_model_starting_scale)) {
*starting_scale =
std::max(*starting_scale, keyframe_model_starting_scale);
} else {
starting_scale_valid = false;
*starting_scale = kNotScaled;
}
}
if (!maximum_scale_valid && !starting_scale_valid)
return false;
}
return true; return true;
} }
......
...@@ -121,19 +121,17 @@ class CC_ANIMATION_EXPORT KeyframeEffect { ...@@ -121,19 +121,17 @@ class CC_ANIMATION_EXPORT KeyframeEffect {
bool HasNonDeletedKeyframeModel() const; bool HasNonDeletedKeyframeModel() const;
bool HasOnlyTranslationTransforms(ElementListType list_type) const;
bool AnimationsPreserveAxisAlignment() const; bool AnimationsPreserveAxisAlignment() const;
// Sets |start_scale| to the maximum of starting keyframe_model scale along // Gets scales transform animations. On return, |maximum_scale| is the maximum
// any dimension at any destination in active KeyframeModels. Returns false // scale along any dimension at any destination in active scale animations,
// if the starting scale cannot be computed. // and |starting_scale| is the maximum of starting animation scale along any
bool AnimationStartScale(ElementListType, float* start_scale) const; // dimension at any destination in active scale animations. They are set to
// kNotScaled if there is no active scale animation or the scales cannot be
// Sets |max_scale| to the maximum scale along any dimension at any // computed. Returns false if the scales cannot be computed.
// destination in active KeyframeModels. Returns false if the maximum scale bool GetAnimationScales(ElementListType,
// cannot be computed. float* maximum_scale,
bool MaximumTargetScale(ElementListType, float* max_scale) const; float* starting_scale) const;
// Returns true if there is a keyframe_model that is either currently // Returns true if there is a keyframe_model that is either currently
// animating the given property or scheduled to animate this property in the // animating the given property or scheduled to animate this property in the
......
...@@ -861,10 +861,9 @@ void LayerTreeImpl::UpdateTransformAnimation(ElementId element_id, ...@@ -861,10 +861,9 @@ void LayerTreeImpl::UpdateTransformAnimation(ElementId element_id,
list_type); list_type);
if (node->has_potential_animation != has_potential_animation) { if (node->has_potential_animation != has_potential_animation) {
node->has_potential_animation = has_potential_animation; node->has_potential_animation = has_potential_animation;
node->maximum_animation_scale = mutator_host()->GetAnimationScales(element_id, list_type,
mutator_host()->MaximumTargetScale(element_id, list_type); &node->maximum_animation_scale,
node->starting_animation_scale = &node->starting_animation_scale);
mutator_host()->AnimationStartScale(element_id, list_type);
transform_tree.set_needs_update(true); transform_tree.set_needs_update(true);
set_needs_update_draw_properties(); set_needs_update_draw_properties();
} }
......
...@@ -26,9 +26,8 @@ class MutatorHostClient; ...@@ -26,9 +26,8 @@ class MutatorHostClient;
class LayerTreeMutator; class LayerTreeMutator;
class ScrollTree; class ScrollTree;
// Used as the return value of MaximumTargetScale() and AnimationStartScale() to // Used as the return value of GetAnimationScales() to indicate that there is
// indicate that there is no active scale animation or the scale cannot be // no active scale animation or the scale cannot be computed.
// computed.
const float kNotScaled = 0; const float kNotScaled = 0;
// A MutatorHost owns all the animation and mutation effects. // A MutatorHost owns all the animation and mutation effects.
...@@ -108,22 +107,18 @@ class MutatorHost { ...@@ -108,22 +107,18 @@ class MutatorHost {
ElementId element_id, ElementId element_id,
TargetProperty::Type property) const = 0; TargetProperty::Type property) const = 0;
virtual bool HasOnlyTranslationTransforms(
ElementId element_id,
ElementListType list_type) const = 0;
virtual bool AnimationsPreserveAxisAlignment(ElementId element_id) const = 0; virtual bool AnimationsPreserveAxisAlignment(ElementId element_id) const = 0;
// Returns the maximum scale along any dimension at any destination in active // Gets scales transform animations. On return, |maximum_scale| is the maximum
// scale animations, or kNotScaled if there is no active scale animation or // scale along any dimension at any destination in active scale animations,
// the maximum scale cannot be computed. // and |starting_scale| is the maximum of starting animation scale along any
virtual float MaximumTargetScale(ElementId element_id, // dimension at any destination in active scale animations. They are set to
ElementListType list_type) const = 0; // kNotScaled if there is no active scale animation or the scales cannot be
// computed.
// Returns the maximum of starting animation scale along any dimension at any virtual void GetAnimationScales(ElementId element_id,
// destination in active scale animations, or kNotScaled if there is no active ElementListType list_type,
// scale animation or the starting scale cannot be computed. float* maximum_scale,
virtual float AnimationStartScale(ElementId element_id, float* starting_scale) const = 0;
ElementListType list_type) const = 0;
virtual bool IsElementAnimating(ElementId element_id) const = 0; virtual bool IsElementAnimating(ElementId element_id) const = 0;
virtual bool HasTickingKeyframeModelForTesting( virtual bool HasTickingKeyframeModelForTesting(
......
...@@ -286,21 +286,13 @@ bool HasPotentiallyRunningTransformAnimation(const MutatorHost& host, ...@@ -286,21 +286,13 @@ bool HasPotentiallyRunningTransformAnimation(const MutatorHost& host,
} }
template <typename LayerType> template <typename LayerType>
bool HasOnlyTranslationTransforms(const MutatorHost& host, LayerType* layer) { void GetAnimationScales(const MutatorHost& host,
return host.HasOnlyTranslationTransforms(layer->element_id(), LayerType* layer,
layer->GetElementTypeForAnimation()); float* maximum_scale,
} float* starting_scale) {
return host.GetAnimationScales(layer->element_id(),
template <typename LayerType> layer->GetElementTypeForAnimation(),
float MaximumAnimationScale(const MutatorHost& host, LayerType* layer) { maximum_scale, starting_scale);
return host.MaximumTargetScale(layer->element_id(),
layer->GetElementTypeForAnimation());
}
template <typename LayerType>
float StartingAnimationScale(const MutatorHost& host, LayerType* layer) {
return host.AnimationStartScale(layer->element_id(),
layer->GetElementTypeForAnimation());
} }
template <typename LayerType> template <typename LayerType>
...@@ -576,8 +568,8 @@ bool PropertyTreeBuilderContext<LayerType>::AddTransformNodeIfNeeded( ...@@ -576,8 +568,8 @@ bool PropertyTreeBuilderContext<LayerType>::AddTransformNodeIfNeeded(
node->has_potential_animation = has_potentially_animated_transform; node->has_potential_animation = has_potentially_animated_transform;
node->is_currently_animating = TransformIsAnimating(mutator_host_, layer); node->is_currently_animating = TransformIsAnimating(mutator_host_, layer);
node->maximum_animation_scale = MaximumAnimationScale(mutator_host_, layer); GetAnimationScales(mutator_host_, layer, &node->maximum_animation_scale,
node->starting_animation_scale = StartingAnimationScale(mutator_host_, layer); &node->starting_animation_scale);
float post_local_scale_factor = 1.0f; float post_local_scale_factor = 1.0f;
......
...@@ -136,8 +136,8 @@ struct CC_EXPORT TransformNode { ...@@ -136,8 +136,8 @@ struct CC_EXPORT TransformNode {
gfx::Vector2dF source_offset; gfx::Vector2dF source_offset;
gfx::Vector2dF source_to_parent; gfx::Vector2dF source_to_parent;
// See ElementAnimations::MaximumTargetScale() and AnimationStartScale() for // See MutatorHost::GetAnimationScales() for their meanings. Updated by
// their meanings. Updated by PropertyTrees::AnimationScalesChanged(). // PropertyTrees::AnimationScalesChanged().
float maximum_animation_scale; float maximum_animation_scale;
float starting_animation_scale; float starting_animation_scale;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment