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(
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(
ElementId element_id) const {
auto element_animations = GetElementAnimationsForElementId(element_id);
......@@ -595,18 +586,17 @@ bool AnimationHost::AnimationsPreserveAxisAlignment(
: true;
}
float AnimationHost::MaximumTargetScale(ElementId element_id,
ElementListType list_type) const {
auto element_animations = GetElementAnimationsForElementId(element_id);
return element_animations ? element_animations->MaximumTargetScale(list_type)
: kNotScaled;
}
float AnimationHost::AnimationStartScale(ElementId element_id,
ElementListType list_type) const {
auto element_animations = GetElementAnimationsForElementId(element_id);
return element_animations ? element_animations->AnimationStartScale(list_type)
: kNotScaled;
void AnimationHost::GetAnimationScales(ElementId element_id,
ElementListType list_type,
float* maximum_scale,
float* starting_scale) const {
if (auto element_animations = GetElementAnimationsForElementId(element_id)) {
element_animations->GetAnimationScales(list_type, maximum_scale,
starting_scale);
return;
}
*maximum_scale = kNotScaled;
*starting_scale = kNotScaled;
}
bool AnimationHost::IsElementAnimating(ElementId element_id) const {
......
......@@ -144,14 +144,12 @@ class CC_ANIMATION_EXPORT AnimationHost : public MutatorHost,
ElementId element_id,
TargetProperty::Type property) const override;
bool HasOnlyTranslationTransforms(ElementId element_id,
ElementListType list_type) const override;
bool AnimationsPreserveAxisAlignment(ElementId element_id) const override;
float MaximumTargetScale(ElementId element_id,
ElementListType list_type) const override;
float AnimationStartScale(ElementId element_id,
ElementListType list_type) const override;
void GetAnimationScales(ElementId element_id,
ElementListType list_type,
float* maximum_scale,
float* starting_scale) const override;
bool IsElementAnimating(ElementId element_id) const override;
bool HasTickingKeyframeModelForTesting(ElementId element_id) const override;
......
......@@ -212,15 +212,6 @@ void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) {
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 {
for (auto& keyframe_effect : keyframe_effects_list_) {
if (!keyframe_effect.AnimationsPreserveAxisAlignment())
......@@ -229,40 +220,25 @@ bool ElementAnimations::AnimationsPreserveAxisAlignment() const {
return true;
}
float ElementAnimations::AnimationStartScale(ElementListType list_type) const {
float start_scale = kNotScaled;
for (auto& keyframe_effect : keyframe_effects_list_) {
if (keyframe_effect.HasOnlyTranslationTransforms(list_type))
continue;
float keyframe_effect_start_scale = kNotScaled;
bool success = keyframe_effect.AnimationStartScale(
list_type, &keyframe_effect_start_scale);
if (!success)
return kNotScaled;
// Union: a maximum.
start_scale = std::max(start_scale, keyframe_effect_start_scale);
}
return start_scale;
}
float ElementAnimations::MaximumTargetScale(ElementListType list_type) const {
float max_scale = kNotScaled;
void ElementAnimations::GetAnimationScales(ElementListType list_type,
float* maximum_scale,
float* starting_scale) const {
*maximum_scale = kNotScaled;
*starting_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);
float keyframe_effect_maximum_scale = kNotScaled;
float keyframe_effect_starting_scale = kNotScaled;
bool success = keyframe_effect.GetAnimationScales(
list_type, &keyframe_effect_maximum_scale,
&keyframe_effect_starting_scale);
if (!success) {
*maximum_scale = kNotScaled;
*starting_scale = kNotScaled;
return;
}
*maximum_scale = std::max(*maximum_scale, keyframe_effect_maximum_scale);
*starting_scale = std::max(*starting_scale, keyframe_effect_starting_scale);
}
return max_scale;
}
bool ElementAnimations::ScrollOffsetAnimationWasInterrupted() const {
......@@ -369,8 +345,12 @@ void ElementAnimations::UpdateClientAnimationState() {
element_id_map, ElementListType::ACTIVE, diff_active, active_state_);
}
float maximum_scale = MaximumTargetScale(ElementListType::ACTIVE);
float starting_scale = AnimationStartScale(ElementListType::ACTIVE);
float maximum_scale = kNotScaled;
float starting_scale = kNotScaled;
if (transform_element_id) {
GetAnimationScales(ElementListType::ACTIVE, &maximum_scale,
&starting_scale);
}
if (maximum_scale != active_maximum_scale_ ||
starting_scale != active_starting_scale_) {
animation_host_->mutator_host_client()->AnimationScalesChanged(
......@@ -389,8 +369,12 @@ void ElementAnimations::UpdateClientAnimationState() {
pending_state_);
}
float maximum_scale = MaximumTargetScale(ElementListType::PENDING);
float starting_scale = AnimationStartScale(ElementListType::PENDING);
float maximum_scale = kNotScaled;
float starting_scale = kNotScaled;
if (transform_element_id) {
GetAnimationScales(ElementListType::PENDING, &maximum_scale,
&starting_scale);
}
if (maximum_scale != pending_maximum_scale_ ||
starting_scale != pending_starting_scale_) {
animation_host_->mutator_host_client()->AnimationScalesChanged(
......
......@@ -107,19 +107,17 @@ class CC_ANIMATION_EXPORT ElementAnimations
has_element_in_pending_list_ = has_element_in_pending_list;
}
bool HasOnlyTranslationTransforms(ElementListType list_type) const;
bool AnimationsPreserveAxisAlignment() const;
// Returns the maximum of starting animation scale along any dimension at any
// destination in active scale animations, or kNotScaled if there is no active
// scale animation or the starting scale cannot be computed.
float AnimationStartScale(ElementListType list_type) const;
// Returns the maximum scale along any dimension at any destination in active
// scale animations, or kNotScaled if there is no active scale animation or
// the maximum scale cannot be computed.
float MaximumTargetScale(ElementListType list_type) const;
// Gets scales transform animations. On return, |maximum_scale| is the maximum
// scale along any dimension at any destination in active scale animations,
// and |starting_scale| is the maximum of starting animation scale along any
// 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
// computed.
void GetAnimationScales(ElementListType list_type,
float* maximum_scale,
float* starting_scale) const;
bool ScrollOffsetAnimationWasInterrupted() const;
......
This diff is collapsed.
......@@ -460,27 +460,6 @@ bool KeyframeEffect::HasNonDeletedKeyframeModel() const {
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 {
for (const auto& keyframe_model : keyframe_models_) {
if (keyframe_model->is_finished() ||
......@@ -495,9 +474,13 @@ bool KeyframeEffect::AnimationsPreserveAxisAlignment() const {
return true;
}
bool KeyframeEffect::AnimationStartScale(ElementListType list_type,
float* start_scale) const {
*start_scale = 0.f;
bool KeyframeEffect::GetAnimationScales(ElementListType list_type,
float* maximum_scale,
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_) {
if (keyframe_model->is_finished() ||
keyframe_model->target_property_id() != TargetProperty::TRANSFORM)
......@@ -509,41 +492,9 @@ bool KeyframeEffect::AnimationStartScale(ElementListType list_type,
!keyframe_model->affects_pending_elements()))
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 =
keyframe_model->curve()->ToTransformAnimationCurve();
float keyframe_model_start_scale = 0.f;
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()))
if (transform_animation_curve->IsTranslation())
continue;
bool forward_direction = true;
......@@ -558,15 +509,32 @@ bool KeyframeEffect::MaximumTargetScale(ElementListType list_type,
break;
}
const TransformAnimationCurve* transform_animation_curve =
keyframe_model->curve()->ToTransformAnimationCurve();
float keyframe_model_scale = 0.f;
if (!transform_animation_curve->MaximumTargetScale(forward_direction,
&keyframe_model_scale))
if (maximum_scale_valid) {
float keyframe_model_maximum_scale = kNotScaled;
if (transform_animation_curve->MaximumTargetScale(
forward_direction, &keyframe_model_maximum_scale)) {
*maximum_scale = std::max(*maximum_scale, keyframe_model_maximum_scale);
} else {
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;
*max_scale = std::max(*max_scale, keyframe_model_scale);
}
return true;
}
......
......@@ -121,19 +121,17 @@ class CC_ANIMATION_EXPORT KeyframeEffect {
bool HasNonDeletedKeyframeModel() const;
bool HasOnlyTranslationTransforms(ElementListType list_type) const;
bool AnimationsPreserveAxisAlignment() const;
// Sets |start_scale| to the maximum of starting keyframe_model scale along
// any dimension at any destination in active KeyframeModels. Returns false
// if the starting scale cannot be computed.
bool AnimationStartScale(ElementListType, float* start_scale) const;
// Sets |max_scale| to the maximum scale along any dimension at any
// destination in active KeyframeModels. Returns false if the maximum scale
// cannot be computed.
bool MaximumTargetScale(ElementListType, float* max_scale) const;
// Gets scales transform animations. On return, |maximum_scale| is the maximum
// scale along any dimension at any destination in active scale animations,
// and |starting_scale| is the maximum of starting animation scale along any
// 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
// computed. Returns false if the scales cannot be computed.
bool GetAnimationScales(ElementListType,
float* maximum_scale,
float* starting_scale) const;
// Returns true if there is a keyframe_model that is either currently
// animating the given property or scheduled to animate this property in the
......
......@@ -861,10 +861,9 @@ void LayerTreeImpl::UpdateTransformAnimation(ElementId element_id,
list_type);
if (node->has_potential_animation != has_potential_animation) {
node->has_potential_animation = has_potential_animation;
node->maximum_animation_scale =
mutator_host()->MaximumTargetScale(element_id, list_type);
node->starting_animation_scale =
mutator_host()->AnimationStartScale(element_id, list_type);
mutator_host()->GetAnimationScales(element_id, list_type,
&node->maximum_animation_scale,
&node->starting_animation_scale);
transform_tree.set_needs_update(true);
set_needs_update_draw_properties();
}
......
......@@ -26,9 +26,8 @@ class MutatorHostClient;
class LayerTreeMutator;
class ScrollTree;
// Used as the return value of MaximumTargetScale() and AnimationStartScale() to
// indicate that there is no active scale animation or the scale cannot be
// computed.
// Used as the return value of GetAnimationScales() to indicate that there is
// no active scale animation or the scale cannot be computed.
const float kNotScaled = 0;
// A MutatorHost owns all the animation and mutation effects.
......@@ -108,22 +107,18 @@ class MutatorHost {
ElementId element_id,
TargetProperty::Type property) const = 0;
virtual bool HasOnlyTranslationTransforms(
ElementId element_id,
ElementListType list_type) const = 0;
virtual bool AnimationsPreserveAxisAlignment(ElementId element_id) const = 0;
// Returns the maximum scale along any dimension at any destination in active
// scale animations, or kNotScaled if there is no active scale animation or
// the maximum scale cannot be computed.
virtual float MaximumTargetScale(ElementId element_id,
ElementListType list_type) const = 0;
// Returns the maximum of starting animation scale along any dimension at any
// destination in active scale animations, or kNotScaled if there is no active
// scale animation or the starting scale cannot be computed.
virtual float AnimationStartScale(ElementId element_id,
ElementListType list_type) const = 0;
// Gets scales transform animations. On return, |maximum_scale| is the maximum
// scale along any dimension at any destination in active scale animations,
// and |starting_scale| is the maximum of starting animation scale along any
// 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
// computed.
virtual void GetAnimationScales(ElementId element_id,
ElementListType list_type,
float* maximum_scale,
float* starting_scale) const = 0;
virtual bool IsElementAnimating(ElementId element_id) const = 0;
virtual bool HasTickingKeyframeModelForTesting(
......
......@@ -286,21 +286,13 @@ bool HasPotentiallyRunningTransformAnimation(const MutatorHost& host,
}
template <typename LayerType>
bool HasOnlyTranslationTransforms(const MutatorHost& host, LayerType* layer) {
return host.HasOnlyTranslationTransforms(layer->element_id(),
layer->GetElementTypeForAnimation());
}
template <typename LayerType>
float MaximumAnimationScale(const MutatorHost& host, LayerType* layer) {
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());
void GetAnimationScales(const MutatorHost& host,
LayerType* layer,
float* maximum_scale,
float* starting_scale) {
return host.GetAnimationScales(layer->element_id(),
layer->GetElementTypeForAnimation(),
maximum_scale, starting_scale);
}
template <typename LayerType>
......@@ -576,8 +568,8 @@ bool PropertyTreeBuilderContext<LayerType>::AddTransformNodeIfNeeded(
node->has_potential_animation = has_potentially_animated_transform;
node->is_currently_animating = TransformIsAnimating(mutator_host_, layer);
node->maximum_animation_scale = MaximumAnimationScale(mutator_host_, layer);
node->starting_animation_scale = StartingAnimationScale(mutator_host_, layer);
GetAnimationScales(mutator_host_, layer, &node->maximum_animation_scale,
&node->starting_animation_scale);
float post_local_scale_factor = 1.0f;
......
......@@ -136,8 +136,8 @@ struct CC_EXPORT TransformNode {
gfx::Vector2dF source_offset;
gfx::Vector2dF source_to_parent;
// See ElementAnimations::MaximumTargetScale() and AnimationStartScale() for
// their meanings. Updated by PropertyTrees::AnimationScalesChanged().
// See MutatorHost::GetAnimationScales() for their meanings. Updated by
// PropertyTrees::AnimationScalesChanged().
float maximum_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