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 ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 5 #ifndef ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
6 #define ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 6 #define ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 class CopyOutputRequest; | |
18 class CopyOutputResult; | 19 class CopyOutputResult; |
19 } // namespace cc | 20 } // namespace cc |
20 | 21 |
21 namespace ui { | 22 namespace ui { |
22 class AnimationMetricsReporter; | 23 class AnimationMetricsReporter; |
23 class Layer; | 24 class Layer; |
24 class LayerTreeOwner; | 25 class LayerTreeOwner; |
25 } // namespace ui | 26 } // namespace ui |
26 | 27 |
27 namespace ash { | 28 namespace ash { |
(...skipping 29 matching lines...) Expand all Loading... | |
57 | 58 |
58 // When screen rotation animation is ended or aborted, calls |Rotate()| with | 59 // When screen rotation animation is ended or aborted, calls |Rotate()| with |
59 // the pending rotation request if the request queue is not empty. Otherwise | 60 // the pending rotation request if the request queue is not empty. Otherwise |
60 // notifies |screen_rotation_animator_observer_|. | 61 // notifies |screen_rotation_animator_observer_|. |
61 void ProcessAnimationQueue(); | 62 void ProcessAnimationQueue(); |
62 | 63 |
63 protected: | 64 protected: |
64 using CopyCallback = | 65 using CopyCallback = |
65 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; | 66 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; |
66 struct ScreenRotationRequest { | 67 struct ScreenRotationRequest { |
67 ScreenRotationRequest(display::Display::Rotation to_rotation, | 68 ScreenRotationRequest(const display::Display::Rotation& from_rotation, |
oshima
2017/04/07 20:48:56
it's enum, so no need to pass by reference.
wutao
2017/04/10 08:01:07
Done.
| |
68 display::Display::RotationSource from_source) | 69 const display::Display::Rotation& to_rotation, |
69 : new_rotation(to_rotation), source(from_source) {} | 70 const display::Display::RotationSource& from_source) |
71 : old_rotation(from_rotation), | |
72 new_rotation(to_rotation), | |
73 source(from_source) {} | |
74 display::Display::Rotation old_rotation; | |
70 display::Display::Rotation new_rotation; | 75 display::Display::Rotation new_rotation; |
71 display::Display::RotationSource source; | 76 display::Display::RotationSource source; |
72 }; | 77 }; |
73 | 78 |
74 // This function can be overridden in unit test to test removing external | 79 // This function can be overridden in unit test to test removing external |
75 // display. | 80 // display. |
76 virtual CopyCallback CreateAfterCopyCallback( | 81 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( |
82 std::unique_ptr<ScreenRotationRequest> rotation_request); | |
83 virtual CopyCallback CreateAfterCopyCallbackAfterRotation( | |
77 std::unique_ptr<ScreenRotationRequest> rotation_request); | 84 std::unique_ptr<ScreenRotationRequest> rotation_request); |
78 | 85 |
79 private: | 86 private: |
80 friend class ash::test::ScreenRotationAnimatorTestApi; | 87 friend class ash::test::ScreenRotationAnimatorTestApi; |
81 | 88 |
82 void StartRotationAnimation( | 89 void StartRotationAnimation( |
83 std::unique_ptr<ScreenRotationRequest> rotation_request); | 90 std::unique_ptr<ScreenRotationRequest> rotation_request); |
84 | 91 |
85 // This is an asynchronous call to request copy output of root layer. | 92 // The fallback to slow animation if copy output request cancled or failed. |
86 void RequestCopyRootLayerAndAnimateRotation( | 93 void StartSlowAnimation( |
87 std::unique_ptr<ScreenRotationRequest> rotation_request); | 94 std::unique_ptr<ScreenRotationRequest> rotation_request); |
88 | 95 |
89 // The callback in |RequestCopyRootLayerAndAnimateRotation()|. | 96 // A wrapper to call |display_manager| to set screen rotation and rotate the |
90 void OnRootLayerCopiedBeforeRotation( | 97 // |old_layer_tree| to the |old_rotation|. |
98 void SetRotation(const display::Display::Rotation& new_rotation, | |
99 const display::Display::Rotation& old_rotation, | |
100 const display::Display::RotationSource& source); | |
101 | |
102 // This is an asynchronous call to request copy output of root layer. | |
103 void RequestCopyScreenRotationContainerLayer( | |
104 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); | |
105 | |
106 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen | |
107 // rotation. | |
108 void OnScreenRotationContainerLayerCopiedBeforeRotation( | |
109 std::unique_ptr<ScreenRotationRequest> rotation_request, | |
110 std::unique_ptr<cc::CopyOutputResult> result); | |
oshima
2017/04/07 20:48:57
new line after this
wutao
2017/04/10 08:01:07
Done.
| |
111 // The callback in |RequestCopyScreenRotationContainerLayer()| after screen | |
112 // rotation. | |
113 void OnScreenRotationContainerLayerCopiedAfterRotation( | |
91 std::unique_ptr<ScreenRotationRequest> rotation_request, | 114 std::unique_ptr<ScreenRotationRequest> rotation_request, |
92 std::unique_ptr<cc::CopyOutputResult> result); | 115 std::unique_ptr<cc::CopyOutputResult> result); |
93 | 116 |
94 // Recreates all |root_window| layers. | 117 // Recreates all |root_window| layers. |
95 void CreateOldLayerTree(); | 118 void CreateOldLayerTree(); |
96 | 119 |
97 // Requests a copy of |root_window| root layer output. | 120 // Creates a new layer from |CopyOutputResult|. |
oshima
2017/04/07 20:48:57
new layer and its layer tree owner
wutao
2017/04/10 08:01:07
Done.
| |
98 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result); | 121 std::unique_ptr<ui::LayerTreeOwner> CopyLayerTree( |
122 std::unique_ptr<cc::CopyOutputResult> result); | |
99 | 123 |
100 // Note: Only call this function when the |old_layer_tree_owner_| is set up | 124 // Note: Only call this function when the |old_layer_tree_owner_| is set up |
101 // properly. | 125 // properly. |
102 // Sets the screen orientation to |new_rotation| and animate the change. The | 126 // Sets the screen orientation to |new_rotation| and animate the change. The |
103 // animation will rotate the initial orientation's layer towards the new | 127 // animation will rotate the initial orientation's layer towards the new |
104 // orientation through |rotation_degrees| while fading out, and the new | 128 // orientation through |rotation_degrees| while fading out, and the new |
105 // orientation's layer will be rotated in to the |new_orientation| through | 129 // orientation's layer will be rotated in to the |new_orientation| through |
106 // |rotation_degrees| arc. | 130 // |rotation_degrees| arc. |
107 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); | 131 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); |
108 | 132 |
109 void set_disable_animation_timers_for_test(bool disable_timers); | 133 void set_disable_animation_timers_for_test(bool disable_timers); |
110 | 134 |
111 void StopAnimating(); | 135 void StopAnimating(); |
112 | 136 |
113 // The id of the display to rotate. | 137 // The id of the display to rotate. |
114 int64_t display_id_; | 138 int64_t display_id_; |
115 bool is_rotating_; | 139 bool is_rotating_; |
116 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 140 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
117 // Only set in unittest to disable animation timers. | 141 // Only set in unittest to disable animation timers. |
118 bool disable_animation_timers_for_test_; | 142 bool disable_animation_timers_for_test_; |
119 base::ObserverList<ScreenRotationAnimatorObserver> | 143 base::ObserverList<ScreenRotationAnimatorObserver> |
120 screen_rotation_animator_observers_; | 144 screen_rotation_animator_observers_; |
121 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 145 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
146 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; | |
122 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 147 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
123 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 148 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
124 | 149 |
125 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 150 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
126 }; | 151 }; |
127 | 152 |
128 } // namespace ash | 153 } // namespace ash |
129 | 154 |
130 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 155 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
OLD | NEW |