Commit 6c38e71b authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Use TimeDelta::operator/() more, cc/ edition.

Bug: 1104532
Change-Id: I02849597d4aa12244cb4656231c7b8b448522939
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354991
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798041}
parent e3a07a7a
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm> #include <algorithm>
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "cc/base/time_util.h"
#include "ui/gfx/animation/tween.h" #include "ui/gfx/animation/tween.h"
#include "ui/gfx/geometry/box_f.h" #include "ui/gfx/geometry/box_f.h"
...@@ -45,7 +46,7 @@ base::TimeDelta TransformedAnimationTime( ...@@ -45,7 +46,7 @@ base::TimeDelta TransformedAnimationTime(
base::TimeDelta duration = base::TimeDelta duration =
(keyframes.back()->Time() - keyframes.front()->Time()) * (keyframes.back()->Time() - keyframes.front()->Time()) *
scaled_duration; scaled_duration;
double progress = TimeUtil::Divide(time - start_time, duration); const double progress = (time - start_time) / duration;
time = (duration * timing_function->GetValue(progress)) + start_time; time = (duration * timing_function->GetValue(progress)) + start_time;
} }
...@@ -77,7 +78,7 @@ double TransformedKeyframeProgress( ...@@ -77,7 +78,7 @@ double TransformedKeyframeProgress(
base::TimeDelta time1 = keyframes[i]->Time() * scaled_duration; base::TimeDelta time1 = keyframes[i]->Time() * scaled_duration;
base::TimeDelta time2 = keyframes[i + 1]->Time() * scaled_duration; base::TimeDelta time2 = keyframes[i + 1]->Time() * scaled_duration;
double progress = TimeUtil::Divide(time - time1, time2 - time1); double progress = (time - time1) / (time2 - time1);
if (keyframes[i]->timing_function()) { if (keyframes[i]->timing_function()) {
progress = keyframes[i]->timing_function()->GetValue(progress); progress = keyframes[i]->timing_function()->GetValue(progress);
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <utility>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
#include "cc/animation/timing_function.h" #include "cc/animation/timing_function.h"
#include "cc/base/time_util.h"
#include "ui/gfx/animation/tween.h" #include "ui/gfx/animation/tween.h"
const double kConstantDuration = 9.0; const double kConstantDuration = 9.0;
...@@ -306,7 +306,7 @@ gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue( ...@@ -306,7 +306,7 @@ gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(
if (t >= duration) if (t >= duration)
return target_value_; return target_value_;
double progress = timing_function_->GetValue(TimeUtil::Divide(t, duration)); double progress = timing_function_->GetValue(t / duration);
return gfx::ScrollOffset( return gfx::ScrollOffset(
gfx::Tween::FloatValueBetween(progress, initial_value_.x(), gfx::Tween::FloatValueBetween(progress, initial_value_.x(),
target_value_.x()), target_value_.x()),
...@@ -347,8 +347,8 @@ void ScrollOffsetAnimationCurve::SetAnimationDurationForTesting( ...@@ -347,8 +347,8 @@ void ScrollOffsetAnimationCurve::SetAnimationDurationForTesting(
double ScrollOffsetAnimationCurve::CalculateVelocity(base::TimeDelta t) { double ScrollOffsetAnimationCurve::CalculateVelocity(base::TimeDelta t) {
base::TimeDelta duration = total_animation_duration_ - last_retarget_; base::TimeDelta duration = total_animation_duration_ - last_retarget_;
double slope = timing_function_->Velocity( const double slope =
((t - last_retarget_).InSecondsF()) / duration.InSecondsF()); timing_function_->Velocity((t - last_retarget_) / duration);
gfx::Vector2dF delta = target_value_.DeltaFrom(initial_value_); gfx::Vector2dF delta = target_value_.DeltaFrom(initial_value_);
......
...@@ -47,7 +47,6 @@ cc_component("base") { ...@@ -47,7 +47,6 @@ cc_component("base") {
"synced_property.h", "synced_property.h",
"tiling_data.cc", "tiling_data.cc",
"tiling_data.h", "tiling_data.h",
"time_util.h",
"unique_notifier.cc", "unique_notifier.cc",
"unique_notifier.h", "unique_notifier.h",
] ]
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_BASE_TIME_UTIL_H_
#define CC_BASE_TIME_UTIL_H_
#include "base/time/time.h"
namespace cc {
class TimeUtil {
public:
static double Divide(base::TimeDelta dividend, base::TimeDelta divisor) {
return static_cast<double>(dividend.InMicroseconds()) /
static_cast<double>(divisor.InMicroseconds());
}
};
} // namespace cc
#endif // CC_BASE_TIME_UTIL_H_
...@@ -190,8 +190,7 @@ float PageScaleAnimation::InterpAtTime(base::TimeTicks monotonic_time) const { ...@@ -190,8 +190,7 @@ float PageScaleAnimation::InterpAtTime(base::TimeTicks monotonic_time) const {
DCHECK(monotonic_time >= start_time_); DCHECK(monotonic_time >= start_time_);
if (IsAnimationCompleteAtTime(monotonic_time)) if (IsAnimationCompleteAtTime(monotonic_time))
return 1.f; return 1.f;
const double normalized_time = const double normalized_time = (monotonic_time - start_time_) / duration_;
(monotonic_time - start_time_).InSecondsF() / duration_.InSecondsF();
return static_cast<float>(timing_function_.Solve(normalized_time)); return static_cast<float>(timing_function_.Solve(normalized_time));
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "cc/input/scrollbar_animation_controller.h" #include "cc/input/scrollbar_animation_controller.h"
#include <algorithm> #include <algorithm>
#include <memory>
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -159,7 +160,7 @@ bool ScrollbarAnimationController::Animate(base::TimeTicks now) { ...@@ -159,7 +160,7 @@ bool ScrollbarAnimationController::Animate(base::TimeTicks now) {
float ScrollbarAnimationController::AnimationProgressAtTime( float ScrollbarAnimationController::AnimationProgressAtTime(
base::TimeTicks now) { base::TimeTicks now) {
base::TimeDelta delta = now - last_awaken_time_; base::TimeDelta delta = now - last_awaken_time_;
float progress = delta.InSecondsF() / fade_duration_.InSecondsF(); float progress = delta / fade_duration_;
return base::ClampToRange(progress, 0.0f, 1.0f); return base::ClampToRange(progress, 0.0f, 1.0f);
} }
......
...@@ -94,15 +94,15 @@ bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) { ...@@ -94,15 +94,15 @@ bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
float SingleScrollbarAnimationControllerThinning::AnimationProgressAtTime( float SingleScrollbarAnimationControllerThinning::AnimationProgressAtTime(
base::TimeTicks now) { base::TimeTicks now) {
// In tests, there may be no duration; snap to the end in such a case.
if (thinning_duration_.is_zero())
return 1.0f;
base::TimeDelta delta = now - last_awaken_time_; base::TimeDelta delta = now - last_awaken_time_;
float progress = delta.InSecondsF() / Duration().InSecondsF(); float progress = delta / thinning_duration_;
return base::ClampToRange(progress, 0.0f, 1.0f); return base::ClampToRange(progress, 0.0f, 1.0f);
} }
const base::TimeDelta& SingleScrollbarAnimationControllerThinning::Duration() {
return thinning_duration_;
}
void SingleScrollbarAnimationControllerThinning::RunAnimationFrame( void SingleScrollbarAnimationControllerThinning::RunAnimationFrame(
float progress) { float progress) {
if (captured_) if (captured_)
......
...@@ -70,7 +70,6 @@ class CC_EXPORT SingleScrollbarAnimationControllerThinning { ...@@ -70,7 +70,6 @@ class CC_EXPORT SingleScrollbarAnimationControllerThinning {
ScrollbarLayerImplBase* GetScrollbar() const; ScrollbarLayerImplBase* GetScrollbar() const;
float AnimationProgressAtTime(base::TimeTicks now); float AnimationProgressAtTime(base::TimeTicks now);
void RunAnimationFrame(float progress); void RunAnimationFrame(float progress);
const base::TimeDelta& Duration();
// Describes whether the current animation should INCREASE (thicken) // Describes whether the current animation should INCREASE (thicken)
// a bar or DECREASE it (thin). // a bar or DECREASE it (thin).
......
...@@ -135,16 +135,14 @@ float AverageLagTracker::LagBetween(base::TimeTicks front_time, ...@@ -135,16 +135,14 @@ float AverageLagTracker::LagBetween(base::TimeTicks front_time,
float front_delta = float front_delta =
(last_event_accumulated_delta_ + (last_event_accumulated_delta_ +
(scroll_delta * (scroll_delta * ((front_time - last_event_timestamp_) /
((front_time - last_event_timestamp_).InMillisecondsF() / (event_timestamp - last_event_timestamp_)))) -
(event_timestamp - last_event_timestamp_).InMillisecondsF()))) -
rendered_accumulated_delta; rendered_accumulated_delta;
float back_delta = float back_delta =
(last_event_accumulated_delta_ + (last_event_accumulated_delta_ +
scroll_delta * scroll_delta * ((back_time - last_event_timestamp_) /
((back_time - last_event_timestamp_).InMillisecondsF() / (event_timestamp - last_event_timestamp_))) -
(event_timestamp - last_event_timestamp_).InMillisecondsF())) -
rendered_accumulated_delta; rendered_accumulated_delta;
// Calculate the trapezoid area. // Calculate the trapezoid area.
...@@ -186,7 +184,8 @@ void AverageLagTracker::CalculateAndReportAverageLagUma(bool send_anyway) { ...@@ -186,7 +184,8 @@ void AverageLagTracker::CalculateAndReportAverageLagUma(bool send_anyway) {
// |ScrollBegin|. Otherwise record UMA when it's ScrollBegin, or when // |ScrollBegin|. Otherwise record UMA when it's ScrollBegin, or when
// reaching the 1 second gap. // reaching the 1 second gap.
if (send_anyway || is_begin_ || if (send_anyway || is_begin_ ||
(frame_lag.frame_time - last_reported_time_).InSecondsF() >= 1.0f) { (frame_lag.frame_time - last_reported_time_) >=
base::TimeDelta::FromSeconds(1)) {
const EventType event_type = const EventType event_type =
is_begin_ ? EventType::ScrollBegin : EventType::ScrollUpdate; is_begin_ ? EventType::ScrollBegin : EventType::ScrollUpdate;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "cc/test/animation_test_common.h" #include "cc/test/animation_test_common.h"
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "cc/animation/animation.h" #include "cc/animation/animation.h"
#include "cc/animation/animation_host.h" #include "cc/animation/animation_host.h"
...@@ -15,7 +18,6 @@ ...@@ -15,7 +18,6 @@
#include "cc/animation/scroll_offset_animation_curve_factory.h" #include "cc/animation/scroll_offset_animation_curve_factory.h"
#include "cc/animation/timing_function.h" #include "cc/animation/timing_function.h"
#include "cc/animation/transform_operations.h" #include "cc/animation/transform_operations.h"
#include "cc/base/time_util.h"
#include "cc/layers/layer.h" #include "cc/layers/layer.h"
#include "cc/layers/layer_impl.h" #include "cc/layers/layer_impl.h"
...@@ -229,7 +231,7 @@ base::TimeDelta FakeFloatTransition::Duration() const { ...@@ -229,7 +231,7 @@ base::TimeDelta FakeFloatTransition::Duration() const {
} }
float FakeFloatTransition::GetValue(base::TimeDelta time) const { float FakeFloatTransition::GetValue(base::TimeDelta time) const {
double progress = TimeUtil::Divide(time, duration_); double progress = time / duration_;
if (progress >= 1.0) if (progress >= 1.0)
progress = 1.0; progress = 1.0;
return (1.0 - progress) * from_ + progress * to_; return (1.0 - progress) * from_ + progress * to_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment