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) {
if (IsFinished())
return false;
const double dt = (current_time - start_time_).InMilliseconds();
const double t = std::min(dt / duration_.InMilliseconds(), 1.);
const base::TimeDelta dt = current_time - start_time_;
const double t = std::min(dt / duration_, 1.);
const float interp = static_cast<float>(Damp(t, 1.));
glow_alpha_ = Lerp(glow_alpha_start_, glow_alpha_finish_, interp);
......
......@@ -31,8 +31,8 @@ constexpr base::TimeDelta kResampleLatency =
inline gfx::PointF lerp(const InputPredictor::InputData& a,
const InputPredictor::InputData& b,
base::TimeTicks sample_time) {
float alpha = (sample_time - a.time_stamp).InMillisecondsF() /
(a.time_stamp - b.time_stamp).InMillisecondsF();
const float alpha =
(sample_time - a.time_stamp) / (a.time_stamp - b.time_stamp);
return a.pos + gfx::ScaleVector2d(a.pos - b.pos, alpha);
}
......
......@@ -103,11 +103,9 @@ int PredictionMetricsHandler::GetInterpolatedEventForPredictedEvent(
if (idx == 0 || idx == events_queue_.size())
return -1;
float alpha =
(interpolation_timestamp - events_queue_[idx - 1].time_stamp)
.InMillisecondsF() /
(events_queue_[idx].time_stamp - events_queue_[idx - 1].time_stamp)
.InMillisecondsF();
const float alpha =
(interpolation_timestamp - events_queue_[idx - 1].time_stamp) /
(events_queue_[idx].time_stamp - events_queue_[idx - 1].time_stamp);
*interpolated =
events_queue_[idx - 1].pos +
ScaleVector2d(events_queue_[idx].pos - events_queue_[idx - 1].pos, alpha);
......
......@@ -5,7 +5,6 @@
#include "ui/compositor/float_animation_curve_adapter.h"
#include "base/memory/ptr_util.h"
#include "cc/base/time_util.h"
namespace ui {
......@@ -34,10 +33,9 @@ float FloatAnimationCurveAdapter::GetValue(base::TimeDelta t) const {
return target_value_;
if (t <= base::TimeDelta())
return initial_value_;
double progress = cc::TimeUtil::Divide(t, duration_);
return gfx::Tween::FloatValueBetween(
gfx::Tween::CalculateValue(tween_type_, progress),
initial_value_,
gfx::Tween::CalculateValue(tween_type_, t / duration_), initial_value_,
target_value_);
}
......
......@@ -628,7 +628,7 @@ bool LayerAnimationElement::Progress(base::TimeTicks now,
base::TimeDelta elapsed = now - effective_start_time_;
if ((duration_ > base::TimeDelta()) && (elapsed < duration_))
t = elapsed.InMillisecondsF() / duration_.InMillisecondsF();
t = elapsed / duration_;
base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate);
if (!alive)
......
......@@ -5,7 +5,6 @@
#include "ui/compositor/transform_animation_curve_adapter.h"
#include "base/memory/ptr_util.h"
#include "cc/base/time_util.h"
namespace ui {
......@@ -56,12 +55,10 @@ cc::TransformOperations TransformAnimationCurveAdapter::GetValue(
return target_wrapped_value_;
if (t <= base::TimeDelta())
return initial_wrapped_value_;
double progress = cc::TimeUtil::Divide(t, duration_);
gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms(
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));
}
......
......@@ -63,8 +63,7 @@ void FractionOfTimeWithoutUserInputRecorder::RecordActiveInterval(
if (end_time < window_end_time)
break;
RecordToUma(current_window_active_time_.InMillisecondsF() /
window_size_.InMillisecondsF());
RecordToUma(current_window_active_time_ / window_size_);
current_window_active_time_ = base::TimeDelta();
window_start_time_ = window_end_time;
......
......@@ -117,8 +117,7 @@ std::unique_ptr<MotionEventGeneric> ResampleMotionEvent(
DCHECK(time0 < time1);
DCHECK(time0 <= resample_time);
const float alpha = (resample_time - time0).InMillisecondsF() /
(time1 - time0).InMillisecondsF();
const float alpha = (resample_time - time0) / (time1 - time0);
std::unique_ptr<MotionEventGeneric> event;
const size_t pointer_count = event0.GetPointerCount();
......
......@@ -720,8 +720,8 @@ TEST_F(MotionEventBufferTest, Interpolation) {
// There should only be one flushed event, with the event interpolated between
// the two events. The second event should remain buffered.
float alpha = (interpolated_time - move0.GetEventTime()).InMillisecondsF() /
(move1.GetEventTime() - move0.GetEventTime()).InMillisecondsF();
const float alpha = (interpolated_time - move0.GetEventTime()) /
(move1.GetEventTime() - move0.GetEventTime());
MockMotionEvent interpolated_event(
MotionEvent::Action::MOVE, interpolated_time,
move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * alpha,
......@@ -771,9 +771,8 @@ TEST_F(MotionEventBufferTest, Extrapolation) {
// determining the extrapolated event.
base::TimeTicks expected_time =
move1.GetEventTime() + (move1.GetEventTime() - move0.GetEventTime()) / 2;
float expected_alpha =
(expected_time - move0.GetEventTime()).InMillisecondsF() /
(move1.GetEventTime() - move0.GetEventTime()).InMillisecondsF();
const float expected_alpha = (expected_time - move0.GetEventTime()) /
(move1.GetEventTime() - move0.GetEventTime());
MockMotionEvent extrapolated_event(
MotionEvent::Action::MOVE, expected_time,
move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * expected_alpha,
......@@ -816,9 +815,8 @@ TEST_F(MotionEventBufferTest, ExtrapolationHorizonLimited) {
// Note that the maximum extrapolation is limited by 8 ms.
base::TimeTicks expected_time =
move1.GetEventTime() + base::TimeDelta::FromMilliseconds(8);
float expected_alpha =
(expected_time - move0.GetEventTime()).InMillisecondsF() /
(move1.GetEventTime() - move0.GetEventTime()).InMillisecondsF();
const float expected_alpha = (expected_time - move0.GetEventTime()) /
(move1.GetEventTime() - move0.GetEventTime());
MockMotionEvent extrapolated_event(
MotionEvent::Action::MOVE, expected_time,
move0.GetX(0) + (move1.GetX(0) - move0.GetX(0)) * expected_alpha,
......
......@@ -81,8 +81,7 @@ void LinearAnimation::SetDuration(base::TimeDelta duration) {
void LinearAnimation::Step(base::TimeTicks time_now) {
base::TimeDelta elapsed_time = time_now - start_time();
state_ = static_cast<double>(elapsed_time.InMicroseconds()) /
static_cast<double>(duration_.InMicroseconds());
state_ = elapsed_time / duration_;
if (state_ >= 1.0)
state_ = 1.0;
......
......@@ -53,8 +53,7 @@ void MultiAnimation::Step(base::TimeTicks time_now) {
} else {
delta %= cycle_time_;
const Part& part = GetPart(&delta, &current_part_index_);
double percent = (delta + part.part_start).InMillisecondsF() /
part.total_length.InMillisecondsF();
const double percent = (delta + part.part_start) / part.total_length;
DCHECK_LE(percent, 1);
current_value_ = Tween::CalculateValue(part.type, percent);
}
......
......@@ -96,11 +96,6 @@ uint8_t BlendColorComponents(uint8_t start,
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
// static
......@@ -147,8 +142,7 @@ float Tween::ClampedFloatValueBetween(const base::TimeTicks& time,
if (time >= target_time)
return target;
double progress =
TimeDeltaDivide(time - start_time, target_time - start_time);
const double progress = (time - start_time) / (target_time - start_time);
return FloatValueBetween(progress, start, target);
}
......
......@@ -95,8 +95,7 @@ void PaintThrobberSpinningWithStartAngle(
// The sweep angle ranges from -270 to 270 over 1333ms. CSS
// 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).
const double arc_progress =
(elapsed_time % kArcTime).InMicrosecondsF() / kArcTime.InMicrosecondsF();
const double arc_progress = (elapsed_time % kArcTime) / kArcTime;
// This tween is equivalent to cubic-bezier(0.4, 0.0, 0.2, 1).
double sweep = kMaxArcSize *
Tween::CalculateValue(Tween::FAST_OUT_SLOW_IN, arc_progress);
......@@ -176,9 +175,7 @@ void PaintThrobberSpinningAfterWaiting(Canvas* canvas,
// Blend the color between "waiting" and "spinning" states.
constexpr auto kColorFadeTime = base::TimeDelta::FromMilliseconds(900);
const float color_progress = float{Tween::CalculateValue(
Tween::LINEAR_OUT_SLOW_IN, std::min(elapsed_time.InMicrosecondsF() /
kColorFadeTime.InMicrosecondsF(),
1.0))};
Tween::LINEAR_OUT_SLOW_IN, std::min(elapsed_time / kColorFadeTime, 1.0))};
const SkColor blend_color =
color_utils::AlphaBlend(color, waiting_state->color, color_progress);
......@@ -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
// 0->1 represents when the throbber moves left to right, time 1->2 represents
// right to left.
float time = 2.0f *
(elapsed_time % kNewThrobberWaitingCycleTime).InMicrosecondsF() /
kNewThrobberWaitingCycleTime.InMicrosecondsF();
float time = 2.0f * (elapsed_time % kNewThrobberWaitingCycleTime) /
kNewThrobberWaitingCycleTime;
// 1 -> 2 values mirror back to 1 -> 0 values to represent right-to-left.
const bool going_back = time > 1.0f;
if (going_back)
......
......@@ -153,7 +153,7 @@ float SkiaVectorAnimation::GetCurrentProgress() const {
} else {
// It may be that the timer hasn't been initialized which may happen if
// 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::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