OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/animation/animation_timeline.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "cc/animation/animation_player.h" |
| 10 |
| 11 namespace cc { |
| 12 |
| 13 scoped_refptr<AnimationTimeline> AnimationTimeline::Create() { |
| 14 return make_scoped_refptr(new AnimationTimeline()); |
| 15 } |
| 16 |
| 17 AnimationTimeline::AnimationTimeline() : layer_tree_mutators_client_() { |
| 18 } |
| 19 |
| 20 AnimationTimeline::~AnimationTimeline() { |
| 21 DCHECK(!layer_tree_mutators_client()); |
| 22 for (auto& player : players_) |
| 23 player->SetAnimationTimeline(nullptr); |
| 24 } |
| 25 |
| 26 void AnimationTimeline::AttachPlayer(AnimationPlayer* player) { |
| 27 player->SetAnimationTimeline(this); |
| 28 players_.push_back(player); |
| 29 } |
| 30 |
| 31 void AnimationTimeline::DetachPlayer(AnimationPlayer* player) { |
| 32 for (AnimationPlayerList::iterator iter = players_.begin(); |
| 33 iter != players_.end(); ++iter) { |
| 34 if (iter->get() != player) |
| 35 continue; |
| 36 |
| 37 players_.erase(iter); |
| 38 player->SetAnimationTimeline(nullptr); |
| 39 break; |
| 40 } |
| 41 } |
| 42 |
| 43 AnimationPlayer* AnimationTimeline::GetPlayerById(int player_id) const { |
| 44 for (auto& player : players_) |
| 45 if (player->id() == player_id) |
| 46 return player.get(); |
| 47 return nullptr; |
| 48 } |
| 49 |
| 50 void AnimationTimeline::SetLayerTreeMutatorsClient( |
| 51 LayerTreeMutatorsClient* client) { |
| 52 if (layer_tree_mutators_client_ == client) |
| 53 return; |
| 54 |
| 55 layer_tree_mutators_client_ = client; |
| 56 } |
| 57 |
| 58 void AnimationTimeline::PushPropertiesTo(AnimationTimeline* timeline_impl) { |
| 59 PushAttachedPlayersToImplThread(timeline_impl); |
| 60 RemoveDetachedPlayersFromImplThread(timeline_impl); |
| 61 PushPropertiesToImplThread(timeline_impl); |
| 62 } |
| 63 |
| 64 void AnimationTimeline::PushAttachedPlayersToImplThread( |
| 65 AnimationTimeline* timeline_impl) const { |
| 66 for (auto& player : players_) { |
| 67 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); |
| 68 if (player_impl) |
| 69 continue; |
| 70 |
| 71 scoped_refptr<AnimationPlayer> to_add = player->CreateImplInstance(); |
| 72 timeline_impl->AttachPlayer(to_add.get()); |
| 73 } |
| 74 } |
| 75 |
| 76 void AnimationTimeline::RemoveDetachedPlayersFromImplThread( |
| 77 AnimationTimeline* timeline_impl) const { |
| 78 AnimationPlayerList& players_impl = timeline_impl->players_; |
| 79 |
| 80 AnimationPlayerList::iterator erase_begin = |
| 81 std::remove_if(players_impl.begin(), players_impl.end(), |
| 82 [this](AnimationPlayerList::value_type player_impl) { |
| 83 return !GetPlayerById(player_impl->id()); |
| 84 }); |
| 85 |
| 86 for (AnimationPlayerList::iterator i = erase_begin; i != players_impl.end(); |
| 87 ++i) |
| 88 (*i)->SetAnimationTimeline(nullptr); |
| 89 |
| 90 players_impl.erase(erase_begin, players_impl.end()); |
| 91 } |
| 92 |
| 93 void AnimationTimeline::PushPropertiesToImplThread( |
| 94 AnimationTimeline* timeline_impl) { |
| 95 for (auto& player : players_) { |
| 96 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); |
| 97 if (player_impl) |
| 98 player->PushPropertiesTo(player_impl); |
| 99 } |
| 100 } |
| 101 |
| 102 } // namespace cc |
OLD | NEW |