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

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

Issue 2771713004: Adds UMA for screen rotation animation smoothness. (Closed)
Patch Set: 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
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/lazy_instance.h"
varkha 2017/03/24 02:50:25 Not necessary?
wutao 2017/03/24 06:12:38 Removed.
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/metrics/histogram_macros.h"
17 #include "base/time/time.h" 19 #include "base/time/time.h"
18 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
19 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
20 #include "ui/compositor/layer_animation_observer.h" 22 #include "ui/compositor/layer_animation_observer.h"
21 #include "ui/compositor/layer_animation_sequence.h" 23 #include "ui/compositor/layer_animation_sequence.h"
22 #include "ui/compositor/layer_animator.h" 24 #include "ui/compositor/layer_animator.h"
23 #include "ui/compositor/layer_owner.h" 25 #include "ui/compositor/layer_owner.h"
24 #include "ui/compositor/layer_tree_owner.h" 26 #include "ui/compositor/layer_tree_owner.h"
25 #include "ui/display/display.h" 27 #include "ui/display/display.h"
26 #include "ui/display/manager/display_manager.h" 28 #include "ui/display/manager/display_manager.h"
(...skipping 13 matching lines...) Expand all
40 // The number of degrees that the rotation animations animate through. 42 // The number of degrees that the rotation animations animate through.
41 const int kRotationDegrees = 20; 43 const int kRotationDegrees = 20;
42 44
43 // The time it takes for the rotation animations to run. 45 // The time it takes for the rotation animations to run.
44 const int kRotationDurationInMs = 250; 46 const int kRotationDurationInMs = 250;
45 47
46 // The rotation factors. 48 // The rotation factors.
47 const int kCounterClockWiseRotationFactor = 1; 49 const int kCounterClockWiseRotationFactor = 1;
48 const int kClockWiseRotationFactor = -1; 50 const int kClockWiseRotationFactor = -1;
49 51
52 // The percentage histogram boundary.
53 const int kPercentage_MIN = 1;
54 const int kPercentage_MAX = 101;
55
50 // Aborts the active animations of the layer, and recurses upon its child 56 // Aborts the active animations of the layer, and recurses upon its child
51 // layers. 57 // layers.
52 void AbortAnimations(ui::Layer* layer) { 58 void AbortAnimations(ui::Layer* layer) {
53 for (ui::Layer* child_layer : layer->children()) 59 for (ui::Layer* child_layer : layer->children())
54 AbortAnimations(child_layer); 60 AbortAnimations(child_layer);
55 layer->GetAnimator()->AbortAllAnimations(); 61 layer->GetAnimator()->AbortAllAnimations();
56 } 62 }
57 63
58 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) { 64 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) {
59 return Shell::GetInstance() 65 return Shell::GetInstance()
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } // namespace 176 } // namespace
171 177
172 struct ScreenRotationAnimator::ScreenRotationRequest { 178 struct ScreenRotationAnimator::ScreenRotationRequest {
173 ScreenRotationRequest(display::Display::Rotation to_rotation, 179 ScreenRotationRequest(display::Display::Rotation to_rotation,
174 display::Display::RotationSource from_source) 180 display::Display::RotationSource from_source)
175 : new_rotation(to_rotation), source(from_source) {} 181 : new_rotation(to_rotation), source(from_source) {}
176 display::Display::Rotation new_rotation; 182 display::Display::Rotation new_rotation;
177 display::Display::RotationSource source; 183 display::Display::RotationSource source;
178 }; 184 };
179 185
186 class ScreenRotationAnimator::ScreenRotationAnimationMetricsReporter
187 : public ui::AnimationMetricsReporter {
188 void Report(int value) override {
189 base::LinearHistogram::FactoryGet(
190 "Ash.Rotator.ScreenRotationAnimationSmoothness", kPercentage_MIN,
varkha 2017/03/24 02:50:25 Suggestion: how about "Ash.Rotation.AnimationSmoot
wutao 2017/03/24 06:12:38 Done.
191 kPercentage_MAX, kPercentage_MAX + 1,
192 base::HistogramBase::kUmaTargetedHistogramFlag)
193 ->Add(value);
varkha 2017/03/24 02:50:25 nit: should the line above be indented?
wutao 2017/03/24 06:12:38 git cl format made this.
194 }
195 };
196
180 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) 197 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
181 : display_id_(display_id), 198 : display_id_(display_id),
182 is_rotating_(false), 199 is_rotating_(false),
183 disable_animation_timers_for_test_(false), 200 disable_animation_timers_for_test_(false),
184 weak_factory_(this) {} 201 weak_factory_(this) {
202 metrics_reporter_ =
203 base::MakeUnique<ScreenRotationAnimationMetricsReporter>();
varkha 2017/03/24 02:50:25 This could be handled in the initializer list. Als
varkha 2017/03/24 03:01:33 One maybe possible scenario to consider is when yo
wutao 2017/03/24 06:12:38 Tried to increase the animation duration and close
wutao 2017/03/24 06:12:38 Moved to initializer list. Good observation. |ani
varkha 2017/03/24 15:08:47 The lifetime part is subtle. Can you please add a
204 }
185 205
186 ScreenRotationAnimator::~ScreenRotationAnimator() {} 206 ScreenRotationAnimator::~ScreenRotationAnimator() {}
187 207
188 void ScreenRotationAnimator::AnimateRotation( 208 void ScreenRotationAnimator::AnimateRotation(
189 std::unique_ptr<ScreenRotationRequest> rotation_request) { 209 std::unique_ptr<ScreenRotationRequest> rotation_request) {
190 aura::Window* root_window = GetRootWindow(display_id_); 210 aura::Window* root_window = GetRootWindow(display_id_);
191 211
192 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); 212 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds();
193 213
194 const int rotation_factor = GetRotationFactor( 214 const int rotation_factor = GetRotationFactor(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 291 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
272 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 292 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
273 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); 293 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation));
274 // Add an observer so that the cloned layers can be cleaned up with the 294 // Add an observer so that the cloned layers can be cleaned up with the
275 // animation completes/aborts. 295 // animation completes/aborts.
276 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); 296 animation_sequence->AddObserver(old_layer_cleanup_observer.release());
277 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to 297 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to
278 // control the animation. 298 // control the animation.
279 if (disable_animation_timers_for_test_) 299 if (disable_animation_timers_for_test_)
280 animator->set_disable_timer_for_test(true); 300 animator->set_disable_timer_for_test(true);
301 animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get());
281 animator->StartAnimation(animation_sequence.release()); 302 animator->StartAnimation(animation_sequence.release());
282 303
283 rotation_request.reset(); 304 rotation_request.reset();
284 } 305 }
285 306
286 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, 307 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation,
287 display::Display::RotationSource source) { 308 display::Display::RotationSource source) {
288 if (GetCurrentScreenRotation(display_id_) == new_rotation) 309 if (GetCurrentScreenRotation(display_id_) == new_rotation)
289 return; 310 return;
290 311
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (child_layer == old_layer_tree_owner_->root()) 369 if (child_layer == old_layer_tree_owner_->root())
349 continue; 370 continue;
350 371
351 child_layer->GetAnimator()->StopAnimating(); 372 child_layer->GetAnimator()->StopAnimating();
352 } 373 }
353 374
354 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); 375 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
355 } 376 }
356 377
357 } // namespace ash 378 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698