Commit 1340d666 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

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

Bug: 1104532
Change-Id: I310d988be0cefd15dbe21a8d58fa9e110602849e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354992
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797982}
parent bb2f7db9
...@@ -204,8 +204,8 @@ bool EdgeEffect::Update(base::TimeTicks current_time) { ...@@ -204,8 +204,8 @@ bool EdgeEffect::Update(base::TimeTicks current_time) {
if (IsFinished()) if (IsFinished())
return false; return false;
const double dt = (current_time - start_time_).InMilliseconds(); const base::TimeDelta dt = current_time - start_time_;
const double t = std::min(dt / duration_.InMilliseconds(), 1.); const double t = std::min(dt / duration_, 1.);
const float interp = static_cast<float>(Damp(t, 1.)); const float interp = static_cast<float>(Damp(t, 1.));
glow_alpha_ = Lerp(glow_alpha_start_, glow_alpha_finish_, interp); glow_alpha_ = Lerp(glow_alpha_start_, glow_alpha_finish_, interp);
......
...@@ -31,8 +31,8 @@ constexpr base::TimeDelta kResampleLatency = ...@@ -31,8 +31,8 @@ constexpr base::TimeDelta kResampleLatency =
inline gfx::PointF lerp(const InputPredictor::InputData& a, inline gfx::PointF lerp(const InputPredictor::InputData& a,
const InputPredictor::InputData& b, const InputPredictor::InputData& b,
base::TimeTicks sample_time) { base::TimeTicks sample_time) {
float alpha = (sample_time - a.time_stamp).InMillisecondsF() / const float alpha =
(a.time_stamp - b.time_stamp).InMillisecondsF(); (sample_time - a.time_stamp) / (a.time_stamp - b.time_stamp);
return a.pos + gfx::ScaleVector2d(a.pos - b.pos, alpha); return a.pos + gfx::ScaleVector2d(a.pos - b.pos, alpha);
} }
......
...@@ -103,11 +103,9 @@ int PredictionMetricsHandler::GetInterpolatedEventForPredictedEvent( ...@@ -103,11 +103,9 @@ int PredictionMetricsHandler::GetInterpolatedEventForPredictedEvent(
if (idx == 0 || idx == events_queue_.size()) if (idx == 0 || idx == events_queue_.size())
return -1; return -1;
float alpha = const float alpha =
(interpolation_timestamp - events_queue_[idx - 1].time_stamp) (interpolation_timestamp - events_queue_[idx - 1].time_stamp) /
.InMillisecondsF() / (events_queue_[idx].time_stamp - events_queue_[idx - 1].time_stamp);
(events_queue_[idx].time_stamp - events_queue_[idx - 1].time_stamp)
.InMillisecondsF();
*interpolated = *interpolated =
events_queue_[idx - 1].pos + events_queue_[idx - 1].pos +
ScaleVector2d(events_queue_[idx].pos - events_queue_[idx - 1].pos, alpha); ScaleVector2d(events_queue_[idx].pos - events_queue_[idx - 1].pos, alpha);
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "ui/compositor/float_animation_curve_adapter.h" #include "ui/compositor/float_animation_curve_adapter.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "cc/base/time_util.h"
namespace ui { namespace ui {
...@@ -34,10 +33,9 @@ float FloatAnimationCurveAdapter::GetValue(base::TimeDelta t) const { ...@@ -34,10 +33,9 @@ float FloatAnimationCurveAdapter::GetValue(base::TimeDelta t) const {
return target_value_; return target_value_;
if (t <= base::TimeDelta()) if (t <= base::TimeDelta())
return initial_value_; return initial_value_;
double progress = cc::TimeUtil::Divide(t, duration_);
return gfx::Tween::FloatValueBetween( return gfx::Tween::FloatValueBetween(
gfx::Tween::CalculateValue(tween_type_, progress), gfx::Tween::CalculateValue(tween_type_, t / duration_), initial_value_,
initial_value_,
target_value_); target_value_);
} }
......
...@@ -628,7 +628,7 @@ bool LayerAnimationElement::Progress(base::TimeTicks now, ...@@ -628,7 +628,7 @@ bool LayerAnimationElement::Progress(base::TimeTicks now,
base::TimeDelta elapsed = now - effective_start_time_; base::TimeDelta elapsed = now - effective_start_time_;
if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) if ((duration_ > base::TimeDelta()) && (elapsed < duration_))
t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); t = elapsed / duration_;
base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr()); base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate); need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate);
if (!alive) if (!alive)
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "ui/compositor/transform_animation_curve_adapter.h" #include "ui/compositor/transform_animation_curve_adapter.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "cc/base/time_util.h"
namespace ui { namespace ui {
...@@ -56,12 +55,10 @@ cc::TransformOperations TransformAnimationCurveAdapter::GetValue( ...@@ -56,12 +55,10 @@ cc::TransformOperations TransformAnimationCurveAdapter::GetValue(
return target_wrapped_value_; return target_wrapped_value_;
if (t <= base::TimeDelta()) if (t <= base::TimeDelta())
return initial_wrapped_value_; return initial_wrapped_value_;
double progress = cc::TimeUtil::Divide(t, duration_);
gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms( gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms(
decomposed_target_value_, decomposed_initial_value_, decomposed_target_value_, decomposed_initial_value_,
gfx::Tween::CalculateValue(tween_type_, progress)); gfx::Tween::CalculateValue(tween_type_, t / duration_));
return WrapTransform(gfx::ComposeTransform(to_return)); return WrapTransform(gfx::ComposeTransform(to_return));
} }
......
...@@ -63,8 +63,7 @@ void FractionOfTimeWithoutUserInputRecorder::RecordActiveInterval( ...@@ -63,8 +63,7 @@ void FractionOfTimeWithoutUserInputRecorder::RecordActiveInterval(
if (end_time < window_end_time) if (end_time < window_end_time)
break; break;
RecordToUma(current_window_active_time_.InMillisecondsF() / RecordToUma(current_window_active_time_ / window_size_);
window_size_.InMillisecondsF());
current_window_active_time_ = base::TimeDelta(); current_window_active_time_ = base::TimeDelta();
window_start_time_ = window_end_time; window_start_time_ = window_end_time;
......
...@@ -117,8 +117,7 @@ std::unique_ptr<MotionEventGeneric> ResampleMotionEvent( ...@@ -117,8 +117,7 @@ std::unique_ptr<MotionEventGeneric> ResampleMotionEvent(
DCHECK(time0 < time1); DCHECK(time0 < time1);
DCHECK(time0 <= resample_time); DCHECK(time0 <= resample_time);
const float alpha = (resample_time - time0).InMillisecondsF() / const float alpha = (resample_time - time0) / (time1 - time0);
(time1 - time0).InMillisecondsF();
std::unique_ptr<MotionEventGeneric> event; std::unique_ptr<MotionEventGeneric> event;
const size_t pointer_count = event0.GetPointerCount(); const size_t pointer_count = event0.GetPointerCount();
......
...@@ -720,8 +720,8 @@ TEST_F(MotionEventBufferTest, Interpolation) { ...@@ -720,8 +720,8 @@ TEST_F(MotionEventBufferTest, Interpolation) {
// There should only be one flushed event, with the event interpolated between // There should only be one flushed event, with the event interpolated between
// the two events. The second event should remain buffered. // the two events. The second event should remain buffered.
float alpha = (interpolated_time - move0.GetEventTime()).InMillisecondsF() / const float alpha = (interpolated_time - move0.GetEventTime()) /
(move1.GetEventTime() - move0.GetEventTime()).InMillisecondsF(); (move1.GetEventTime() - move0.GetEventTime());
MockMotionEvent interpolated_event( MockMotionEvent interpolated_event(
MotionEvent::Action::MOVE, interpolated_time, MotionEvent::Action::MOVE, interpolated_time,
move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * alpha, move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * alpha,
...@@ -771,9 +771,8 @@ TEST_F(MotionEventBufferTest, Extrapolation) { ...@@ -771,9 +771,8 @@ TEST_F(MotionEventBufferTest, Extrapolation) {
// determining the extrapolated event. // determining the extrapolated event.
base::TimeTicks expected_time = base::TimeTicks expected_time =
move1.GetEventTime() + (move1.GetEventTime() - move0.GetEventTime()) / 2; move1.GetEventTime() + (move1.GetEventTime() - move0.GetEventTime()) / 2;
float expected_alpha = const float expected_alpha = (expected_time - move0.GetEventTime()) /
(expected_time - move0.GetEventTime()).InMillisecondsF() / (move1.GetEventTime() - move0.GetEventTime());
(move1.GetEventTime() - move0.GetEventTime()).InMillisecondsF();
MockMotionEvent extrapolated_event( MockMotionEvent extrapolated_event(
MotionEvent::Action::MOVE, expected_time, MotionEvent::Action::MOVE, expected_time,
move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * expected_alpha, move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * expected_alpha,
...@@ -816,9 +815,8 @@ TEST_F(MotionEventBufferTest, ExtrapolationHorizonLimited) { ...@@ -816,9 +815,8 @@ TEST_F(MotionEventBufferTest, ExtrapolationHorizonLimited) {
// Note that the maximum extrapolation is limited by 8 ms. // Note that the maximum extrapolation is limited by 8 ms.
base::TimeTicks expected_time = base::TimeTicks expected_time =
move1.GetEventTime() + base::TimeDelta::FromMilliseconds(8); move1.GetEventTime() + base::TimeDelta::FromMilliseconds(8);
float expected_alpha = const float expected_alpha = (expected_time - move0.GetEventTime()) /
(expected_time - move0.GetEventTime()).InMillisecondsF() / (move1.GetEventTime() - move0.GetEventTime());
(move1.GetEventTime() - move0.GetEventTime()).InMillisecondsF();
MockMotionEvent extrapolated_event( MockMotionEvent extrapolated_event(
MotionEvent::Action::MOVE, expected_time, MotionEvent::Action::MOVE, expected_time,
move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * expected_alpha, move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * expected_alpha,
......
...@@ -81,8 +81,7 @@ void LinearAnimation::SetDuration(base::TimeDelta duration) { ...@@ -81,8 +81,7 @@ void LinearAnimation::SetDuration(base::TimeDelta duration) {
void LinearAnimation::Step(base::TimeTicks time_now) { void LinearAnimation::Step(base::TimeTicks time_now) {
base::TimeDelta elapsed_time = time_now - start_time(); base::TimeDelta elapsed_time = time_now - start_time();
state_ = static_cast<double>(elapsed_time.InMicroseconds()) / state_ = elapsed_time / duration_;
static_cast<double>(duration_.InMicroseconds());
if (state_ >= 1.0) if (state_ >= 1.0)
state_ = 1.0; state_ = 1.0;
......
...@@ -53,8 +53,7 @@ void MultiAnimation::Step(base::TimeTicks time_now) { ...@@ -53,8 +53,7 @@ void MultiAnimation::Step(base::TimeTicks time_now) {
} else { } else {
delta %= cycle_time_; delta %= cycle_time_;
const Part& part = GetPart(&delta, &current_part_index_); const Part& part = GetPart(&delta, &current_part_index_);
double percent = (delta + part.part_start).InMillisecondsF() / const double percent = (delta + part.part_start) / part.total_length;
part.total_length.InMillisecondsF();
DCHECK_LE(percent, 1); DCHECK_LE(percent, 1);
current_value_ = Tween::CalculateValue(part.type, percent); current_value_ = Tween::CalculateValue(part.type, percent);
} }
......
...@@ -96,11 +96,6 @@ uint8_t BlendColorComponents(uint8_t start, ...@@ -96,11 +96,6 @@ uint8_t BlendColorComponents(uint8_t start,
return FloatToColorByte(blended_premultiplied / blended_alpha); return FloatToColorByte(blended_premultiplied / blended_alpha);
} }
double TimeDeltaDivide(base::TimeDelta dividend, base::TimeDelta divisor) {
return static_cast<double>(dividend.InMicroseconds()) /
static_cast<double>(divisor.InMicroseconds());
}
} // namespace } // namespace
// static // static
...@@ -147,8 +142,7 @@ float Tween::ClampedFloatValueBetween(const base::TimeTicks& time, ...@@ -147,8 +142,7 @@ float Tween::ClampedFloatValueBetween(const base::TimeTicks& time,
if (time >= target_time) if (time >= target_time)
return target; return target;
double progress = const double progress = (time - start_time) / (target_time - start_time);
TimeDeltaDivide(time - start_time, target_time - start_time);
return FloatValueBetween(progress, start, target); return FloatValueBetween(progress, start, target);
} }
......
...@@ -95,8 +95,7 @@ void PaintThrobberSpinningWithStartAngle( ...@@ -95,8 +95,7 @@ void PaintThrobberSpinningWithStartAngle(
// The sweep angle ranges from -270 to 270 over 1333ms. CSS // The sweep angle ranges from -270 to 270 over 1333ms. CSS
// animation timing functions apply in between key frames, so we have to // animation timing functions apply in between key frames, so we have to
// break up the 1333ms into two keyframes (-270 to 0, then 0 to 270). // break up the 1333ms into two keyframes (-270 to 0, then 0 to 270).
const double arc_progress = const double arc_progress = (elapsed_time % kArcTime) / kArcTime;
(elapsed_time % kArcTime).InMicrosecondsF() / kArcTime.InMicrosecondsF();
// This tween is equivalent to cubic-bezier(0.4, 0.0, 0.2, 1). // This tween is equivalent to cubic-bezier(0.4, 0.0, 0.2, 1).
double sweep = kMaxArcSize * double sweep = kMaxArcSize *
Tween::CalculateValue(Tween::FAST_OUT_SLOW_IN, arc_progress); Tween::CalculateValue(Tween::FAST_OUT_SLOW_IN, arc_progress);
...@@ -176,9 +175,7 @@ void PaintThrobberSpinningAfterWaiting(Canvas* canvas, ...@@ -176,9 +175,7 @@ void PaintThrobberSpinningAfterWaiting(Canvas* canvas,
// Blend the color between "waiting" and "spinning" states. // Blend the color between "waiting" and "spinning" states.
constexpr auto kColorFadeTime = base::TimeDelta::FromMilliseconds(900); constexpr auto kColorFadeTime = base::TimeDelta::FromMilliseconds(900);
const float color_progress = float{Tween::CalculateValue( const float color_progress = float{Tween::CalculateValue(
Tween::LINEAR_OUT_SLOW_IN, std::min(elapsed_time.InMicrosecondsF() / Tween::LINEAR_OUT_SLOW_IN, std::min(elapsed_time / kColorFadeTime, 1.0))};
kColorFadeTime.InMicrosecondsF(),
1.0))};
const SkColor blend_color = const SkColor blend_color =
color_utils::AlphaBlend(color, waiting_state->color, color_progress); color_utils::AlphaBlend(color, waiting_state->color, color_progress);
...@@ -203,9 +200,8 @@ GFX_EXPORT void PaintNewThrobberWaiting(Canvas* canvas, ...@@ -203,9 +200,8 @@ GFX_EXPORT void PaintNewThrobberWaiting(Canvas* canvas,
// The throbber bounces back and forth. We map the elapsed time to 0->2. Time // The throbber bounces back and forth. We map the elapsed time to 0->2. Time
// 0->1 represents when the throbber moves left to right, time 1->2 represents // 0->1 represents when the throbber moves left to right, time 1->2 represents
// right to left. // right to left.
float time = 2.0f * float time = 2.0f * (elapsed_time % kNewThrobberWaitingCycleTime) /
(elapsed_time % kNewThrobberWaitingCycleTime).InMicrosecondsF() / kNewThrobberWaitingCycleTime;
kNewThrobberWaitingCycleTime.InMicrosecondsF();
// 1 -> 2 values mirror back to 1 -> 0 values to represent right-to-left. // 1 -> 2 values mirror back to 1 -> 0 values to represent right-to-left.
const bool going_back = time > 1.0f; const bool going_back = time > 1.0f;
if (going_back) if (going_back)
......
...@@ -153,7 +153,7 @@ float SkiaVectorAnimation::GetCurrentProgress() const { ...@@ -153,7 +153,7 @@ float SkiaVectorAnimation::GetCurrentProgress() const {
} else { } else {
// It may be that the timer hasn't been initialized which may happen if // It may be that the timer hasn't been initialized which may happen if
// the animation was paused while it was in |kScheculePlay| state. // the animation was paused while it was in |kScheculePlay| state.
return scheduled_start_offset_.InMillisecondsF() / skottie_->duration(); return scheduled_start_offset_ / GetAnimationDuration();
} }
case PlayState::kSchedulePlay: case PlayState::kSchedulePlay:
case PlayState::kPlaying: case PlayState::kPlaying:
......
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