Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "ui/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 : gfx::Transform()), | 440 : gfx::Transform()), |
| 441 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), | 441 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), |
| 442 visibility(delegate ? delegate->GetVisibilityForAnimation() : false), | 442 visibility(delegate ? delegate->GetVisibilityForAnimation() : false), |
| 443 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f), | 443 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f), |
| 444 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f), | 444 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f), |
| 445 color(delegate ? delegate->GetColorForAnimation() : SK_ColorTRANSPARENT) { | 445 color(delegate ? delegate->GetColorForAnimation() : SK_ColorTRANSPARENT) { |
| 446 } | 446 } |
| 447 | 447 |
| 448 // LayerAnimationElement ------------------------------------------------------- | 448 // LayerAnimationElement ------------------------------------------------------- |
| 449 | 449 |
| 450 LayerAnimationElement::LayerAnimationElement( | 450 LayerAnimationElement::LayerAnimationElement(AnimatableProperties properties, |
| 451 AnimatableProperties properties, base::TimeDelta duration) | 451 base::TimeDelta duration) |
| 452 : first_frame_(true), | 452 : first_frame_(true), |
| 453 properties_(properties), | 453 properties_(properties), |
| 454 duration_(GetEffectiveDuration(duration)), | 454 duration_(GetEffectiveDuration(duration)), |
| 455 tween_type_(gfx::Tween::LINEAR), | 455 tween_type_(gfx::Tween::LINEAR), |
| 456 animation_id_(cc::AnimationIdProvider::NextAnimationId()), | 456 animation_id_(cc::AnimationIdProvider::NextAnimationId()), |
| 457 animation_group_id_(0), | 457 animation_group_id_(0), |
| 458 last_progressed_fraction_(0.0), | 458 last_progressed_fraction_(0.0), |
| 459 weak_ptr_factory_(this) { | 459 animation_metrics_reporter_(nullptr), |
| 460 } | 460 start_frame_number_(0), |
| 461 weak_ptr_factory_(this) {} | |
| 461 | 462 |
| 462 LayerAnimationElement::LayerAnimationElement( | 463 LayerAnimationElement::LayerAnimationElement( |
| 463 const LayerAnimationElement &element) | 464 const LayerAnimationElement& element) |
| 464 : first_frame_(element.first_frame_), | 465 : first_frame_(element.first_frame_), |
| 465 properties_(element.properties_), | 466 properties_(element.properties_), |
| 466 duration_(element.duration_), | 467 duration_(element.duration_), |
| 467 tween_type_(element.tween_type_), | 468 tween_type_(element.tween_type_), |
| 468 animation_id_(cc::AnimationIdProvider::NextAnimationId()), | 469 animation_id_(cc::AnimationIdProvider::NextAnimationId()), |
| 469 animation_group_id_(element.animation_group_id_), | 470 animation_group_id_(element.animation_group_id_), |
| 470 last_progressed_fraction_(element.last_progressed_fraction_), | 471 last_progressed_fraction_(element.last_progressed_fraction_), |
| 471 weak_ptr_factory_(this) { | 472 animation_metrics_reporter_(nullptr), |
| 472 } | 473 start_frame_number_(0), |
| 474 weak_ptr_factory_(this) {} | |
| 473 | 475 |
| 474 LayerAnimationElement::~LayerAnimationElement() { | 476 LayerAnimationElement::~LayerAnimationElement() { |
| 475 } | 477 } |
| 476 | 478 |
| 477 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, | 479 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, |
| 478 int animation_group_id) { | 480 int animation_group_id) { |
| 479 DCHECK(requested_start_time_ != base::TimeTicks()); | 481 DCHECK(requested_start_time_ != base::TimeTicks()); |
| 480 DCHECK(first_frame_); | 482 DCHECK(first_frame_); |
| 481 animation_group_id_ = animation_group_id; | 483 animation_group_id_ = animation_group_id; |
| 482 last_progressed_fraction_ = 0.0; | 484 last_progressed_fraction_ = 0.0; |
| 483 OnStart(delegate); | 485 OnStart(delegate); |
| 486 if (delegate) | |
| 487 start_frame_number_ = delegate->GetFrameNumber(); | |
| 484 RequestEffectiveStart(delegate); | 488 RequestEffectiveStart(delegate); |
| 485 first_frame_ = false; | 489 first_frame_ = false; |
| 486 } | 490 } |
| 487 | 491 |
| 488 bool LayerAnimationElement::Progress(base::TimeTicks now, | 492 bool LayerAnimationElement::Progress(base::TimeTicks now, |
| 489 LayerAnimationDelegate* delegate) { | 493 LayerAnimationDelegate* delegate) { |
| 490 DCHECK(requested_start_time_ != base::TimeTicks()); | 494 DCHECK(requested_start_time_ != base::TimeTicks()); |
| 491 DCHECK(!first_frame_); | 495 DCHECK(!first_frame_); |
| 492 | 496 |
| 493 bool need_draw; | 497 bool need_draw; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 | 531 |
| 528 base::TimeDelta elapsed = time - requested_start_time_; | 532 base::TimeDelta elapsed = time - requested_start_time_; |
| 529 if (elapsed >= duration_ + queueing_delay) { | 533 if (elapsed >= duration_ + queueing_delay) { |
| 530 *total_duration = duration_ + queueing_delay; | 534 *total_duration = duration_ + queueing_delay; |
| 531 return true; | 535 return true; |
| 532 } | 536 } |
| 533 return false; | 537 return false; |
| 534 } | 538 } |
| 535 | 539 |
| 536 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) { | 540 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) { |
| 537 if (first_frame_) | 541 const int frame_number = delegate ? delegate->GetFrameNumber() : 0; |
| 542 if (first_frame_) { | |
| 538 OnStart(delegate); | 543 OnStart(delegate); |
| 544 start_frame_number_ = frame_number; | |
| 545 } | |
| 539 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr()); | 546 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr()); |
| 540 bool need_draw = OnProgress(1.0, delegate); | 547 bool need_draw = OnProgress(1.0, delegate); |
| 548 | |
| 549 int end_frame_number = frame_number; | |
| 550 if (animation_metrics_reporter_ && end_frame_number > start_frame_number_ && | |
| 551 !duration_.is_zero()) { | |
| 552 base::TimeDelta elapsed = base::TimeTicks::Now() - effective_start_time_; | |
| 553 if (elapsed >= duration_) { | |
| 554 int smoothness = 100; | |
| 555 const double kFrameInterval = 1000.f / 60.f; | |
|
reveman
2017/01/21 15:27:39
Should we get the actual vsync interval here inste
varkha
2017/01/24 00:18:57
Is there an easy place to get it from in composito
reveman
2017/01/24 17:21:45
VSync manager observer interface provides this: ht
varkha
2017/01/24 20:18:29
Looks like it is the Compositor that always sets t
varkha
2017/01/24 23:56:20
Please see if this works.
| |
| 556 const double actual_duration = | |
| 557 (end_frame_number - start_frame_number_) * kFrameInterval; | |
| 558 if (duration_.InMillisecondsF() - actual_duration >= kFrameInterval) | |
| 559 smoothness = 100 * (actual_duration / duration_.InMillisecondsF()); | |
|
reveman
2017/01/21 15:27:39
Did you consider just reporting dropped frames ins
varkha
2017/01/24 00:18:57
one dropped frame could indeed ruin user experienc
| |
| 560 animation_metrics_reporter_->Report(smoothness); | |
| 561 } | |
| 562 } | |
| 541 if (!alive) | 563 if (!alive) |
| 542 return need_draw; | 564 return need_draw; |
| 543 last_progressed_fraction_ = 1.0; | 565 last_progressed_fraction_ = 1.0; |
| 544 first_frame_ = true; | 566 first_frame_ = true; |
| 545 return need_draw; | 567 return need_draw; |
| 546 } | 568 } |
| 547 | 569 |
| 548 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { | 570 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { |
| 549 OnGetTarget(target); | 571 OnGetTarget(target); |
| 550 } | 572 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 } | 679 } |
| 658 | 680 |
| 659 // static | 681 // static |
| 660 std::unique_ptr<LayerAnimationElement> | 682 std::unique_ptr<LayerAnimationElement> |
| 661 LayerAnimationElement::CreateColorElement(SkColor color, | 683 LayerAnimationElement::CreateColorElement(SkColor color, |
| 662 base::TimeDelta duration) { | 684 base::TimeDelta duration) { |
| 663 return base::MakeUnique<ColorTransition>(color, duration); | 685 return base::MakeUnique<ColorTransition>(color, duration); |
| 664 } | 686 } |
| 665 | 687 |
| 666 } // namespace ui | 688 } // namespace ui |
| OLD | NEW |