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; |
24 class LayerTreeOwner; | 29 class LayerTreeOwner; |
25 } // namespace ui | 30 } // namespace ui |
26 | 31 |
27 namespace ash { | 32 namespace ash { |
(...skipping 30 matching lines...) Expand all Loading... |
58 // When screen rotation animation is ended or aborted, calls |Rotate()| with | 63 // When screen rotation animation is ended or aborted, calls |Rotate()| with |
59 // the pending rotation request if the request queue is not empty. Otherwise | 64 // the pending rotation request if the request queue is not empty. Otherwise |
60 // notifies |screen_rotation_animator_observer_|. | 65 // notifies |screen_rotation_animator_observer_|. |
61 void ProcessAnimationQueue(); | 66 void ProcessAnimationQueue(); |
62 | 67 |
63 protected: | 68 protected: |
64 using CopyCallback = | 69 using CopyCallback = |
65 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; | 70 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; |
66 struct ScreenRotationRequest { | 71 struct ScreenRotationRequest { |
67 ScreenRotationRequest(int64_t id, | 72 ScreenRotationRequest(int64_t id, |
| 73 display::Display::Rotation from_rotation, |
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), |
| 77 old_rotation(from_rotation), |
| 78 new_rotation(to_rotation), |
| 79 source(from_source) {} |
71 int64_t id; | 80 int64_t id; |
| 81 display::Display::Rotation old_rotation; |
72 display::Display::Rotation new_rotation; | 82 display::Display::Rotation new_rotation; |
73 display::Display::RotationSource source; | 83 display::Display::RotationSource source; |
74 }; | 84 }; |
75 | 85 |
76 // This function can be overridden in unit test to test removing external | 86 // This function can be overridden in unit test to test removing external |
77 // display. | 87 // display. |
78 virtual CopyCallback CreateAfterCopyCallback( | 88 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 89 std::unique_ptr<ScreenRotationRequest> rotation_request); |
| 90 |
| 91 virtual CopyCallback CreateAfterCopyCallbackAfterRotation( |
79 std::unique_ptr<ScreenRotationRequest> rotation_request); | 92 std::unique_ptr<ScreenRotationRequest> rotation_request); |
80 | 93 |
81 private: | 94 private: |
82 friend class ash::test::ScreenRotationAnimatorTestApi; | 95 friend class ash::test::ScreenRotationAnimatorTestApi; |
83 | 96 |
84 void StartRotationAnimation( | 97 void StartRotationAnimation( |
85 std::unique_ptr<ScreenRotationRequest> rotation_request); | 98 std::unique_ptr<ScreenRotationRequest> rotation_request); |
86 | 99 |
87 // This is an asynchronous call to request copy output of root layer. | 100 // The fallback to slow animation if copy output request cancled or failed. |
88 void RequestCopyRootLayerAndAnimateRotation( | 101 void StartSlowAnimation( |
89 std::unique_ptr<ScreenRotationRequest> rotation_request); | 102 std::unique_ptr<ScreenRotationRequest> rotation_request); |
90 | 103 |
91 // The callback in |RequestCopyRootLayerAndAnimateRotation()|. | 104 // A wrapper to call |display_manager| to set screen rotation and rotate the |
92 void OnRootLayerCopiedBeforeRotation( | 105 // |old_layer_tree| to the |old_rotation|. |
| 106 void SetRotation(display::Display::Rotation new_rotation, |
| 107 display::Display::Rotation old_rotation, |
| 108 display::Display::RotationSource source); |
| 109 |
| 110 // This is an asynchronous call to request copy output of root layer. |
| 111 void RequestCopyScreenRotationContainerLayer( |
| 112 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); |
| 113 |
| 114 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen |
| 115 // rotation. |
| 116 void OnScreenRotationContainerLayerCopiedBeforeRotation( |
93 std::unique_ptr<ScreenRotationRequest> rotation_request, | 117 std::unique_ptr<ScreenRotationRequest> rotation_request, |
94 std::unique_ptr<cc::CopyOutputResult> result); | 118 std::unique_ptr<cc::CopyOutputResult> result); |
95 | 119 |
96 // Recreates all |root_window| layers. | 120 // The callback in |RequestCopyScreenRotationContainerLayer()| after screen |
| 121 // rotation. |
| 122 void OnScreenRotationContainerLayerCopiedAfterRotation( |
| 123 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 124 std::unique_ptr<cc::CopyOutputResult> result); |
| 125 |
| 126 // Recreates all |root_window| layers and their layer tree owner. |
97 void CreateOldLayerTree(); | 127 void CreateOldLayerTree(); |
98 | 128 |
99 // Requests a copy of |root_window| root layer output. | 129 // Creates a new layer and its layer tree owner from |CopyOutputResult|. |
100 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result); | 130 std::unique_ptr<ui::LayerTreeOwner> CopyLayerTree( |
| 131 std::unique_ptr<cc::CopyOutputResult> result); |
101 | 132 |
102 // Note: Only call this function when the |old_layer_tree_owner_| is set up | 133 // Note: Only call this function when the |old_layer_tree_owner_| is set up |
103 // properly. | 134 // properly. |
104 // Sets the screen orientation to |new_rotation| and animate the change. The | 135 // Sets the screen orientation to |new_rotation| and animate the change. The |
105 // animation will rotate the initial orientation's layer towards the new | 136 // animation will rotate the initial orientation's layer towards the new |
106 // orientation through |rotation_degrees| while fading out, and the new | 137 // orientation through |rotation_degrees| while fading out, and the new |
107 // orientation's layer will be rotated in to the |new_orientation| through | 138 // orientation's layer will be rotated in to the |new_orientation| through |
108 // |rotation_degrees| arc. | 139 // |rotation_degrees| arc. |
109 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); | 140 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); |
110 | 141 |
(...skipping 17 matching lines...) Expand all Loading... |
128 // Rotation request id, used to ignore copy request callback if we decide to | 159 // Rotation request id, used to ignore copy request callback if we decide to |
129 // cancel the previous rotation request. | 160 // cancel the previous rotation request. |
130 int64_t rotation_request_id_; | 161 int64_t rotation_request_id_; |
131 | 162 |
132 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 163 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
133 // Only set in unittest to disable animation timers. | 164 // Only set in unittest to disable animation timers. |
134 bool disable_animation_timers_for_test_; | 165 bool disable_animation_timers_for_test_; |
135 base::ObserverList<ScreenRotationAnimatorObserver> | 166 base::ObserverList<ScreenRotationAnimatorObserver> |
136 screen_rotation_animator_observers_; | 167 screen_rotation_animator_observers_; |
137 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 168 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
| 169 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; |
138 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 170 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
| 171 bool has_switch_ash_enable_smooth_screen_rotation_; |
| 172 ui::Layer* screen_rotation_container_layer_; |
| 173 aura::Window* root_window_; |
139 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 174 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
140 | 175 |
141 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 176 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
142 }; | 177 }; |
143 | 178 |
144 } // namespace ash | 179 } // namespace ash |
145 | 180 |
146 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 181 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
OLD | NEW |