| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class Layer; | 28 class Layer; |
| 29 class LayerOwner; | 29 class LayerOwner; |
| 30 class LayerTreeOwner; | 30 class LayerTreeOwner; |
| 31 } // namespace ui | 31 } // namespace ui |
| 32 | 32 |
| 33 namespace ash { | 33 namespace ash { |
| 34 namespace test { | 34 namespace test { |
| 35 class ScreenRotationAnimatorTestApi; | 35 class ScreenRotationAnimatorTestApi; |
| 36 } // namespace test | 36 } // namespace test |
| 37 | 37 |
| 38 class ScreenRotationAnimatorLock; |
| 38 class ScreenRotationAnimatorObserver; | 39 class ScreenRotationAnimatorObserver; |
| 39 | 40 |
| 40 // Utility to perform a screen rotation with an animation. | 41 // Utility to perform a screen rotation with an animation. |
| 41 class ASH_EXPORT ScreenRotationAnimator { | 42 class ASH_EXPORT ScreenRotationAnimator { |
| 42 public: | 43 public: |
| 43 explicit ScreenRotationAnimator(int64_t display_id); | 44 explicit ScreenRotationAnimator(int64_t display_id); |
| 44 virtual ~ScreenRotationAnimator(); | 45 virtual ~ScreenRotationAnimator(); |
| 45 | 46 |
| 46 // Rotates the display::Display specified by |display_id_| to the | 47 // Rotates the display::Display specified by |display_id_| to the |
| 47 // |new_rotation| orientation, for the given |source|. The rotation will also | 48 // |new_rotation| orientation, for the given |source|. The rotation will also |
| (...skipping 11 matching lines...) Expand all Loading... |
| 59 void AddScreenRotationAnimatorObserver( | 60 void AddScreenRotationAnimatorObserver( |
| 60 ScreenRotationAnimatorObserver* observer); | 61 ScreenRotationAnimatorObserver* observer); |
| 61 void RemoveScreenRotationAnimatorObserver( | 62 void RemoveScreenRotationAnimatorObserver( |
| 62 ScreenRotationAnimatorObserver* observer); | 63 ScreenRotationAnimatorObserver* observer); |
| 63 | 64 |
| 64 // When screen rotation animation is ended or aborted, calls |Rotate()| with | 65 // When screen rotation animation is ended or aborted, calls |Rotate()| with |
| 65 // the pending rotation request if the request queue is not empty. Otherwise | 66 // the pending rotation request if the request queue is not empty. Otherwise |
| 66 // notifies |screen_rotation_animator_observer_|. | 67 // notifies |screen_rotation_animator_observer_|. |
| 67 void ProcessAnimationQueue(); | 68 void ProcessAnimationQueue(); |
| 68 | 69 |
| 70 void AddAnimatorLock(ScreenRotationAnimatorLock* lock); |
| 71 void RemoveAnimatorLock(ScreenRotationAnimatorLock* lock); |
| 72 |
| 69 protected: | 73 protected: |
| 70 using CopyCallback = | 74 using CopyCallback = |
| 71 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; | 75 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; |
| 72 struct ScreenRotationRequest { | 76 struct ScreenRotationRequest { |
| 73 ScreenRotationRequest(int64_t id, | 77 ScreenRotationRequest(int64_t id, |
| 74 display::Display::Rotation to_rotation, | 78 display::Display::Rotation to_rotation, |
| 75 display::Display::RotationSource from_source) | 79 display::Display::RotationSource from_source) |
| 76 : id(id), new_rotation(to_rotation), source(from_source) {} | 80 : id(id), new_rotation(to_rotation), source(from_source) {} |
| 77 int64_t id; | 81 int64_t id; |
| 78 display::Display::Rotation old_rotation; | 82 display::Display::Rotation old_rotation; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |
| 157 ScreenRotationAnimatorLock* CreateAnimatorLock(); |
| 158 void TimeoutAnimatorLocks(); |
| 159 void ResetCreatedAnimatorLocks(); |
| 160 |
| 153 // The id of the display to rotate. | 161 // The id of the display to rotate. |
| 154 int64_t display_id_; | 162 int64_t display_id_; |
| 155 | 163 |
| 156 // For current slow rotation animation, there are two states |ROTATING| and | 164 // For current slow rotation animation, there are two states |ROTATING| and |
| 157 // |IDLE|. For the smooth rotation animation, we need to send copy request | 165 // |IDLE|. For the smooth rotation animation, we need to send copy request |
| 158 // and get copy result before animating. | 166 // and get copy result before animating. |
| 159 enum ScreenRotationState { | 167 enum ScreenRotationState { |
| 160 COPY_REQUESTED, | 168 COPY_REQUESTED, |
| 161 ROTATING, | 169 ROTATING, |
| 162 IDLE, | 170 IDLE, |
| 163 }; | 171 }; |
| 164 ScreenRotationState screen_rotation_state_; | 172 ScreenRotationState screen_rotation_state_; |
| 165 | 173 |
| 166 // Rotation request id, used to ignore copy request callback if we decide to | 174 // Rotation request id, used to ignore copy request callback if we decide to |
| 167 // cancel the previous rotation request. | 175 // cancel the previous rotation request. |
| 168 int64_t rotation_request_id_; | 176 int64_t rotation_request_id_; |
| 169 | 177 |
| 178 // The cached rotation request while waiting for the animator lock. |
| 179 std::unique_ptr<ScreenRotationRequest> rotation_request_after_unlock_; |
| 180 // The active locks waiting for. |
| 181 std::vector<ScreenRotationAnimatorLock*> active_locks_; |
| 182 // All the unique_ptr of the locks created. Hold the ownership so that we can |
| 183 // release after animation. |
| 184 std::vector<std::unique_ptr<ScreenRotationAnimatorLock>> created_locks_; |
| 185 |
| 170 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 186 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
| 171 // Only set in unittest to disable animation timers. | 187 // Only set in unittest to disable animation timers. |
| 172 bool disable_animation_timers_for_test_; | 188 bool disable_animation_timers_for_test_; |
| 173 base::ObserverList<ScreenRotationAnimatorObserver> | 189 base::ObserverList<ScreenRotationAnimatorObserver> |
| 174 screen_rotation_animator_observers_; | 190 screen_rotation_animator_observers_; |
| 175 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 191 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
| 176 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; | 192 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; |
| 177 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_; | 193 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_; |
| 178 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 194 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
| 179 bool has_switch_ash_disable_smooth_screen_rotation_; | 195 bool has_switch_ash_disable_smooth_screen_rotation_; |
| 180 aura::Window* root_window_; | 196 aura::Window* root_window_; |
| 181 ui::Layer* screen_rotation_container_layer_; | 197 ui::Layer* screen_rotation_container_layer_; |
| 182 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 198 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
| 199 base::WeakPtrFactory<ScreenRotationAnimator> lock_weak_ptr_factory_; |
| 183 | 200 |
| 184 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 201 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
| 185 }; | 202 }; |
| 186 | 203 |
| 187 } // namespace ash | 204 } // namespace ash |
| 188 | 205 |
| 189 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 206 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
| OLD | NEW |