| 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 { | 17 namespace aura { |
| 18 class Window; | 18 class Window; |
| 19 } // namesapce aura | 19 } // namesapce aura |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 class CopyOutputRequest; | 22 class CopyOutputRequest; |
| 23 class CopyOutputResult; | 23 class CopyOutputResult; |
| 24 } // namespace cc | 24 } // namespace cc |
| 25 | 25 |
| 26 namespace ui { | 26 namespace ui { |
| 27 class AnimationMetricsReporter; | 27 class AnimationMetricsReporter; |
| 28 class Layer; | 28 class Layer; |
| 29 class LayerOwner; | |
| 30 class LayerTreeOwner; | 29 class LayerTreeOwner; |
| 31 } // namespace ui | 30 } // namespace ui |
| 32 | 31 |
| 33 namespace ash { | 32 namespace ash { |
| 34 namespace test { | 33 namespace test { |
| 35 class ScreenRotationAnimatorTestApi; | 34 class ScreenRotationAnimatorTestApi; |
| 36 } // namespace test | 35 } // namespace test |
| 37 | 36 |
| 38 class ScreenRotationAnimatorObserver; | 37 class ScreenRotationAnimatorObserver; |
| 39 | 38 |
| 40 // Utility to perform a screen rotation with an animation. | 39 // Utility to perform a screen rotation with an animation. |
| 41 class ASH_EXPORT ScreenRotationAnimator { | 40 class ASH_EXPORT ScreenRotationAnimator { |
| 42 public: | 41 public: |
| 43 explicit ScreenRotationAnimator(int64_t display_id); | 42 explicit ScreenRotationAnimator(aura::Window* root_window); |
| 44 virtual ~ScreenRotationAnimator(); | 43 virtual ~ScreenRotationAnimator(); |
| 45 | 44 |
| 46 // Rotates the display::Display specified by |display_id_| to the | 45 // Rotates the display::Display specified by |display_id| to the |
| 47 // |new_rotation| orientation, for the given |source|. The rotation will also | 46 // |new_rotation| orientation, for the given |source|. The rotation will also |
| 48 // become active. Should only be called when |display_id_| references a valid | 47 // become active. Should only be called when |display_id| references a valid |
| 49 // display::Display. |screen_rotation_animator_observer_| will be notified | 48 // display::Display. |screen_rotation_animator_observer_| will be notified |
| 50 // when rotation is finished and there is no more pending rotation request. | 49 // when rotation is finished and there is no more pending rotation request. |
| 51 // Otherwise, any ongoing animation will be stopped and progressed to the | 50 // Otherwise, any ongoing animation will be stopped and progressed to the |
| 52 // target position, followed by a new |Rotate()| call with the pending | 51 // target position, followed by a new |Rotate()| call with the pending |
| 53 // rotation request. | 52 // rotation request. |
| 54 void Rotate(display::Display::Rotation new_rotation, | 53 void Rotate(int64_t display_id, |
| 54 display::Display::Rotation new_rotation, |
| 55 display::Display::RotationSource source); | 55 display::Display::RotationSource source); |
| 56 | 56 |
| 57 int64_t display_id() const { return display_id_; } | |
| 58 | |
| 59 void AddScreenRotationAnimatorObserver( | 57 void AddScreenRotationAnimatorObserver( |
| 60 ScreenRotationAnimatorObserver* observer); | 58 ScreenRotationAnimatorObserver* observer); |
| 61 void RemoveScreenRotationAnimatorObserver( | 59 void RemoveScreenRotationAnimatorObserver( |
| 62 ScreenRotationAnimatorObserver* observer); | 60 ScreenRotationAnimatorObserver* observer); |
| 63 | 61 |
| 64 // When screen rotation animation is ended or aborted, calls |Rotate()| with | 62 // When screen rotation animation is ended or aborted, calls |Rotate()| with |
| 65 // the pending rotation request if the request queue is not empty. Otherwise | 63 // the pending rotation request if the request queue is not empty. Otherwise |
| 66 // notifies |screen_rotation_animator_observer_|. | 64 // notifies |screen_rotation_animator_observer_|. |
| 67 void ProcessAnimationQueue(); | 65 void ProcessAnimationQueue(); |
| 68 | 66 |
| 69 protected: | 67 protected: |
| 70 using CopyCallback = | 68 using CopyCallback = |
| 71 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; | 69 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; |
| 72 struct ScreenRotationRequest { | 70 struct ScreenRotationRequest { |
| 73 ScreenRotationRequest(int64_t id, | 71 ScreenRotationRequest(int64_t id, |
| 72 int64_t display_id, |
| 74 display::Display::Rotation to_rotation, | 73 display::Display::Rotation to_rotation, |
| 75 display::Display::RotationSource from_source) | 74 display::Display::RotationSource from_source) |
| 76 : id(id), new_rotation(to_rotation), source(from_source) {} | 75 : id(id), |
| 76 display_id(display_id), |
| 77 new_rotation(to_rotation), |
| 78 source(from_source) {} |
| 77 int64_t id; | 79 int64_t id; |
| 80 int64_t display_id; |
| 78 display::Display::Rotation old_rotation; | 81 display::Display::Rotation old_rotation; |
| 79 display::Display::Rotation new_rotation; | 82 display::Display::Rotation new_rotation; |
| 80 display::Display::RotationSource source; | 83 display::Display::RotationSource source; |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 // 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 |
| 84 // display. | 87 // display. |
| 85 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( | 88 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 86 std::unique_ptr<ScreenRotationRequest> rotation_request); | 89 std::unique_ptr<ScreenRotationRequest> rotation_request); |
| 87 | 90 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 101 // layers before rotation and use the recreated layers and rotated layers for | 104 // layers before rotation and use the recreated layers and rotated layers for |
| 102 // cross-fading animation. This is slow by adding multiple layer animation | 105 // cross-fading animation. This is slow by adding multiple layer animation |
| 103 // elements. The "smooth animation" copies the layer output before and after | 106 // elements. The "smooth animation" copies the layer output before and after |
| 104 // rotation, and use them for cross-fading animation. The output copy layer | 107 // rotation, and use them for cross-fading animation. The output copy layer |
| 105 // flatten the layer hierarchy and makes the animation smooth. | 108 // flatten the layer hierarchy and makes the animation smooth. |
| 106 void StartSlowAnimation( | 109 void StartSlowAnimation( |
| 107 std::unique_ptr<ScreenRotationRequest> rotation_request); | 110 std::unique_ptr<ScreenRotationRequest> rotation_request); |
| 108 | 111 |
| 109 // A wrapper to call |display_manager| to set screen rotation and rotate the | 112 // A wrapper to call |display_manager| to set screen rotation and rotate the |
| 110 // |old_layer_tree| to the |old_rotation|. | 113 // |old_layer_tree| to the |old_rotation|. |
| 111 void SetRotation(display::Display::Rotation old_rotation, | 114 void SetRotation(int64_t display_id, |
| 115 display::Display::Rotation old_rotation, |
| 112 display::Display::Rotation new_rotation, | 116 display::Display::Rotation new_rotation, |
| 113 display::Display::RotationSource source); | 117 display::Display::RotationSource source); |
| 114 | 118 |
| 115 // This is an asynchronous call to request copy output of root layer. | 119 // This is an asynchronous call to request copy output of root layer. |
| 116 void RequestCopyScreenRotationContainerLayer( | 120 void RequestCopyScreenRotationContainerLayer( |
| 117 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); | 121 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); |
| 118 | 122 |
| 119 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen | 123 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen |
| 120 // rotation. | 124 // rotation. |
| 121 void OnScreenRotationContainerLayerCopiedBeforeRotation( | 125 void OnScreenRotationContainerLayerCopiedBeforeRotation( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 143 // 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 |
| 144 // |rotation_degrees| arc. | 148 // |rotation_degrees| arc. |
| 145 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); | 149 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); |
| 146 | 150 |
| 147 void set_disable_animation_timers_for_test(bool disable_timers) { | 151 void set_disable_animation_timers_for_test(bool disable_timers) { |
| 148 disable_animation_timers_for_test_ = disable_timers; | 152 disable_animation_timers_for_test_ = disable_timers; |
| 149 } | 153 } |
| 150 | 154 |
| 151 void StopAnimating(); | 155 void StopAnimating(); |
| 152 | 156 |
| 153 // The id of the display to rotate. | 157 aura::Window* root_window_; |
| 154 int64_t display_id_; | 158 ui::Layer* screen_rotation_container_layer_; |
| 155 | 159 |
| 156 // For current slow rotation animation, there are two states |ROTATING| and | 160 // For current slow rotation animation, there are two states |ROTATING| and |
| 157 // |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 |
| 158 // and get copy result before animating. | 162 // and get copy result before animating. |
| 159 enum ScreenRotationState { | 163 enum ScreenRotationState { |
| 160 COPY_REQUESTED, | 164 COPY_REQUESTED, |
| 161 ROTATING, | 165 ROTATING, |
| 162 IDLE, | 166 IDLE, |
| 163 }; | 167 }; |
| 164 ScreenRotationState screen_rotation_state_; | 168 ScreenRotationState screen_rotation_state_; |
| 165 | 169 |
| 166 // 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 |
| 167 // cancel the previous rotation request. | 171 // cancel the previous rotation request. |
| 168 int64_t rotation_request_id_; | 172 int64_t rotation_request_id_; |
| 169 | 173 |
| 170 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 174 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
| 171 // Only set in unittest to disable animation timers. | 175 // Only set in unittest to disable animation timers. |
| 172 bool disable_animation_timers_for_test_; | 176 bool disable_animation_timers_for_test_; |
| 173 base::ObserverList<ScreenRotationAnimatorObserver> | 177 base::ObserverList<ScreenRotationAnimatorObserver> |
| 174 screen_rotation_animator_observers_; | 178 screen_rotation_animator_observers_; |
| 175 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 179 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
| 176 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; | 180 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; |
| 177 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_; | 181 std::unique_ptr<ui::LayerTreeOwner> mask_layer_tree_owner_; |
| 178 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 182 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
| 179 bool has_switch_ash_disable_smooth_screen_rotation_; | 183 bool has_switch_ash_disable_smooth_screen_rotation_; |
| 180 aura::Window* root_window_; | |
| 181 ui::Layer* screen_rotation_container_layer_; | |
| 182 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 184 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
| 183 | 185 |
| 184 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 186 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
| 185 }; | 187 }; |
| 186 | 188 |
| 187 } // namespace ash | 189 } // namespace ash |
| 188 | 190 |
| 189 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 191 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| OLD | NEW |