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