Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: cc/animation/animation_timeline.cc

Issue 2261113002: CC Animation: Introduce some dirty flags to optimize PushProperties on commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/animation/animation_timeline.h" 5 #include "cc/animation/animation_timeline.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/animation/animation_host.h"
9 #include "cc/animation/animation_player.h" 10 #include "cc/animation/animation_player.h"
10 11
11 namespace cc { 12 namespace cc {
12 13
13 scoped_refptr<AnimationTimeline> AnimationTimeline::Create(int id) { 14 scoped_refptr<AnimationTimeline> AnimationTimeline::Create(int id) {
14 return make_scoped_refptr(new AnimationTimeline(id)); 15 return make_scoped_refptr(new AnimationTimeline(id));
15 } 16 }
16 17
17 AnimationTimeline::AnimationTimeline(int id) 18 AnimationTimeline::AnimationTimeline(int id)
18 : id_(id), animation_host_(), is_impl_only_(false) { 19 : id_(id),
19 } 20 animation_host_(),
21 needs_push_properties_(false),
22 is_impl_only_(false) {}
20 23
21 AnimationTimeline::~AnimationTimeline() { 24 AnimationTimeline::~AnimationTimeline() {
22 for (auto& kv : id_to_player_map_) 25 for (auto& kv : id_to_player_map_)
23 kv.second->SetAnimationTimeline(nullptr); 26 kv.second->SetAnimationTimeline(nullptr);
24 } 27 }
25 28
26 scoped_refptr<AnimationTimeline> AnimationTimeline::CreateImplInstance() const { 29 scoped_refptr<AnimationTimeline> AnimationTimeline::CreateImplInstance() const {
27 scoped_refptr<AnimationTimeline> timeline = AnimationTimeline::Create(id()); 30 scoped_refptr<AnimationTimeline> timeline = AnimationTimeline::Create(id());
28 return timeline; 31 return timeline;
29 } 32 }
30 33
31 void AnimationTimeline::SetAnimationHost(AnimationHost* animation_host) { 34 void AnimationTimeline::SetAnimationHost(AnimationHost* animation_host) {
32 animation_host_ = animation_host; 35 animation_host_ = animation_host;
33 for (auto& kv : id_to_player_map_) 36 for (auto& kv : id_to_player_map_)
34 kv.second->SetAnimationHost(animation_host); 37 kv.second->SetAnimationHost(animation_host);
38
39 if (needs_push_properties() && animation_host_)
40 SetNeedsPushProperties();
35 } 41 }
36 42
37 void AnimationTimeline::AttachPlayer(scoped_refptr<AnimationPlayer> player) { 43 void AnimationTimeline::AttachPlayer(scoped_refptr<AnimationPlayer> player) {
38 DCHECK(player->id()); 44 DCHECK(player->id());
39 player->SetAnimationHost(animation_host_); 45 player->SetAnimationHost(animation_host_);
40 player->SetAnimationTimeline(this); 46 player->SetAnimationTimeline(this);
41 id_to_player_map_.insert(std::make_pair(player->id(), std::move(player))); 47 id_to_player_map_.insert(std::make_pair(player->id(), std::move(player)));
48
49 SetNeedsPushProperties();
42 } 50 }
43 51
44 void AnimationTimeline::DetachPlayer(scoped_refptr<AnimationPlayer> player) { 52 void AnimationTimeline::DetachPlayer(scoped_refptr<AnimationPlayer> player) {
45 DCHECK(player->id()); 53 DCHECK(player->id());
46 ErasePlayer(player); 54 ErasePlayer(player);
47 id_to_player_map_.erase(player->id()); 55 id_to_player_map_.erase(player->id());
56
57 SetNeedsPushProperties();
48 } 58 }
49 59
50 AnimationPlayer* AnimationTimeline::GetPlayerById(int player_id) const { 60 AnimationPlayer* AnimationTimeline::GetPlayerById(int player_id) const {
51 auto f = id_to_player_map_.find(player_id); 61 auto f = id_to_player_map_.find(player_id);
52 return f == id_to_player_map_.end() ? nullptr : f->second.get(); 62 return f == id_to_player_map_.end() ? nullptr : f->second.get();
53 } 63 }
54 64
55 void AnimationTimeline::ClearPlayers() { 65 void AnimationTimeline::ClearPlayers() {
56 for (auto& kv : id_to_player_map_) 66 for (auto& kv : id_to_player_map_)
57 ErasePlayer(kv.second); 67 ErasePlayer(kv.second);
58 id_to_player_map_.clear(); 68 id_to_player_map_.clear();
69
70 SetNeedsPushProperties();
71 }
72
73 void AnimationTimeline::SetNeedsPushProperties() {
74 needs_push_properties_ = true;
75 if (animation_host_)
76 animation_host_->SetNeedsPushProperties();
59 } 77 }
60 78
61 void AnimationTimeline::PushPropertiesTo(AnimationTimeline* timeline_impl) { 79 void AnimationTimeline::PushPropertiesTo(AnimationTimeline* timeline_impl) {
62 PushAttachedPlayersToImplThread(timeline_impl); 80 if (needs_push_properties_) {
63 RemoveDetachedPlayersFromImplThread(timeline_impl); 81 needs_push_properties_ = false;
64 PushPropertiesToImplThread(timeline_impl); 82 PushAttachedPlayersToImplThread(timeline_impl);
83 RemoveDetachedPlayersFromImplThread(timeline_impl);
84 PushPropertiesToImplThread(timeline_impl);
85 }
65 } 86 }
66 87
67 void AnimationTimeline::PushAttachedPlayersToImplThread( 88 void AnimationTimeline::PushAttachedPlayersToImplThread(
68 AnimationTimeline* timeline_impl) const { 89 AnimationTimeline* timeline_impl) const {
69 for (auto& kv : id_to_player_map_) { 90 for (auto& kv : id_to_player_map_) {
70 auto& player = kv.second; 91 auto& player = kv.second;
71 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); 92 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id());
72 if (player_impl) 93 if (player_impl)
73 continue; 94 continue;
74 95
(...skipping 21 matching lines...) Expand all
96 if (player->element_animations()) 117 if (player->element_animations())
97 player->DetachElement(); 118 player->DetachElement();
98 player->SetAnimationTimeline(nullptr); 119 player->SetAnimationTimeline(nullptr);
99 player->SetAnimationHost(nullptr); 120 player->SetAnimationHost(nullptr);
100 } 121 }
101 122
102 void AnimationTimeline::PushPropertiesToImplThread( 123 void AnimationTimeline::PushPropertiesToImplThread(
103 AnimationTimeline* timeline_impl) { 124 AnimationTimeline* timeline_impl) {
104 for (auto& kv : id_to_player_map_) { 125 for (auto& kv : id_to_player_map_) {
105 AnimationPlayer* player = kv.second.get(); 126 AnimationPlayer* player = kv.second.get();
106 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id()); 127 if (player->needs_push_properties()) {
107 if (player_impl) 128 AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id());
108 player->PushPropertiesTo(player_impl); 129 if (player_impl)
130 player->PushPropertiesTo(player_impl);
131 }
109 } 132 }
110 } 133 }
111 134
112 } // namespace cc 135 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698