Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: ash/rotator/screen_rotation_animator.h

Issue 2919393002: [merge to m60] cros: Do not cache |root_window| in ScreenRotationAnimator. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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| of the |root_window|
47 // |new_rotation| orientation, for the given |source|. The rotation will also 46 // to the |new_rotation| orientation, for the given |source|. The rotation
48 // become active. Should only be called when |display_id_| references a valid 47 // will also become active. |screen_rotation_animator_observer_| will be
49 // display::Display. |screen_rotation_animator_observer_| will be notified 48 // notified when rotation is finished and there is no more pending rotation
50 // when rotation is finished and there is no more pending rotation request. 49 // request. Otherwise, any ongoing animation will be stopped and progressed to
51 // Otherwise, any ongoing animation will be stopped and progressed to the 50 // the target position, followed by a new |Rotate()| call with the pending
52 // target position, followed by a new |Rotate()| call with the pending
53 // rotation request. 51 // rotation request.
54 void Rotate(display::Display::Rotation new_rotation, 52 void Rotate(display::Display::Rotation new_rotation,
55 display::Display::RotationSource source); 53 display::Display::RotationSource source);
56 54
57 int64_t display_id() const { return display_id_; }
58
59 void AddScreenRotationAnimatorObserver( 55 void AddScreenRotationAnimatorObserver(
60 ScreenRotationAnimatorObserver* observer); 56 ScreenRotationAnimatorObserver* observer);
61 void RemoveScreenRotationAnimatorObserver( 57 void RemoveScreenRotationAnimatorObserver(
62 ScreenRotationAnimatorObserver* observer); 58 ScreenRotationAnimatorObserver* observer);
63 59
64 // When screen rotation animation is ended or aborted, calls |Rotate()| with 60 // When screen rotation animation is ended or aborted, calls |Rotate()| with
65 // the pending rotation request if the request queue is not empty. Otherwise 61 // the pending rotation request if the request queue is not empty. Otherwise
66 // notifies |screen_rotation_animator_observer_|. 62 // notifies |screen_rotation_animator_observer_|.
67 void ProcessAnimationQueue(); 63 void ProcessAnimationQueue();
68 64
69 protected: 65 protected:
70 using CopyCallback = 66 using CopyCallback =
71 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; 67 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>;
72 struct ScreenRotationRequest { 68 struct ScreenRotationRequest {
73 ScreenRotationRequest(int64_t id, 69 ScreenRotationRequest(int64_t id,
70 int64_t display_id,
74 display::Display::Rotation to_rotation, 71 display::Display::Rotation to_rotation,
75 display::Display::RotationSource from_source) 72 display::Display::RotationSource from_source)
76 : id(id), new_rotation(to_rotation), source(from_source) {} 73 : id(id),
74 display_id(display_id),
75 new_rotation(to_rotation),
76 source(from_source) {}
77 int64_t id; 77 int64_t id;
78 int64_t display_id;
78 display::Display::Rotation old_rotation; 79 display::Display::Rotation old_rotation;
79 display::Display::Rotation new_rotation; 80 display::Display::Rotation new_rotation;
80 display::Display::RotationSource source; 81 display::Display::RotationSource source;
81 }; 82 };
82 83
83 // This function can be overridden in unit test to test removing external 84 // This function can be overridden in unit test to test removing external
84 // display. 85 // display.
85 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation( 86 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation(
86 std::unique_ptr<ScreenRotationRequest> rotation_request); 87 std::unique_ptr<ScreenRotationRequest> rotation_request);
87 88
(...skipping 13 matching lines...) Expand all
101 // layers before rotation and use the recreated layers and rotated layers for 102 // layers before rotation and use the recreated layers and rotated layers for
102 // cross-fading animation. This is slow by adding multiple layer animation 103 // cross-fading animation. This is slow by adding multiple layer animation
103 // elements. The "smooth animation" copies the layer output before and after 104 // elements. The "smooth animation" copies the layer output before and after
104 // rotation, and use them for cross-fading animation. The output copy layer 105 // rotation, and use them for cross-fading animation. The output copy layer
105 // flatten the layer hierarchy and makes the animation smooth. 106 // flatten the layer hierarchy and makes the animation smooth.
106 void StartSlowAnimation( 107 void StartSlowAnimation(
107 std::unique_ptr<ScreenRotationRequest> rotation_request); 108 std::unique_ptr<ScreenRotationRequest> rotation_request);
108 109
109 // A wrapper to call |display_manager| to set screen rotation and rotate the 110 // A wrapper to call |display_manager| to set screen rotation and rotate the
110 // |old_layer_tree| to the |old_rotation|. 111 // |old_layer_tree| to the |old_rotation|.
111 void SetRotation(display::Display::Rotation old_rotation, 112 void SetRotation(int64_t display_id,
113 display::Display::Rotation old_rotation,
112 display::Display::Rotation new_rotation, 114 display::Display::Rotation new_rotation,
113 display::Display::RotationSource source); 115 display::Display::RotationSource source);
114 116
115 // This is an asynchronous call to request copy output of root layer. 117 // This is an asynchronous call to request copy output of root layer.
116 void RequestCopyScreenRotationContainerLayer( 118 void RequestCopyScreenRotationContainerLayer(
117 std::unique_ptr<cc::CopyOutputRequest> copy_output_request); 119 std::unique_ptr<cc::CopyOutputRequest> copy_output_request);
118 120
119 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen 121 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen
120 // rotation. 122 // rotation.
121 void OnScreenRotationContainerLayerCopiedBeforeRotation( 123 void OnScreenRotationContainerLayerCopiedBeforeRotation(
(...skipping 21 matching lines...) Expand all
143 // orientation's layer will be rotated in to the |new_orientation| through 145 // orientation's layer will be rotated in to the |new_orientation| through
144 // |rotation_degrees| arc. 146 // |rotation_degrees| arc.
145 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); 147 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request);
146 148
147 void set_disable_animation_timers_for_test(bool disable_timers) { 149 void set_disable_animation_timers_for_test(bool disable_timers) {
148 disable_animation_timers_for_test_ = disable_timers; 150 disable_animation_timers_for_test_ = disable_timers;
149 } 151 }
150 152
151 void StopAnimating(); 153 void StopAnimating();
152 154
153 // The id of the display to rotate. 155 aura::Window* root_window_;
154 int64_t display_id_; 156 ui::Layer* screen_rotation_container_layer_;
155 157
156 // For current slow rotation animation, there are two states |ROTATING| and 158 // For current slow rotation animation, there are two states |ROTATING| and
157 // |IDLE|. For the smooth rotation animation, we need to send copy request 159 // |IDLE|. For the smooth rotation animation, we need to send copy request
158 // and get copy result before animating. 160 // and get copy result before animating.
159 enum ScreenRotationState { 161 enum ScreenRotationState {
160 COPY_REQUESTED, 162 COPY_REQUESTED,
161 ROTATING, 163 ROTATING,
162 IDLE, 164 IDLE,
163 }; 165 };
164 ScreenRotationState screen_rotation_state_; 166 ScreenRotationState screen_rotation_state_;
165 167
166 // Rotation request id, used to ignore copy request callback if we decide to 168 // Rotation request id, used to ignore copy request callback if we decide to
167 // cancel the previous rotation request. 169 // cancel the previous rotation request.
168 int64_t rotation_request_id_; 170 int64_t rotation_request_id_;
169 171
170 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; 172 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_;
171 // Only set in unittest to disable animation timers. 173 // Only set in unittest to disable animation timers.
172 bool disable_animation_timers_for_test_; 174 bool disable_animation_timers_for_test_;
173 base::ObserverList<ScreenRotationAnimatorObserver> 175 base::ObserverList<ScreenRotationAnimatorObserver>
174 screen_rotation_animator_observers_; 176 screen_rotation_animator_observers_;
175 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; 177 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
176 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_; 178 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_;
177 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_; 179 std::unique_ptr<ui::LayerTreeOwner> mask_layer_tree_owner_;
178 std::unique_ptr<ScreenRotationRequest> last_pending_request_; 180 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
179 bool has_switch_ash_disable_smooth_screen_rotation_; 181 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_; 182 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_;
183 183
184 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); 184 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator);
185 }; 185 };
186 186
187 } // namespace ash 187 } // namespace ash
188 188
189 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 189 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
OLDNEW
« no previous file with comments | « ash/display/display_configuration_controller_unittest.cc ('k') | ash/rotator/screen_rotation_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698