| 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..cfd7a09ca3383055ee98b3703eb30e08937672a2
|
| --- /dev/null
|
| +++ b/cc/animation/animation_timeline.cc
|
| @@ -0,0 +1,139 @@
|
| +// 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::RegisterLayerImpl(int layer_id, bool is_active_tree) {
|
| + AnimationPlayer* player = GetPlayerForLayerId(layer_id);
|
| + if (player)
|
| + player->LayerImplRegistered(layer_id, is_active_tree);
|
| +}
|
| +
|
| +void AnimationTimeline::UnregisterLayerImpl(int layer_id, bool is_active_tree) {
|
| + AnimationPlayer* player = GetPlayerForLayerId(layer_id);
|
| + if (player)
|
| + player->LayerImplUnregistered(layer_id, is_active_tree);
|
| +}
|
| +
|
| +void AnimationTimeline::RegisterPlayerForLayer(int layer_id,
|
| + AnimationPlayer* player) {
|
| + DCHECK(layer_id);
|
| + DCHECK(player);
|
| + layer_to_player_map_[layer_id] = player;
|
| +}
|
| +
|
| +void AnimationTimeline::UnregisterPlayerForLayer(int layer_id,
|
| + AnimationPlayer* player) {
|
| + DCHECK(layer_id);
|
| + DCHECK(player);
|
| + auto iter = layer_to_player_map_.find(layer_id);
|
| + if (iter != layer_to_player_map_.end() && iter->second == player)
|
| + layer_to_player_map_.erase(iter);
|
| +}
|
| +
|
| +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_;
|
| +
|
| + auto to_erase =
|
| + std::partition(players_impl.begin(), players_impl.end(),
|
| + [this](AnimationPlayerList::value_type player_impl) {
|
| + return GetPlayerById(player_impl->id());
|
| + });
|
| +
|
| + for (auto i = to_erase; i != players_impl.end(); ++i) {
|
| + auto& player_impl = *i;
|
| + if (player_impl->layer_animation_controller())
|
| + player_impl->DetachLayer();
|
| + player_impl->SetAnimationTimeline(nullptr);
|
| + }
|
| +
|
| + players_impl.erase(to_erase, 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);
|
| + }
|
| +}
|
| +
|
| +AnimationPlayer* AnimationTimeline::GetPlayerForLayerId(int layer_id) const {
|
| + DCHECK(layer_id);
|
| + auto iter = layer_to_player_map_.find(layer_id);
|
| + return iter == layer_to_player_map_.end() ? nullptr : iter->second;
|
| +}
|
| +
|
| +} // namespace cc
|
|
|