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

Side by Side Diff: ash/wm/window_animations.cc

Issue 2869263002: Add UMA for CrossFadeAnimation. (Closed)
Patch Set: Fix nits. Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wm/window_animations.h" 5 #include "ash/wm/window_animations.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "ash/shelf/wm_shelf.h" 12 #include "ash/shelf/wm_shelf.h"
13 #include "ash/wm/window_animation_types.h" 13 #include "ash/wm/window_animation_types.h"
14 #include "ash/wm/window_util.h" 14 #include "ash/wm/window_util.h"
15 #include "ash/wm/workspace_controller.h" 15 #include "ash/wm/workspace_controller.h"
16 #include "ash/wm_window.h" 16 #include "ash/wm_window.h"
17 #include "base/i18n/rtl.h" 17 #include "base/i18n/rtl.h"
18 #include "base/lazy_instance.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/histogram_macros.h"
20 #include "base/stl_util.h" 22 #include "base/stl_util.h"
21 #include "base/time/time.h" 23 #include "base/time/time.h"
22 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
24 #include "ui/aura/window_observer.h" 26 #include "ui/aura/window_observer.h"
25 #include "ui/base/class_property.h" 27 #include "ui/base/class_property.h"
26 #include "ui/compositor/compositor_observer.h" 28 #include "ui/compositor/compositor_observer.h"
27 #include "ui/compositor/layer.h" 29 #include "ui/compositor/layer.h"
28 #include "ui/compositor/layer_animation_observer.h" 30 #include "ui/compositor/layer_animation_observer.h"
29 #include "ui/compositor/layer_animation_sequence.h" 31 #include "ui/compositor/layer_animation_sequence.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // If the area didn't change, the animation is instantaneous. 79 // If the area didn't change, the animation is instantaneous.
78 if (delta_area == 0) 80 if (delta_area == 0)
79 return base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS); 81 return base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS);
80 82
81 float factor = static_cast<float>(delta_area) / static_cast<float>(max_area); 83 float factor = static_cast<float>(delta_area) / static_cast<float>(max_area);
82 const float kRange = kCrossFadeDurationMaxMs - kCrossFadeDurationMinMs; 84 const float kRange = kCrossFadeDurationMaxMs - kCrossFadeDurationMinMs;
83 return base::TimeDelta::FromMilliseconds( 85 return base::TimeDelta::FromMilliseconds(
84 Round64(kCrossFadeDurationMinMs + (factor * kRange))); 86 Round64(kCrossFadeDurationMinMs + (factor * kRange)));
85 } 87 }
86 88
89 class CrossFadeMetricsReporter : public ui::AnimationMetricsReporter {
90 public:
91 CrossFadeMetricsReporter() = default;
92 ~CrossFadeMetricsReporter() override = default;
93
94 void Report(int value) override {
95 UMA_HISTOGRAM_PERCENTAGE("Ash.Window.AnimationSmoothness.CrossFade", value);
96 }
97
98 private:
99 DISALLOW_COPY_AND_ASSIGN(CrossFadeMetricsReporter);
100 };
101
102 base::LazyInstance<CrossFadeMetricsReporter>::Leaky g_reporter_cross_fade =
103 LAZY_INSTANCE_INITIALIZER;
104
87 } // namespace 105 } // namespace
88 106
89 const int kCrossFadeDurationMS = 200; 107 const int kCrossFadeDurationMS = 200;
90 108
91 void AddLayerAnimationsForMinimize(aura::Window* window, bool show) { 109 void AddLayerAnimationsForMinimize(aura::Window* window, bool show) {
92 // Recalculate the transform at restore time since the launcher item may have 110 // Recalculate the transform at restore time since the launcher item may have
93 // moved while the window was minimized. 111 // moved while the window was minimized.
94 gfx::Rect bounds = window->bounds(); 112 gfx::Rect bounds = window->bounds();
95 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); 113 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window);
96 ::wm::ConvertRectFromScreen(window->parent(), &target_bounds); 114 ::wm::ConvertRectFromScreen(window->parent(), &target_bounds);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 ui::Layer* old_layer = old_layer_owner->root(); 330 ui::Layer* old_layer = old_layer_owner->root();
313 old_layer->GetAnimator()->StopAnimating(); 331 old_layer->GetAnimator()->StopAnimating();
314 old_layer->SetTransform(old_transform); 332 old_layer->SetTransform(old_transform);
315 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); 333 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator());
316 334
317 // Animation observer owns the old layer and deletes itself. 335 // Animation observer owns the old layer and deletes itself.
318 settings.AddObserver( 336 settings.AddObserver(
319 new CrossFadeObserver(window, std::move(old_layer_owner))); 337 new CrossFadeObserver(window, std::move(old_layer_owner)));
320 settings.SetTransitionDuration(duration); 338 settings.SetTransitionDuration(duration);
321 settings.SetTweenType(tween_type); 339 settings.SetTweenType(tween_type);
340 // Only add reporter to |old_layer|.
341 settings.SetAnimationMetricsReporter(g_reporter_cross_fade.Pointer());
322 gfx::Transform out_transform; 342 gfx::Transform out_transform;
323 float scale_x = static_cast<float>(new_bounds.width()) / 343 float scale_x = static_cast<float>(new_bounds.width()) /
324 static_cast<float>(old_bounds.width()); 344 static_cast<float>(old_bounds.width());
325 float scale_y = static_cast<float>(new_bounds.height()) / 345 float scale_y = static_cast<float>(new_bounds.height()) /
326 static_cast<float>(old_bounds.height()); 346 static_cast<float>(old_bounds.height());
327 out_transform.Translate(new_bounds.x() - old_bounds.x(), 347 out_transform.Translate(new_bounds.x() - old_bounds.x(),
328 new_bounds.y() - old_bounds.y()); 348 new_bounds.y() - old_bounds.y());
329 out_transform.Scale(scale_x, scale_y); 349 out_transform.Scale(scale_x, scale_y);
330 old_layer->SetTransform(out_transform); 350 old_layer->SetTransform(out_transform);
331 if (old_on_top) { 351 if (old_on_top) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 case SHELF_ALIGNMENT_LEFT: 471 case SHELF_ALIGNMENT_LEFT:
452 return gfx::Rect(work_area.x(), work_area.y(), 0, 0); 472 return gfx::Rect(work_area.x(), work_area.y(), 0, 0);
453 case SHELF_ALIGNMENT_RIGHT: 473 case SHELF_ALIGNMENT_RIGHT:
454 return gfx::Rect(work_area.right(), work_area.y(), 0, 0); 474 return gfx::Rect(work_area.right(), work_area.y(), 0, 0);
455 } 475 }
456 NOTREACHED(); 476 NOTREACHED();
457 return gfx::Rect(); 477 return gfx::Rect();
458 } 478 }
459 479
460 } // namespace ash 480 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/scoped_overview_animation_settings_aura.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698