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

Side by Side Diff: cc/animation/animation_host.cc

Issue 1009233002: CC Animations: Port Impl-only-scrolling to use compositor animation timelines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ui
Patch Set: Fix the nit. Created 5 years, 5 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
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/animation_host.h" 5 #include "cc/animation/animation_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_id_provider.h"
9 #include "cc/animation/animation_player.h" 11 #include "cc/animation/animation_player.h"
10 #include "cc/animation/animation_registrar.h" 12 #include "cc/animation/animation_registrar.h"
11 #include "cc/animation/animation_timeline.h" 13 #include "cc/animation/animation_timeline.h"
12 #include "cc/animation/element_animations.h" 14 #include "cc/animation/element_animations.h"
15 #include "cc/animation/scroll_offset_animation_curve.h"
16 #include "cc/animation/timing_function.h"
13 #include "ui/gfx/geometry/box_f.h" 17 #include "ui/gfx/geometry/box_f.h"
18 #include "ui/gfx/geometry/scroll_offset.h"
14 19
15 namespace cc { 20 namespace cc {
16 21
17 scoped_ptr<AnimationHost> AnimationHost::Create() { 22 class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
18 return make_scoped_ptr(new AnimationHost); 23 public:
24 explicit ScrollOffsetAnimations(AnimationHost* animation_host)
25 : animation_host_(animation_host),
26 scroll_offset_timeline_(
27 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId())),
28 scroll_offset_animation_player_(
29 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId())) {
30 scroll_offset_timeline_->set_is_impl_only(true);
31 scroll_offset_animation_player_->set_layer_animation_delegate(this);
32
33 animation_host_->AddAnimationTimeline(scroll_offset_timeline_.get());
34 scroll_offset_timeline_->AttachPlayer(
35 scroll_offset_animation_player_.get());
36 }
37
38 ~ScrollOffsetAnimations() override {
39 scroll_offset_timeline_->DetachPlayer(
40 scroll_offset_animation_player_.get());
41 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get());
42 }
43
44 void ScrollAnimationCreate(int layer_id,
45 const gfx::ScrollOffset& target_offset,
46 const gfx::ScrollOffset& current_offset) {
47 scoped_ptr<ScrollOffsetAnimationCurve> curve =
48 ScrollOffsetAnimationCurve::Create(target_offset,
49 EaseInOutTimingFunction::Create());
50 curve->SetInitialValue(current_offset);
51
52 scoped_ptr<Animation> animation = Animation::Create(
53 curve.Pass(), AnimationIdProvider::NextAnimationId(),
54 AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET);
55 animation->set_is_impl_only(true);
56
57 DCHECK(scroll_offset_animation_player_);
58 DCHECK(scroll_offset_animation_player_->animation_timeline());
59
60 if (scroll_offset_animation_player_->layer_id() != layer_id) {
61 if (scroll_offset_animation_player_->layer_id())
62 scroll_offset_animation_player_->DetachLayer();
63 scroll_offset_animation_player_->AttachLayer(layer_id);
64 }
65
66 scroll_offset_animation_player_->AddAnimation(animation.Pass());
67 }
68
69 bool ScrollAnimationUpdateTarget(int layer_id,
70 const gfx::Vector2dF& scroll_delta,
71 const gfx::ScrollOffset& max_scroll_offset,
72 base::TimeTicks frame_monotonic_time) {
73 DCHECK(scroll_offset_animation_player_);
74 DCHECK_EQ(layer_id, scroll_offset_animation_player_->layer_id());
75
76 Animation* animation = scroll_offset_animation_player_->element_animations()
77 ->layer_animation_controller()
78 ->GetAnimation(Animation::SCROLL_OFFSET);
79 if (!animation) {
80 scroll_offset_animation_player_->DetachLayer();
81 return false;
82 }
83
84 ScrollOffsetAnimationCurve* curve =
85 animation->curve()->ToScrollOffsetAnimationCurve();
86
87 gfx::ScrollOffset new_target =
88 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta);
89 new_target.SetToMax(gfx::ScrollOffset());
90 new_target.SetToMin(max_scroll_offset);
91
92 curve->UpdateTarget(animation->TrimTimeToCurrentIteration(
93 frame_monotonic_time).InSecondsF(),
94 new_target);
95
96 return true;
97 }
98
99 // AnimationDelegate implementation.
100 void NotifyAnimationStarted(base::TimeTicks monotonic_time,
101 Animation::TargetProperty target_property,
102 int group) override {}
103 void NotifyAnimationFinished(base::TimeTicks monotonic_time,
104 Animation::TargetProperty target_property,
105 int group) override {
106 DCHECK_EQ(target_property, Animation::SCROLL_OFFSET);
107 DCHECK(animation_host_->mutator_host_client());
108 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished();
109 }
110
111 private:
112 AnimationHost* animation_host_;
113 scoped_refptr<AnimationTimeline> scroll_offset_timeline_;
114
115 // We have just one player for impl-only scroll offset animations.
116 // I.e. only one layer can have an impl-only scroll offset animation at
117 // any given time.
118 scoped_refptr<AnimationPlayer> scroll_offset_animation_player_;
119
120 DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations);
121 };
122
123 scoped_ptr<AnimationHost> AnimationHost::Create(
124 ThreadInstance thread_instance) {
125 return make_scoped_ptr(new AnimationHost(thread_instance));
19 } 126 }
20 127
21 AnimationHost::AnimationHost() 128 AnimationHost::AnimationHost(ThreadInstance thread_instance)
22 : animation_registrar_(AnimationRegistrar::Create()), 129 : animation_registrar_(AnimationRegistrar::Create()),
23 mutator_host_client_(nullptr) { 130 mutator_host_client_(nullptr),
131 thread_instance_(thread_instance) {
132 if (thread_instance_ == ThreadInstance::IMPL)
133 scroll_offset_animations_ =
134 make_scoped_ptr(new ScrollOffsetAnimations(this));
24 } 135 }
25 136
26 AnimationHost::~AnimationHost() { 137 AnimationHost::~AnimationHost() {
138 scroll_offset_animations_ = nullptr;
139
27 ClearTimelines(); 140 ClearTimelines();
28 DCHECK(!mutator_host_client()); 141 DCHECK(!mutator_host_client());
29 DCHECK(layer_to_element_animations_map_.empty()); 142 DCHECK(layer_to_element_animations_map_.empty());
30 } 143 }
31 144
32 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const { 145 AnimationTimeline* AnimationHost::GetTimelineById(int timeline_id) const {
33 for (auto& timeline : timelines_) 146 for (auto& timeline : timelines_)
34 if (timeline->id() == timeline_id) 147 if (timeline->id() == timeline_id)
35 return timeline.get(); 148 return timeline.get();
36 return nullptr; 149 return nullptr;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 bool AnimationHost::HasAnyAnimation(int layer_id) const { 482 bool AnimationHost::HasAnyAnimation(int layer_id) const {
370 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 483 LayerAnimationController* controller = GetControllerForLayerId(layer_id);
371 return controller ? controller->has_any_animation() : false; 484 return controller ? controller->has_any_animation() : false;
372 } 485 }
373 486
374 bool AnimationHost::HasActiveAnimation(int layer_id) const { 487 bool AnimationHost::HasActiveAnimation(int layer_id) const {
375 LayerAnimationController* controller = GetControllerForLayerId(layer_id); 488 LayerAnimationController* controller = GetControllerForLayerId(layer_id);
376 return controller ? controller->HasActiveAnimation() : false; 489 return controller ? controller->HasActiveAnimation() : false;
377 } 490 }
378 491
492 void AnimationHost::ImplOnlyScrollAnimationCreate(
493 int layer_id,
494 const gfx::ScrollOffset& target_offset,
495 const gfx::ScrollOffset& current_offset) {
496 DCHECK(scroll_offset_animations_);
497 scroll_offset_animations_->ScrollAnimationCreate(layer_id, target_offset,
498 current_offset);
499 }
500
501 bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget(
502 int layer_id,
503 const gfx::Vector2dF& scroll_delta,
504 const gfx::ScrollOffset& max_scroll_offset,
505 base::TimeTicks frame_monotonic_time) {
506 DCHECK(scroll_offset_animations_);
507 return scroll_offset_animations_->ScrollAnimationUpdateTarget(
508 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time);
509 }
510
379 } // namespace cc 511 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation_host.h ('k') | cc/animation/animation_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698