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/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
14 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
15 | 16 |
17 namespace cc { | |
18 class CopyOutputResult; | |
19 } // namespace cc | |
20 | |
16 namespace ui { | 21 namespace ui { |
17 class AnimationMetricsReporter; | 22 class AnimationMetricsReporter; |
18 class Layer; | 23 class Layer; |
19 class LayerTreeOwner; | 24 class LayerTreeOwner; |
20 } // namespace ui | 25 } // namespace ui |
21 | 26 |
22 namespace ash { | 27 namespace ash { |
23 namespace test { | 28 namespace test { |
24 class ScreenRotationAnimatorTestApi; | 29 class ScreenRotationAnimatorTestApi; |
25 } // namespace test | 30 } // namespace test |
26 | 31 |
27 class ScreenRotationAnimatorObserver; | 32 class ScreenRotationAnimatorObserver; |
28 | 33 |
29 // Utility to perform a screen rotation with an animation. | 34 // Utility to perform a screen rotation with an animation. |
30 class ASH_EXPORT ScreenRotationAnimator { | 35 class ASH_EXPORT ScreenRotationAnimator { |
31 public: | 36 public: |
32 explicit ScreenRotationAnimator(int64_t display_id); | 37 explicit ScreenRotationAnimator(int64_t display_id); |
33 ~ScreenRotationAnimator(); | 38 virtual ~ScreenRotationAnimator(); |
34 | 39 |
35 // Rotates the display::Display specified by |display_id_| to the | 40 // Rotates the display::Display specified by |display_id_| to the |
36 // |new_rotation| orientation, for the given |source|. The rotation will also | 41 // |new_rotation| orientation, for the given |source|. The rotation will also |
37 // become active. Should only be called when |display_id_| references a valid | 42 // become active. Should only be called when |display_id_| references a valid |
38 // display::Display. |screen_rotation_animator_observer_| will be notified | 43 // display::Display. |screen_rotation_animator_observer_| will be notified |
39 // when rotation is finished and there is no more pending rotation request. | 44 // when rotation is finished and there is no more pending rotation request. |
40 // Otherwise, any ongoing animation will be stopped and progressed to the | 45 // Otherwise, any ongoing animation will be stopped and progressed to the |
41 // target position, followed by a new |Rotate()| call with the pending | 46 // target position, followed by a new |Rotate()| call with the pending |
42 // rotation request. | 47 // rotation request. |
43 void Rotate(display::Display::Rotation new_rotation, | 48 void Rotate(display::Display::Rotation new_rotation, |
44 display::Display::RotationSource source); | 49 display::Display::RotationSource source); |
45 | 50 |
46 int64_t display_id() const { return display_id_; } | 51 int64_t display_id() const { return display_id_; } |
47 | 52 |
48 void AddScreenRotationAnimatorObserver( | 53 void AddScreenRotationAnimatorObserver( |
49 ScreenRotationAnimatorObserver* observer); | 54 ScreenRotationAnimatorObserver* observer); |
50 void RemoveScreenRotationAnimatorObserver( | 55 void RemoveScreenRotationAnimatorObserver( |
51 ScreenRotationAnimatorObserver* observer); | 56 ScreenRotationAnimatorObserver* observer); |
52 | 57 |
53 // When screen rotation animation is ended or aborted, calls |Rotate()| with | 58 // When screen rotation animation is ended or aborted, calls |Rotate()| with |
54 // the pending rotation request if the request queue is not empty. Otherwise | 59 // the pending rotation request if the request queue is not empty. Otherwise |
55 // notifies |screen_rotation_animator_observer_|. | 60 // notifies |screen_rotation_animator_observer_|. |
56 void ProcessAnimationQueue(); | 61 void ProcessAnimationQueue(); |
57 | 62 |
63 protected: | |
64 struct ScreenRotationRequest { | |
65 ScreenRotationRequest(display::Display::Rotation to_rotation, | |
66 display::Display::RotationSource from_source) | |
67 : new_rotation(to_rotation), source(from_source) {} | |
68 display::Display::Rotation new_rotation; | |
69 display::Display::RotationSource source; | |
70 }; | |
71 | |
72 // This function can be overridden in unit test to test removing external | |
73 // display. | |
74 virtual base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)> | |
oshima
2017/04/05 01:55:42
using CopyCallback = OnceCallback<....>
wutao
2017/04/05 07:41:57
Changed to: using CopyCallback = base::Callback<>.
| |
75 CreateAfterCopyCallback( | |
76 std::unique_ptr<ScreenRotationRequest> rotation_request); | |
77 | |
78 // The callback in |RequestCopyRootLayerAndAnimateRotation()|. | |
79 void OnRootLayerCopiedBeforeRotation( | |
80 std::unique_ptr<ScreenRotationRequest> rotation_request, | |
81 std::unique_ptr<cc::CopyOutputResult> result); | |
82 | |
58 private: | 83 private: |
59 friend class ash::test::ScreenRotationAnimatorTestApi; | 84 friend class ash::test::ScreenRotationAnimatorTestApi; |
60 struct ScreenRotationRequest; | |
61 | 85 |
62 // Set the screen orientation to |new_rotation| and animate the change. The | 86 void StartRotationAnimation( |
87 std::unique_ptr<ScreenRotationRequest> rotation_request); | |
88 | |
89 // This is an asynchronous call to request copy output of root layer. | |
90 void RequestCopyRootLayerAndAnimateRotation( | |
91 std::unique_ptr<ScreenRotationRequest> rotation_request); | |
92 | |
93 // Recreates all |root_window| layers. | |
94 void CreateOldLayerTree(); | |
95 | |
96 // Requests a copy of |root_window| root layer output. | |
97 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result); | |
98 | |
99 // Note: Only call this function when the |old_layer_tree_owner_| is set up | |
100 // properly. | |
101 // Sets the screen orientation to |new_rotation| and animate the change. The | |
63 // animation will rotate the initial orientation's layer towards the new | 102 // animation will rotate the initial orientation's layer towards the new |
64 // orientation through |rotation_degrees| while fading out, and the new | 103 // orientation through |rotation_degrees| while fading out, and the new |
65 // orientation's layer will be rotated in to the |new_orientation| through | 104 // orientation's layer will be rotated in to the |new_orientation| through |
66 // |rotation_degrees| arc. | 105 // |rotation_degrees| arc. |
67 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); | 106 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); |
68 | 107 |
69 void set_disable_animation_timers_for_test(bool disable_timers); | 108 void set_disable_animation_timers_for_test(bool disable_timers); |
70 | 109 |
71 void StopAnimating(); | 110 void StopAnimating(); |
72 | 111 |
73 // The id of the display to rotate. | 112 // The id of the display to rotate. |
74 int64_t display_id_; | 113 int64_t display_id_; |
75 bool is_rotating_; | 114 bool is_rotating_; |
76 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; | 115 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; |
77 // Only set in unittest to disable animation timers. | 116 // Only set in unittest to disable animation timers. |
78 bool disable_animation_timers_for_test_; | 117 bool disable_animation_timers_for_test_; |
79 base::ObserverList<ScreenRotationAnimatorObserver> | 118 base::ObserverList<ScreenRotationAnimatorObserver> |
80 screen_rotation_animator_observers_; | 119 screen_rotation_animator_observers_; |
81 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; | 120 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; |
82 std::unique_ptr<ScreenRotationRequest> last_pending_request_; | 121 std::unique_ptr<ScreenRotationRequest> last_pending_request_; |
83 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; | 122 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; |
84 | 123 |
85 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); | 124 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); |
86 }; | 125 }; |
87 | 126 |
88 } // namespace ash | 127 } // namespace ash |
89 | 128 |
90 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ | 129 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ |
OLD | NEW |