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

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

Issue 2869263002: Add UMA for CrossFadeAnimation. (Closed)
Patch Set: 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 {
varkha 2017/05/12 15:14:25 There was a nit in a previous similar CL to define
wutao 2017/05/12 17:46:37 I kept copying from your first code. I will make c
90 void Report(int value) override {
91 UMA_HISTOGRAM_PERCENTAGE("Ash.Window.AnimationSmoothness.CrossFade", value);
92 }
93 };
94
95 base::LazyInstance<CrossFadeMetricsReporter>::Leaky g_reporter_cross_fade =
96 LAZY_INSTANCE_INITIALIZER;
97
87 } // namespace 98 } // namespace
88 99
89 const int kCrossFadeDurationMS = 200; 100 const int kCrossFadeDurationMS = 200;
90 101
91 void AddLayerAnimationsForMinimize(aura::Window* window, bool show) { 102 void AddLayerAnimationsForMinimize(aura::Window* window, bool show) {
92 // Recalculate the transform at restore time since the launcher item may have 103 // Recalculate the transform at restore time since the launcher item may have
93 // moved while the window was minimized. 104 // moved while the window was minimized.
94 gfx::Rect bounds = window->bounds(); 105 gfx::Rect bounds = window->bounds();
95 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); 106 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window);
96 ::wm::ConvertRectFromScreen(window->parent(), &target_bounds); 107 ::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(); 323 ui::Layer* old_layer = old_layer_owner->root();
313 old_layer->GetAnimator()->StopAnimating(); 324 old_layer->GetAnimator()->StopAnimating();
314 old_layer->SetTransform(old_transform); 325 old_layer->SetTransform(old_transform);
315 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); 326 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator());
316 327
317 // Animation observer owns the old layer and deletes itself. 328 // Animation observer owns the old layer and deletes itself.
318 settings.AddObserver( 329 settings.AddObserver(
319 new CrossFadeObserver(window, std::move(old_layer_owner))); 330 new CrossFadeObserver(window, std::move(old_layer_owner)));
320 settings.SetTransitionDuration(duration); 331 settings.SetTransitionDuration(duration);
321 settings.SetTweenType(tween_type); 332 settings.SetTweenType(tween_type);
333 // Only add reporter to |old_layer|.
334 settings.SetAnimationMetricsReporter(g_reporter_cross_fade.Pointer());
322 gfx::Transform out_transform; 335 gfx::Transform out_transform;
323 float scale_x = static_cast<float>(new_bounds.width()) / 336 float scale_x = static_cast<float>(new_bounds.width()) /
324 static_cast<float>(old_bounds.width()); 337 static_cast<float>(old_bounds.width());
325 float scale_y = static_cast<float>(new_bounds.height()) / 338 float scale_y = static_cast<float>(new_bounds.height()) /
326 static_cast<float>(old_bounds.height()); 339 static_cast<float>(old_bounds.height());
327 out_transform.Translate(new_bounds.x() - old_bounds.x(), 340 out_transform.Translate(new_bounds.x() - old_bounds.x(),
328 new_bounds.y() - old_bounds.y()); 341 new_bounds.y() - old_bounds.y());
329 out_transform.Scale(scale_x, scale_y); 342 out_transform.Scale(scale_x, scale_y);
330 old_layer->SetTransform(out_transform); 343 old_layer->SetTransform(out_transform);
331 if (old_on_top) { 344 if (old_on_top) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 case SHELF_ALIGNMENT_LEFT: 464 case SHELF_ALIGNMENT_LEFT:
452 return gfx::Rect(work_area.x(), work_area.y(), 0, 0); 465 return gfx::Rect(work_area.x(), work_area.y(), 0, 0);
453 case SHELF_ALIGNMENT_RIGHT: 466 case SHELF_ALIGNMENT_RIGHT:
454 return gfx::Rect(work_area.right(), work_area.y(), 0, 0); 467 return gfx::Rect(work_area.right(), work_area.y(), 0, 0);
455 } 468 }
456 NOTREACHED(); 469 NOTREACHED();
457 return gfx::Rect(); 470 return gfx::Rect();
458 } 471 }
459 472
460 } // namespace ash 473 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698