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

Side by Side Diff: ui/views/animation/flood_fill_ink_drop_ripple.cc

Issue 2631333002: [animations] Adds metrics for jank on selected layer animations (Closed)
Patch Set: Adds UMA reporting for ripples and overview mode (committed frames) Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/views/animation/flood_fill_ink_drop_ripple.h" 5 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/lazy_instance.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram_macros.h"
10 #include "third_party/skia/include/core/SkColor.h" 12 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_animation_sequence.h" 14 #include "ui/compositor/layer_animation_sequence.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h" 15 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/geometry/point_conversions.h" 16 #include "ui/gfx/geometry/point_conversions.h"
15 #include "ui/gfx/geometry/vector2d_f.h" 17 #include "ui/gfx/geometry/vector2d_f.h"
16 18
17 namespace { 19 namespace {
18 20
19 // The minimum radius to use when scaling the painted layers. Smaller values 21 // The minimum radius to use when scaling the painted layers. Smaller values
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 const gfx::Insets& clip_insets) { 108 const gfx::Insets& clip_insets) {
107 gfx::Rect clip_bounds(host_size); 109 gfx::Rect clip_bounds(host_size);
108 clip_bounds.Inset(clip_insets); 110 clip_bounds.Inset(clip_insets);
109 return clip_bounds; 111 return clip_bounds;
110 } 112 }
111 113
112 float CalculateCircleLayerRadius(const gfx::Rect& clip_bounds) { 114 float CalculateCircleLayerRadius(const gfx::Rect& clip_bounds) {
113 return std::max(clip_bounds.width(), clip_bounds.height()) / 2.f; 115 return std::max(clip_bounds.width(), clip_bounds.height()) / 2.f;
114 } 116 }
115 117
118 class FloodRippleMetricsReporter : public ui::AnimationMetricsReporter {
119 void Report(int value) override {
120 UMA_HISTOGRAM_PERCENTAGE("Views.AnimationSmoothness.FloodFillRipple",
bruthig 2017/01/24 15:56:30 I'm not sure how helpful it will be to get an aggr
varkha 2017/01/24 20:23:25 I thought of those more as examples to use the new
121 value);
122 }
123 };
124 base::LazyInstance<FloodRippleMetricsReporter>::Leaky g_reporter =
bruthig 2017/01/24 15:56:30 Do these really need to be global state? Would an
varkha 2017/01/24 20:23:25 Chatted offline about it. I think so far with a ve
125 LAZY_INSTANCE_INITIALIZER;
126
116 } // namespace 127 } // namespace
117 128
118 namespace views { 129 namespace views {
119 130
120 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size, 131 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size,
121 const gfx::Insets& clip_insets, 132 const gfx::Insets& clip_insets,
122 const gfx::Point& center_point, 133 const gfx::Point& center_point,
123 SkColor color, 134 SkColor color,
124 float visible_opacity) 135 float visible_opacity)
125 : clip_insets_(clip_insets), 136 : clip_insets_(clip_insets),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 331
321 std::unique_ptr<ui::LayerAnimationElement> element = 332 std::unique_ptr<ui::LayerAnimationElement> element =
322 ui::LayerAnimationElement::CreateTransformElement(transform, duration); 333 ui::LayerAnimationElement::CreateTransformElement(transform, duration);
323 334
324 ui::LayerAnimationSequence* sequence = 335 ui::LayerAnimationSequence* sequence =
325 new ui::LayerAnimationSequence(std::move(element)); 336 new ui::LayerAnimationSequence(std::move(element));
326 337
327 if (animation_observer) 338 if (animation_observer)
328 sequence->AddObserver(animation_observer); 339 sequence->AddObserver(animation_observer);
329 340
341 sequence->SetAnimationMetricsReporter(g_reporter.Pointer());
330 animator->StartAnimation(sequence); 342 animator->StartAnimation(sequence);
331 } 343 }
332 344
333 void FloodFillInkDropRipple::PauseTransformAnimation( 345 void FloodFillInkDropRipple::PauseTransformAnimation(
334 base::TimeDelta duration, 346 base::TimeDelta duration,
335 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 347 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
336 ui::LayerAnimationObserver* observer) { 348 ui::LayerAnimationObserver* observer) {
337 ui::LayerAnimator* animator = painted_layer_.GetAnimator(); 349 ui::LayerAnimator* animator = painted_layer_.GetAnimator();
338 ui::ScopedLayerAnimationSettings animation(animator); 350 ui::ScopedLayerAnimationSettings animation(animator);
339 animation.SetPreemptionStrategy(preemption_strategy); 351 animation.SetPreemptionStrategy(preemption_strategy);
340 352
341 std::unique_ptr<ui::LayerAnimationElement> element = 353 std::unique_ptr<ui::LayerAnimationElement> element =
342 ui::LayerAnimationElement::CreatePauseElement( 354 ui::LayerAnimationElement::CreatePauseElement(
343 ui::LayerAnimationElement::TRANSFORM, duration); 355 ui::LayerAnimationElement::TRANSFORM, duration);
344 356
345 ui::LayerAnimationSequence* sequence = 357 ui::LayerAnimationSequence* sequence =
346 new ui::LayerAnimationSequence(std::move(element)); 358 new ui::LayerAnimationSequence(std::move(element));
347 359
348 if (observer) 360 if (observer)
349 sequence->AddObserver(observer); 361 sequence->AddObserver(observer);
350 362
363 sequence->SetAnimationMetricsReporter(g_reporter.Pointer());
351 animator->StartAnimation(sequence); 364 animator->StartAnimation(sequence);
352 } 365 }
353 366
354 void FloodFillInkDropRipple::SetOpacity(float opacity) { 367 void FloodFillInkDropRipple::SetOpacity(float opacity) {
355 root_layer_.SetOpacity(opacity); 368 root_layer_.SetOpacity(opacity);
356 } 369 }
357 370
358 void FloodFillInkDropRipple::AnimateToOpacity( 371 void FloodFillInkDropRipple::AnimateToOpacity(
359 float opacity, 372 float opacity,
360 base::TimeDelta duration, 373 base::TimeDelta duration,
361 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 374 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
362 gfx::Tween::Type tween, 375 gfx::Tween::Type tween,
363 ui::LayerAnimationObserver* animation_observer) { 376 ui::LayerAnimationObserver* animation_observer) {
364 ui::LayerAnimator* animator = root_layer_.GetAnimator(); 377 ui::LayerAnimator* animator = root_layer_.GetAnimator();
365 ui::ScopedLayerAnimationSettings animation_settings(animator); 378 ui::ScopedLayerAnimationSettings animation_settings(animator);
366 animation_settings.SetPreemptionStrategy(preemption_strategy); 379 animation_settings.SetPreemptionStrategy(preemption_strategy);
367 animation_settings.SetTweenType(tween); 380 animation_settings.SetTweenType(tween);
368 std::unique_ptr<ui::LayerAnimationElement> animation_element = 381 std::unique_ptr<ui::LayerAnimationElement> animation_element =
369 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); 382 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration);
370 ui::LayerAnimationSequence* animation_sequence = 383 ui::LayerAnimationSequence* animation_sequence =
371 new ui::LayerAnimationSequence(std::move(animation_element)); 384 new ui::LayerAnimationSequence(std::move(animation_element));
372 385
373 if (animation_observer) 386 if (animation_observer)
374 animation_sequence->AddObserver(animation_observer); 387 animation_sequence->AddObserver(animation_observer);
375 388
389 animation_sequence->SetAnimationMetricsReporter(g_reporter.Pointer());
376 animator->StartAnimation(animation_sequence); 390 animator->StartAnimation(animation_sequence);
377 } 391 }
378 392
379 void FloodFillInkDropRipple::PauseOpacityAnimation( 393 void FloodFillInkDropRipple::PauseOpacityAnimation(
380 base::TimeDelta duration, 394 base::TimeDelta duration,
381 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 395 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
382 ui::LayerAnimationObserver* observer) { 396 ui::LayerAnimationObserver* observer) {
383 ui::LayerAnimator* animator = root_layer_.GetAnimator(); 397 ui::LayerAnimator* animator = root_layer_.GetAnimator();
384 ui::ScopedLayerAnimationSettings animation(animator); 398 ui::ScopedLayerAnimationSettings animation(animator);
385 animation.SetPreemptionStrategy(preemption_strategy); 399 animation.SetPreemptionStrategy(preemption_strategy);
386 400
387 std::unique_ptr<ui::LayerAnimationElement> element = 401 std::unique_ptr<ui::LayerAnimationElement> element =
388 ui::LayerAnimationElement::CreatePauseElement( 402 ui::LayerAnimationElement::CreatePauseElement(
389 ui::LayerAnimationElement::OPACITY, duration); 403 ui::LayerAnimationElement::OPACITY, duration);
390 404
391 ui::LayerAnimationSequence* sequence = 405 ui::LayerAnimationSequence* sequence =
392 new ui::LayerAnimationSequence(std::move(element)); 406 new ui::LayerAnimationSequence(std::move(element));
393 407
394 if (observer) 408 if (observer)
395 sequence->AddObserver(observer); 409 sequence->AddObserver(observer);
396 410
411 sequence->SetAnimationMetricsReporter(g_reporter.Pointer());
397 animator->StartAnimation(sequence); 412 animator->StartAnimation(sequence);
398 } 413 }
399 414
400 gfx::Transform FloodFillInkDropRipple::CalculateTransform( 415 gfx::Transform FloodFillInkDropRipple::CalculateTransform(
401 float target_radius) const { 416 float target_radius) const {
402 const float target_scale = target_radius / circle_layer_delegate_.radius(); 417 const float target_scale = target_radius / circle_layer_delegate_.radius();
403 418
404 gfx::Transform transform = gfx::Transform(); 419 gfx::Transform transform = gfx::Transform();
405 transform.Translate(center_point_.x() - root_layer_.bounds().x(), 420 transform.Translate(center_point_.x() - root_layer_.bounds().x(),
406 center_point_.y() - root_layer_.bounds().y()); 421 center_point_.y() - root_layer_.bounds().y());
(...skipping 20 matching lines...) Expand all
427 (bounds.bottom_right() - point).Length(); 442 (bounds.bottom_right() - point).Length();
428 443
429 float largest_distance = 444 float largest_distance =
430 std::max(distance_to_top_left, distance_to_top_right); 445 std::max(distance_to_top_left, distance_to_top_right);
431 largest_distance = std::max(largest_distance, distance_to_bottom_left); 446 largest_distance = std::max(largest_distance, distance_to_bottom_left);
432 largest_distance = std::max(largest_distance, distance_to_bottom_right); 447 largest_distance = std::max(largest_distance, distance_to_bottom_right);
433 return largest_distance; 448 return largest_distance;
434 } 449 }
435 450
436 } // namespace views 451 } // namespace views
OLDNEW
« no previous file with comments | « ui/compositor/test/test_layer_animation_delegate.cc ('k') | ui/views/animation/square_ink_drop_ripple.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698