Skip to content

Commit

Permalink
CC Animation: Rename Active Players to Ticking Players.
Browse files Browse the repository at this point in the history
To avoid confusion with active/pending trees in LTH and tree activation
process.

BUG=669755
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2554773002
Cr-Commit-Position: refs/heads/master@{#436834}
  • Loading branch information
loyso authored and Commit bot committed Dec 7, 2016
1 parent 132d936 commit a90a138
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 354 deletions.
63 changes: 30 additions & 33 deletions cc/animation/animation_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void AnimationHost::UnregisterPlayerForElement(ElementId element_id,
element_animations->SetAnimationHost(nullptr);
}

DeactivateAnimationPlayer(player);
RemoveFromTicking(player);
}

void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
Expand Down Expand Up @@ -270,44 +270,44 @@ bool AnimationHost::SupportsScrollAnimations() const {
return supports_scroll_animations_;
}

bool AnimationHost::NeedsAnimateLayers() const {
return !active_players_.empty();
bool AnimationHost::NeedsTickAnimations() const {
return !ticking_players_.empty();
}

bool AnimationHost::ActivateAnimations() {
if (!NeedsAnimateLayers())
if (!NeedsTickAnimations())
return false;

TRACE_EVENT0("cc", "AnimationHost::ActivateAnimations");
PlayersList active_active_players_copy = active_players_;
for (auto& it : active_active_players_copy)
PlayersList ticking_players_copy = ticking_players_;
for (auto& it : ticking_players_copy)
it->ActivateAnimations();

return true;
}

bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) {
if (!NeedsAnimateLayers())
bool AnimationHost::TickAnimations(base::TimeTicks monotonic_time) {
if (!NeedsTickAnimations())
return false;

TRACE_EVENT0("cc", "AnimationHost::AnimateLayers");
PlayersList active_active_players_copy = active_players_;
for (auto& it : active_active_players_copy)
it->Animate(monotonic_time);
TRACE_EVENT0("cc", "AnimationHost::TickAnimations");
PlayersList ticking_players_copy = ticking_players_;
for (auto& it : ticking_players_copy)
it->Tick(monotonic_time);

return true;
}

bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
MutatorEvents* mutator_events) {
if (!NeedsAnimateLayers())
if (!NeedsTickAnimations())
return false;

auto animation_events = static_cast<AnimationEvents*>(mutator_events);

TRACE_EVENT0("cc", "AnimationHost::UpdateAnimationState");
PlayersList active_active_players_copy = active_players_;
for (auto& it : active_active_players_copy)
PlayersList ticking_players_copy = ticking_players_;
for (auto& it : ticking_players_copy)
it->UpdateState(start_ready_animations, animation_events);

return true;
Expand All @@ -326,9 +326,8 @@ void AnimationHost::SetAnimationEvents(
++event_index) {
ElementId element_id = events->events_[event_index].element_id;

// Use the map of all ElementAnimations, not just active ones, since
// non-active ElementAnimations may still receive events for impl-only
// animations.
// Use the map of all ElementAnimations, not just ticking players, since
// non-ticking Players may still receive events for impl-only animations.
const ElementToAnimationsMap& all_element_animations =
element_to_animations_map_;
auto iter = all_element_animations.find(element_id);
Expand Down Expand Up @@ -520,9 +519,9 @@ bool AnimationHost::HasAnyAnimation(ElementId element_id) const {
return element_animations ? element_animations->HasAnyAnimation() : false;
}

bool AnimationHost::HasActiveAnimationForTesting(ElementId element_id) const {
bool AnimationHost::HasTickingAnimationForTesting(ElementId element_id) const {
auto element_animations = GetElementAnimationsForElementId(element_id);
return element_animations ? element_animations->HasActiveAnimation() : false;
return element_animations ? element_animations->HasTickingAnimation() : false;
}

void AnimationHost::ImplOnlyScrollAnimationCreate(
Expand Down Expand Up @@ -557,28 +556,26 @@ void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion);
}

void AnimationHost::ActivateAnimationPlayer(
scoped_refptr<AnimationPlayer> player) {
DCHECK(std::find(active_players_.begin(), active_players_.end(), player) ==
active_players_.end());
active_players_.push_back(player);
void AnimationHost::AddToTicking(scoped_refptr<AnimationPlayer> player) {
DCHECK(std::find(ticking_players_.begin(), ticking_players_.end(), player) ==
ticking_players_.end());
ticking_players_.push_back(player);
}

void AnimationHost::DeactivateAnimationPlayer(
scoped_refptr<AnimationPlayer> player) {
void AnimationHost::RemoveFromTicking(scoped_refptr<AnimationPlayer> player) {
auto to_erase =
std::find(active_players_.begin(), active_players_.end(), player);
if (to_erase != active_players_.end())
active_players_.erase(to_erase);
std::find(ticking_players_.begin(), ticking_players_.end(), player);
if (to_erase != ticking_players_.end())
ticking_players_.erase(to_erase);
}

const AnimationHost::PlayersList& AnimationHost::active_players_for_testing()
const AnimationHost::PlayersList& AnimationHost::ticking_players_for_testing()
const {
return active_players_;
return ticking_players_;
}

const AnimationHost::ElementToAnimationsMap&
AnimationHost::all_element_animations_for_testing() const {
AnimationHost::element_animations_for_testing() const {
return element_to_animations_map_;
}

Expand Down
22 changes: 11 additions & 11 deletions cc/animation/animation_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class CC_ANIMATION_EXPORT AnimationHost
void PushPropertiesTo(MutatorHost* host_impl) override;

void SetSupportsScrollAnimations(bool supports_scroll_animations) override;
bool NeedsAnimateLayers() const override;
bool NeedsTickAnimations() const override;

bool ActivateAnimations() override;
bool AnimateLayers(base::TimeTicks monotonic_time) override;
bool TickAnimations(base::TimeTicks monotonic_time) override;
bool UpdateAnimationState(bool start_ready_animations,
MutatorEvents* events) override;

Expand Down Expand Up @@ -153,7 +153,7 @@ class CC_ANIMATION_EXPORT AnimationHost
float* start_scale) const override;

bool HasAnyAnimation(ElementId element_id) const override;
bool HasActiveAnimationForTesting(ElementId element_id) const override;
bool HasTickingAnimationForTesting(ElementId element_id) const override;

void ImplOnlyScrollAnimationCreate(ElementId element_id,
const gfx::ScrollOffset& target_offset,
Expand All @@ -171,16 +171,16 @@ class CC_ANIMATION_EXPORT AnimationHost
// This should only be called from the main thread.
ScrollOffsetAnimations& scroll_offset_animations() const;

// Registers the given animation player as active. An active animation
// player is one that has a running animation that needs to be ticked.
void ActivateAnimationPlayer(scoped_refptr<AnimationPlayer> player);
// Registers the given animation player as ticking. A ticking animation
// player is one that has a running animation.
void AddToTicking(scoped_refptr<AnimationPlayer> player);

// Unregisters the given animation player. When this happens, the
// animation player will no longer be ticked (since it's not active).
void DeactivateAnimationPlayer(scoped_refptr<AnimationPlayer> player);
// animation player will no longer be ticked.
void RemoveFromTicking(scoped_refptr<AnimationPlayer> player);

const PlayersList& active_players_for_testing() const;
const ElementToAnimationsMap& all_element_animations_for_testing() const;
const PlayersList& ticking_players_for_testing() const;
const ElementToAnimationsMap& element_animations_for_testing() const;

private:
explicit AnimationHost(ThreadInstance thread_instance);
Expand All @@ -192,7 +192,7 @@ class CC_ANIMATION_EXPORT AnimationHost
void EraseTimeline(scoped_refptr<AnimationTimeline> timeline);

ElementToAnimationsMap element_to_animations_map_;
PlayersList active_players_;
PlayersList ticking_players_;

// A list of all timelines which this host owns.
using IdToTimelineMap =
Expand Down
36 changes: 18 additions & 18 deletions cc/animation/animation_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AnimationPlayer::AnimationPlayer(int id)
id_(id),
needs_push_properties_(false),
needs_to_start_animations_(false),
is_active_(false),
is_ticking_(false),
scroll_offset_animation_was_interrupted_(false) {
DCHECK(id_);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ void AnimationPlayer::AnimationAdded() {
SetNeedsCommit();
needs_to_start_animations_ = true;

UpdateActivation(ActivationType::NORMAL);
UpdateTickingState(UpdateTickingType::NORMAL);
element_animations_->UpdateClientAnimationState();
}

Expand Down Expand Up @@ -183,7 +183,7 @@ void AnimationPlayer::RemoveAnimation(int animation_id) {
animations_.erase(animations_to_remove, animations_.end());

if (element_animations_) {
UpdateActivation(ActivationType::NORMAL);
UpdateTickingState(UpdateTickingType::NORMAL);
if (animation_removed)
element_animations_->UpdateClientAnimationState();
SetNeedsCommit();
Expand Down Expand Up @@ -262,10 +262,10 @@ void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) {

PushPropertiesToImplThread(player_impl);

player_impl->UpdateActivation(ActivationType::NORMAL);
player_impl->UpdateTickingState(UpdateTickingType::NORMAL);
}

void AnimationPlayer::Animate(base::TimeTicks monotonic_time) {
void AnimationPlayer::Tick(base::TimeTicks monotonic_time) {
DCHECK(!monotonic_time.is_null());
DCHECK(element_animations_);

Expand Down Expand Up @@ -305,32 +305,32 @@ void AnimationPlayer::UpdateState(bool start_ready_animations,
}
}

UpdateActivation(ActivationType::NORMAL);
UpdateTickingState(UpdateTickingType::NORMAL);
}

void AnimationPlayer::UpdateActivation(ActivationType type) {
bool force = type == ActivationType::FORCE;
void AnimationPlayer::UpdateTickingState(UpdateTickingType type) {
bool force = type == UpdateTickingType::FORCE;
if (animation_host_) {
bool was_active = is_active_;
is_active_ = HasNonDeletedAnimation();
bool was_ticking = is_ticking_;
is_ticking_ = HasNonDeletedAnimation();

bool has_element_in_any_list =
element_animations_->has_element_in_any_list();

if (is_active_ && ((!was_active && has_element_in_any_list) || force)) {
animation_host_->ActivateAnimationPlayer(this);
} else if (!is_active_ && (was_active || force)) {
Deactivate();
if (is_ticking_ && ((!was_ticking && has_element_in_any_list) || force)) {
animation_host_->AddToTicking(this);
} else if (!is_ticking_ && (was_ticking || force)) {
RemoveFromTicking();
}
}
}

void AnimationPlayer::Deactivate() {
void AnimationPlayer::RemoveFromTicking() {
DCHECK(animation_host_);
// Resetting last_tick_time_ here ensures that calling ::UpdateState
// before ::Animate doesn't start an animation.
last_tick_time_ = base::TimeTicks();
animation_host_->DeactivateAnimationPlayer(this);
animation_host_->RemoveFromTicking(this);
}

bool AnimationPlayer::NotifyAnimationStarted(const AnimationEvent& event) {
Expand Down Expand Up @@ -432,7 +432,7 @@ void AnimationPlayer::SetNeedsPushProperties() {
element_animations_->SetNeedsPushProperties();
}

bool AnimationPlayer::HasActiveAnimation() const {
bool AnimationPlayer::HasTickingAnimation() const {
for (size_t i = 0; i < animations_.size(); ++i) {
if (!animations_[i]->is_finished())
return true;
Expand Down Expand Up @@ -823,7 +823,7 @@ void AnimationPlayer::ActivateAnimations() {
element_animations_->UpdateClientAnimationState();

scroll_offset_animation_was_interrupted_ = false;
UpdateActivation(ActivationType::NORMAL);
UpdateTickingState(UpdateTickingType::NORMAL);
}

bool AnimationPlayer::HasFilterAnimationThatInflatesBounds() const {
Expand Down
14 changes: 7 additions & 7 deletions cc/animation/animation_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class CC_ANIMATION_EXPORT AnimationPlayer

void PushPropertiesTo(AnimationPlayer* player_impl);

void Animate(base::TimeTicks monotonic_time);
void Tick(base::TimeTicks monotonic_time);
void UpdateState(bool start_ready_animations, AnimationEvents* events);

void UpdateActivation(ActivationType type);
void Deactivate();
void UpdateTickingState(UpdateTickingType type);
void RemoveFromTicking();

// AnimationDelegate routing.
bool NotifyAnimationStarted(const AnimationEvent& event);
Expand All @@ -92,7 +92,7 @@ class CC_ANIMATION_EXPORT AnimationPlayer

// Returns true if there are any animations that have neither finished nor
// aborted.
bool HasActiveAnimation() const;
bool HasTickingAnimation() const;

// Returns true if there are any animations at all to process.
bool has_any_animation() const { return !animations_.empty(); }
Expand Down Expand Up @@ -149,11 +149,11 @@ class CC_ANIMATION_EXPORT AnimationPlayer
bool HasElementInActiveList() const;
gfx::ScrollOffset ScrollOffsetForAnimation() const;

// Returns the active animation animating the given property that is either
// Returns the animation animating the given property that is either
// running, or is next to run, if such an animation exists.
Animation* GetAnimation(TargetProperty::Type target_property) const;

// Returns the active animation for the given unique animation id.
// Returns animation for the given unique animation id.
Animation* GetAnimationById(int animation_id) const;

void GetPropertyAnimationState(PropertyAnimationState* pending_state,
Expand Down Expand Up @@ -214,7 +214,7 @@ class CC_ANIMATION_EXPORT AnimationPlayer
bool needs_to_start_animations_;

// This is used to ensure that we don't spam the animation host.
bool is_active_;
bool is_ticking_;

bool scroll_offset_animation_was_interrupted_;

Expand Down
12 changes: 6 additions & 6 deletions cc/animation/animation_player_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ TEST_F(AnimationPlayerTest, PropertiesMutate) {

base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
AnimateLayersTransferEvents(time, 3u);
TickAnimationsTransferEvents(time, 3u);
EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));

time += base::TimeDelta::FromSecondsD(duration);
AnimateLayersTransferEvents(time, 3u);
TickAnimationsTransferEvents(time, 3u);
EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));

client_.ExpectOpacityPropertyMutated(element_id_, ElementListType::ACTIVE,
Expand Down Expand Up @@ -248,7 +248,7 @@ TEST_F(AnimationPlayerTest, AttachTwoPlayersToOneLayer) {

base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
AnimateLayersTransferEvents(time, 2u);
TickAnimationsTransferEvents(time, 2u);

EXPECT_TRUE(delegate1.started());
EXPECT_FALSE(delegate1.finished());
Expand All @@ -260,7 +260,7 @@ TEST_F(AnimationPlayerTest, AttachTwoPlayersToOneLayer) {
EXPECT_FALSE(player2->needs_push_properties());

time += base::TimeDelta::FromSecondsD(duration);
AnimateLayersTransferEvents(time, 2u);
TickAnimationsTransferEvents(time, 2u);

EXPECT_TRUE(delegate1.finished());
EXPECT_TRUE(delegate2.finished());
Expand Down Expand Up @@ -333,10 +333,10 @@ TEST_F(AnimationPlayerTest, AddRemoveAnimationToNonAttachedPlayer) {

base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
AnimateLayersTransferEvents(time, 1u);
TickAnimationsTransferEvents(time, 1u);

time += base::TimeDelta::FromSecondsD(duration);
AnimateLayersTransferEvents(time, 1u);
TickAnimationsTransferEvents(time, 1u);

client_.ExpectOpacityPropertyMutated(element_id_, ElementListType::ACTIVE,
end_opacity);
Expand Down
Loading

0 comments on commit a90a138

Please sign in to comment.