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

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

Issue 2291463003: Revert "CC Animation: Introduce some dirty flags to optimize PushProperties on commit" (Closed)
Patch Set: 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
« no previous file with comments | « cc/animation/element_animations.h ('k') | cc/animation/element_animations_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/element_animations.h" 5 #include "cc/animation/element_animations.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 ElementAnimations::ElementAnimations() 28 ElementAnimations::ElementAnimations()
29 : players_list_(new PlayersList()), 29 : players_list_(new PlayersList()),
30 animation_host_(), 30 animation_host_(),
31 element_id_(), 31 element_id_(),
32 is_active_(false), 32 is_active_(false),
33 has_element_in_active_list_(false), 33 has_element_in_active_list_(false),
34 has_element_in_pending_list_(false), 34 has_element_in_pending_list_(false),
35 needs_to_start_animations_(false), 35 needs_to_start_animations_(false),
36 scroll_offset_animation_was_interrupted_(false), 36 scroll_offset_animation_was_interrupted_(false) {}
37 needs_push_properties_(false) {}
38 37
39 ElementAnimations::~ElementAnimations() {} 38 ElementAnimations::~ElementAnimations() {}
40 39
41 void ElementAnimations::SetAnimationHost(AnimationHost* host) { 40 void ElementAnimations::SetAnimationHost(AnimationHost* host) {
42 animation_host_ = host; 41 animation_host_ = host;
43 } 42 }
44 43
45 void ElementAnimations::SetElementId(ElementId element_id) { 44 void ElementAnimations::SetElementId(ElementId element_id) {
46 element_id_ = element_id; 45 element_id_ = element_id;
47 } 46 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 115 }
117 116
118 void ElementAnimations::RemovePlayer(AnimationPlayer* player) { 117 void ElementAnimations::RemovePlayer(AnimationPlayer* player) {
119 players_list_->RemoveObserver(player); 118 players_list_->RemoveObserver(player);
120 } 119 }
121 120
122 bool ElementAnimations::IsEmpty() const { 121 bool ElementAnimations::IsEmpty() const {
123 return !players_list_->might_have_observers(); 122 return !players_list_->might_have_observers();
124 } 123 }
125 124
126 void ElementAnimations::SetNeedsPushProperties() {
127 needs_push_properties_ = true;
128 }
129
130 void ElementAnimations::PushPropertiesTo( 125 void ElementAnimations::PushPropertiesTo(
131 scoped_refptr<ElementAnimations> element_animations_impl) { 126 scoped_refptr<ElementAnimations> element_animations_impl) {
132 DCHECK_NE(this, element_animations_impl); 127 DCHECK_NE(this, element_animations_impl);
133
134 if (!needs_push_properties_)
135 return;
136 needs_push_properties_ = false;
137
138 if (!has_any_animation() && !element_animations_impl->has_any_animation()) 128 if (!has_any_animation() && !element_animations_impl->has_any_animation())
139 return; 129 return;
140 MarkAbortedAnimationsForDeletion(element_animations_impl.get()); 130 MarkAbortedAnimationsForDeletion(element_animations_impl.get());
141 PurgeAnimationsMarkedForDeletion(); 131 PurgeAnimationsMarkedForDeletion();
142 PushNewAnimationsToImplThread(element_animations_impl.get()); 132 PushNewAnimationsToImplThread(element_animations_impl.get());
143 133
144 // Remove finished impl side animations only after pushing, 134 // Remove finished impl side animations only after pushing,
145 // and only after the animations are deleted on the main thread 135 // and only after the animations are deleted on the main thread
146 // this insures we will never push an animation twice. 136 // this insures we will never push an animation twice.
147 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); 137 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get());
(...skipping 12 matching lines...) Expand all
160 UpdateActivation(NORMAL_ACTIVATION); 150 UpdateActivation(NORMAL_ACTIVATION);
161 switch (target_property) { 151 switch (target_property) {
162 case TargetProperty::TRANSFORM: 152 case TargetProperty::TRANSFORM:
163 case TargetProperty::OPACITY: 153 case TargetProperty::OPACITY:
164 case TargetProperty::FILTER: 154 case TargetProperty::FILTER:
165 UpdateClientAnimationState(target_property); 155 UpdateClientAnimationState(target_property);
166 break; 156 break;
167 default: 157 default:
168 break; 158 break;
169 } 159 }
170 SetNeedsPushProperties();
171 } 160 }
172 161
173 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { 162 void ElementAnimations::Animate(base::TimeTicks monotonic_time) {
174 DCHECK(!monotonic_time.is_null()); 163 DCHECK(!monotonic_time.is_null());
175 if (!has_element_in_active_list() && !has_element_in_pending_list()) 164 if (!has_element_in_active_list() && !has_element_in_pending_list())
176 return; 165 return;
177 166
178 if (needs_to_start_animations_) 167 if (needs_to_start_animations_)
179 StartAnimations(monotonic_time); 168 StartAnimations(monotonic_time);
180 TickAnimations(monotonic_time); 169 TickAnimations(monotonic_time);
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 else 879 else
891 events->events_.push_back(finished_event); 880 events->events_.push_back(finished_event);
892 } 881 }
893 animations_[animation_index]->SetRunState( 882 animations_[animation_index]->SetRunState(
894 Animation::WAITING_FOR_DELETION, monotonic_time); 883 Animation::WAITING_FOR_DELETION, monotonic_time);
895 } 884 }
896 marked_animations_for_deletions = true; 885 marked_animations_for_deletions = true;
897 } 886 }
898 } 887 }
899 if (marked_animations_for_deletions) 888 if (marked_animations_for_deletions)
900 NotifyPlayersAnimationWaitingForDeletion(); 889 NotifyClientAnimationWaitingForDeletion();
901 } 890 }
902 891
903 void ElementAnimations::MarkAbortedAnimationsForDeletion( 892 void ElementAnimations::MarkAbortedAnimationsForDeletion(
904 ElementAnimations* element_animations_impl) const { 893 ElementAnimations* element_animations_impl) const {
905 bool aborted_transform_animation = false; 894 bool aborted_transform_animation = false;
906 bool aborted_opacity_animation = false; 895 bool aborted_opacity_animation = false;
907 bool aborted_filter_animation = false; 896 bool aborted_filter_animation = false;
908 auto& animations_impl = element_animations_impl->animations_; 897 auto& animations_impl = element_animations_impl->animations_;
909 for (const auto& animation_impl : animations_impl) { 898 for (const auto& animation_impl : animations_impl) {
910 // If the animation has been aborted on the main thread, mark it for 899 // If the animation has been aborted on the main thread, mark it for
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 void ElementAnimations::NotifyClientScrollOffsetAnimated( 1058 void ElementAnimations::NotifyClientScrollOffsetAnimated(
1070 const gfx::ScrollOffset& scroll_offset, 1059 const gfx::ScrollOffset& scroll_offset,
1071 bool notify_active_elements, 1060 bool notify_active_elements,
1072 bool notify_pending_elements) { 1061 bool notify_pending_elements) {
1073 if (notify_active_elements && has_element_in_active_list()) 1062 if (notify_active_elements && has_element_in_active_list())
1074 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); 1063 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset);
1075 if (notify_pending_elements && has_element_in_pending_list()) 1064 if (notify_pending_elements && has_element_in_pending_list())
1076 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); 1065 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset);
1077 } 1066 }
1078 1067
1068 void ElementAnimations::NotifyClientAnimationWaitingForDeletion() {
1069 OnAnimationWaitingForDeletion();
1070 }
1071
1079 void ElementAnimations::NotifyClientAnimationChanged( 1072 void ElementAnimations::NotifyClientAnimationChanged(
1080 TargetProperty::Type property, 1073 TargetProperty::Type property,
1081 ElementListType list_type, 1074 ElementListType list_type,
1082 bool notify_elements_about_potential_animation, 1075 bool notify_elements_about_potential_animation,
1083 bool notify_elements_about_running_animation) { 1076 bool notify_elements_about_running_animation) {
1084 struct PropertyAnimationState* animation_state = nullptr; 1077 struct PropertyAnimationState* animation_state = nullptr;
1085 switch (property) { 1078 switch (property) {
1086 case TargetProperty::OPACITY: 1079 case TargetProperty::OPACITY:
1087 animation_state = &opacity_animation_state_; 1080 animation_state = &opacity_animation_state_;
1088 break; 1081 break;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 1238
1246 void ElementAnimations::PauseAnimation(int animation_id, 1239 void ElementAnimations::PauseAnimation(int animation_id,
1247 base::TimeDelta time_offset) { 1240 base::TimeDelta time_offset) {
1248 for (size_t i = 0; i < animations_.size(); ++i) { 1241 for (size_t i = 0; i < animations_.size(); ++i) {
1249 if (animations_[i]->id() == animation_id) { 1242 if (animations_[i]->id() == animation_id) {
1250 animations_[i]->SetRunState(Animation::PAUSED, 1243 animations_[i]->SetRunState(Animation::PAUSED,
1251 time_offset + animations_[i]->start_time() + 1244 time_offset + animations_[i]->start_time() +
1252 animations_[i]->time_offset()); 1245 animations_[i]->time_offset());
1253 } 1246 }
1254 } 1247 }
1255 SetNeedsPushProperties();
1256 } 1248 }
1257 1249
1258 void ElementAnimations::RemoveAnimation(int animation_id) { 1250 void ElementAnimations::RemoveAnimation(int animation_id) {
1259 bool removed_transform_animation = false; 1251 bool removed_transform_animation = false;
1260 bool removed_opacity_animation = false; 1252 bool removed_opacity_animation = false;
1261 bool removed_filter_animation = false; 1253 bool removed_filter_animation = false;
1262 // Since we want to use the animations that we're going to remove, we need to 1254 // Since we want to use the animations that we're going to remove, we need to
1263 // use a stable_parition here instead of remove_if. Remove_if leaves the 1255 // use a stable_parition here instead of remove_if. Remove_if leaves the
1264 // removed items in an unspecified state. 1256 // removed items in an unspecified state.
1265 auto animations_to_remove = std::stable_partition( 1257 auto animations_to_remove = std::stable_partition(
(...skipping 17 matching lines...) Expand all
1283 } 1275 }
1284 1276
1285 animations_.erase(animations_to_remove, animations_.end()); 1277 animations_.erase(animations_to_remove, animations_.end());
1286 UpdateActivation(NORMAL_ACTIVATION); 1278 UpdateActivation(NORMAL_ACTIVATION);
1287 if (removed_transform_animation) 1279 if (removed_transform_animation)
1288 UpdateClientAnimationState(TargetProperty::TRANSFORM); 1280 UpdateClientAnimationState(TargetProperty::TRANSFORM);
1289 if (removed_opacity_animation) 1281 if (removed_opacity_animation)
1290 UpdateClientAnimationState(TargetProperty::OPACITY); 1282 UpdateClientAnimationState(TargetProperty::OPACITY);
1291 if (removed_filter_animation) 1283 if (removed_filter_animation)
1292 UpdateClientAnimationState(TargetProperty::FILTER); 1284 UpdateClientAnimationState(TargetProperty::FILTER);
1293
1294 SetNeedsPushProperties();
1295 } 1285 }
1296 1286
1297 void ElementAnimations::AbortAnimation(int animation_id) { 1287 void ElementAnimations::AbortAnimation(int animation_id) {
1298 if (Animation* animation = GetAnimationById(animation_id)) { 1288 if (Animation* animation = GetAnimationById(animation_id)) {
1299 if (!animation->is_finished()) { 1289 if (!animation->is_finished()) {
1300 animation->SetRunState(Animation::ABORTED, last_tick_time_); 1290 animation->SetRunState(Animation::ABORTED, last_tick_time_);
1301 switch (animation->target_property()) { 1291 switch (animation->target_property()) {
1302 case TargetProperty::TRANSFORM: 1292 case TargetProperty::TRANSFORM:
1303 case TargetProperty::OPACITY: 1293 case TargetProperty::OPACITY:
1304 case TargetProperty::FILTER: 1294 case TargetProperty::FILTER:
1305 UpdateClientAnimationState(animation->target_property()); 1295 UpdateClientAnimationState(animation->target_property());
1306 break; 1296 break;
1307 default: 1297 default:
1308 break; 1298 break;
1309 } 1299 }
1310 } 1300 }
1311 } 1301 }
1312
1313 SetNeedsPushProperties();
1314 } 1302 }
1315 1303
1316 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, 1304 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property,
1317 bool needs_completion) { 1305 bool needs_completion) {
1318 if (needs_completion) 1306 if (needs_completion)
1319 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); 1307 DCHECK(target_property == TargetProperty::SCROLL_OFFSET);
1320 1308
1321 bool aborted_animation = false; 1309 bool aborted_animation = false;
1322 for (size_t i = 0; i < animations_.size(); ++i) { 1310 for (size_t i = 0; i < animations_.size(); ++i) {
1323 if (animations_[i]->target_property() == target_property && 1311 if (animations_[i]->target_property() == target_property &&
(...skipping 13 matching lines...) Expand all
1337 switch (target_property) { 1325 switch (target_property) {
1338 case TargetProperty::TRANSFORM: 1326 case TargetProperty::TRANSFORM:
1339 case TargetProperty::OPACITY: 1327 case TargetProperty::OPACITY:
1340 case TargetProperty::FILTER: 1328 case TargetProperty::FILTER:
1341 UpdateClientAnimationState(target_property); 1329 UpdateClientAnimationState(target_property);
1342 break; 1330 break;
1343 default: 1331 default:
1344 break; 1332 break;
1345 } 1333 }
1346 } 1334 }
1347
1348 SetNeedsPushProperties();
1349 } 1335 }
1350 1336
1351 Animation* ElementAnimations::GetAnimation( 1337 Animation* ElementAnimations::GetAnimation(
1352 TargetProperty::Type target_property) const { 1338 TargetProperty::Type target_property) const {
1353 for (size_t i = 0; i < animations_.size(); ++i) { 1339 for (size_t i = 0; i < animations_.size(); ++i) {
1354 size_t index = animations_.size() - i - 1; 1340 size_t index = animations_.size() - i - 1;
1355 if (animations_[index]->target_property() == target_property) 1341 if (animations_[index]->target_property() == target_property)
1356 return animations_[index].get(); 1342 return animations_[index].get();
1357 } 1343 }
1358 return nullptr; 1344 return nullptr;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 void ElementAnimations::OnScrollOffsetAnimated( 1381 void ElementAnimations::OnScrollOffsetAnimated(
1396 ElementListType list_type, 1382 ElementListType list_type,
1397 const gfx::ScrollOffset& scroll_offset) { 1383 const gfx::ScrollOffset& scroll_offset) {
1398 DCHECK(element_id()); 1384 DCHECK(element_id());
1399 DCHECK(animation_host()); 1385 DCHECK(animation_host());
1400 DCHECK(animation_host()->mutator_host_client()); 1386 DCHECK(animation_host()->mutator_host_client());
1401 animation_host()->mutator_host_client()->SetElementScrollOffsetMutated( 1387 animation_host()->mutator_host_client()->SetElementScrollOffsetMutated(
1402 element_id(), list_type, scroll_offset); 1388 element_id(), list_type, scroll_offset);
1403 } 1389 }
1404 1390
1391 void ElementAnimations::OnAnimationWaitingForDeletion() {
1392 // TODO(loyso): Invalidate AnimationHost::SetNeedsPushProperties here.
1393 // But we always do PushProperties in AnimationHost for now. crbug.com/604280
1394 DCHECK(animation_host());
1395 animation_host()->OnAnimationWaitingForDeletion();
1396 }
1397
1405 void ElementAnimations::IsAnimatingChanged(ElementListType list_type, 1398 void ElementAnimations::IsAnimatingChanged(ElementListType list_type,
1406 TargetProperty::Type property, 1399 TargetProperty::Type property,
1407 AnimationChangeType change_type, 1400 AnimationChangeType change_type,
1408 bool is_animating) { 1401 bool is_animating) {
1409 if (!element_id()) 1402 if (!element_id())
1410 return; 1403 return;
1411 DCHECK(animation_host()); 1404 DCHECK(animation_host());
1412 if (animation_host()->mutator_host_client()) { 1405 if (animation_host()->mutator_host_client()) {
1413 switch (property) { 1406 switch (property) {
1414 case TargetProperty::OPACITY: 1407 case TargetProperty::OPACITY:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 void ElementAnimations::NotifyPlayersAnimationAborted( 1454 void ElementAnimations::NotifyPlayersAnimationAborted(
1462 base::TimeTicks monotonic_time, 1455 base::TimeTicks monotonic_time,
1463 TargetProperty::Type target_property, 1456 TargetProperty::Type target_property,
1464 int group) { 1457 int group) {
1465 ElementAnimations::PlayersList::Iterator it(players_list_.get()); 1458 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1466 AnimationPlayer* player; 1459 AnimationPlayer* player;
1467 while ((player = it.GetNext()) != nullptr) 1460 while ((player = it.GetNext()) != nullptr)
1468 player->NotifyAnimationAborted(monotonic_time, target_property, group); 1461 player->NotifyAnimationAborted(monotonic_time, target_property, group);
1469 } 1462 }
1470 1463
1471 void ElementAnimations::NotifyPlayersAnimationWaitingForDeletion() {
1472 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1473 AnimationPlayer* player;
1474 while ((player = it.GetNext()) != nullptr)
1475 player->NotifyAnimationWaitingForDeletion();
1476 }
1477
1478 void ElementAnimations::NotifyPlayersAnimationTakeover( 1464 void ElementAnimations::NotifyPlayersAnimationTakeover(
1479 base::TimeTicks monotonic_time, 1465 base::TimeTicks monotonic_time,
1480 TargetProperty::Type target_property, 1466 TargetProperty::Type target_property,
1481 double animation_start_time, 1467 double animation_start_time,
1482 std::unique_ptr<AnimationCurve> curve) { 1468 std::unique_ptr<AnimationCurve> curve) {
1483 DCHECK(curve); 1469 DCHECK(curve);
1484 ElementAnimations::PlayersList::Iterator it(players_list_.get()); 1470 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1485 AnimationPlayer* player; 1471 AnimationPlayer* player;
1486 while ((player = it.GetNext()) != nullptr) { 1472 while ((player = it.GetNext()) != nullptr) {
1487 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone(); 1473 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone();
1488 player->NotifyAnimationTakeover(monotonic_time, target_property, 1474 player->NotifyAnimationTakeover(monotonic_time, target_property,
1489 animation_start_time, 1475 animation_start_time,
1490 std::move(animation_curve)); 1476 std::move(animation_curve));
1491 } 1477 }
1492 } 1478 }
1493 1479
1494 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const { 1480 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const {
1495 if (animation_host()) { 1481 if (animation_host()) {
1496 DCHECK(animation_host()->mutator_host_client()); 1482 DCHECK(animation_host()->mutator_host_client());
1497 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( 1483 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation(
1498 element_id()); 1484 element_id());
1499 } 1485 }
1500 1486
1501 return gfx::ScrollOffset(); 1487 return gfx::ScrollOffset();
1502 } 1488 }
1503 1489
1504 } // namespace cc 1490 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/element_animations.h ('k') | cc/animation/element_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698