Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2183)

Unified Diff: cc/animation/scroll_offset_animation_curve.cc

Issue 2040543002: Take MT jank into account when animating the scroll offset on CC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback from tdresser@ Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/animation/scroll_offset_animation_curve.cc
diff --git a/cc/animation/scroll_offset_animation_curve.cc b/cc/animation/scroll_offset_animation_curve.cc
index b207994c092a327a70c753d99b7c93f4446bf4c2..54a404a7359a1cf8425760a342e253bb0b74bd8d 100644
--- a/cc/animation/scroll_offset_animation_curve.cc
+++ b/cc/animation/scroll_offset_animation_curve.cc
@@ -41,7 +41,8 @@ static float MaximumDimension(const gfx::Vector2dF& delta) {
}
static base::TimeDelta SegmentDuration(const gfx::Vector2dF& delta,
- DurationBehavior behavior) {
+ DurationBehavior behavior,
+ base::TimeDelta delayed_by) {
double duration = kConstantDuration;
switch (behavior) {
case DurationBehavior::CONSTANT:
@@ -60,8 +61,14 @@ static base::TimeDelta SegmentDuration(const gfx::Vector2dF& delta,
default:
NOTREACHED();
}
- return base::TimeDelta::FromMicroseconds(duration / kDurationDivisor *
- base::Time::kMicrosecondsPerSecond);
+
+ base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds(
+ duration / kDurationDivisor * base::Time::kMicrosecondsPerSecond);
+
+ time_delta -= delayed_by;
+ if (time_delta >= base::TimeDelta())
+ return time_delta;
+ return base::TimeDelta();
}
static std::unique_ptr<TimingFunction> EaseOutWithInitialVelocity(
@@ -98,11 +105,12 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {}
void ScrollOffsetAnimationCurve::SetInitialValue(
- const gfx::ScrollOffset& initial_value) {
+ const gfx::ScrollOffset& initial_value,
+ base::TimeDelta delayed_by) {
initial_value_ = initial_value;
has_set_initial_value_ = true;
total_animation_duration_ = SegmentDuration(
- target_value_.DeltaFrom(initial_value_), duration_behavior_);
+ target_value_.DeltaFrom(initial_value_), duration_behavior_, delayed_by);
}
bool ScrollOffsetAnimationCurve::HasSetInitialValue() const {
@@ -120,6 +128,9 @@ gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(
base::TimeDelta duration = total_animation_duration_ - last_retarget_;
t -= last_retarget_;
+ if (has_set_initial_value_ && duration.is_zero())
skobes 2016/08/29 22:13:11 Does it ever make sense to call GetValue if has_se
ymalik 2016/08/29 23:44:05 You're right, we never call GetValue without calli
+ return target_value_;
+
if (t <= base::TimeDelta())
return initial_value_;
@@ -194,6 +205,13 @@ void ScrollOffsetAnimationCurve::UpdateTarget(
target_value_ = new_target;
return;
}
+
+ if (t == 0) {
+ // Just update the target since the animation hasn't started yet.
skobes 2016/08/29 22:13:11 Remind me why the early return is here? Shouldn't
ymalik 2016/08/29 23:44:05 This is an optimization for the case where we get
skobes 2016/08/29 23:49:43 But the duration depends on the target, so this se
ymalik 2016/09/01 15:31:13 Hmm yeah you're right. Fixed.
+ target_value_ = new_target;
+ return;
+ }
+
gfx::ScrollOffset current_position =
GetValue(base::TimeDelta::FromSecondsD(t));
gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_);
@@ -208,7 +226,8 @@ void ScrollOffsetAnimationCurve::UpdateTarget(
// segment duration. This minimizes the "rubber-band" bouncing effect when
// old_normalized_velocity is large and new_delta is small.
double new_duration =
- std::min(SegmentDuration(new_delta, duration_behavior_).InSecondsF(),
+ std::min(SegmentDuration(new_delta, duration_behavior_, base::TimeDelta())
+ .InSecondsF(),
VelocityBasedDurationBound(old_delta, old_normalized_velocity,
old_duration, new_delta));

Powered by Google App Engine
This is Rietveld 408576698