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 29 matching lines...) Expand all Loading... |
57 | 62 |
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(display::Display::Rotation to_rotation, | 72 ScreenRotationRequest(display::Display::Rotation from_rotation, |
| 73 display::Display::Rotation to_rotation, |
68 display::Display::RotationSource from_source) | 74 display::Display::RotationSource from_source) |
69 : new_rotation(to_rotation), source(from_source) {} | 75 : old_rotation(from_rotation), |
| 76 new_rotation(to_rotation), |
| 77 source(from_source) {} |
| 78 display::Display::Rotation old_rotation; |
70 display::Display::Rotation new_rotation; | 79 display::Display::Rotation new_rotation; |
71 display::Display::RotationSource source; | 80 display::Display::RotationSource source; |
72 }; | 81 }; |
73 | 82 |
74 // 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 |
75 // display. | 84 // display. |
76 virtual CopyCallback CreateAfterCopyCallback( | 85 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 86 std::unique_ptr<ScreenRotationRequest> rotation_request); |
| 87 virtual CopyCallback CreateAfterCopyCallbackAfterRotation( |
77 std::unique_ptr<ScreenRotationRequest> rotation_request); | 88 std::unique_ptr<ScreenRotationRequest> rotation_request); |
78 | 89 |
79 private: | 90 private: |
80 friend class ash::test::ScreenRotationAnimatorTestApi; | 91 friend class ash::test::ScreenRotationAnimatorTestApi; |
81 | 92 |
82 void StartRotationAnimation( | 93 void StartRotationAnimation( |
83 std::unique_ptr<ScreenRotationRequest> rotation_request); | 94 std::unique_ptr<ScreenRotationRequest> rotation_request); |
84 | 95 |
85 // This is an asynchronous call to request copy output of root layer. | 96 // The fallback to slow animation if copy output request cancled or failed. |
86 void RequestCopyRootLayerAndAnimateRotation( | 97 void StartSlowAnimation( |
87 std::unique_ptr<ScreenRotationRequest> rotation_request); | 98 std::unique_ptr<ScreenRotationRequest> rotation_request); |
88 | 99 |
89 // The callback in |RequestCopyRootLayerAndAnimateRotation()|. | 100 // A wrapper to call |display_manager| to set screen rotation and rotate the |
90 void OnRootLayerCopiedBeforeRotation( | 101 // |old_layer_tree| to the |old_rotation|. |
| 102 void SetRotation(display::Display::Rotation new_rotation, |
| 103 display::Display::Rotation old_rotation, |
| 104 display::Display::RotationSource source); |
| 105 |
| 106 // This is an asynchronous call to request copy output of root layer. |
| 107 void RequestCopyScreenRotationContainerLayer( |
| 108 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); |
| 109 |
| 110 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen |
| 111 // rotation. |
| 112 void OnScreenRotationContainerLayerCopiedBeforeRotation( |
91 std::unique_ptr<ScreenRotationRequest> rotation_request, | 113 std::unique_ptr<ScreenRotationRequest> rotation_request, |
92 std::unique_ptr<cc::CopyOutputResult> result); | 114 std::unique_ptr<cc::CopyOutputResult> result); |
93 | 115 |
94 // Recreates all |root_window| layers. | 116 // The callback in |RequestCopyScreenRotationContainerLayer()| after screen |
| 117 // rotation. |
| 118 void OnScreenRotationContainerLayerCopiedAfterRotation( |
| 119 std::unique_ptr<ScreenRotationRequest> rotation_request, |
| 120 std::unique_ptr<cc::CopyOutputResult> result); |
| 121 |
| 122 // Recreates all |root_window| layers and their layer tree owner. |
95 void CreateOldLayerTree(); | 123 void CreateOldLayerTree(); |
96 | 124 |
97 // Requests a copy of |root_window| root layer output. | 125 // Creates a new layer and its layer tree owner from |CopyOutputResult|. |
98 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result); | 126 std::unique_ptr<ui::LayerTreeOwner> CopyLayerTree( |
| 127 std::unique_ptr<cc::CopyOutputResult> result); |
99 | 128 |
100 // Note: Only call this function when the |old_layer_tree_owner_| is set up | 129 // Note: Only call this function when the |old_layer_tree_owner_| is set up |
101 // properly. | 130 // properly. |
102 // Sets the screen orientation to |new_rotation| and animate the change. The | 131 // Sets the screen orientation to |new_rotation| and animate the change. The |
103 // animation will rotate the initial orientation's layer towards the new | 132 // animation will rotate the initial orientation's layer towards the new |
104 // orientation through |rotation_degrees| while fading out, and the new | 133 // orientation through |rotation_degrees| while fading out, and the new |
105 // orientation's layer will be rotated in to the |new_orientation| through | 134 // orientation's layer will be rotated in to the |new_orientation| through |
106 // |rotation_degrees| arc. | 135 // |rotation_degrees| arc. |
107 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); | 136 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); |
108 | 137 |
109 void set_disable_animation_timers_for_test(bool disable_timers); | 138 void set_disable_animation_timers_for_test(bool disable_timers); |
110 | 139 |
111 void StopAnimating(); | 140 void StopAnimating(); |
112 | 141 |
113 // The id of the display to rotate. | 142 // The id of the display to rotate. |
114 int64_t display_id_; | 143 int64_t display_id_; |
115 bool is_rotating_; | 144 bool is_rotating_; |
116 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 145 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
117 // Only set in unittest to disable animation timers. | 146 // Only set in unittest to disable animation timers. |
118 bool disable_animation_timers_for_test_; | 147 bool disable_animation_timers_for_test_; |
119 base::ObserverList<ScreenRotationAnimatorObserver> | 148 base::ObserverList<ScreenRotationAnimatorObserver> |
120 screen_rotation_animator_observers_; | 149 screen_rotation_animator_observers_; |
121 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 150 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
| 151 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; |
122 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 152 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
| 153 bool has_switch_ash_enable_smooth_screen_rotation_; |
| 154 ui::Layer* screen_rotation_container_layer_; |
| 155 aura::Window* root_window_; |
123 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 156 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
124 | 157 |
125 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 158 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
126 }; | 159 }; |
127 | 160 |
128 } // namespace ash | 161 } // namespace ash |
129 | 162 |
130 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 163 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
OLD | NEW |