| OLD | NEW |
| 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_host.h" | 5 #include "cc/animation/animation_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "cc/animation/animation_delegate.h" | 11 #include "cc/animation/animation_delegate.h" |
| 11 #include "cc/animation/animation_events.h" | 12 #include "cc/animation/animation_events.h" |
| 12 #include "cc/animation/animation_id_provider.h" | 13 #include "cc/animation/animation_id_provider.h" |
| 13 #include "cc/animation/animation_player.h" | 14 #include "cc/animation/animation_player.h" |
| 14 #include "cc/animation/animation_registrar.h" | 15 #include "cc/animation/animation_registrar.h" |
| 15 #include "cc/animation/animation_timeline.h" | 16 #include "cc/animation/animation_timeline.h" |
| 16 #include "cc/animation/element_animations.h" | 17 #include "cc/animation/element_animations.h" |
| 17 #include "cc/animation/scroll_offset_animation_curve.h" | 18 #include "cc/animation/scroll_offset_animation_curve.h" |
| 18 #include "cc/animation/timing_function.h" | 19 #include "cc/animation/timing_function.h" |
| 19 #include "ui/gfx/geometry/box_f.h" | 20 #include "ui/gfx/geometry/box_f.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 | 40 |
| 40 ~ScrollOffsetAnimations() override { | 41 ~ScrollOffsetAnimations() override { |
| 41 scroll_offset_timeline_->DetachPlayer( | 42 scroll_offset_timeline_->DetachPlayer( |
| 42 scroll_offset_animation_player_.get()); | 43 scroll_offset_animation_player_.get()); |
| 43 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get()); | 44 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get()); |
| 44 } | 45 } |
| 45 | 46 |
| 46 void ScrollAnimationCreate(int layer_id, | 47 void ScrollAnimationCreate(int layer_id, |
| 47 const gfx::ScrollOffset& target_offset, | 48 const gfx::ScrollOffset& target_offset, |
| 48 const gfx::ScrollOffset& current_offset) { | 49 const gfx::ScrollOffset& current_offset) { |
| 49 scoped_ptr<ScrollOffsetAnimationCurve> curve = | 50 std::unique_ptr<ScrollOffsetAnimationCurve> curve = |
| 50 ScrollOffsetAnimationCurve::Create( | 51 ScrollOffsetAnimationCurve::Create( |
| 51 target_offset, EaseInOutTimingFunction::Create(), | 52 target_offset, EaseInOutTimingFunction::Create(), |
| 52 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); | 53 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); |
| 53 curve->SetInitialValue(current_offset); | 54 curve->SetInitialValue(current_offset); |
| 54 | 55 |
| 55 scoped_ptr<Animation> animation = Animation::Create( | 56 std::unique_ptr<Animation> animation = Animation::Create( |
| 56 std::move(curve), AnimationIdProvider::NextAnimationId(), | 57 std::move(curve), AnimationIdProvider::NextAnimationId(), |
| 57 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); | 58 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); |
| 58 animation->set_is_impl_only(true); | 59 animation->set_is_impl_only(true); |
| 59 | 60 |
| 60 DCHECK(scroll_offset_animation_player_); | 61 DCHECK(scroll_offset_animation_player_); |
| 61 DCHECK(scroll_offset_animation_player_->animation_timeline()); | 62 DCHECK(scroll_offset_animation_player_->animation_timeline()); |
| 62 | 63 |
| 63 ReattachScrollOffsetPlayerIfNeeded(layer_id); | 64 ReattachScrollOffsetPlayerIfNeeded(layer_id); |
| 64 | 65 |
| 65 scroll_offset_animation_player_->AddAnimation(std::move(animation)); | 66 scroll_offset_animation_player_->AddAnimation(std::move(animation)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); | 115 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET); |
| 115 DCHECK(animation_host_->mutator_host_client()); | 116 DCHECK(animation_host_->mutator_host_client()); |
| 116 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); | 117 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); |
| 117 } | 118 } |
| 118 void NotifyAnimationAborted(base::TimeTicks monotonic_time, | 119 void NotifyAnimationAborted(base::TimeTicks monotonic_time, |
| 119 TargetProperty::Type target_property, | 120 TargetProperty::Type target_property, |
| 120 int group) override {} | 121 int group) override {} |
| 121 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, | 122 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, |
| 122 TargetProperty::Type target_property, | 123 TargetProperty::Type target_property, |
| 123 double animation_start_time, | 124 double animation_start_time, |
| 124 scoped_ptr<AnimationCurve> curve) override {} | 125 std::unique_ptr<AnimationCurve> curve) override { |
| 126 } |
| 125 | 127 |
| 126 private: | 128 private: |
| 127 void ReattachScrollOffsetPlayerIfNeeded(int layer_id) { | 129 void ReattachScrollOffsetPlayerIfNeeded(int layer_id) { |
| 128 if (scroll_offset_animation_player_->layer_id() != layer_id) { | 130 if (scroll_offset_animation_player_->layer_id() != layer_id) { |
| 129 if (scroll_offset_animation_player_->layer_id()) | 131 if (scroll_offset_animation_player_->layer_id()) |
| 130 scroll_offset_animation_player_->DetachLayer(); | 132 scroll_offset_animation_player_->DetachLayer(); |
| 131 if (layer_id) | 133 if (layer_id) |
| 132 scroll_offset_animation_player_->AttachLayer(layer_id); | 134 scroll_offset_animation_player_->AttachLayer(layer_id); |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 | 137 |
| 136 AnimationHost* animation_host_; | 138 AnimationHost* animation_host_; |
| 137 scoped_refptr<AnimationTimeline> scroll_offset_timeline_; | 139 scoped_refptr<AnimationTimeline> scroll_offset_timeline_; |
| 138 | 140 |
| 139 // We have just one player for impl-only scroll offset animations. | 141 // We have just one player for impl-only scroll offset animations. |
| 140 // I.e. only one layer can have an impl-only scroll offset animation at | 142 // I.e. only one layer can have an impl-only scroll offset animation at |
| 141 // any given time. | 143 // any given time. |
| 142 scoped_refptr<AnimationPlayer> scroll_offset_animation_player_; | 144 scoped_refptr<AnimationPlayer> scroll_offset_animation_player_; |
| 143 | 145 |
| 144 DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations); | 146 DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations); |
| 145 }; | 147 }; |
| 146 | 148 |
| 147 scoped_ptr<AnimationHost> AnimationHost::Create( | 149 std::unique_ptr<AnimationHost> AnimationHost::Create( |
| 148 ThreadInstance thread_instance) { | 150 ThreadInstance thread_instance) { |
| 149 return make_scoped_ptr(new AnimationHost(thread_instance)); | 151 return base::WrapUnique(new AnimationHost(thread_instance)); |
| 150 } | 152 } |
| 151 | 153 |
| 152 AnimationHost::AnimationHost(ThreadInstance thread_instance) | 154 AnimationHost::AnimationHost(ThreadInstance thread_instance) |
| 153 : animation_registrar_(AnimationRegistrar::Create()), | 155 : animation_registrar_(AnimationRegistrar::Create()), |
| 154 mutator_host_client_(nullptr), | 156 mutator_host_client_(nullptr), |
| 155 thread_instance_(thread_instance) { | 157 thread_instance_(thread_instance) { |
| 156 if (thread_instance_ == ThreadInstance::IMPL) | 158 if (thread_instance_ == ThreadInstance::IMPL) |
| 157 scroll_offset_animations_ = | 159 scroll_offset_animations_ = |
| 158 make_scoped_ptr(new ScrollOffsetAnimations(this)); | 160 base::WrapUnique(new ScrollOffsetAnimations(this)); |
| 159 } | 161 } |
| 160 | 162 |
| 161 AnimationHost::~AnimationHost() { | 163 AnimationHost::~AnimationHost() { |
| 162 scroll_offset_animations_ = nullptr; | 164 scroll_offset_animations_ = nullptr; |
| 163 | 165 |
| 164 ClearTimelines(); | 166 ClearTimelines(); |
| 165 DCHECK(!mutator_host_client()); | 167 DCHECK(!mutator_host_client()); |
| 166 DCHECK(layer_to_element_animations_map_.empty()); | 168 DCHECK(layer_to_element_animations_map_.empty()); |
| 167 } | 169 } |
| 168 | 170 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { | 362 bool AnimationHost::AnimateLayers(base::TimeTicks monotonic_time) { |
| 361 return animation_registrar_->AnimateLayers(monotonic_time); | 363 return animation_registrar_->AnimateLayers(monotonic_time); |
| 362 } | 364 } |
| 363 | 365 |
| 364 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, | 366 bool AnimationHost::UpdateAnimationState(bool start_ready_animations, |
| 365 AnimationEvents* events) { | 367 AnimationEvents* events) { |
| 366 return animation_registrar_->UpdateAnimationState(start_ready_animations, | 368 return animation_registrar_->UpdateAnimationState(start_ready_animations, |
| 367 events); | 369 events); |
| 368 } | 370 } |
| 369 | 371 |
| 370 scoped_ptr<AnimationEvents> AnimationHost::CreateEvents() { | 372 std::unique_ptr<AnimationEvents> AnimationHost::CreateEvents() { |
| 371 return animation_registrar_->CreateEvents(); | 373 return animation_registrar_->CreateEvents(); |
| 372 } | 374 } |
| 373 | 375 |
| 374 void AnimationHost::SetAnimationEvents(scoped_ptr<AnimationEvents> events) { | 376 void AnimationHost::SetAnimationEvents( |
| 377 std::unique_ptr<AnimationEvents> events) { |
| 375 return animation_registrar_->SetAnimationEvents(std::move(events)); | 378 return animation_registrar_->SetAnimationEvents(std::move(events)); |
| 376 } | 379 } |
| 377 | 380 |
| 378 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const { | 381 bool AnimationHost::ScrollOffsetAnimationWasInterrupted(int layer_id) const { |
| 379 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 382 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
| 380 return controller ? controller->scroll_offset_animation_was_interrupted() | 383 return controller ? controller->scroll_offset_animation_was_interrupted() |
| 381 : false; | 384 : false; |
| 382 } | 385 } |
| 383 | 386 |
| 384 static LayerAnimationController::ObserverType ObserverTypeFromTreeType( | 387 static LayerAnimationController::ObserverType ObserverTypeFromTreeType( |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 return scroll_offset_animations_->ScrollAnimationUpdateTarget( | 598 return scroll_offset_animations_->ScrollAnimationUpdateTarget( |
| 596 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 599 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
| 597 } | 600 } |
| 598 | 601 |
| 599 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { | 602 void AnimationHost::ScrollAnimationAbort(bool needs_completion) { |
| 600 DCHECK(scroll_offset_animations_); | 603 DCHECK(scroll_offset_animations_); |
| 601 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); | 604 return scroll_offset_animations_->ScrollAnimationAbort(needs_completion); |
| 602 } | 605 } |
| 603 | 606 |
| 604 } // namespace cc | 607 } // namespace cc |
| OLD | NEW |