Commit 1d79ebf7 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Use TimeDelta directly more pervasively.

Converts temps to TimeDelta, or eliminates code that is not needed
when using TimeDelta directly.  This is generally clearer and safer.

Bug: none
Change-Id: Iae002ee0938ea91e2c785aa1ba588f74bce092cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352626
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarThomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarJames Darpinian <jdarpinian@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797870}
parent 25dcc111
...@@ -25,7 +25,7 @@ namespace ash { ...@@ -25,7 +25,7 @@ namespace ash {
namespace { namespace {
// Delay between timer callbacks. Each one plays a tick sound. // Delay between timer callbacks. Each one plays a tick sound.
constexpr int kTimerDelayInMS = 500; constexpr auto kTimerDelay = base::TimeDelta::FromMilliseconds(500);
// The number of ticks of the timer before the first sound is generated. // The number of ticks of the timer before the first sound is generated.
constexpr int kTimerTicksOfFirstSoundFeedback = 6; constexpr int kTimerTicksOfFirstSoundFeedback = 6;
...@@ -147,8 +147,8 @@ void TouchAccessibilityEnabler::StartTimer() { ...@@ -147,8 +147,8 @@ void TouchAccessibilityEnabler::StartTimer() {
if (timer_.IsRunning()) if (timer_.IsRunning())
return; return;
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimerDelayInMS), timer_.Start(FROM_HERE, kTimerDelay, this,
this, &TouchAccessibilityEnabler::OnTimer); &TouchAccessibilityEnabler::OnTimer);
} }
void TouchAccessibilityEnabler::CancelTimer() { void TouchAccessibilityEnabler::CancelTimer() {
...@@ -160,8 +160,7 @@ void TouchAccessibilityEnabler::CancelTimer() { ...@@ -160,8 +160,7 @@ void TouchAccessibilityEnabler::CancelTimer() {
void TouchAccessibilityEnabler::OnTimer() { void TouchAccessibilityEnabler::OnTimer() {
base::TimeTicks now = Now(); base::TimeTicks now = Now();
double tick_count_f = double tick_count_f = (now - two_finger_start_time_) / kTimerDelay;
(now - two_finger_start_time_).InMillisecondsF() / kTimerDelayInMS;
int tick_count = base::ClampRound(tick_count_f); int tick_count = base::ClampRound(tick_count_f);
if (tick_count == kTimerTicksOfFirstSoundFeedback) { if (tick_count == kTimerTicksOfFirstSoundFeedback) {
......
...@@ -46,13 +46,13 @@ static void Timing(const size_t len) { ...@@ -46,13 +46,13 @@ static void Timing(const size_t len) {
unsigned char digest[base::kSHA1Length]; unsigned char digest[base::kSHA1Length];
memset(digest, 0, base::kSHA1Length); memset(digest, 0, base::kSHA1Length);
double total_test_time = 0.0; base::TimeDelta total_test_time;
for (int i = 0; i < runs; ++i) { for (int i = 0; i < runs; ++i) {
auto start = base::TimeTicks::Now(); auto start = base::TimeTicks::Now();
base::SHA1HashBytes(buf.data(), len, digest); base::SHA1HashBytes(buf.data(), len, digest);
auto end = base::TimeTicks::Now(); auto end = base::TimeTicks::Now();
utime[i] = end - start; utime[i] = end - start;
total_test_time += utime[i].InMicroseconds(); total_test_time += utime[i];
} }
std::sort(utime.begin(), utime.end()); std::sort(utime.begin(), utime.end());
...@@ -75,7 +75,7 @@ static void Timing(const size_t len) { ...@@ -75,7 +75,7 @@ static void Timing(const size_t len) {
rates.pop_back(); rates.pop_back();
auto reporter = SetUpReporter(base::NumberToString(len) + "_bytes"); auto reporter = SetUpReporter(base::NumberToString(len) + "_bytes");
reporter.AddResult(kMetricRuntime, total_test_time); reporter.AddResult(kMetricRuntime, total_test_time.InMicrosecondsF());
reporter.AddResult(kMetricMedianThroughput, median_rate); reporter.AddResult(kMetricMedianThroughput, median_rate);
reporter.AddResultList(kMetricThroughput, rates); reporter.AddResultList(kMetricThroughput, rates);
} }
......
...@@ -20,7 +20,7 @@ constexpr double kDistanceEstimatorScalar = 25; ...@@ -20,7 +20,7 @@ constexpr double kDistanceEstimatorScalar = 25;
// The delta to be scrolled in next frame is 0.92 of the delta in last frame. // The delta to be scrolled in next frame is 0.92 of the delta in last frame.
constexpr double kRatio = 0.92; constexpr double kRatio = 0.92;
#endif #endif
constexpr double kMsPerFrame = 16; constexpr auto kFrameTime = base::TimeDelta::FromMilliseconds(16);
constexpr base::TimeDelta kMaximumSnapDuration = constexpr base::TimeDelta kMaximumSnapDuration =
base::TimeDelta::FromSecondsD(5); base::TimeDelta::FromSecondsD(5);
...@@ -67,7 +67,7 @@ SnapFlingCurve::SnapFlingCurve(const gfx::Vector2dF& start_offset, ...@@ -67,7 +67,7 @@ SnapFlingCurve::SnapFlingCurve(const gfx::Vector2dF& start_offset,
start_time_(first_gsu_time), start_time_(first_gsu_time),
total_frames_(EstimateFramesFromDistance(total_distance_)), total_frames_(EstimateFramesFromDistance(total_distance_)),
first_delta_(CalculateFirstDelta(total_distance_, total_frames_)), first_delta_(CalculateFirstDelta(total_distance_, total_frames_)),
duration_(base::TimeDelta::FromMilliseconds(total_frames_ * kMsPerFrame)), duration_(total_frames_ * kFrameTime),
is_finished_(total_distance_ == 0) { is_finished_(total_distance_ == 0) {
if (is_finished_) if (is_finished_)
return; return;
...@@ -78,8 +78,8 @@ SnapFlingCurve::SnapFlingCurve(const gfx::Vector2dF& start_offset, ...@@ -78,8 +78,8 @@ SnapFlingCurve::SnapFlingCurve(const gfx::Vector2dF& start_offset,
SnapFlingCurve::~SnapFlingCurve() = default; SnapFlingCurve::~SnapFlingCurve() = default;
double SnapFlingCurve::GetCurrentCurveDistance(base::TimeDelta current_time) { double SnapFlingCurve::GetCurrentCurveDistance(base::TimeDelta current_time) {
double current_frame = current_time.InMillisecondsF() / kMsPerFrame + 1; const double current_frame = current_time / kFrameTime + 1;
double sum = const double sum =
first_delta_ * (1 - std::pow(kRatio, current_frame)) / (1 - kRatio); first_delta_ * (1 - std::pow(kRatio, current_frame)) / (1 - kRatio);
return sum <= total_distance_ ? sum : total_distance_; return sum <= total_distance_ ? sum : total_distance_;
} }
......
...@@ -487,7 +487,7 @@ void CrostiniInstaller::RunProgressCallback() { ...@@ -487,7 +487,7 @@ void CrostiniInstaller::RunProgressCallback() {
double state_start_mark = 0; double state_start_mark = 0;
double state_end_mark = 0; double state_end_mark = 0;
int state_max_seconds = 1; auto state_max_time = base::TimeDelta::FromSeconds(1);
switch (installing_state_) { switch (installing_state_) {
case InstallerState::kStart: case InstallerState::kStart:
...@@ -497,7 +497,7 @@ void CrostiniInstaller::RunProgressCallback() { ...@@ -497,7 +497,7 @@ void CrostiniInstaller::RunProgressCallback() {
case InstallerState::kInstallImageLoader: case InstallerState::kInstallImageLoader:
state_start_mark = 0.0; state_start_mark = 0.0;
state_end_mark = 0.20; state_end_mark = 0.20;
state_max_seconds = 30; state_max_time = base::TimeDelta::FromSeconds(30);
break; break;
case InstallerState::kStartConcierge: case InstallerState::kStartConcierge:
state_start_mark = 0.20; state_start_mark = 0.20;
...@@ -510,28 +510,28 @@ void CrostiniInstaller::RunProgressCallback() { ...@@ -510,28 +510,28 @@ void CrostiniInstaller::RunProgressCallback() {
case InstallerState::kStartTerminaVm: case InstallerState::kStartTerminaVm:
state_start_mark = 0.22; state_start_mark = 0.22;
state_end_mark = 0.28; state_end_mark = 0.28;
state_max_seconds = 8; state_max_time = base::TimeDelta::FromSeconds(8);
break; break;
case InstallerState::kCreateContainer: case InstallerState::kCreateContainer:
state_start_mark = 0.28; state_start_mark = 0.28;
state_end_mark = 0.72; state_end_mark = 0.72;
state_max_seconds = 180; state_max_time = base::TimeDelta::FromSeconds(180);
break; break;
case InstallerState::kSetupContainer: case InstallerState::kSetupContainer:
state_start_mark = 0.72; state_start_mark = 0.72;
state_end_mark = 0.76; state_end_mark = 0.76;
state_max_seconds = 8; state_max_time = base::TimeDelta::FromSeconds(8);
break; break;
case InstallerState::kStartContainer: case InstallerState::kStartContainer:
state_start_mark = 0.76; state_start_mark = 0.76;
state_end_mark = 0.79; state_end_mark = 0.79;
state_max_seconds = 8; state_max_time = base::TimeDelta::FromSeconds(8);
break; break;
case InstallerState::kConfigureContainer: case InstallerState::kConfigureContainer:
state_start_mark = 0.79; state_start_mark = 0.79;
state_end_mark = 0.99; state_end_mark = 0.99;
// Ansible installation and playbook application. // Ansible installation and playbook application.
state_max_seconds = 140 + 300; state_max_time = base::TimeDelta::FromSeconds(140 + 300);
break; break;
case InstallerState::kFetchSshKeys: case InstallerState::kFetchSshKeys:
state_start_mark = 0.99; state_start_mark = 0.99;
...@@ -545,7 +545,7 @@ void CrostiniInstaller::RunProgressCallback() { ...@@ -545,7 +545,7 @@ void CrostiniInstaller::RunProgressCallback() {
NOTREACHED(); NOTREACHED();
} }
double state_fraction = time_in_state.InSecondsF() / state_max_seconds; double state_fraction = time_in_state / state_max_time;
if (installing_state_ == InstallerState::kCreateContainer) { if (installing_state_ == InstallerState::kCreateContainer) {
// In CREATE_CONTAINER, consume half the progress bar with downloading, // In CREATE_CONTAINER, consume half the progress bar with downloading,
......
...@@ -30,12 +30,11 @@ void HttpsEngagementService::RecordTimeOnPage(base::TimeDelta foreground_time, ...@@ -30,12 +30,11 @@ void HttpsEngagementService::RecordTimeOnPage(base::TimeDelta foreground_time,
} }
void HttpsEngagementService::StoreMetricsAndClear() { void HttpsEngagementService::StoreMetricsAndClear() {
double total_time = const base::TimeDelta total_time = time_on_https_ + time_on_http_;
time_on_https_.InMillisecondsF() + time_on_http_.InMillisecondsF(); if (total_time.is_zero())
if (total_time == 0)
return; return;
double https_ratio = 100.0 * (time_on_https_.InMillisecondsF() / total_time); const double https_ratio = 100.0 * (time_on_https_ / total_time);
UMA_HISTOGRAM_PERCENTAGE(internal::kHttpsEngagementSessionPercentage, UMA_HISTOGRAM_PERCENTAGE(internal::kHttpsEngagementSessionPercentage,
https_ratio); https_ratio);
......
...@@ -35,11 +35,11 @@ void AppResult::UpdateFromLastLaunchedOrInstalledTime( ...@@ -35,11 +35,11 @@ void AppResult::UpdateFromLastLaunchedOrInstalledTime(
} }
base::TimeDelta delta = current_time - old_time; base::TimeDelta delta = current_time - old_time;
const int kSecondsInWeek = 60 * 60 * 24 * 7; const auto kOneWeek = base::TimeDelta::FromDays(7);
// Set the relevance to a value between 0 and 1. This function decays as the // Set the relevance to a value between 0 and 1. This function decays as the
// time delta increases and reaches a value of 0.5 at 1 week. // time delta increases and reaches a value of 0.5 at 1 week.
set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); set_relevance(1 / (1 + delta / kOneWeek));
} }
ash::SearchResultType AppResult::GetSearchResultType() const { ash::SearchResultType AppResult::GetSearchResultType() const {
......
...@@ -49,13 +49,13 @@ constexpr int kTotalLayerPadding = ...@@ -49,13 +49,13 @@ constexpr int kTotalLayerPadding =
kPadding + kStrokeWidth + kGradientWidth + kLayerPadding; kPadding + kStrokeWidth + kGradientWidth + kLayerPadding;
// The amount of time it should take for the highlight to fade in. // The amount of time it should take for the highlight to fade in.
constexpr int kFadeInTimeMilliseconds = 100; constexpr auto kFadeInTime = base::TimeDelta::FromMilliseconds(100);
// The amount of time the highlight should persist before beginning to fade. // The amount of time the highlight should persist before beginning to fade.
constexpr int kHighlightPersistTimeMilliseconds = 1000; constexpr auto kHighlightPersistTime = base::TimeDelta::FromSeconds(1);
// The amount of time it should take for the highlight to fade out. // The amount of time it should take for the highlight to fade out.
constexpr int kFadeOutTimeMilliseconds = 600; constexpr auto kFadeOutTime = base::TimeDelta::FromMilliseconds(600);
} // namespace } // namespace
...@@ -95,11 +95,9 @@ AccessibilityFocusHighlight::AccessibilityFocusHighlight( ...@@ -95,11 +95,9 @@ AccessibilityFocusHighlight::AccessibilityFocusHighlight(
// One-time initialization of statics the first time an instance is created. // One-time initialization of statics the first time an instance is created.
if (fade_in_time_.is_zero()) { if (fade_in_time_.is_zero()) {
fade_in_time_ = base::TimeDelta::FromMilliseconds(kFadeInTimeMilliseconds); fade_in_time_ = kFadeInTime;
persist_time_ = persist_time_ = kHighlightPersistTime;
base::TimeDelta::FromMilliseconds(kHighlightPersistTimeMilliseconds); fade_out_time_ = kFadeOutTime;
fade_out_time_ =
base::TimeDelta::FromMilliseconds(kFadeOutTimeMilliseconds);
default_color_ = SkColorSetRGB(16, 16, 16); // #101010 default_color_ = SkColorSetRGB(16, 16, 16); // #101010
} }
} }
......
...@@ -209,11 +209,10 @@ base::TimeDelta PeriodicSamplingScheduler::GetTimeToNextCollection() { ...@@ -209,11 +209,10 @@ base::TimeDelta PeriodicSamplingScheduler::GetTimeToNextCollection() {
// the current TimeTicks. // the current TimeTicks.
period_start_time_ = std::max(period_start_time_, now); period_start_time_ = std::max(period_start_time_, now);
double sampling_offset_seconds = const base::TimeDelta sampling_offset =
(period_duration_ - sampling_duration_).InSecondsF() * RandDouble(); (period_duration_ - sampling_duration_) * RandDouble();
base::TimeTicks next_collection_time = const base::TimeTicks next_collection_time =
period_start_time_ + period_start_time_ + sampling_offset;
base::TimeDelta::FromSecondsD(sampling_offset_seconds);
period_start_time_ += period_duration_; period_start_time_ += period_duration_;
return next_collection_time - now; return next_collection_time - now;
} }
......
...@@ -147,12 +147,10 @@ void SyntheticTouchpadPinchGesture::CalculateEndTime( ...@@ -147,12 +147,10 @@ void SyntheticTouchpadPinchGesture::CalculateEndTime(
float scale_factor_delta = float scale_factor_delta =
(scale_factor - 1.0f) * kPixelsNeededToDoubleOrHalve; (scale_factor - 1.0f) * kPixelsNeededToDoubleOrHalve;
int64_t total_duration_in_us = const base::TimeDelta total_duration = base::TimeDelta::FromSecondsD(
static_cast<int64_t>(1e6 * (static_cast<double>(scale_factor_delta) / scale_factor_delta / params_.relative_pointer_speed_in_pixels_s);
params_.relative_pointer_speed_in_pixels_s)); DCHECK_GT(total_duration, base::TimeDelta());
DCHECK_GT(total_duration_in_us, 0); stop_time_ = start_time_ + total_duration;
stop_time_ =
start_time_ + base::TimeDelta::FromMicroseconds(total_duration_in_us);
} }
base::TimeTicks SyntheticTouchpadPinchGesture::ClampTimestamp( base::TimeTicks SyntheticTouchpadPinchGesture::ClampTimestamp(
......
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
namespace {
// If a request completes faster than this amount (in ms), then we ignore it.
// Any delays on such a request was negligible.
const int kMinRequestTimeToCareMs = 10;
} // namespace
ExtensionWebRequestTimeTracker::RequestTimeLog::RequestTimeLog() = default; ExtensionWebRequestTimeTracker::RequestTimeLog::RequestTimeLog() = default;
ExtensionWebRequestTimeTracker::RequestTimeLog::~RequestTimeLog() = default; ExtensionWebRequestTimeTracker::RequestTimeLog::~RequestTimeLog() = default;
...@@ -69,7 +63,8 @@ void ExtensionWebRequestTimeTracker::AnalyzeLogRequest( ...@@ -69,7 +63,8 @@ void ExtensionWebRequestTimeTracker::AnalyzeLogRequest(
// Ignore really short requests. Time spent on these is negligible, and any // Ignore really short requests. Time spent on these is negligible, and any
// extra delay the extension adds is likely to be noise. // extra delay the extension adds is likely to be noise.
if (request_duration.InMilliseconds() >= kMinRequestTimeToCareMs) { constexpr auto kMinRequestTimeToCare = base::TimeDelta::FromMilliseconds(10);
if (request_duration >= kMinRequestTimeToCare) {
double percentage = log.block_duration.InMillisecondsF() / double percentage = log.block_duration.InMillisecondsF() /
request_duration.InMillisecondsF(); request_duration.InMillisecondsF();
UMA_HISTOGRAM_PERCENTAGE("Extensions.NetworkDelayPercentage", UMA_HISTOGRAM_PERCENTAGE("Extensions.NetworkDelayPercentage",
......
...@@ -189,7 +189,7 @@ TEST_F(GLHelperBenchmark, ScaleBenchmark) { ...@@ -189,7 +189,7 @@ TEST_F(GLHelperBenchmark, ScaleBenchmark) {
if (iterations > 2000) { if (iterations > 2000) {
break; break;
} }
if ((end_time - start_time).InMillisecondsF() > 1000) { if ((end_time - start_time) > base::TimeDelta::FromSeconds(1)) {
break; break;
} }
} }
......
...@@ -262,7 +262,7 @@ void AdaptiveCongestionControl::PruneFrameStats() { ...@@ -262,7 +262,7 @@ void AdaptiveCongestionControl::PruneFrameStats() {
dead_time_in_history_ -= DeadTime(frame_stats_[0], frame_stats_[1]); dead_time_in_history_ -= DeadTime(frame_stats_[0], frame_stats_[1]);
DCHECK_GE(acked_bits_in_history_, 0UL); DCHECK_GE(acked_bits_in_history_, 0UL);
VLOG(2) << "DT: " << dead_time_in_history_.InSecondsF(); VLOG(2) << "DT: " << dead_time_in_history_.InSecondsF();
DCHECK_GE(dead_time_in_history_.InSecondsF(), 0.0); DCHECK_GE(dead_time_in_history_, base::TimeDelta());
frame_stats_.pop_front(); frame_stats_.pop_front();
} }
} }
......
...@@ -1217,10 +1217,9 @@ static int CalculateBitrate(AVFormatContext* format_context, ...@@ -1217,10 +1217,9 @@ static int CalculateBitrate(AVFormatContext* format_context,
// See if we can approximate the bitrate as long as we have a filesize and // See if we can approximate the bitrate as long as we have a filesize and
// valid duration. // valid duration.
if (duration.InMicroseconds() <= 0 || duration == kInfiniteDuration || if (duration <= base::TimeDelta() || duration == kInfiniteDuration ||
filesize_in_bytes == 0) { !filesize_in_bytes)
return 0; return 0;
}
// Don't multiply by 8 first; it will overflow if (filesize_in_bytes >= 2^60). // Don't multiply by 8 first; it will overflow if (filesize_in_bytes >= 2^60).
return base::ClampRound(filesize_in_bytes * duration.ToHz() * 8); return base::ClampRound(filesize_in_bytes * duration.ToHz() * 8);
......
...@@ -212,8 +212,8 @@ void VideoFrameCallbackRequesterImpl::OnRenderingSteps(double high_res_now_ms) { ...@@ -212,8 +212,8 @@ void VideoFrameCallbackRequesterImpl::OnRenderingSteps(double high_res_now_ms) {
// static // static
double VideoFrameCallbackRequesterImpl::GetClampedTimeInMillis( double VideoFrameCallbackRequesterImpl::GetClampedTimeInMillis(
base::TimeDelta time) { base::TimeDelta time) {
constexpr double kSecondsToMillis = 1000.0; return Performance::ClampTimeResolution(time.InSecondsF()) *
return Performance::ClampTimeResolution(time.InSecondsF()) * kSecondsToMillis; base::Time::kMillisecondsPerSecond;
} }
// static // static
......
...@@ -119,7 +119,7 @@ bool PhysicsBasedFlingCurve::ComputeScrollOffset(base::TimeTicks time, ...@@ -119,7 +119,7 @@ bool PhysicsBasedFlingCurve::ComputeScrollOffset(base::TimeTicks time,
} }
bool still_active = true; bool still_active = true;
double x = elapsed_time.InSecondsF() / curve_duration_; double x = elapsed_time / curve_duration_;
if (x < 1.0f) { if (x < 1.0f) {
double progress = bezier_.Solve(x); double progress = bezier_.Solve(x);
*offset = GetPositionAtTime(distance_, progress); *offset = GetPositionAtTime(distance_, progress);
...@@ -143,7 +143,8 @@ bool PhysicsBasedFlingCurve::ComputeScrollOffset(base::TimeTicks time, ...@@ -143,7 +143,8 @@ bool PhysicsBasedFlingCurve::ComputeScrollOffset(base::TimeTicks time,
// bezier curve based on velocity and |distance_|. It calculate the slope based // bezier curve based on velocity and |distance_|. It calculate the slope based
// on the input velocity (initial velocity), curve duration and |distance_|. // on the input velocity (initial velocity), curve duration and |distance_|.
// Slope is then used to configure the value of control points for curve. // Slope is then used to configure the value of control points for curve.
float PhysicsBasedFlingCurve::CalculateDurationAndConfigureControlPoints( base::TimeDelta
PhysicsBasedFlingCurve::CalculateDurationAndConfigureControlPoints(
const gfx::Vector2dF& velocity) { const gfx::Vector2dF& velocity) {
float fling_velocity = std::max(fabs(velocity.x()), fabs(velocity.y())); float fling_velocity = std::max(fabs(velocity.x()), fabs(velocity.y()));
float duration = std::min(kMaxCurveDurationForFling, float duration = std::min(kMaxCurveDurationForFling,
...@@ -161,6 +162,6 @@ float PhysicsBasedFlingCurve::CalculateDurationAndConfigureControlPoints( ...@@ -161,6 +162,6 @@ float PhysicsBasedFlingCurve::CalculateDurationAndConfigureControlPoints(
p1_.set_x(p1_.y() / slope); p1_.set_x(p1_.y() / slope);
} }
return duration; return base::TimeDelta::FromSecondsD(duration);
} }
} // namespace ui } // namespace ui
\ No newline at end of file
...@@ -37,7 +37,9 @@ class EVENTS_BASE_EXPORT PhysicsBasedFlingCurve : public GestureCurve { ...@@ -37,7 +37,9 @@ class EVENTS_BASE_EXPORT PhysicsBasedFlingCurve : public GestureCurve {
gfx::Vector2dF* offset, gfx::Vector2dF* offset,
gfx::Vector2dF* velocity) override; gfx::Vector2dF* velocity) override;
float curve_duration() const { return curve_duration_; } // TODO(crbug.com/1028501): Use base::TimeDelta for curve_duration()
// once crrev.com/c/1865928 is merged.
float curve_duration() const { return curve_duration_.InSecondsF(); }
const gfx::PointF& p1_for_testing() const { return p1_; } const gfx::PointF& p1_for_testing() const { return p1_; }
const gfx::PointF& p2_for_testing() const { return p2_; } const gfx::PointF& p2_for_testing() const { return p2_; }
static int default_bounds_multiplier_for_testing() { static int default_bounds_multiplier_for_testing() {
...@@ -45,6 +47,14 @@ class EVENTS_BASE_EXPORT PhysicsBasedFlingCurve : public GestureCurve { ...@@ -45,6 +47,14 @@ class EVENTS_BASE_EXPORT PhysicsBasedFlingCurve : public GestureCurve {
} }
private: private:
// Default value used to scale the viewport when it is passed in as a
// parameter in the generation of a physics based fling curve. This value
// increases the upper bound of the scroll distance for a fling.
constexpr static int kDefaultBoundsMultiplier = 3;
base::TimeDelta CalculateDurationAndConfigureControlPoints(
const gfx::Vector2dF& velocity);
// Time when fling curve is generated. // Time when fling curve is generated.
const base::TimeTicks start_timestamp_; const base::TimeTicks start_timestamp_;
// Cubic bezier curve control points. // Cubic bezier curve control points.
...@@ -52,26 +62,14 @@ class EVENTS_BASE_EXPORT PhysicsBasedFlingCurve : public GestureCurve { ...@@ -52,26 +62,14 @@ class EVENTS_BASE_EXPORT PhysicsBasedFlingCurve : public GestureCurve {
gfx::PointF p2_; gfx::PointF p2_;
// Distance it can scroll with input velocity. // Distance it can scroll with input velocity.
const gfx::Vector2dF distance_; const gfx::Vector2dF distance_;
// Time in seconds, till which fling can remain active relative to // Time until which fling can remain active relative to |start_timestamp_|.
// |start_timestamp_|. const base::TimeDelta curve_duration_;
// TODO (sarsha): Use base::TimeDelta for |curve_duration_| once
// crrev.com/c/1865928 is merged.
// crbug.com/1028501
const float curve_duration_;
// Default value used to scale the viewport when it is passed in as a
// parameter in the generation of a physics based fling curve. This value
// increases the upper bound of the scroll distance for a fling.
constexpr static int kDefaultBoundsMultiplier = 3;
const gfx::CubicBezier bezier_; const gfx::CubicBezier bezier_;
base::TimeDelta previous_time_delta_; base::TimeDelta previous_time_delta_;
gfx::Vector2dF cumulative_scroll_; gfx::Vector2dF cumulative_scroll_;
gfx::Vector2dF prev_offset_; gfx::Vector2dF prev_offset_;
float CalculateDurationAndConfigureControlPoints(
const gfx::Vector2dF& velocity);
DISALLOW_COPY_AND_ASSIGN(PhysicsBasedFlingCurve); DISALLOW_COPY_AND_ASSIGN(PhysicsBasedFlingCurve);
}; };
......
...@@ -26,7 +26,7 @@ SkiaVectorAnimation::TimerControl::TimerControl( ...@@ -26,7 +26,7 @@ SkiaVectorAnimation::TimerControl::TimerControl(
: start_offset_(offset), : start_offset_(offset),
end_offset_((offset + cycle_duration)), end_offset_((offset + cycle_duration)),
cycle_duration_(end_offset_ - start_offset_), cycle_duration_(end_offset_ - start_offset_),
progress_per_millisecond_(1.0 / total_duration.InMillisecondsF()), total_duration_(total_duration),
previous_tick_(start_timestamp), previous_tick_(start_timestamp),
progress_(base::TimeDelta::FromMilliseconds(0)), progress_(base::TimeDelta::FromMilliseconds(0)),
current_cycle_progress_(start_offset_), current_cycle_progress_(start_offset_),
...@@ -58,15 +58,15 @@ void SkiaVectorAnimation::TimerControl::Resume( ...@@ -58,15 +58,15 @@ void SkiaVectorAnimation::TimerControl::Resume(
double SkiaVectorAnimation::TimerControl::GetNormalizedCurrentCycleProgress() double SkiaVectorAnimation::TimerControl::GetNormalizedCurrentCycleProgress()
const { const {
return current_cycle_progress_.InMillisecondsF() * progress_per_millisecond_; return current_cycle_progress_ / total_duration_;
} }
double SkiaVectorAnimation::TimerControl::GetNormalizedStartOffset() const { double SkiaVectorAnimation::TimerControl::GetNormalizedStartOffset() const {
return start_offset_.InMillisecondsF() * progress_per_millisecond_; return start_offset_ / total_duration_;
} }
double SkiaVectorAnimation::TimerControl::GetNormalizedEndOffset() const { double SkiaVectorAnimation::TimerControl::GetNormalizedEndOffset() const {
return end_offset_.InMillisecondsF() * progress_per_millisecond_; return end_offset_ / total_duration_;
} }
SkiaVectorAnimation::SkiaVectorAnimation( SkiaVectorAnimation::SkiaVectorAnimation(
......
...@@ -192,9 +192,8 @@ class GFX_EXPORT SkiaVectorAnimation { ...@@ -192,9 +192,8 @@ class GFX_EXPORT SkiaVectorAnimation {
// difference between |end_offset_| - |start_offset_|. // difference between |end_offset_| - |start_offset_|.
const base::TimeDelta cycle_duration_; const base::TimeDelta cycle_duration_;
// Normalized animation progress delta per millisecond, that is, the // Total duration of all cycles.
// normalized progress in per millisecond of time duration. const base::TimeDelta total_duration_;
const double progress_per_millisecond_;
// The timetick at which |progress_| was updated last. // The timetick at which |progress_| was updated last.
base::TimeTicks previous_tick_; base::TimeTicks previous_tick_;
......
This diff is collapsed.
...@@ -17,7 +17,7 @@ namespace ui { ...@@ -17,7 +17,7 @@ namespace ui {
namespace { namespace {
// Maximum duration of a fade sequence. // Maximum duration of a fade sequence.
const double kFadeDurationMs = 200; constexpr auto kFadeDuration = base::TimeDelta::FromMilliseconds(200);
// Maximum amount of travel for a fade sequence. This avoids handle "ghosting" // Maximum amount of travel for a fade sequence. This avoids handle "ghosting"
// when the handle is moving rapidly while the fade is active. // when the handle is moving rapidly while the fade is active.
...@@ -236,8 +236,7 @@ bool TouchHandle::Animate(base::TimeTicks frame_time) { ...@@ -236,8 +236,7 @@ bool TouchHandle::Animate(base::TimeTicks frame_time) {
DCHECK(enabled_); DCHECK(enabled_);
float time_u = float time_u = 1.f - (fade_end_time_ - frame_time) / kFadeDuration;
1.f - (fade_end_time_ - frame_time).InMillisecondsF() / kFadeDurationMs;
float position_u = (focus_bottom_ - fade_start_position_).LengthSquared() / float position_u = (focus_bottom_ - fade_start_position_).LengthSquared() /
kFadeDistanceSquared; kFadeDistanceSquared;
float u = std::max(time_u, position_u); float u = std::max(time_u, position_u);
...@@ -419,9 +418,8 @@ void TouchHandle::BeginFade() { ...@@ -419,9 +418,8 @@ void TouchHandle::BeginFade() {
return; return;
} }
fade_end_time_ = base::TimeTicks::Now() + fade_end_time_ =
base::TimeDelta::FromMillisecondsD( base::TimeTicks::Now() + kFadeDuration * std::abs(target_alpha - alpha_);
kFadeDurationMs * std::abs(target_alpha - alpha_));
fade_start_position_ = focus_bottom_; fade_start_position_ = focus_bottom_;
client_->SetNeedsAnimate(); client_->SetNeedsAnimate();
} }
......
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