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

Side by Side Diff: cc/animation/animation_player.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: Add more tests. Created 4 years, 3 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_player.h" 5 #include "cc/animation/animation_player.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_host.h" 10 #include "cc/animation/animation_host.h"
11 #include "cc/animation/animation_timeline.h" 11 #include "cc/animation/animation_timeline.h"
12 #include "cc/animation/element_animations.h" 12 #include "cc/animation/element_animations.h"
13 13
14 namespace cc { 14 namespace cc {
15 15
16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) { 16 scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) {
17 return make_scoped_refptr(new AnimationPlayer(id)); 17 return make_scoped_refptr(new AnimationPlayer(id));
18 } 18 }
19 19
20 AnimationPlayer::AnimationPlayer(int id) 20 AnimationPlayer::AnimationPlayer(int id)
21 : animation_host_(), 21 : animation_host_(),
22 animation_timeline_(), 22 animation_timeline_(),
23 element_animations_(), 23 element_animations_(),
24 animation_delegate_(), 24 animation_delegate_(),
25 id_(id) { 25 id_(id),
26 needs_push_properties_(false) {
26 DCHECK(id_); 27 DCHECK(id_);
27 } 28 }
28 29
29 AnimationPlayer::~AnimationPlayer() { 30 AnimationPlayer::~AnimationPlayer() {
30 DCHECK(!animation_timeline_); 31 DCHECK(!animation_timeline_);
31 DCHECK(!element_animations_); 32 DCHECK(!element_animations_);
32 } 33 }
33 34
34 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const { 35 scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const {
35 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id()); 36 scoped_refptr<AnimationPlayer> player = AnimationPlayer::Create(id());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 animation_host_->UnregisterPlayerForElement(element_id_, this); 98 animation_host_->UnregisterPlayerForElement(element_id_, this);
98 } 99 }
99 100
100 void AnimationPlayer::BindElementAnimations() { 101 void AnimationPlayer::BindElementAnimations() {
101 DCHECK(!element_animations_); 102 DCHECK(!element_animations_);
102 element_animations_ = 103 element_animations_ =
103 animation_host_->GetElementAnimationsForElementId(element_id_); 104 animation_host_->GetElementAnimationsForElementId(element_id_);
104 DCHECK(element_animations_); 105 DCHECK(element_animations_);
105 106
106 // Pass all accumulated animations to ElementAnimations. 107 // Pass all accumulated animations to ElementAnimations.
107 for (auto& animation : animations_) { 108 for (auto& animation : animations_)
108 element_animations_->AddAnimation(std::move(animation)); 109 element_animations_->AddAnimation(std::move(animation));
109 }
110 if (!animations_.empty())
111 SetNeedsCommit();
112 animations_.clear(); 110 animations_.clear();
111
112 SetNeedsPushProperties();
113 } 113 }
114 114
115 void AnimationPlayer::UnbindElementAnimations() { 115 void AnimationPlayer::UnbindElementAnimations() {
116 SetNeedsPushProperties();
117
116 element_animations_ = nullptr; 118 element_animations_ = nullptr;
117 DCHECK(animations_.empty()); 119 DCHECK(animations_.empty());
118 } 120 }
119 121
120 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) { 122 void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) {
121 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET || 123 DCHECK(animation->target_property() != TargetProperty::SCROLL_OFFSET ||
122 (animation_host_ && animation_host_->SupportsScrollAnimations())); 124 (animation_host_ && animation_host_->SupportsScrollAnimations()));
123 125
124 if (element_animations_) { 126 if (element_animations_) {
125 element_animations_->AddAnimation(std::move(animation)); 127 element_animations_->AddAnimation(std::move(animation));
126 SetNeedsCommit(); 128 SetNeedsPushProperties();
127 } else { 129 } else {
128 animations_.push_back(std::move(animation)); 130 animations_.push_back(std::move(animation));
129 } 131 }
130 } 132 }
131 133
132 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) { 134 void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) {
133 DCHECK(element_animations_); 135 DCHECK(element_animations_);
134 element_animations_->PauseAnimation( 136 element_animations_->PauseAnimation(
135 animation_id, base::TimeDelta::FromSecondsD(time_offset)); 137 animation_id, base::TimeDelta::FromSecondsD(time_offset));
136 SetNeedsCommit(); 138 SetNeedsPushProperties();
137 } 139 }
138 140
139 void AnimationPlayer::RemoveAnimation(int animation_id) { 141 void AnimationPlayer::RemoveAnimation(int animation_id) {
140 if (element_animations_) { 142 if (element_animations_) {
141 element_animations_->RemoveAnimation(animation_id); 143 element_animations_->RemoveAnimation(animation_id);
142 SetNeedsCommit(); 144 SetNeedsPushProperties();
143 } else { 145 } else {
144 auto animations_to_remove = std::remove_if( 146 auto animations_to_remove = std::remove_if(
145 animations_.begin(), animations_.end(), 147 animations_.begin(), animations_.end(),
146 [animation_id](const std::unique_ptr<Animation>& animation) { 148 [animation_id](const std::unique_ptr<Animation>& animation) {
147 return animation->id() == animation_id; 149 return animation->id() == animation_id;
148 }); 150 });
149 animations_.erase(animations_to_remove, animations_.end()); 151 animations_.erase(animations_to_remove, animations_.end());
150 } 152 }
151 } 153 }
152 154
153 void AnimationPlayer::AbortAnimation(int animation_id) { 155 void AnimationPlayer::AbortAnimation(int animation_id) {
154 DCHECK(element_animations_); 156 DCHECK(element_animations_);
155 element_animations_->AbortAnimation(animation_id); 157 element_animations_->AbortAnimation(animation_id);
156 SetNeedsCommit(); 158 SetNeedsPushProperties();
157 } 159 }
158 160
159 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property, 161 void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property,
160 bool needs_completion) { 162 bool needs_completion) {
161 if (element_animations_) { 163 if (element_animations_) {
162 element_animations_->AbortAnimations(target_property, needs_completion); 164 element_animations_->AbortAnimations(target_property, needs_completion);
163 SetNeedsCommit(); 165 SetNeedsPushProperties();
164 } else { 166 } else {
165 auto animations_to_remove = std::remove_if( 167 auto animations_to_remove = std::remove_if(
166 animations_.begin(), animations_.end(), 168 animations_.begin(), animations_.end(),
167 [target_property](const std::unique_ptr<Animation>& animation) { 169 [target_property](const std::unique_ptr<Animation>& animation) {
168 return animation->target_property() == target_property; 170 return animation->target_property() == target_property;
169 }); 171 });
170 animations_.erase(animations_to_remove, animations_.end()); 172 animations_.erase(animations_to_remove, animations_.end());
171 } 173 }
172 } 174 }
173 175
174 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) { 176 void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) {
177 if (!needs_push_properties_)
178 return;
179 needs_push_properties_ = false;
180
175 if (element_id_ != player_impl->element_id()) { 181 if (element_id_ != player_impl->element_id()) {
176 if (player_impl->element_id()) 182 if (player_impl->element_id())
177 player_impl->DetachElement(); 183 player_impl->DetachElement();
178 if (element_id_) 184 if (element_id_)
179 player_impl->AttachElement(element_id_); 185 player_impl->AttachElement(element_id_);
180 } 186 }
181 } 187 }
182 188
183 void AnimationPlayer::NotifyAnimationStarted( 189 void AnimationPlayer::NotifyAnimationStarted(
184 base::TimeTicks monotonic_time, 190 base::TimeTicks monotonic_time,
(...skipping 15 matching lines...) Expand all
200 206
201 void AnimationPlayer::NotifyAnimationAborted( 207 void AnimationPlayer::NotifyAnimationAborted(
202 base::TimeTicks monotonic_time, 208 base::TimeTicks monotonic_time,
203 TargetProperty::Type target_property, 209 TargetProperty::Type target_property,
204 int group) { 210 int group) {
205 if (animation_delegate_) 211 if (animation_delegate_)
206 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property, 212 animation_delegate_->NotifyAnimationAborted(monotonic_time, target_property,
207 group); 213 group);
208 } 214 }
209 215
216 void AnimationPlayer::NotifyAnimationWaitingForDeletion() {
217 // We need to purge animations marked for deletion.
218 SetNeedsPushProperties();
219 }
220
210 void AnimationPlayer::NotifyAnimationTakeover( 221 void AnimationPlayer::NotifyAnimationTakeover(
211 base::TimeTicks monotonic_time, 222 base::TimeTicks monotonic_time,
212 TargetProperty::Type target_property, 223 TargetProperty::Type target_property,
213 double animation_start_time, 224 double animation_start_time,
214 std::unique_ptr<AnimationCurve> curve) { 225 std::unique_ptr<AnimationCurve> curve) {
226 // We need to purge animations marked for deletion on CT.
227 SetNeedsPushProperties();
228
215 if (animation_delegate_) { 229 if (animation_delegate_) {
216 DCHECK(curve); 230 DCHECK(curve);
217 animation_delegate_->NotifyAnimationTakeover( 231 animation_delegate_->NotifyAnimationTakeover(
218 monotonic_time, target_property, animation_start_time, 232 monotonic_time, target_property, animation_start_time,
219 std::move(curve)); 233 std::move(curve));
220 } 234 }
221 } 235 }
222 236
223 void AnimationPlayer::SetNeedsCommit() { 237 void AnimationPlayer::SetNeedsPushProperties() {
224 DCHECK(animation_host_); 238 needs_push_properties_ = true;
225 animation_host_->SetNeedsCommit(); 239
226 animation_host_->SetNeedsRebuildPropertyTrees(); 240 DCHECK(animation_timeline_);
241 animation_timeline_->SetNeedsPushProperties();
242
243 DCHECK(element_animations_);
244 element_animations_->SetNeedsPushProperties();
227 } 245 }
228 246
229 } // namespace cc 247 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698