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

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

Issue 2771713004: Adds UMA for screen rotation animation smoothness. (Closed)
Patch Set: Adds histograms.xml. Created 3 years, 9 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 #include "ash/rotator/screen_rotation_animator.h" 5 #include "ash/rotator/screen_rotation_animator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/display/window_tree_host_manager.h" 11 #include "ash/display/window_tree_host_manager.h"
12 #include "ash/rotator/screen_rotation_animation.h" 12 #include "ash/rotator/screen_rotation_animation.h"
13 #include "ash/rotator/screen_rotation_animator_observer.h" 13 #include "ash/rotator/screen_rotation_animator_observer.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
20 #include "ui/compositor/layer_animation_observer.h" 21 #include "ui/compositor/layer_animation_observer.h"
21 #include "ui/compositor/layer_animation_sequence.h" 22 #include "ui/compositor/layer_animation_sequence.h"
22 #include "ui/compositor/layer_animator.h" 23 #include "ui/compositor/layer_animator.h"
23 #include "ui/compositor/layer_owner.h" 24 #include "ui/compositor/layer_owner.h"
24 #include "ui/compositor/layer_tree_owner.h" 25 #include "ui/compositor/layer_tree_owner.h"
25 #include "ui/display/display.h" 26 #include "ui/display/display.h"
26 #include "ui/display/manager/display_manager.h" 27 #include "ui/display/manager/display_manager.h"
(...skipping 13 matching lines...) Expand all
40 // The number of degrees that the rotation animations animate through. 41 // The number of degrees that the rotation animations animate through.
41 const int kRotationDegrees = 20; 42 const int kRotationDegrees = 20;
42 43
43 // The time it takes for the rotation animations to run. 44 // The time it takes for the rotation animations to run.
44 const int kRotationDurationInMs = 250; 45 const int kRotationDurationInMs = 250;
45 46
46 // The rotation factors. 47 // The rotation factors.
47 const int kCounterClockWiseRotationFactor = 1; 48 const int kCounterClockWiseRotationFactor = 1;
48 const int kClockWiseRotationFactor = -1; 49 const int kClockWiseRotationFactor = -1;
49 50
51 // The percentage histogram boundary.
52 const int kPercentage_MIN = 1;
53 const int kPercentage_MAX = 101;
varkha 2017/03/24 20:38:21 Don't need those if you use UMA_HISTOGRAM_PERCENTA
wutao 2017/03/24 21:48:24 Will remove.
54
50 // Aborts the active animations of the layer, and recurses upon its child 55 // Aborts the active animations of the layer, and recurses upon its child
51 // layers. 56 // layers.
52 void AbortAnimations(ui::Layer* layer) { 57 void AbortAnimations(ui::Layer* layer) {
53 for (ui::Layer* child_layer : layer->children()) 58 for (ui::Layer* child_layer : layer->children())
54 AbortAnimations(child_layer); 59 AbortAnimations(child_layer);
55 layer->GetAnimator()->AbortAllAnimations(); 60 layer->GetAnimator()->AbortAllAnimations();
56 } 61 }
57 62
58 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) { 63 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) {
59 return Shell::GetInstance() 64 return Shell::GetInstance()
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 LayerCleanupObserver::~LayerCleanupObserver() { 141 LayerCleanupObserver::~LayerCleanupObserver() {
137 // We must eplicitly detach from |sequence_| because we return true from 142 // We must eplicitly detach from |sequence_| because we return true from
138 // RequiresNotificationWhenAnimatorDestroyed. 143 // RequiresNotificationWhenAnimatorDestroyed.
139 if (sequence_) 144 if (sequence_)
140 sequence_->RemoveObserver(this); 145 sequence_->RemoveObserver(this);
141 } 146 }
142 147
143 void LayerCleanupObserver::OnLayerAnimationEnded( 148 void LayerCleanupObserver::OnLayerAnimationEnded(
144 ui::LayerAnimationSequence* sequence) { 149 ui::LayerAnimationSequence* sequence) {
145 if (animator_) 150 if (animator_)
146 animator_->OnLayerAnimationEnded(); 151 animator_->ProcessAnimationQueue();
147 152
148 delete this; 153 delete this;
149 } 154 }
150 155
151 void LayerCleanupObserver::OnLayerAnimationAborted( 156 void LayerCleanupObserver::OnLayerAnimationAborted(
152 ui::LayerAnimationSequence* sequence) { 157 ui::LayerAnimationSequence* sequence) {
153 if (animator_) 158 if (animator_)
154 animator_->OnLayerAnimationAborted(); 159 animator_->ProcessAnimationQueue();
155 160
156 delete this; 161 delete this;
157 } 162 }
158 163
159 void LayerCleanupObserver::OnAttachedToSequence( 164 void LayerCleanupObserver::OnAttachedToSequence(
160 ui::LayerAnimationSequence* sequence) { 165 ui::LayerAnimationSequence* sequence) {
161 sequence_ = sequence; 166 sequence_ = sequence;
162 } 167 }
163 168
164 void LayerCleanupObserver::OnDetachedFromSequence( 169 void LayerCleanupObserver::OnDetachedFromSequence(
165 ui::LayerAnimationSequence* sequence) { 170 ui::LayerAnimationSequence* sequence) {
166 DCHECK_EQ(sequence, sequence_); 171 DCHECK_EQ(sequence, sequence_);
167 sequence_ = nullptr; 172 sequence_ = nullptr;
168 } 173 }
169 174
170 } // namespace 175 } // namespace
171 176
172 struct ScreenRotationAnimator::ScreenRotationRequest { 177 struct ScreenRotationAnimator::ScreenRotationRequest {
173 ScreenRotationRequest(display::Display::Rotation to_rotation, 178 ScreenRotationRequest(display::Display::Rotation to_rotation,
174 display::Display::RotationSource from_source) 179 display::Display::RotationSource from_source)
175 : new_rotation(to_rotation), source(from_source) {} 180 : new_rotation(to_rotation), source(from_source) {}
176 display::Display::Rotation new_rotation; 181 display::Display::Rotation new_rotation;
177 display::Display::RotationSource source; 182 display::Display::RotationSource source;
178 }; 183 };
179 184
185 class ScreenRotationAnimator::ScreenRotationAnimationMetricsReporter
186 : public ui::AnimationMetricsReporter {
187 void Report(int value) override {
188 base::LinearHistogram::FactoryGet(
Mark P 2017/03/24 20:32:41 Maybe I haven't thought about this enough, but why
varkha 2017/03/24 20:38:21 UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSm
wutao 2017/03/24 21:48:24 Thanks.
wutao 2017/03/24 21:48:24 I was confused by the use case of UMA_HISTOGRAM_PE
189 "Ash.Rotation.AnimationSmoothness", kPercentage_MIN, kPercentage_MAX,
190 kPercentage_MAX + 1, base::HistogramBase::kUmaTargetedHistogramFlag)
191 ->Add(value);
192 }
193 };
194
180 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) 195 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
181 : display_id_(display_id), 196 : display_id_(display_id),
182 is_rotating_(false), 197 is_rotating_(false),
198 metrics_reporter_(
199 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()),
183 disable_animation_timers_for_test_(false), 200 disable_animation_timers_for_test_(false),
184 weak_factory_(this) {} 201 weak_factory_(this) {}
185 202
186 ScreenRotationAnimator::~ScreenRotationAnimator() {} 203 ScreenRotationAnimator::~ScreenRotationAnimator() {
204 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from
205 // calling a method on the |animator_|.
206 weak_factory_.InvalidateWeakPtrs();
207
208 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in
209 // order to make sure |metrics_reporter_| outlives the attached animation
210 // sequence.
211 old_layer_tree_owner_.reset();
212 metrics_reporter_.reset();
213 }
187 214
188 void ScreenRotationAnimator::AnimateRotation( 215 void ScreenRotationAnimator::AnimateRotation(
189 std::unique_ptr<ScreenRotationRequest> rotation_request) { 216 std::unique_ptr<ScreenRotationRequest> rotation_request) {
190 aura::Window* root_window = GetRootWindow(display_id_); 217 aura::Window* root_window = GetRootWindow(display_id_);
191 218
192 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); 219 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds();
193 220
194 const int rotation_factor = GetRotationFactor( 221 const int rotation_factor = GetRotationFactor(
195 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); 222 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation);
196 223
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 298 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
272 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 299 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
273 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); 300 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation));
274 // Add an observer so that the cloned layers can be cleaned up with the 301 // Add an observer so that the cloned layers can be cleaned up with the
275 // animation completes/aborts. 302 // animation completes/aborts.
276 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); 303 animation_sequence->AddObserver(old_layer_cleanup_observer.release());
277 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to 304 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to
278 // control the animation. 305 // control the animation.
279 if (disable_animation_timers_for_test_) 306 if (disable_animation_timers_for_test_)
280 animator->set_disable_timer_for_test(true); 307 animator->set_disable_timer_for_test(true);
308 animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get());
281 animator->StartAnimation(animation_sequence.release()); 309 animator->StartAnimation(animation_sequence.release());
282 310
283 rotation_request.reset(); 311 rotation_request.reset();
284 } 312 }
285 313
286 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, 314 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation,
287 display::Display::RotationSource source) { 315 display::Display::RotationSource source) {
288 if (GetCurrentScreenRotation(display_id_) == new_rotation) 316 if (GetCurrentScreenRotation(display_id_) == new_rotation)
289 return; 317 return;
290 318
(...skipping 15 matching lines...) Expand all
306 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( 334 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver(
307 ScreenRotationAnimatorObserver* observer) { 335 ScreenRotationAnimatorObserver* observer) {
308 screen_rotation_animator_observers_.AddObserver(observer); 336 screen_rotation_animator_observers_.AddObserver(observer);
309 } 337 }
310 338
311 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( 339 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver(
312 ScreenRotationAnimatorObserver* observer) { 340 ScreenRotationAnimatorObserver* observer) {
313 screen_rotation_animator_observers_.RemoveObserver(observer); 341 screen_rotation_animator_observers_.RemoveObserver(observer);
314 } 342 }
315 343
316 void ScreenRotationAnimator::OnLayerAnimationEnded() {
317 ProcessAnimationQueue();
318 }
319
320 void ScreenRotationAnimator::OnLayerAnimationAborted() {
321 AbortAnimations(old_layer_tree_owner_->root());
322 ProcessAnimationQueue();
323 }
324
325 void ScreenRotationAnimator::ProcessAnimationQueue() { 344 void ScreenRotationAnimator::ProcessAnimationQueue() {
326 is_rotating_ = false; 345 is_rotating_ = false;
327 old_layer_tree_owner_.reset(); 346 old_layer_tree_owner_.reset();
328 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { 347 if (last_pending_request_ && IsDisplayIdValid(display_id_)) {
329 std::unique_ptr<ScreenRotationRequest> rotation_request = 348 std::unique_ptr<ScreenRotationRequest> rotation_request =
330 std::move(last_pending_request_); 349 std::move(last_pending_request_);
331 Rotate(rotation_request->new_rotation, rotation_request->source); 350 Rotate(rotation_request->new_rotation, rotation_request->source);
332 rotation_request.reset(); 351 rotation_request.reset();
333 return; 352 return;
334 } 353 }
(...skipping 13 matching lines...) Expand all
348 if (child_layer == old_layer_tree_owner_->root()) 367 if (child_layer == old_layer_tree_owner_->root())
349 continue; 368 continue;
350 369
351 child_layer->GetAnimator()->StopAnimating(); 370 child_layer->GetAnimator()->StopAnimating();
352 } 371 }
353 372
354 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); 373 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
355 } 374 }
356 375
357 } // namespace ash 376 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698