Chromium Code Reviews| 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 #ifndef CC_ANIMATION_ANIMATION_HOST_H_ | 5 #ifndef CC_ANIMATION_ANIMATION_HOST_H_ |
| 6 #define CC_ANIMATION_ANIMATION_HOST_H_ | 6 #define CC_ANIMATION_ANIMATION_HOST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "cc/animation/animation.h" | 15 #include "cc/animation/animation.h" |
| 16 #include "cc/animation/scroll_offset_animations_impl.h" | |
| 17 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
| 18 #include "cc/trees/mutator_host_client.h" | 17 #include "cc/trees/mutator_host_client.h" |
| 19 #include "ui/gfx/geometry/box_f.h" | 18 #include "ui/gfx/geometry/box_f.h" |
| 20 #include "ui/gfx/geometry/vector2d_f.h" | 19 #include "ui/gfx/geometry/vector2d_f.h" |
| 21 | 20 |
| 22 namespace gfx { | 21 namespace gfx { |
| 23 class ScrollOffset; | 22 class ScrollOffset; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 | 26 |
| 28 class AnimationEvents; | 27 class AnimationEvents; |
| 29 class AnimationPlayer; | 28 class AnimationPlayer; |
| 30 class AnimationTimeline; | 29 class AnimationTimeline; |
| 31 class ElementAnimations; | 30 class ElementAnimations; |
| 32 class LayerTreeHost; | 31 class LayerTreeHost; |
| 32 class ScrollOffsetAnimations; | |
| 33 class ScrollOffsetAnimationsImpl; | |
| 34 | |
| 35 struct ScrollOffsetAnimationUpdate; | |
| 33 | 36 |
| 34 enum class ThreadInstance { MAIN, IMPL }; | 37 enum class ThreadInstance { MAIN, IMPL }; |
| 35 | 38 |
| 36 // An AnimationHost contains all the state required to play animations. | 39 // An AnimationHost contains all the state required to play animations. |
| 37 // Specifically, it owns all the AnimationTimelines objects. | 40 // Specifically, it owns all the AnimationTimelines objects. |
| 38 // There is just one AnimationHost for LayerTreeHost on main renderer thread | 41 // There is just one AnimationHost for LayerTreeHost on main renderer thread |
| 39 // and just one AnimationHost for LayerTreeHostImpl on impl thread. | 42 // and just one AnimationHost for LayerTreeHostImpl on impl thread. |
| 40 // We synchronize them during the commit process in a one-way data flow process | 43 // We synchronize them during the commit process in a one-way data flow process |
| 41 // (PushPropertiesTo). | 44 // (PushPropertiesTo). |
| 42 // An AnimationHost talks to its correspondent LayerTreeHost via | 45 // An AnimationHost talks to its correspondent LayerTreeHost via |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 68 // Parent LayerTreeHost or LayerTreeHostImpl. | 71 // Parent LayerTreeHost or LayerTreeHostImpl. |
| 69 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } | 72 MutatorHostClient* mutator_host_client() { return mutator_host_client_; } |
| 70 const MutatorHostClient* mutator_host_client() const { | 73 const MutatorHostClient* mutator_host_client() const { |
| 71 return mutator_host_client_; | 74 return mutator_host_client_; |
| 72 } | 75 } |
| 73 void SetMutatorHostClient(MutatorHostClient* client); | 76 void SetMutatorHostClient(MutatorHostClient* client); |
| 74 | 77 |
| 75 void SetNeedsCommit(); | 78 void SetNeedsCommit(); |
| 76 void SetNeedsRebuildPropertyTrees(); | 79 void SetNeedsRebuildPropertyTrees(); |
| 77 | 80 |
| 78 void PushPropertiesTo(AnimationHost* host_impl); | 81 void PushPropertiesTo( |
| 82 AnimationHost* host_impl, | |
| 83 base::TimeTicks frame_monotonic_time = base::TimeTicks()); | |
| 79 | 84 |
| 80 void SetSupportsScrollAnimations(bool supports_scroll_animations); | 85 void SetSupportsScrollAnimations(bool supports_scroll_animations); |
| 81 bool SupportsScrollAnimations() const; | 86 bool SupportsScrollAnimations() const; |
| 82 bool NeedsAnimateLayers() const; | 87 bool NeedsAnimateLayers() const; |
| 83 | 88 |
| 84 bool ActivateAnimations(); | 89 bool ActivateAnimations(); |
| 85 bool AnimateLayers(base::TimeTicks monotonic_time); | 90 bool AnimateLayers(base::TimeTicks monotonic_time); |
| 86 bool UpdateAnimationState(bool start_ready_animations, | 91 bool UpdateAnimationState(bool start_ready_animations, |
| 87 AnimationEvents* events); | 92 AnimationEvents* events); |
| 88 | 93 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 const gfx::ScrollOffset& target_offset, | 147 const gfx::ScrollOffset& target_offset, |
| 143 const gfx::ScrollOffset& current_offset); | 148 const gfx::ScrollOffset& current_offset); |
| 144 bool ImplOnlyScrollAnimationUpdateTarget( | 149 bool ImplOnlyScrollAnimationUpdateTarget( |
| 145 ElementId element_id, | 150 ElementId element_id, |
| 146 const gfx::Vector2dF& scroll_delta, | 151 const gfx::Vector2dF& scroll_delta, |
| 147 const gfx::ScrollOffset& max_scroll_offset, | 152 const gfx::ScrollOffset& max_scroll_offset, |
| 148 base::TimeTicks frame_monotonic_time); | 153 base::TimeTicks frame_monotonic_time); |
| 149 | 154 |
| 150 void ScrollAnimationAbort(bool needs_completion); | 155 void ScrollAnimationAbort(bool needs_completion); |
| 151 | 156 |
| 157 // Adds an update to be made to impl-only animations during PushPropertiesTo. | |
| 158 // This should only be called from the main thread. | |
| 159 void AddScrollOffsetAnimationUpdate(ScrollOffsetAnimationUpdate); | |
| 160 bool HasScrollOffsetAnimationUpdatesForTesting() const; | |
|
loyso (OOO)
2016/05/06 01:04:38
It's better to have a general accessor:
ScrollOffs
ymalik
2016/05/06 05:41:49
Done.
| |
| 161 | |
| 152 // Registers the given element animations as active. An active element | 162 // Registers the given element animations as active. An active element |
| 153 // animations is one that has a running animation that needs to be ticked. | 163 // animations is one that has a running animation that needs to be ticked. |
| 154 void DidActivateElementAnimations(ElementAnimations* element_animations); | 164 void DidActivateElementAnimations(ElementAnimations* element_animations); |
| 155 | 165 |
| 156 // Unregisters the given element animations. When this happens, the | 166 // Unregisters the given element animations. When this happens, the |
| 157 // element animations will no longer be ticked (since it's not active). | 167 // element animations will no longer be ticked (since it's not active). |
| 158 void DidDeactivateElementAnimations(ElementAnimations* element_animations); | 168 void DidDeactivateElementAnimations(ElementAnimations* element_animations); |
| 159 | 169 |
| 160 // Registers the given ElementAnimations as alive. | 170 // Registers the given ElementAnimations as alive. |
| 161 void RegisterElementAnimations(ElementAnimations* element_animations); | 171 void RegisterElementAnimations(ElementAnimations* element_animations); |
| 162 // Unregisters the given ElementAnimations as alive. | 172 // Unregisters the given ElementAnimations as alive. |
| 163 void UnregisterElementAnimations(ElementAnimations* element_animations); | 173 void UnregisterElementAnimations(ElementAnimations* element_animations); |
| 164 | 174 |
| 165 const ElementToAnimationsMap& active_element_animations_for_testing() const; | 175 const ElementToAnimationsMap& active_element_animations_for_testing() const; |
| 166 const ElementToAnimationsMap& all_element_animations_for_testing() const; | 176 const ElementToAnimationsMap& all_element_animations_for_testing() const; |
| 167 | 177 |
| 168 bool animation_waiting_for_deletion() const { | 178 bool animation_waiting_for_deletion() const { |
| 169 return animation_waiting_for_deletion_; | 179 return animation_waiting_for_deletion_; |
| 170 } | 180 } |
| 171 void OnAnimationWaitingForDeletion(); | 181 void OnAnimationWaitingForDeletion(); |
| 172 | 182 |
| 173 private: | 183 private: |
| 174 explicit AnimationHost(ThreadInstance thread_instance); | 184 explicit AnimationHost(ThreadInstance thread_instance); |
| 175 | 185 |
| 176 void PushTimelinesToImplThread(AnimationHost* host_impl) const; | 186 void PushTimelinesToImplThread(AnimationHost* host_impl) const; |
| 177 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; | 187 void RemoveTimelinesFromImplThread(AnimationHost* host_impl) const; |
| 178 void PushPropertiesToImplThread(AnimationHost* host_impl); | 188 void PushPropertiesToImplThread(AnimationHost* host_impl, |
| 189 base::TimeTicks frame_monotonic_time); | |
| 179 | 190 |
| 180 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); | 191 void EraseTimeline(scoped_refptr<AnimationTimeline> timeline); |
| 181 | 192 |
| 182 ElementToAnimationsMap element_to_animations_map_; | 193 ElementToAnimationsMap element_to_animations_map_; |
| 183 ElementToAnimationsMap active_element_to_animations_map_; | 194 ElementToAnimationsMap active_element_to_animations_map_; |
| 184 | 195 |
| 185 // A list of all timelines which this host owns. | 196 // A list of all timelines which this host owns. |
| 186 using IdToTimelineMap = | 197 using IdToTimelineMap = |
| 187 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; | 198 std::unordered_map<int, scoped_refptr<AnimationTimeline>>; |
| 188 IdToTimelineMap id_to_timeline_map_; | 199 IdToTimelineMap id_to_timeline_map_; |
| 189 | 200 |
| 190 MutatorHostClient* mutator_host_client_; | 201 MutatorHostClient* mutator_host_client_; |
| 191 | 202 |
| 203 std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_; | |
| 192 std::unique_ptr<ScrollOffsetAnimationsImpl> scroll_offset_animations_impl_; | 204 std::unique_ptr<ScrollOffsetAnimationsImpl> scroll_offset_animations_impl_; |
| 193 | 205 |
| 194 const ThreadInstance thread_instance_; | 206 const ThreadInstance thread_instance_; |
| 195 | 207 |
| 196 bool supports_scroll_animations_; | 208 bool supports_scroll_animations_; |
| 197 bool animation_waiting_for_deletion_; | 209 bool animation_waiting_for_deletion_; |
| 198 | 210 |
| 199 DISALLOW_COPY_AND_ASSIGN(AnimationHost); | 211 DISALLOW_COPY_AND_ASSIGN(AnimationHost); |
| 200 }; | 212 }; |
| 201 | 213 |
| 202 } // namespace cc | 214 } // namespace cc |
| 203 | 215 |
| 204 #endif // CC_ANIMATION_ANIMATION_HOST_H_ | 216 #endif // CC_ANIMATION_ANIMATION_HOST_H_ |
| OLD | NEW |