| OLD | NEW |
| 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 Loading... |
| 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", |
| 121 value); |
| 122 } |
| 123 }; |
| 124 |
| 125 base::LazyInstance<FloodRippleMetricsReporter>::Leaky g_reporter = |
| 126 LAZY_INSTANCE_INITIALIZER; |
| 127 |
| 116 } // namespace | 128 } // namespace |
| 117 | 129 |
| 118 namespace views { | 130 namespace views { |
| 119 | 131 |
| 120 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size, | 132 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size, |
| 121 const gfx::Insets& clip_insets, | 133 const gfx::Insets& clip_insets, |
| 122 const gfx::Point& center_point, | 134 const gfx::Point& center_point, |
| 123 SkColor color, | 135 SkColor color, |
| 124 float visible_opacity) | 136 float visible_opacity) |
| 125 : clip_insets_(clip_insets), | 137 : clip_insets_(clip_insets), |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 328 |
| 317 std::unique_ptr<ui::LayerAnimationElement> element = | 329 std::unique_ptr<ui::LayerAnimationElement> element = |
| 318 ui::LayerAnimationElement::CreateTransformElement(transform, duration); | 330 ui::LayerAnimationElement::CreateTransformElement(transform, duration); |
| 319 | 331 |
| 320 ui::LayerAnimationSequence* sequence = | 332 ui::LayerAnimationSequence* sequence = |
| 321 new ui::LayerAnimationSequence(std::move(element)); | 333 new ui::LayerAnimationSequence(std::move(element)); |
| 322 | 334 |
| 323 if (animation_observer) | 335 if (animation_observer) |
| 324 sequence->AddObserver(animation_observer); | 336 sequence->AddObserver(animation_observer); |
| 325 | 337 |
| 338 sequence->SetAnimationMetricsReporter(g_reporter.Pointer()); |
| 326 animator->StartAnimation(sequence); | 339 animator->StartAnimation(sequence); |
| 327 } | 340 } |
| 328 | 341 |
| 329 void FloodFillInkDropRipple::PauseTransformAnimation( | 342 void FloodFillInkDropRipple::PauseTransformAnimation( |
| 330 base::TimeDelta duration, | 343 base::TimeDelta duration, |
| 331 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 344 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 332 ui::LayerAnimationObserver* observer) { | 345 ui::LayerAnimationObserver* observer) { |
| 333 ui::LayerAnimator* animator = painted_layer_.GetAnimator(); | 346 ui::LayerAnimator* animator = painted_layer_.GetAnimator(); |
| 334 ui::ScopedLayerAnimationSettings animation(animator); | 347 ui::ScopedLayerAnimationSettings animation(animator); |
| 335 animation.SetPreemptionStrategy(preemption_strategy); | 348 animation.SetPreemptionStrategy(preemption_strategy); |
| 336 | 349 |
| 337 std::unique_ptr<ui::LayerAnimationElement> element = | 350 std::unique_ptr<ui::LayerAnimationElement> element = |
| 338 ui::LayerAnimationElement::CreatePauseElement( | 351 ui::LayerAnimationElement::CreatePauseElement( |
| 339 ui::LayerAnimationElement::TRANSFORM, duration); | 352 ui::LayerAnimationElement::TRANSFORM, duration); |
| 340 | 353 |
| 341 ui::LayerAnimationSequence* sequence = | 354 ui::LayerAnimationSequence* sequence = |
| 342 new ui::LayerAnimationSequence(std::move(element)); | 355 new ui::LayerAnimationSequence(std::move(element)); |
| 343 | 356 |
| 344 if (observer) | 357 if (observer) |
| 345 sequence->AddObserver(observer); | 358 sequence->AddObserver(observer); |
| 346 | 359 |
| 360 sequence->SetAnimationMetricsReporter(g_reporter.Pointer()); |
| 347 animator->StartAnimation(sequence); | 361 animator->StartAnimation(sequence); |
| 348 } | 362 } |
| 349 | 363 |
| 350 void FloodFillInkDropRipple::SetOpacity(float opacity) { | 364 void FloodFillInkDropRipple::SetOpacity(float opacity) { |
| 351 root_layer_.SetOpacity(opacity); | 365 root_layer_.SetOpacity(opacity); |
| 352 } | 366 } |
| 353 | 367 |
| 354 void FloodFillInkDropRipple::AnimateToOpacity( | 368 void FloodFillInkDropRipple::AnimateToOpacity( |
| 355 float opacity, | 369 float opacity, |
| 356 base::TimeDelta duration, | 370 base::TimeDelta duration, |
| 357 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 371 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 358 gfx::Tween::Type tween, | 372 gfx::Tween::Type tween, |
| 359 ui::LayerAnimationObserver* animation_observer) { | 373 ui::LayerAnimationObserver* animation_observer) { |
| 360 ui::LayerAnimator* animator = root_layer_.GetAnimator(); | 374 ui::LayerAnimator* animator = root_layer_.GetAnimator(); |
| 361 ui::ScopedLayerAnimationSettings animation_settings(animator); | 375 ui::ScopedLayerAnimationSettings animation_settings(animator); |
| 362 animation_settings.SetPreemptionStrategy(preemption_strategy); | 376 animation_settings.SetPreemptionStrategy(preemption_strategy); |
| 363 animation_settings.SetTweenType(tween); | 377 animation_settings.SetTweenType(tween); |
| 364 std::unique_ptr<ui::LayerAnimationElement> animation_element = | 378 std::unique_ptr<ui::LayerAnimationElement> animation_element = |
| 365 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); | 379 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); |
| 366 ui::LayerAnimationSequence* animation_sequence = | 380 ui::LayerAnimationSequence* animation_sequence = |
| 367 new ui::LayerAnimationSequence(std::move(animation_element)); | 381 new ui::LayerAnimationSequence(std::move(animation_element)); |
| 368 | 382 |
| 369 if (animation_observer) | 383 if (animation_observer) |
| 370 animation_sequence->AddObserver(animation_observer); | 384 animation_sequence->AddObserver(animation_observer); |
| 371 | 385 |
| 386 animation_sequence->SetAnimationMetricsReporter(g_reporter.Pointer()); |
| 372 animator->StartAnimation(animation_sequence); | 387 animator->StartAnimation(animation_sequence); |
| 373 } | 388 } |
| 374 | 389 |
| 375 void FloodFillInkDropRipple::PauseOpacityAnimation( | 390 void FloodFillInkDropRipple::PauseOpacityAnimation( |
| 376 base::TimeDelta duration, | 391 base::TimeDelta duration, |
| 377 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 392 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 378 ui::LayerAnimationObserver* observer) { | 393 ui::LayerAnimationObserver* observer) { |
| 379 ui::LayerAnimator* animator = root_layer_.GetAnimator(); | 394 ui::LayerAnimator* animator = root_layer_.GetAnimator(); |
| 380 ui::ScopedLayerAnimationSettings animation(animator); | 395 ui::ScopedLayerAnimationSettings animation(animator); |
| 381 animation.SetPreemptionStrategy(preemption_strategy); | 396 animation.SetPreemptionStrategy(preemption_strategy); |
| 382 | 397 |
| 383 std::unique_ptr<ui::LayerAnimationElement> element = | 398 std::unique_ptr<ui::LayerAnimationElement> element = |
| 384 ui::LayerAnimationElement::CreatePauseElement( | 399 ui::LayerAnimationElement::CreatePauseElement( |
| 385 ui::LayerAnimationElement::OPACITY, duration); | 400 ui::LayerAnimationElement::OPACITY, duration); |
| 386 | 401 |
| 387 ui::LayerAnimationSequence* sequence = | 402 ui::LayerAnimationSequence* sequence = |
| 388 new ui::LayerAnimationSequence(std::move(element)); | 403 new ui::LayerAnimationSequence(std::move(element)); |
| 389 | 404 |
| 390 if (observer) | 405 if (observer) |
| 391 sequence->AddObserver(observer); | 406 sequence->AddObserver(observer); |
| 392 | 407 |
| 408 sequence->SetAnimationMetricsReporter(g_reporter.Pointer()); |
| 393 animator->StartAnimation(sequence); | 409 animator->StartAnimation(sequence); |
| 394 } | 410 } |
| 395 | 411 |
| 396 gfx::Transform FloodFillInkDropRipple::CalculateTransform( | 412 gfx::Transform FloodFillInkDropRipple::CalculateTransform( |
| 397 float target_radius) const { | 413 float target_radius) const { |
| 398 const float target_scale = target_radius / circle_layer_delegate_.radius(); | 414 const float target_scale = target_radius / circle_layer_delegate_.radius(); |
| 399 | 415 |
| 400 gfx::Transform transform = gfx::Transform(); | 416 gfx::Transform transform = gfx::Transform(); |
| 401 transform.Translate(center_point_.x() - root_layer_.bounds().x(), | 417 transform.Translate(center_point_.x() - root_layer_.bounds().x(), |
| 402 center_point_.y() - root_layer_.bounds().y()); | 418 center_point_.y() - root_layer_.bounds().y()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 423 (bounds.bottom_right() - point).Length(); | 439 (bounds.bottom_right() - point).Length(); |
| 424 | 440 |
| 425 float largest_distance = | 441 float largest_distance = |
| 426 std::max(distance_to_top_left, distance_to_top_right); | 442 std::max(distance_to_top_left, distance_to_top_right); |
| 427 largest_distance = std::max(largest_distance, distance_to_bottom_left); | 443 largest_distance = std::max(largest_distance, distance_to_bottom_left); |
| 428 largest_distance = std::max(largest_distance, distance_to_bottom_right); | 444 largest_distance = std::max(largest_distance, distance_to_bottom_right); |
| 429 return largest_distance; | 445 return largest_distance; |
| 430 } | 446 } |
| 431 | 447 |
| 432 } // namespace views | 448 } // namespace views |
| OLD | NEW |