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 aura { |
| 18 class Window; |
| 19 } // namesapce aura |
| 20 |
17 namespace cc { | 21 namespace cc { |
| 22 class CopyOutputRequest; |
18 class CopyOutputResult; | 23 class CopyOutputResult; |
19 } // namespace cc | 24 } // namespace cc |
20 | 25 |
21 namespace ui { | 26 namespace ui { |
22 class AnimationMetricsReporter; | 27 class AnimationMetricsReporter; |
23 class Layer; | 28 class Layer; |
| 29 class LayerOwner; |
24 class LayerTreeOwner; | 30 class LayerTreeOwner; |
25 } // namespace ui | 31 } // namespace ui |
26 | 32 |
27 namespace ash { | 33 namespace ash { |
28 namespace test { | 34 namespace test { |
29 class ScreenRotationAnimatorTestApi; | 35 class ScreenRotationAnimatorTestApi; |
30 } // namespace test | 36 } // namespace test |
31 | 37 |
32 class ScreenRotationAnimatorObserver; | 38 class ScreenRotationAnimatorObserver; |
33 | 39 |
(...skipping 24 matching lines...) Expand all Loading... |
58 // When screen rotation animation is ended or aborted, calls |Rotate()| with | 64 // When screen rotation animation is ended or aborted, calls |Rotate()| with |
59 // the pending rotation request if the request queue is not empty. Otherwise | 65 // the pending rotation request if the request queue is not empty. Otherwise |
60 // notifies |screen_rotation_animator_observer_|. | 66 // notifies |screen_rotation_animator_observer_|. |
61 void ProcessAnimationQueue(); | 67 void ProcessAnimationQueue(); |
62 | 68 |
63 protected: | 69 protected: |
64 using CopyCallback = | 70 using CopyCallback = |
65 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; | 71 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; |
66 struct ScreenRotationRequest { | 72 struct ScreenRotationRequest { |
67 ScreenRotationRequest(int64_t id, | 73 ScreenRotationRequest(int64_t id, |
| 74 display::Display::Rotation from_rotation, |
68 display::Display::Rotation to_rotation, | 75 display::Display::Rotation to_rotation, |
69 display::Display::RotationSource from_source) | 76 display::Display::RotationSource from_source) |
70 : id(id), new_rotation(to_rotation), source(from_source) {} | 77 : id(id), |
| 78 old_rotation(from_rotation), |
| 79 new_rotation(to_rotation), |
| 80 source(from_source) {} |
71 int64_t id; | 81 int64_t id; |
| 82 display::Display::Rotation old_rotation; |
72 display::Display::Rotation new_rotation; | 83 display::Display::Rotation new_rotation; |
73 display::Display::RotationSource source; | 84 display::Display::RotationSource source; |
74 }; | 85 }; |
75 | 86 |
76 // This function can be overridden in unit test to test removing external | 87 // This function can be overridden in unit test to test removing external |
77 // display. | 88 // display. |
78 virtual CopyCallback CreateAfterCopyCallback( | 89 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 90 std::unique_ptr<ScreenRotationRequest> rotation_request); |
| 91 |
| 92 // This function can be overridden in unit test to test removing external |
| 93 // display. |
| 94 virtual CopyCallback CreateAfterCopyCallbackAfterRotation( |
79 std::unique_ptr<ScreenRotationRequest> rotation_request); | 95 std::unique_ptr<ScreenRotationRequest> rotation_request); |
80 | 96 |
81 private: | 97 private: |
82 friend class ash::test::ScreenRotationAnimatorTestApi; | 98 friend class ash::test::ScreenRotationAnimatorTestApi; |
83 | 99 |
84 void StartRotationAnimation( | 100 void StartRotationAnimation( |
85 std::unique_ptr<ScreenRotationRequest> rotation_request); | 101 std::unique_ptr<ScreenRotationRequest> rotation_request); |
86 | 102 |
87 // This is an asynchronous call to request copy output of root layer. | 103 // The code path to start "slow animation". The difference between the "slow" |
88 void RequestCopyRootLayerAndAnimateRotation( | 104 // and "smooth" animation, is that "slow animation" will recreate all the |
| 105 // layers before rotation and use the recreated layers and rotated layers for |
| 106 // cross-fading animation. This is slow by adding multiple layer animation |
| 107 // elements. The "smooth animation" copies the layer output before and after |
| 108 // rotation, and use them for cross-fading animation. The output copy layer |
| 109 // flatten the layer hierarchy and makes the animation smooth. |
| 110 void StartSlowAnimation( |
89 std::unique_ptr<ScreenRotationRequest> rotation_request); | 111 std::unique_ptr<ScreenRotationRequest> rotation_request); |
90 | 112 |
91 // The callback in |RequestCopyRootLayerAndAnimateRotation()|. | 113 // A wrapper to call |display_manager| to set screen rotation and rotate the |
92 void OnRootLayerCopiedBeforeRotation( | 114 // |old_layer_tree| to the |old_rotation|. |
| 115 void SetRotation(display::Display::Rotation old_rotation, |
| 116 display::Display::Rotation new_rotation, |
| 117 display::Display::RotationSource source); |
| 118 |
| 119 // This is an asynchronous call to request copy output of root layer. |
| 120 void RequestCopyScreenRotationContainerLayer( |
| 121 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); |
| 122 |
| 123 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen |
| 124 // rotation. |
| 125 void OnScreenRotationContainerLayerCopiedBeforeRotation( |
93 std::unique_ptr<ScreenRotationRequest> rotation_request, | 126 std::unique_ptr<ScreenRotationRequest> rotation_request, |
94 std::unique_ptr<cc::CopyOutputResult> result); | 127 std::unique_ptr<cc::CopyOutputResult> result); |
95 | 128 |
96 // Recreates all |root_window| layers. | 129 // The callback in |RequestCopyScreenRotationContainerLayer()| after screen |
97 void CreateOldLayerTree(); | 130 // rotation. |
| 131 void OnScreenRotationContainerLayerCopiedAfterRotation( |
| 132 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 133 std::unique_ptr<cc::CopyOutputResult> result); |
98 | 134 |
99 // Requests a copy of |root_window| root layer output. | 135 // Recreates all |root_window| layers and their layer tree owner. |
100 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result); | 136 void CreateOldLayerTreeForSlowAnimation(); |
| 137 |
| 138 // Creates a new layer and its layer tree owner from |CopyOutputResult|. |
| 139 std::unique_ptr<ui::LayerTreeOwner> CopyLayerTree( |
| 140 std::unique_ptr<cc::CopyOutputResult> result); |
101 | 141 |
102 // Note: Only call this function when the |old_layer_tree_owner_| is set up | 142 // Note: Only call this function when the |old_layer_tree_owner_| is set up |
103 // properly. | 143 // properly. |
104 // Sets the screen orientation to |new_rotation| and animate the change. The | 144 // Sets the screen orientation to |new_rotation| and animate the change. The |
105 // animation will rotate the initial orientation's layer towards the new | 145 // animation will rotate the initial orientation's layer towards the new |
106 // orientation through |rotation_degrees| while fading out, and the new | 146 // orientation through |rotation_degrees| while fading out, and the new |
107 // orientation's layer will be rotated in to the |new_orientation| through | 147 // orientation's layer will be rotated in to the |new_orientation| through |
108 // |rotation_degrees| arc. | 148 // |rotation_degrees| arc. |
109 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); | 149 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); |
110 | 150 |
111 void set_disable_animation_timers_for_test(bool disable_timers); | 151 void set_disable_animation_timers_for_test(bool disable_timers) { |
| 152 disable_animation_timers_for_test_ = disable_timers; |
| 153 } |
| 154 |
| 155 void set_switch_smooth_rotation_for_test(bool enable) { |
| 156 has_switch_ash_enable_smooth_screen_rotation_ = enable; |
| 157 } |
112 | 158 |
113 void StopAnimating(); | 159 void StopAnimating(); |
114 | 160 |
115 // The id of the display to rotate. | 161 // The id of the display to rotate. |
116 int64_t display_id_; | 162 int64_t display_id_; |
117 | 163 |
118 // For current slow rotation animation, there are two states |ROTATING| and | 164 // For current slow rotation animation, there are two states |ROTATING| and |
119 // |IDLE|. For the smooth rotation animation, we need to send copy request | 165 // |IDLE|. For the smooth rotation animation, we need to send copy request |
120 // and get copy result before animating. | 166 // and get copy result before animating. |
121 enum ScreenRotationState { | 167 enum ScreenRotationState { |
122 COPY_REQUESTED, | 168 COPY_REQUESTED, |
123 ROTATING, | 169 ROTATING, |
124 IDLE, | 170 IDLE, |
125 }; | 171 }; |
126 ScreenRotationState screen_rotation_state_; | 172 ScreenRotationState screen_rotation_state_; |
127 | 173 |
128 // Rotation request id, used to ignore copy request callback if we decide to | 174 // Rotation request id, used to ignore copy request callback if we decide to |
129 // cancel the previous rotation request. | 175 // cancel the previous rotation request. |
130 int64_t rotation_request_id_; | 176 int64_t rotation_request_id_; |
131 | 177 |
132 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 178 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
133 // Only set in unittest to disable animation timers. | 179 // Only set in unittest to disable animation timers. |
134 bool disable_animation_timers_for_test_; | 180 bool disable_animation_timers_for_test_; |
135 base::ObserverList<ScreenRotationAnimatorObserver> | 181 base::ObserverList<ScreenRotationAnimatorObserver> |
136 screen_rotation_animator_observers_; | 182 screen_rotation_animator_observers_; |
137 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 183 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
| 184 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; |
| 185 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_; |
138 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 186 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
| 187 bool has_switch_ash_enable_smooth_screen_rotation_; |
| 188 aura::Window* root_window_; |
| 189 ui::Layer* screen_rotation_container_layer_; |
139 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 190 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
140 | 191 |
141 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 192 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
142 }; | 193 }; |
143 | 194 |
144 } // namespace ash | 195 } // namespace ash |
145 | 196 |
146 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 197 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
OLD | NEW |