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 } |
112 | 150 |
113 void StopAnimating(); | 151 void StopAnimating(); |
114 | 152 |
115 // The id of the display to rotate. | 153 // The id of the display to rotate. |
116 int64_t display_id_; | 154 int64_t display_id_; |
117 | 155 |
118 // For current slow rotation animation, there are two states |ROTATING| and | 156 // For current slow rotation animation, there are two states |ROTATING| and |
119 // |IDLE|. For the smooth rotation animation, we need to send copy request | 157 // |IDLE|. For the smooth rotation animation, we need to send copy request |
120 // and get copy result before animating. | 158 // and get copy result before animating. |
121 enum ScreenRotationState { | 159 enum ScreenRotationState { |
122 COPY_REQUESTED, | 160 COPY_REQUESTED, |
123 ROTATING, | 161 ROTATING, |
124 IDLE, | 162 IDLE, |
125 }; | 163 }; |
126 ScreenRotationState screen_rotation_state_; | 164 ScreenRotationState screen_rotation_state_; |
127 | 165 |
128 // Rotation request id, used to ignore copy request callback if we decide to | 166 // Rotation request id, used to ignore copy request callback if we decide to |
129 // cancel the previous rotation request. | 167 // cancel the previous rotation request. |
130 int64_t rotation_request_id_; | 168 int64_t rotation_request_id_; |
131 | 169 |
132 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 170 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
133 // Only set in unittest to disable animation timers. | 171 // Only set in unittest to disable animation timers. |
134 bool disable_animation_timers_for_test_; | 172 bool disable_animation_timers_for_test_; |
135 base::ObserverList<ScreenRotationAnimatorObserver> | 173 base::ObserverList<ScreenRotationAnimatorObserver> |
136 screen_rotation_animator_observers_; | 174 screen_rotation_animator_observers_; |
137 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 175 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
| 176 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; |
| 177 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_; |
138 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 178 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
| 179 bool has_switch_ash_enable_smooth_screen_rotation_; |
| 180 aura::Window* root_window_; |
| 181 ui::Layer* screen_rotation_container_layer_; |
139 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 182 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
140 | 183 |
141 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 184 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
142 }; | 185 }; |
143 | 186 |
144 } // namespace ash | 187 } // namespace ash |
145 | 188 |
146 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 189 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
OLD | NEW |