Commit cf6458cc authored by loyso's avatar loyso Committed by Commit bot

CC Animation: Extract PropertyAnimationState as a non-nested struct.

Next step: Rework UpdateClientAnimationState to deal with
a bitset instead of single property
(batch, batch, batch)

BUG=592873
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://codereview.chromium.org/2349643003
Cr-Commit-Position: refs/heads/master@{#422704}
parent 78cf6596
......@@ -28,6 +28,8 @@ component("cc") {
"animation/element_id.h",
"animation/keyframed_animation_curve.cc",
"animation/keyframed_animation_curve.h",
"animation/property_animation_state.cc",
"animation/property_animation_state.h",
"animation/scroll_offset_animation_curve.cc",
"animation/scroll_offset_animation_curve.h",
"animation/scroll_offset_animations.cc",
......
......@@ -9,6 +9,7 @@
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/property_animation_state.h"
#include "cc/animation/scroll_offset_animation_curve.h"
namespace cc {
......@@ -995,6 +996,26 @@ Animation* AnimationPlayer::GetAnimationById(int animation_id) const {
return nullptr;
}
void AnimationPlayer::GetPropertyAnimationStateFor(
TargetProperty::Type property,
PropertyAnimationState* state) const {
state->Clear();
for (const auto& animation : animations_) {
if (!animation->is_finished() && animation->target_property() == property) {
state->potentially_animating_for_active_elements |=
animation->affects_active_elements();
state->potentially_animating_for_pending_elements |=
animation->affects_pending_elements();
state->currently_running_for_active_elements |=
animation->affects_active_elements() &&
animation->InEffect(last_tick_time_);
state->currently_running_for_pending_elements |=
animation->affects_pending_elements() &&
animation->InEffect(last_tick_time_);
}
}
}
void AnimationPlayer::MarkAbortedAnimationsForDeletion(
AnimationPlayer* animation_player_impl) const {
bool aborted_transform_animation = false;
......
......@@ -23,6 +23,7 @@ class AnimationDelegate;
class AnimationEvents;
class AnimationHost;
class AnimationTimeline;
struct PropertyAnimationState;
// An AnimationPlayer owns all animations to be run on particular CC Layer.
// Multiple AnimationPlayers can be attached to one layer. In this case,
......@@ -94,9 +95,6 @@ class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> {
bool HasNonDeletedAnimation() const;
using Animations = std::vector<std::unique_ptr<Animation>>;
const Animations& animations() const { return animations_; }
bool needs_to_start_animations() const { return needs_to_start_animations_; }
void StartAnimations(base::TimeTicks monotonic_time);
......@@ -153,6 +151,9 @@ class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> {
// Returns the active animation for the given unique animation id.
Animation* GetAnimationById(int animation_id) const;
void GetPropertyAnimationStateFor(TargetProperty::Type property,
PropertyAnimationState* state) const;
private:
friend class base::RefCounted<AnimationPlayer>;
......@@ -182,6 +183,7 @@ class CC_EXPORT AnimationPlayer : public base::RefCounted<AnimationPlayer> {
AnimationPlayer* animation_player_impl) const;
void PushPropertiesToImplThread(AnimationPlayer* animation_player_impl);
using Animations = std::vector<std::unique_ptr<Animation>>;
Animations animations_;
AnimationHost* animation_host_;
......
......@@ -538,7 +538,7 @@ void ElementAnimations::NotifyClientAnimationChanged(
ElementListType list_type,
bool notify_elements_about_potential_animation,
bool notify_elements_about_running_animation) {
struct PropertyAnimationState* animation_state = nullptr;
PropertyAnimationState* animation_state = nullptr;
switch (property) {
case TargetProperty::OPACITY:
animation_state = &opacity_animation_state_;
......@@ -585,7 +585,7 @@ void ElementAnimations::NotifyClientAnimationChanged(
void ElementAnimations::UpdateClientAnimationStateInternal(
TargetProperty::Type property) {
struct PropertyAnimationState* animation_state = nullptr;
PropertyAnimationState* animation_state = nullptr;
switch (property) {
case TargetProperty::OPACITY:
animation_state = &opacity_animation_state_;
......@@ -600,68 +600,34 @@ void ElementAnimations::UpdateClientAnimationStateInternal(
NOTREACHED();
break;
}
bool was_currently_running_animation_for_active_elements =
animation_state->currently_running_for_active_elements;
bool was_currently_running_animation_for_pending_elements =
animation_state->currently_running_for_pending_elements;
bool was_potentially_animating_for_active_elements =
animation_state->potentially_animating_for_active_elements;
bool was_potentially_animating_for_pending_elements =
animation_state->potentially_animating_for_pending_elements;
PropertyAnimationState previous_state = *animation_state;
animation_state->Clear();
DCHECK(was_potentially_animating_for_active_elements ||
!was_currently_running_animation_for_active_elements);
DCHECK(was_potentially_animating_for_pending_elements ||
!was_currently_running_animation_for_pending_elements);
DCHECK(previous_state.IsValid());
ElementAnimations::PlayersList::Iterator it(players_list_.get());
AnimationPlayer* player;
while ((player = it.GetNext()) != nullptr) {
for (const auto& animation : player->animations()) {
if (!animation->is_finished() &&
animation->target_property() == property) {
animation_state->potentially_animating_for_active_elements |=
animation->affects_active_elements();
animation_state->potentially_animating_for_pending_elements |=
animation->affects_pending_elements();
animation_state->currently_running_for_active_elements |=
animation->affects_active_elements() &&
animation->InEffect(last_tick_time_);
animation_state->currently_running_for_pending_elements |=
animation->affects_pending_elements() &&
animation->InEffect(last_tick_time_);
}
}
PropertyAnimationState player_state;
player->GetPropertyAnimationStateFor(property, &player_state);
*animation_state |= player_state;
}
bool potentially_animating_changed_for_active_elements =
was_potentially_animating_for_active_elements !=
animation_state->potentially_animating_for_active_elements;
bool potentially_animating_changed_for_pending_elements =
was_potentially_animating_for_pending_elements !=
animation_state->potentially_animating_for_pending_elements;
bool currently_running_animation_changed_for_active_elements =
was_currently_running_animation_for_active_elements !=
animation_state->currently_running_for_active_elements;
bool currently_running_animation_changed_for_pending_elements =
was_currently_running_animation_for_pending_elements !=
animation_state->currently_running_for_pending_elements;
if (!potentially_animating_changed_for_active_elements &&
!potentially_animating_changed_for_pending_elements &&
!currently_running_animation_changed_for_active_elements &&
!currently_running_animation_changed_for_pending_elements)
if (*animation_state == previous_state)
return;
PropertyAnimationState diff_state = previous_state ^ *animation_state;
if (has_element_in_active_list())
NotifyClientAnimationChanged(
property, ElementListType::ACTIVE,
potentially_animating_changed_for_active_elements,
currently_running_animation_changed_for_active_elements);
diff_state.potentially_animating_for_active_elements,
diff_state.currently_running_for_active_elements);
if (has_element_in_pending_list())
NotifyClientAnimationChanged(
property, ElementListType::PENDING,
potentially_animating_changed_for_pending_elements,
currently_running_animation_changed_for_pending_elements);
diff_state.potentially_animating_for_pending_elements,
diff_state.currently_running_for_pending_elements);
}
bool ElementAnimations::HasActiveAnimation() const {
......
......@@ -15,6 +15,7 @@
#include "cc/animation/animation.h"
#include "cc/animation/animation_curve.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/property_animation_state.h"
#include "cc/animation/target_property.h"
#include "cc/base/cc_export.h"
#include "ui/gfx/geometry/scroll_offset.h"
......@@ -246,22 +247,9 @@ class CC_EXPORT ElementAnimations : public base::RefCounted<ElementAnimations> {
bool needs_push_properties_;
struct PropertyAnimationState {
bool currently_running_for_active_elements = false;
bool currently_running_for_pending_elements = false;
bool potentially_animating_for_active_elements = false;
bool potentially_animating_for_pending_elements = false;
void Clear() {
currently_running_for_active_elements = false;
currently_running_for_pending_elements = false;
potentially_animating_for_active_elements = false;
potentially_animating_for_pending_elements = false;
}
};
struct PropertyAnimationState filter_animation_state_;
struct PropertyAnimationState opacity_animation_state_;
struct PropertyAnimationState transform_animation_state_;
PropertyAnimationState filter_animation_state_;
PropertyAnimationState opacity_animation_state_;
PropertyAnimationState transform_animation_state_;
bool needs_update_impl_client_state_transform_ : 1;
bool needs_update_impl_client_state_opacity_ : 1;
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/animation/property_animation_state.h"
#include "base/logging.h"
namespace cc {
bool PropertyAnimationState::operator==(
const PropertyAnimationState& other) const {
return currently_running_for_active_elements ==
other.currently_running_for_active_elements &&
currently_running_for_pending_elements ==
other.currently_running_for_pending_elements &&
potentially_animating_for_active_elements ==
other.potentially_animating_for_active_elements &&
potentially_animating_for_pending_elements ==
other.potentially_animating_for_pending_elements;
}
bool PropertyAnimationState::operator!=(
const PropertyAnimationState& other) const {
return !operator==(other);
}
PropertyAnimationState& PropertyAnimationState::operator|=(
const PropertyAnimationState& other) {
currently_running_for_active_elements |=
other.currently_running_for_active_elements;
currently_running_for_pending_elements |=
other.currently_running_for_pending_elements;
potentially_animating_for_active_elements |=
other.potentially_animating_for_active_elements;
potentially_animating_for_pending_elements |=
other.potentially_animating_for_pending_elements;
return *this;
}
PropertyAnimationState& PropertyAnimationState::operator^=(
const PropertyAnimationState& other) {
currently_running_for_active_elements ^=
other.currently_running_for_active_elements;
currently_running_for_pending_elements ^=
other.currently_running_for_pending_elements;
potentially_animating_for_active_elements ^=
other.potentially_animating_for_active_elements;
potentially_animating_for_pending_elements ^=
other.potentially_animating_for_pending_elements;
return *this;
}
PropertyAnimationState operator^(const PropertyAnimationState& lhs,
const PropertyAnimationState& rhs) {
PropertyAnimationState result = lhs;
result ^= rhs;
return result;
}
bool PropertyAnimationState::IsValid() const {
// currently_running must be a subset for potentially_animating.
// currently <= potentially.
return currently_running_for_active_elements <=
potentially_animating_for_active_elements &&
currently_running_for_pending_elements <=
potentially_animating_for_pending_elements;
}
void PropertyAnimationState::Clear() {
currently_running_for_active_elements = false;
currently_running_for_pending_elements = false;
potentially_animating_for_active_elements = false;
potentially_animating_for_pending_elements = false;
}
} // namespace cc
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_ANIMATION_PROPERTY_ANIMATION_STATE_H_
#define CC_ANIMATION_PROPERTY_ANIMATION_STATE_H_
#include "cc/base/cc_export.h"
namespace cc {
struct CC_EXPORT PropertyAnimationState {
bool currently_running_for_active_elements = false;
bool currently_running_for_pending_elements = false;
bool potentially_animating_for_active_elements = false;
bool potentially_animating_for_pending_elements = false;
bool operator==(const PropertyAnimationState& other) const;
bool operator!=(const PropertyAnimationState& other) const;
PropertyAnimationState& operator|=(const PropertyAnimationState& other);
PropertyAnimationState& operator^=(const PropertyAnimationState& other);
bool IsValid() const;
void Clear();
};
PropertyAnimationState operator^(const PropertyAnimationState& lhs,
const PropertyAnimationState& rhs);
} // namespace cc
#endif // CC_ANIMATION_PROPERTY_ANIMATION_STATE_H_
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