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

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

Issue 2790583004: Add second copy request after screen rotation to flatten the layers in animation. (Closed)
Patch Set: Add new tests and add doc to handle new rotation request in |Rotate()|. Created 3 years, 8 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 {
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;
29 class LayerOwner;
24 class LayerTreeOwner; 30 class LayerTreeOwner;
25 } // namespace ui 31 } // namespace ui
26 32
27 namespace ash { 33 namespace ash {
28 namespace test { 34 namespace test {
29 class ScreenRotationAnimatorTestApi; 35 class ScreenRotationAnimatorTestApi;
30 } // namespace test 36 } // namespace test
31 37
32 class ScreenRotationAnimatorObserver; 38 class ScreenRotationAnimatorObserver;
33 39
(...skipping 24 matching lines...) Expand all
58 // When screen rotation animation is ended or aborted, calls |Rotate()| with 64 // When screen rotation animation is ended or aborted, calls |Rotate()| with
59 // the pending rotation request if the request queue is not empty. Otherwise 65 // the pending rotation request if the request queue is not empty. Otherwise
60 // notifies |screen_rotation_animator_observer_|. 66 // notifies |screen_rotation_animator_observer_|.
61 void ProcessAnimationQueue(); 67 void ProcessAnimationQueue();
62 68
63 protected: 69 protected:
64 using CopyCallback = 70 using CopyCallback =
65 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>; 71 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>;
66 struct ScreenRotationRequest { 72 struct ScreenRotationRequest {
67 ScreenRotationRequest(int64_t id, 73 ScreenRotationRequest(int64_t id,
74 display::Display::Rotation from_rotation,
68 display::Display::Rotation to_rotation, 75 display::Display::Rotation to_rotation,
69 display::Display::RotationSource from_source) 76 display::Display::RotationSource from_source)
70 : id(id), new_rotation(to_rotation), source(from_source) {} 77 : id(id),
78 old_rotation(from_rotation),
79 new_rotation(to_rotation),
80 source(from_source) {}
71 int64_t id; 81 int64_t id;
82 display::Display::Rotation old_rotation;
72 display::Display::Rotation new_rotation; 83 display::Display::Rotation new_rotation;
73 display::Display::RotationSource source; 84 display::Display::RotationSource source;
74 }; 85 };
75 86
76 // This function can be overridden in unit test to test removing external 87 // This function can be overridden in unit test to test removing external
77 // display. 88 // display.
78 virtual CopyCallback CreateAfterCopyCallback( 89 virtual CopyCallback CreateAfterCopyCallbackBeforeRotation(
90 std::unique_ptr<ScreenRotationRequest> rotation_request);
91
92 // This function can be overridden in unit test to test removing external
93 // display.
94 virtual CopyCallback CreateAfterCopyCallbackAfterRotation(
79 std::unique_ptr<ScreenRotationRequest> rotation_request); 95 std::unique_ptr<ScreenRotationRequest> rotation_request);
80 96
81 private: 97 private:
82 friend class ash::test::ScreenRotationAnimatorTestApi; 98 friend class ash::test::ScreenRotationAnimatorTestApi;
83 99
84 void StartRotationAnimation( 100 void StartRotationAnimation(
85 std::unique_ptr<ScreenRotationRequest> rotation_request); 101 std::unique_ptr<ScreenRotationRequest> rotation_request);
86 102
87 // This is an asynchronous call to request copy output of root layer. 103 // The code path to start slow animation.
oshima 2017/04/18 18:32:25 nit: can you explain the difference in logic? (not
wutao 2017/04/18 19:56:58 Done.
88 void RequestCopyRootLayerAndAnimateRotation( 104 void StartSlowAnimation(
89 std::unique_ptr<ScreenRotationRequest> rotation_request); 105 std::unique_ptr<ScreenRotationRequest> rotation_request);
90 106
91 // The callback in |RequestCopyRootLayerAndAnimateRotation()|. 107 // A wrapper to call |display_manager| to set screen rotation and rotate the
92 void OnRootLayerCopiedBeforeRotation( 108 // |old_layer_tree| to the |old_rotation|.
109 void SetRotation(display::Display::Rotation old_rotation,
110 display::Display::Rotation new_rotation,
111 display::Display::RotationSource source);
112
113 // This is an asynchronous call to request copy output of root layer.
114 void RequestCopyScreenRotationContainerLayer(
115 std::unique_ptr<cc::CopyOutputRequest> copy_output_request);
116
117 // The callback in |RequestCopyScreenRotationContainerLayer()| before screen
118 // rotation.
119 void OnScreenRotationContainerLayerCopiedBeforeRotation(
93 std::unique_ptr<ScreenRotationRequest> rotation_request, 120 std::unique_ptr<ScreenRotationRequest> rotation_request,
94 std::unique_ptr<cc::CopyOutputResult> result); 121 std::unique_ptr<cc::CopyOutputResult> result);
95 122
96 // Recreates all |root_window| layers. 123 // The callback in |RequestCopyScreenRotationContainerLayer()| after screen
124 // rotation.
125 void OnScreenRotationContainerLayerCopiedAfterRotation(
126 std::unique_ptr<ScreenRotationRequest> rotation_request,
127 std::unique_ptr<cc::CopyOutputResult> result);
128
129 // Recreates all |root_window| layers and their layer tree owner.
97 void CreateOldLayerTree(); 130 void CreateOldLayerTree();
98 131
99 // Requests a copy of |root_window| root layer output. 132 // Creates a new layer and its layer tree owner from |CopyOutputResult|.
100 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result); 133 std::unique_ptr<ui::LayerTreeOwner> CopyLayerTree(
134 std::unique_ptr<cc::CopyOutputResult> result);
101 135
102 // Note: Only call this function when the |old_layer_tree_owner_| is set up 136 // Note: Only call this function when the |old_layer_tree_owner_| is set up
103 // properly. 137 // properly.
104 // Sets the screen orientation to |new_rotation| and animate the change. The 138 // Sets the screen orientation to |new_rotation| and animate the change. The
105 // animation will rotate the initial orientation's layer towards the new 139 // animation will rotate the initial orientation's layer towards the new
106 // orientation through |rotation_degrees| while fading out, and the new 140 // orientation through |rotation_degrees| while fading out, and the new
107 // orientation's layer will be rotated in to the |new_orientation| through 141 // orientation's layer will be rotated in to the |new_orientation| through
108 // |rotation_degrees| arc. 142 // |rotation_degrees| arc.
109 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); 143 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request);
110 144
111 void set_disable_animation_timers_for_test(bool disable_timers); 145 void set_disable_animation_timers_for_test(bool disable_timers) {
146 disable_animation_timers_for_test_ = disable_timers;
147 }
148
149 void set_switch_smooth_rotation_for_test(bool enable) {
150 has_switch_ash_enable_smooth_screen_rotation_ = enable;
151 }
112 152
113 void StopAnimating(); 153 void StopAnimating();
114 154
115 // The id of the display to rotate. 155 // The id of the display to rotate.
116 int64_t display_id_; 156 int64_t display_id_;
117 157
118 // For current slow rotation animation, there are two states |ROTATING| and 158 // For current slow rotation animation, there are two states |ROTATING| and
119 // |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
120 // and get copy result before animating. 160 // and get copy result before animating.
121 enum ScreenRotationState { 161 enum ScreenRotationState {
122 COPY_REQUESTED, 162 COPY_REQUESTED,
123 ROTATING, 163 ROTATING,
124 IDLE, 164 IDLE,
125 }; 165 };
126 ScreenRotationState screen_rotation_state_; 166 ScreenRotationState screen_rotation_state_;
127 167
128 // 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
129 // cancel the previous rotation request. 169 // cancel the previous rotation request.
130 int64_t rotation_request_id_; 170 int64_t rotation_request_id_;
131 171
132 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; 172 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_;
133 // Only set in unittest to disable animation timers. 173 // Only set in unittest to disable animation timers.
134 bool disable_animation_timers_for_test_; 174 bool disable_animation_timers_for_test_;
135 base::ObserverList<ScreenRotationAnimatorObserver> 175 base::ObserverList<ScreenRotationAnimatorObserver>
136 screen_rotation_animator_observers_; 176 screen_rotation_animator_observers_;
137 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; 177 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
178 std::unique_ptr<ui::LayerTreeOwner> new_layer_tree_owner_;
179 std::unique_ptr<ui::LayerOwner> black_mask_layer_owner_;
138 std::unique_ptr<ScreenRotationRequest> last_pending_request_; 180 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
181 bool has_switch_ash_enable_smooth_screen_rotation_;
182 aura::Window* root_window_;
183 ui::Layer* screen_rotation_container_layer_;
139 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; 184 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_;
140 185
141 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); 186 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator);
142 }; 187 };
143 188
144 } // namespace ash 189 } // namespace ash
145 190
146 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 191 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698