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