| Index: cc/animation/animation_timeline.cc
|
| diff --git a/cc/animation/animation_timeline.cc b/cc/animation/animation_timeline.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..64075965b49ce77f40acfe3b5ac5f552d4ac0489
|
| --- /dev/null
|
| +++ b/cc/animation/animation_timeline.cc
|
| @@ -0,0 +1,102 @@
|
| +// Copyright 2015 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/animation_timeline.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "cc/animation/animation_player.h"
|
| +
|
| +namespace cc {
|
| +
|
| +scoped_refptr<AnimationTimeline> AnimationTimeline::Create() {
|
| + return make_scoped_refptr(new AnimationTimeline());
|
| +}
|
| +
|
| +AnimationTimeline::AnimationTimeline() : layer_tree_mutators_client_() {
|
| +}
|
| +
|
| +AnimationTimeline::~AnimationTimeline() {
|
| + DCHECK(!layer_tree_mutators_client());
|
| + for (auto& player : players_)
|
| + player->SetAnimationTimeline(nullptr);
|
| +}
|
| +
|
| +void AnimationTimeline::AttachPlayer(AnimationPlayer* player) {
|
| + player->SetAnimationTimeline(this);
|
| + players_.push_back(player);
|
| +}
|
| +
|
| +void AnimationTimeline::DetachPlayer(AnimationPlayer* player) {
|
| + for (AnimationPlayerList::iterator iter = players_.begin();
|
| + iter != players_.end(); ++iter) {
|
| + if (iter->get() != player)
|
| + continue;
|
| +
|
| + players_.erase(iter);
|
| + player->SetAnimationTimeline(nullptr);
|
| + break;
|
| + }
|
| +}
|
| +
|
| +AnimationPlayer* AnimationTimeline::GetPlayerById(int player_id) const {
|
| + for (auto& player : players_)
|
| + if (player->id() == player_id)
|
| + return player.get();
|
| + return nullptr;
|
| +}
|
| +
|
| +void AnimationTimeline::SetLayerTreeMutatorsClient(
|
| + LayerTreeMutatorsClient* client) {
|
| + if (layer_tree_mutators_client_ == client)
|
| + return;
|
| +
|
| + layer_tree_mutators_client_ = client;
|
| +}
|
| +
|
| +void AnimationTimeline::PushPropertiesTo(AnimationTimeline* timeline_impl) {
|
| + PushAttachedPlayersToImplThread(timeline_impl);
|
| + RemoveDetachedPlayersFromImplThread(timeline_impl);
|
| + PushPropertiesToImplThread(timeline_impl);
|
| +}
|
| +
|
| +void AnimationTimeline::PushAttachedPlayersToImplThread(
|
| + AnimationTimeline* timeline_impl) const {
|
| + for (auto& player : players_) {
|
| + AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id());
|
| + if (player_impl)
|
| + continue;
|
| +
|
| + scoped_refptr<AnimationPlayer> to_add = player->CreateImplInstance();
|
| + timeline_impl->AttachPlayer(to_add.get());
|
| + }
|
| +}
|
| +
|
| +void AnimationTimeline::RemoveDetachedPlayersFromImplThread(
|
| + AnimationTimeline* timeline_impl) const {
|
| + AnimationPlayerList& players_impl = timeline_impl->players_;
|
| +
|
| + AnimationPlayerList::iterator erase_begin =
|
| + std::remove_if(players_impl.begin(), players_impl.end(),
|
| + [this](AnimationPlayerList::value_type player_impl) {
|
| + return !GetPlayerById(player_impl->id());
|
| + });
|
| +
|
| + for (AnimationPlayerList::iterator i = erase_begin; i != players_impl.end();
|
| + ++i)
|
| + (*i)->SetAnimationTimeline(nullptr);
|
| +
|
| + players_impl.erase(erase_begin, players_impl.end());
|
| +}
|
| +
|
| +void AnimationTimeline::PushPropertiesToImplThread(
|
| + AnimationTimeline* timeline_impl) {
|
| + for (auto& player : players_) {
|
| + AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id());
|
| + if (player_impl)
|
| + player->PushPropertiesTo(player_impl);
|
| + }
|
| +}
|
| +
|
| +} // namespace cc
|
|
|