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

Side by Side Diff: cc/animation/scroll_offset_animations_impl.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: Remove unused plumbing Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/animation/scroll_offset_animations_impl.h" 5 #include "cc/animation/scroll_offset_animations_impl.h"
6 6
7 #include "cc/animation/animation_events.h" 7 #include "cc/animation/animation_events.h"
8 #include "cc/animation/animation_host.h" 8 #include "cc/animation/animation_host.h"
9 #include "cc/animation/animation_id_provider.h" 9 #include "cc/animation/animation_id_provider.h"
10 #include "cc/animation/animation_player.h" 10 #include "cc/animation/animation_player.h"
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 ScrollOffsetAnimationsImpl::~ScrollOffsetAnimationsImpl() { 31 ScrollOffsetAnimationsImpl::~ScrollOffsetAnimationsImpl() {
32 scroll_offset_timeline_->DetachPlayer(scroll_offset_animation_player_.get()); 32 scroll_offset_timeline_->DetachPlayer(scroll_offset_animation_player_.get());
33 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get()); 33 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get());
34 } 34 }
35 35
36 void ScrollOffsetAnimationsImpl::ScrollAnimationCreate( 36 void ScrollOffsetAnimationsImpl::ScrollAnimationCreate(
37 ElementId element_id, 37 ElementId element_id,
38 const gfx::ScrollOffset& target_offset, 38 const gfx::ScrollOffset& target_offset,
39 const gfx::ScrollOffset& current_offset) { 39 const gfx::ScrollOffset& current_offset,
40 base::TimeDelta delayed_by) {
40 std::unique_ptr<ScrollOffsetAnimationCurve> curve = 41 std::unique_ptr<ScrollOffsetAnimationCurve> curve =
41 ScrollOffsetAnimationCurve::Create( 42 ScrollOffsetAnimationCurve::Create(
42 target_offset, CubicBezierTimingFunction::CreatePreset( 43 target_offset, CubicBezierTimingFunction::CreatePreset(
43 CubicBezierTimingFunction::EaseType::EASE_IN_OUT), 44 CubicBezierTimingFunction::EaseType::EASE_IN_OUT),
44 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); 45 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA);
45 curve->SetInitialValue(current_offset); 46 curve->SetInitialValue(current_offset, delayed_by);
46 47
47 std::unique_ptr<Animation> animation = Animation::Create( 48 std::unique_ptr<Animation> animation = Animation::Create(
48 std::move(curve), AnimationIdProvider::NextAnimationId(), 49 std::move(curve), AnimationIdProvider::NextAnimationId(),
49 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET); 50 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET);
50 animation->set_is_impl_only(true); 51 animation->set_is_impl_only(true);
51 52
52 DCHECK(scroll_offset_animation_player_); 53 DCHECK(scroll_offset_animation_player_);
53 DCHECK(scroll_offset_animation_player_->animation_timeline()); 54 DCHECK(scroll_offset_animation_player_->animation_timeline());
54 55
55 ReattachScrollOffsetPlayerIfNeeded(element_id); 56 ReattachScrollOffsetPlayerIfNeeded(element_id);
56 57
57 scroll_offset_animation_player_->AddAnimation(std::move(animation)); 58 scroll_offset_animation_player_->AddAnimation(std::move(animation));
58 } 59 }
59 60
60 bool ScrollOffsetAnimationsImpl::ScrollAnimationUpdateTarget( 61 bool ScrollOffsetAnimationsImpl::ScrollAnimationUpdateTarget(
61 ElementId element_id, 62 ElementId element_id,
62 const gfx::Vector2dF& scroll_delta, 63 const gfx::Vector2dF& scroll_delta,
63 const gfx::ScrollOffset& max_scroll_offset, 64 const gfx::ScrollOffset& max_scroll_offset,
64 base::TimeTicks frame_monotonic_time) { 65 base::TimeTicks frame_monotonic_time,
66 base::TimeDelta delayed_by) {
65 DCHECK(scroll_offset_animation_player_); 67 DCHECK(scroll_offset_animation_player_);
66 if (!scroll_offset_animation_player_->element_animations()) 68 if (!scroll_offset_animation_player_->element_animations())
67 return false; 69 return false;
68 70
69 DCHECK_EQ(element_id, scroll_offset_animation_player_->element_id()); 71 DCHECK_EQ(element_id, scroll_offset_animation_player_->element_id());
70 72
71 Animation* animation = 73 Animation* animation =
72 scroll_offset_animation_player_->element_animations()->GetAnimation( 74 scroll_offset_animation_player_->element_animations()->GetAnimation(
73 TargetProperty::SCROLL_OFFSET); 75 TargetProperty::SCROLL_OFFSET);
74 if (!animation) { 76 if (!animation) {
(...skipping 11 matching lines...) Expand all
86 new_target.SetToMax(gfx::ScrollOffset()); 88 new_target.SetToMax(gfx::ScrollOffset());
87 new_target.SetToMin(max_scroll_offset); 89 new_target.SetToMin(max_scroll_offset);
88 90
89 // TODO(ymalik): Animation::TrimTimeToCurrentIteration should probably check 91 // TODO(ymalik): Animation::TrimTimeToCurrentIteration should probably check
90 // for run_state == Animation::WAITING_FOR_TARGET_AVAILABILITY. 92 // for run_state == Animation::WAITING_FOR_TARGET_AVAILABILITY.
91 base::TimeDelta trimmed = 93 base::TimeDelta trimmed =
92 animation->run_state() == Animation::WAITING_FOR_TARGET_AVAILABILITY 94 animation->run_state() == Animation::WAITING_FOR_TARGET_AVAILABILITY
93 ? base::TimeDelta() 95 ? base::TimeDelta()
94 : animation->TrimTimeToCurrentIteration(frame_monotonic_time); 96 : animation->TrimTimeToCurrentIteration(frame_monotonic_time);
95 97
98 // Re-target taking the delay into account.
99 if (delayed_by > base::TimeDelta())
tdresser 2016/08/25 15:55:54 !delayed_by.is_zero()
ymalik 2016/08/29 14:52:05 Covered this on chat, but for posterity: delayed_b
100 trimmed = delayed_by < trimmed ? trimmed - delayed_by : base::TimeDelta();
tdresser 2016/08/25 15:55:54 I'm not completely clear on what's going on here.
tdresser 2016/08/29 14:31:33 Subtraction is just saturated. This seems reasonab
ymalik 2016/08/29 14:52:05 Yes. We're just trying to use the delay as a signa
101
96 curve->UpdateTarget(trimmed.InSecondsF(), new_target); 102 curve->UpdateTarget(trimmed.InSecondsF(), new_target);
97 103
98 return true; 104 return true;
99 } 105 }
100 106
101 void ScrollOffsetAnimationsImpl::ScrollAnimationApplyAdjustment( 107 void ScrollOffsetAnimationsImpl::ScrollAnimationApplyAdjustment(
102 ElementId element_id, 108 ElementId element_id,
103 const gfx::Vector2dF& adjustment) { 109 const gfx::Vector2dF& adjustment) {
104 DCHECK(scroll_offset_animation_player_); 110 DCHECK(scroll_offset_animation_player_);
105 if (element_id != scroll_offset_animation_player_->element_id()) 111 if (element_id != scroll_offset_animation_player_->element_id())
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ElementId element_id) { 159 ElementId element_id) {
154 if (scroll_offset_animation_player_->element_id() != element_id) { 160 if (scroll_offset_animation_player_->element_id() != element_id) {
155 if (scroll_offset_animation_player_->element_id()) 161 if (scroll_offset_animation_player_->element_id())
156 scroll_offset_animation_player_->DetachElement(); 162 scroll_offset_animation_player_->DetachElement();
157 if (element_id) 163 if (element_id)
158 scroll_offset_animation_player_->AttachElement(element_id); 164 scroll_offset_animation_player_->AttachElement(element_id);
159 } 165 }
160 } 166 }
161 167
162 } // namespace cc 168 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698