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

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

Issue 1734063003: Share animations from compositor to main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make NotifyAnimationTakeover pure virtual Created 4 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "cc/animation/animation.h" 12 #include "cc/animation/animation.h"
13 #include "cc/animation/animation_curve.h"
13 #include "cc/animation/animation_delegate.h" 14 #include "cc/animation/animation_delegate.h"
14 #include "cc/animation/animation_events.h" 15 #include "cc/animation/animation_events.h"
15 #include "cc/animation/animation_registrar.h" 16 #include "cc/animation/animation_registrar.h"
16 #include "cc/animation/keyframed_animation_curve.h" 17 #include "cc/animation/keyframed_animation_curve.h"
17 #include "cc/animation/layer_animation_value_observer.h" 18 #include "cc/animation/layer_animation_value_observer.h"
18 #include "cc/animation/layer_animation_value_provider.h" 19 #include "cc/animation/layer_animation_value_provider.h"
19 #include "cc/animation/scroll_offset_animation_curve.h" 20 #include "cc/animation/scroll_offset_animation_curve.h"
20 #include "cc/output/filter_operations.h" 21 #include "cc/output/filter_operations.h"
21 #include "ui/gfx/geometry/box_f.h" 22 #include "ui/gfx/geometry/box_f.h"
22 #include "ui/gfx/transform.h" 23 #include "ui/gfx/transform.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 animation->SetRunState(Animation::ABORTED, last_tick_time_); 121 animation->SetRunState(Animation::ABORTED, last_tick_time_);
121 if (animation->target_property() == TargetProperty::TRANSFORM) 122 if (animation->target_property() == TargetProperty::TRANSFORM)
122 aborted_transform_animation = true; 123 aborted_transform_animation = true;
123 } 124 }
124 } 125 }
125 if (aborted_transform_animation) 126 if (aborted_transform_animation)
126 UpdatePotentiallyAnimatingTransform(); 127 UpdatePotentiallyAnimatingTransform();
127 } 128 }
128 129
129 void LayerAnimationController::AbortAnimations( 130 void LayerAnimationController::AbortAnimations(
130 TargetProperty::Type target_property) { 131 TargetProperty::Type target_property,
132 bool needs_completion) {
133 if (needs_completion)
134 DCHECK(target_property == TargetProperty::SCROLL_OFFSET);
135
131 bool aborted_transform_animation = false; 136 bool aborted_transform_animation = false;
132 for (size_t i = 0; i < animations_.size(); ++i) { 137 for (size_t i = 0; i < animations_.size(); ++i) {
133 if (animations_[i]->target_property() == target_property && 138 if (animations_[i]->target_property() == target_property &&
134 !animations_[i]->is_finished()) { 139 !animations_[i]->is_finished()) {
135 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); 140 // Currently only impl-only scroll offset animations can be completed on
141 // the main thread.
142 if (needs_completion && animations_[i]->is_impl_only()) {
143 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION,
144 last_tick_time_);
145 } else {
146 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_);
147 }
136 if (target_property == TargetProperty::TRANSFORM) 148 if (target_property == TargetProperty::TRANSFORM)
137 aborted_transform_animation = true; 149 aborted_transform_animation = true;
138 } 150 }
139 } 151 }
140 if (aborted_transform_animation) 152 if (aborted_transform_animation)
141 UpdatePotentiallyAnimatingTransform(); 153 UpdatePotentiallyAnimatingTransform();
142 } 154 }
143 155
144 // Ensures that the list of active animations on the main thread and the impl 156 // Ensures that the list of active animations on the main thread and the impl
145 // thread are kept in sync. 157 // thread are kept in sync.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 animations_[i]->set_received_finished_event(true); 429 animations_[i]->set_received_finished_event(true);
418 if (layer_animation_delegate_) 430 if (layer_animation_delegate_)
419 layer_animation_delegate_->NotifyAnimationFinished( 431 layer_animation_delegate_->NotifyAnimationFinished(
420 event.monotonic_time, event.target_property, event.group_id); 432 event.monotonic_time, event.target_property, event.group_id);
421 433
422 return; 434 return;
423 } 435 }
424 } 436 }
425 } 437 }
426 438
439 void LayerAnimationController::NotifyAnimationTakeover(
440 const AnimationEvent& event) {
441 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET);
442 if (layer_animation_delegate_) {
443 scoped_ptr<AnimationCurve> animation_curve = event.curve->Clone();
444 layer_animation_delegate_->NotifyAnimationTakeover(
445 event.monotonic_time, event.animation_start_time,
446 std::move(animation_curve));
447 }
448 }
449
427 void LayerAnimationController::NotifyAnimationAborted( 450 void LayerAnimationController::NotifyAnimationAborted(
428 const AnimationEvent& event) { 451 const AnimationEvent& event) {
429 bool aborted_transform_animation = false; 452 bool aborted_transform_animation = false;
430 for (size_t i = 0; i < animations_.size(); ++i) { 453 for (size_t i = 0; i < animations_.size(); ++i) {
431 if (animations_[i]->group() == event.group_id && 454 if (animations_[i]->group() == event.group_id &&
432 animations_[i]->target_property() == event.target_property) { 455 animations_[i]->target_property() == event.target_property) {
433 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); 456 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time);
434 animations_[i]->set_received_finished_event(true); 457 animations_[i]->set_received_finished_event(true);
435 if (layer_animation_delegate_) 458 if (layer_animation_delegate_)
436 layer_animation_delegate_->NotifyAnimationAborted( 459 layer_animation_delegate_->NotifyAnimationAborted(
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // AnimationEvent::FINISHED event is sent or received. This means that if 927 // AnimationEvent::FINISHED event is sent or received. This means that if
905 // we don't have an events vector, we must ensure that non-aborted animations 928 // we don't have an events vector, we must ensure that non-aborted animations
906 // have received a finished event before marking them for deletion. 929 // have received a finished event before marking them for deletion.
907 for (size_t i = 0; i < animations_.size(); i++) { 930 for (size_t i = 0; i < animations_.size(); i++) {
908 int group_id = animations_[i]->group(); 931 int group_id = animations_[i]->group();
909 if (animations_[i]->run_state() == Animation::ABORTED) { 932 if (animations_[i]->run_state() == Animation::ABORTED) {
910 if (events && !animations_[i]->is_impl_only()) { 933 if (events && !animations_[i]->is_impl_only()) {
911 AnimationEvent aborted_event(AnimationEvent::ABORTED, id_, group_id, 934 AnimationEvent aborted_event(AnimationEvent::ABORTED, id_, group_id,
912 animations_[i]->target_property(), 935 animations_[i]->target_property(),
913 monotonic_time); 936 monotonic_time);
914 events->events_.push_back(aborted_event); 937 events->events_.push_back(std::move(aborted_event));
ajuma 2016/02/26 23:56:54 AnimationEvent doesn't have a move constructor, so
ymalik 2016/02/29 16:31:09 Yes, that's correct. Got rid of the std::move call
915 } 938 }
916 // If on the compositor or on the main thread and received finish event, 939 // If on the compositor or on the main thread and received finish event,
917 // animation can be marked for deletion. 940 // animation can be marked for deletion.
918 if (events || animations_[i]->received_finished_event()) { 941 if (events || animations_[i]->received_finished_event()) {
919 animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION, 942 animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION,
920 monotonic_time); 943 monotonic_time);
921 marked_animations_for_deletions = true; 944 marked_animations_for_deletions = true;
922 } 945 }
923 continue; 946 continue;
924 } 947 }
925 948
949 // If running on the compositor and need to complete an aborted animation
950 // on the main thread.
951 if (events &&
952 animations_[i]->run_state() ==
953 Animation::ABORTED_BUT_NEEDS_COMPLETION) {
954 AnimationEvent aborted_event(AnimationEvent::TAKEOVER, id_, group_id,
955 animations_[i]->target_property(),
956 monotonic_time);
957 aborted_event.animation_start_time =
958 (animations_[i]->start_time() - base::TimeTicks()).InSecondsF();
959 const ScrollOffsetAnimationCurve* scroll_offset_animation_curve =
960 animations_[i]->curve()->ToScrollOffsetAnimationCurve();
961 aborted_event.curve = scroll_offset_animation_curve->Clone();
962 // Notify the compositor that the animation is finished.
963 if (layer_animation_delegate_) {
964 layer_animation_delegate_->NotifyAnimationFinished(
965 aborted_event.monotonic_time, aborted_event.target_property,
966 aborted_event.group_id);
967 }
968 // Notify main thread.
969 events->events_.push_back(aborted_event);
970
971 // Remove the animation from the compositor.
972 animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION,
973 monotonic_time);
974 marked_animations_for_deletions = true;
975 continue;
976 }
977
926 bool all_anims_with_same_id_are_finished = false; 978 bool all_anims_with_same_id_are_finished = false;
927 979
928 // Since deleting an animation on the main thread leads to its deletion 980 // Since deleting an animation on the main thread leads to its deletion
929 // on the impl thread, we only mark a FINISHED main thread animation for 981 // on the impl thread, we only mark a FINISHED main thread animation for
930 // deletion once it has received a FINISHED event from the impl thread. 982 // deletion once it has received a FINISHED event from the impl thread.
931 bool animation_i_will_send_or_has_received_finish_event = 983 bool animation_i_will_send_or_has_received_finish_event =
932 animations_[i]->is_controlling_instance() || 984 animations_[i]->is_controlling_instance() ||
933 animations_[i]->is_impl_only() || 985 animations_[i]->is_impl_only() ||
934 animations_[i]->received_finished_event(); 986 animations_[i]->received_finished_event();
935 // If an animation is finished, and not already marked for deletion, 987 // If an animation is finished, and not already marked for deletion,
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 &value_observers_); 1274 &value_observers_);
1223 LayerAnimationValueObserver* obs; 1275 LayerAnimationValueObserver* obs;
1224 while ((obs = it.GetNext()) != nullptr) 1276 while ((obs = it.GetNext()) != nullptr)
1225 if (obs->IsActive()) 1277 if (obs->IsActive())
1226 return true; 1278 return true;
1227 } 1279 }
1228 return false; 1280 return false;
1229 } 1281 }
1230 1282
1231 } // namespace cc 1283 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698