Rename and refactor ScrollOffsetAnimations to ScrollOffsetAnimationsImpl
Pre-req CL to enable communication between MT and impl-only animations. This
is described in http://bit.ly/1Y6RA6y.
Note that this CL has no behavioral change.
BUG=594456
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review-Url: https://codereview.chromium.org/1952563002
Cr-Commit-Position: refs/heads/master@{#391530}
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index cf4cd6a2..63b95be 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -28,6 +28,8 @@
"animation/keyframed_animation_curve.h",
"animation/scroll_offset_animation_curve.cc",
"animation/scroll_offset_animation_curve.h",
+ "animation/scroll_offset_animations_impl.cc",
+ "animation/scroll_offset_animations_impl.h",
"animation/target_property.cc",
"animation/target_property.h",
"animation/timing_function.cc",
diff --git a/cc/animation/animation_host.cc b/cc/animation/animation_host.cc
index 29ab6bd..66ebaa4 100644
--- a/cc/animation/animation_host.cc
+++ b/cc/animation/animation_host.cc
@@ -23,129 +23,6 @@
namespace cc {
-class AnimationHost::ScrollOffsetAnimations : public AnimationDelegate {
- public:
- explicit ScrollOffsetAnimations(AnimationHost* animation_host)
- : animation_host_(animation_host),
- scroll_offset_timeline_(
- AnimationTimeline::Create(AnimationIdProvider::NextTimelineId())),
- scroll_offset_animation_player_(
- AnimationPlayer::Create(AnimationIdProvider::NextPlayerId())) {
- scroll_offset_timeline_->set_is_impl_only(true);
- scroll_offset_animation_player_->set_animation_delegate(this);
-
- animation_host_->AddAnimationTimeline(scroll_offset_timeline_.get());
- scroll_offset_timeline_->AttachPlayer(
- scroll_offset_animation_player_.get());
- }
-
- ~ScrollOffsetAnimations() override {
- scroll_offset_timeline_->DetachPlayer(
- scroll_offset_animation_player_.get());
- animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get());
- }
-
- void ScrollAnimationCreate(ElementId element_id,
- const gfx::ScrollOffset& target_offset,
- const gfx::ScrollOffset& current_offset) {
- std::unique_ptr<ScrollOffsetAnimationCurve> curve =
- ScrollOffsetAnimationCurve::Create(
- target_offset, EaseInOutTimingFunction::Create(),
- ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA);
- curve->SetInitialValue(current_offset);
-
- std::unique_ptr<Animation> animation = Animation::Create(
- std::move(curve), AnimationIdProvider::NextAnimationId(),
- AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET);
- animation->set_is_impl_only(true);
-
- DCHECK(scroll_offset_animation_player_);
- DCHECK(scroll_offset_animation_player_->animation_timeline());
-
- ReattachScrollOffsetPlayerIfNeeded(element_id);
-
- scroll_offset_animation_player_->AddAnimation(std::move(animation));
- }
-
- bool ScrollAnimationUpdateTarget(ElementId element_id,
- const gfx::Vector2dF& scroll_delta,
- const gfx::ScrollOffset& max_scroll_offset,
- base::TimeTicks frame_monotonic_time) {
- DCHECK(scroll_offset_animation_player_);
- if (!scroll_offset_animation_player_->element_animations())
- return false;
-
- DCHECK_EQ(element_id, scroll_offset_animation_player_->element_id());
-
- Animation* animation = scroll_offset_animation_player_->element_animations()
- ->GetAnimation(TargetProperty::SCROLL_OFFSET);
- if (!animation) {
- scroll_offset_animation_player_->DetachElement();
- return false;
- }
-
- ScrollOffsetAnimationCurve* curve =
- animation->curve()->ToScrollOffsetAnimationCurve();
-
- gfx::ScrollOffset new_target =
- gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta);
- new_target.SetToMax(gfx::ScrollOffset());
- new_target.SetToMin(max_scroll_offset);
-
- curve->UpdateTarget(animation->TrimTimeToCurrentIteration(
- frame_monotonic_time).InSecondsF(),
- new_target);
-
- return true;
- }
-
- void ScrollAnimationAbort(bool needs_completion) {
- DCHECK(scroll_offset_animation_player_);
- scroll_offset_animation_player_->AbortAnimations(
- TargetProperty::SCROLL_OFFSET, needs_completion);
- }
-
- // AnimationDelegate implementation.
- void NotifyAnimationStarted(base::TimeTicks monotonic_time,
- TargetProperty::Type target_property,
- int group) override {}
- void NotifyAnimationFinished(base::TimeTicks monotonic_time,
- TargetProperty::Type target_property,
- int group) override {
- DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET);
- DCHECK(animation_host_->mutator_host_client());
- animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished();
- }
- void NotifyAnimationAborted(base::TimeTicks monotonic_time,
- TargetProperty::Type target_property,
- int group) override {}
- void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
- TargetProperty::Type target_property,
- double animation_start_time,
- std::unique_ptr<AnimationCurve> curve) override {
- }
-
- private:
- void ReattachScrollOffsetPlayerIfNeeded(ElementId element_id) {
- if (scroll_offset_animation_player_->element_id() != element_id) {
- if (scroll_offset_animation_player_->element_id())
- scroll_offset_animation_player_->DetachElement();
- if (element_id)
- scroll_offset_animation_player_->AttachElement(element_id);
- }
- }
-
- AnimationHost* animation_host_;
- scoped_refptr<AnimationTimeline> scroll_offset_timeline_;
-
- // We have just one player for impl-only scroll offset animations.
- // I.e. only one element can have an impl-only scroll offset animation at
- // any given time.
- scoped_refptr<AnimationPlayer> scroll_offset_animation_player_;
-
- DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimations);
-};
-
std::unique_ptr<AnimationHost> AnimationHost::Create(
ThreadInstance thread_instance) {
return base::WrapUnique(new AnimationHost(thread_instance));
@@ -157,12 +34,12 @@
supports_scroll_animations_(false),
animation_waiting_for_deletion_(false) {
if (thread_instance_ == ThreadInstance::IMPL)
- scroll_offset_animations_ =
- base::WrapUnique(new ScrollOffsetAnimations(this));
+ scroll_offset_animations_impl_ =
+ base::WrapUnique(new ScrollOffsetAnimationsImpl(this));
}
AnimationHost::~AnimationHost() {
- scroll_offset_animations_ = nullptr;
+ scroll_offset_animations_impl_ = nullptr;
ClearTimelines();
DCHECK(!mutator_host_client());
@@ -641,9 +518,9 @@
ElementId element_id,
const gfx::ScrollOffset& target_offset,
const gfx::ScrollOffset& current_offset) {
- DCHECK(scroll_offset_animations_);
- scroll_offset_animations_->ScrollAnimationCreate(element_id, target_offset,
- current_offset);
+ DCHECK(scroll_offset_animations_impl_);
+ scroll_offset_animations_impl_->ScrollAnimationCreate(
+ element_id, target_offset, current_offset);
}
bool AnimationHost::ImplOnlyScrollAnimationUpdateTarget(
@@ -651,14 +528,14 @@
const gfx::Vector2dF& scroll_delta,
const gfx::ScrollOffset& max_scroll_offset,
base::TimeTicks frame_monotonic_time) {
- DCHECK(scroll_offset_animations_);
- return scroll_offset_animations_->ScrollAnimationUpdateTarget(
+ DCHECK(scroll_offset_animations_impl_);
+ return scroll_offset_animations_impl_->ScrollAnimationUpdateTarget(
element_id, scroll_delta, max_scroll_offset, frame_monotonic_time);
}
void AnimationHost::ScrollAnimationAbort(bool needs_completion) {
- DCHECK(scroll_offset_animations_);
- return scroll_offset_animations_->ScrollAnimationAbort(needs_completion);
+ DCHECK(scroll_offset_animations_impl_);
+ return scroll_offset_animations_impl_->ScrollAnimationAbort(needs_completion);
}
void AnimationHost::DidActivateElementAnimations(
diff --git a/cc/animation/animation_host.h b/cc/animation/animation_host.h
index 49f25b7d..5839d59 100644
--- a/cc/animation/animation_host.h
+++ b/cc/animation/animation_host.h
@@ -13,6 +13,7 @@
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "cc/animation/animation.h"
+#include "cc/animation/scroll_offset_animations_impl.h"
#include "cc/base/cc_export.h"
#include "cc/trees/mutator_host_client.h"
#include "ui/gfx/geometry/box_f.h"
@@ -188,8 +189,7 @@
MutatorHostClient* mutator_host_client_;
- class ScrollOffsetAnimations;
- std::unique_ptr<ScrollOffsetAnimations> scroll_offset_animations_;
+ std::unique_ptr<ScrollOffsetAnimationsImpl> scroll_offset_animations_impl_;
const ThreadInstance thread_instance_;
diff --git a/cc/animation/scroll_offset_animations_impl.cc b/cc/animation/scroll_offset_animations_impl.cc
new file mode 100644
index 0000000..ffebdbc
--- /dev/null
+++ b/cc/animation/scroll_offset_animations_impl.cc
@@ -0,0 +1,118 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/animation/scroll_offset_animations_impl.h"
+
+#include "cc/animation/animation_events.h"
+#include "cc/animation/animation_host.h"
+#include "cc/animation/animation_id_provider.h"
+#include "cc/animation/animation_player.h"
+#include "cc/animation/animation_timeline.h"
+#include "cc/animation/element_animations.h"
+#include "cc/animation/timing_function.h"
+
+namespace cc {
+
+ScrollOffsetAnimationsImpl::ScrollOffsetAnimationsImpl(
+ AnimationHost* animation_host)
+ : animation_host_(animation_host),
+ scroll_offset_timeline_(
+ AnimationTimeline::Create(AnimationIdProvider::NextTimelineId())),
+ scroll_offset_animation_player_(
+ AnimationPlayer::Create(AnimationIdProvider::NextPlayerId())) {
+ scroll_offset_timeline_->set_is_impl_only(true);
+ scroll_offset_animation_player_->set_animation_delegate(this);
+
+ animation_host_->AddAnimationTimeline(scroll_offset_timeline_.get());
+ scroll_offset_timeline_->AttachPlayer(scroll_offset_animation_player_.get());
+}
+
+ScrollOffsetAnimationsImpl::~ScrollOffsetAnimationsImpl() {
+ scroll_offset_timeline_->DetachPlayer(scroll_offset_animation_player_.get());
+ animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get());
+}
+
+void ScrollOffsetAnimationsImpl::ScrollAnimationCreate(
+ ElementId element_id,
+ const gfx::ScrollOffset& target_offset,
+ const gfx::ScrollOffset& current_offset) {
+ std::unique_ptr<ScrollOffsetAnimationCurve> curve =
+ ScrollOffsetAnimationCurve::Create(
+ target_offset, EaseInOutTimingFunction::Create(),
+ ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA);
+ curve->SetInitialValue(current_offset);
+
+ std::unique_ptr<Animation> animation = Animation::Create(
+ std::move(curve), AnimationIdProvider::NextAnimationId(),
+ AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET);
+ animation->set_is_impl_only(true);
+
+ DCHECK(scroll_offset_animation_player_);
+ DCHECK(scroll_offset_animation_player_->animation_timeline());
+
+ ReattachScrollOffsetPlayerIfNeeded(element_id);
+
+ scroll_offset_animation_player_->AddAnimation(std::move(animation));
+}
+
+bool ScrollOffsetAnimationsImpl::ScrollAnimationUpdateTarget(
+ ElementId element_id,
+ const gfx::Vector2dF& scroll_delta,
+ const gfx::ScrollOffset& max_scroll_offset,
+ base::TimeTicks frame_monotonic_time) {
+ DCHECK(scroll_offset_animation_player_);
+ if (!scroll_offset_animation_player_->element_animations())
+ return false;
+
+ DCHECK_EQ(element_id, scroll_offset_animation_player_->element_id());
+
+ Animation* animation =
+ scroll_offset_animation_player_->element_animations()->GetAnimation(
+ TargetProperty::SCROLL_OFFSET);
+ if (!animation) {
+ scroll_offset_animation_player_->DetachElement();
+ return false;
+ }
+
+ ScrollOffsetAnimationCurve* curve =
+ animation->curve()->ToScrollOffsetAnimationCurve();
+
+ gfx::ScrollOffset new_target =
+ gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta);
+ new_target.SetToMax(gfx::ScrollOffset());
+ new_target.SetToMin(max_scroll_offset);
+
+ curve->UpdateTarget(
+ animation->TrimTimeToCurrentIteration(frame_monotonic_time).InSecondsF(),
+ new_target);
+
+ return true;
+}
+
+void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) {
+ DCHECK(scroll_offset_animation_player_);
+ scroll_offset_animation_player_->AbortAnimations(
+ TargetProperty::SCROLL_OFFSET, needs_completion);
+}
+
+void ScrollOffsetAnimationsImpl::NotifyAnimationFinished(
+ base::TimeTicks monotonic_time,
+ TargetProperty::Type target_property,
+ int group) {
+ DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET);
+ DCHECK(animation_host_->mutator_host_client());
+ animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished();
+}
+
+void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded(
+ ElementId element_id) {
+ if (scroll_offset_animation_player_->element_id() != element_id) {
+ if (scroll_offset_animation_player_->element_id())
+ scroll_offset_animation_player_->DetachElement();
+ if (element_id)
+ scroll_offset_animation_player_->AttachElement(element_id);
+ }
+}
+
+} // namespace cc
diff --git a/cc/animation/scroll_offset_animations_impl.h b/cc/animation/scroll_offset_animations_impl.h
new file mode 100644
index 0000000..47e6d2b
--- /dev/null
+++ b/cc/animation/scroll_offset_animations_impl.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_ANIMATION_SCROLL_OFFSET_ANIMATIONS_IMPL_H_
+#define CC_ANIMATION_SCROLL_OFFSET_ANIMATIONS_IMPL_H_
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
+#include "cc/animation/animation_delegate.h"
+#include "cc/animation/scroll_offset_animation_curve.h"
+#include "cc/trees/mutator_host_client.h"
+#include "ui/gfx/geometry/scroll_offset.h"
+
+namespace cc {
+
+class AnimationPlayer;
+class AnimationHost;
+class AnimationTimeline;
+class ElementAnimations;
+
+// Contains an AnimationTimeline and its AnimationPlayer that owns the impl
+// only scroll offset animations running on a particular CC Layer.
+// We have just one player for impl-only scroll offset animations. I.e. only
+// one element can have an impl-only scroll offset animation at any given time.
+// Note that this class only exists on the compositor thread.
+class CC_EXPORT ScrollOffsetAnimationsImpl : public AnimationDelegate {
+ public:
+ explicit ScrollOffsetAnimationsImpl(AnimationHost* animation_host);
+
+ ~ScrollOffsetAnimationsImpl() override;
+
+ void ScrollAnimationCreate(ElementId element_id,
+ const gfx::ScrollOffset& target_offset,
+ const gfx::ScrollOffset& current_offset);
+
+ bool ScrollAnimationUpdateTarget(ElementId element_id,
+ const gfx::Vector2dF& scroll_delta,
+ const gfx::ScrollOffset& max_scroll_offset,
+ base::TimeTicks frame_monotonic_time);
+
+ void ScrollAnimationAbort(bool needs_completion);
+
+ // AnimationDelegate implementation.
+ void NotifyAnimationStarted(base::TimeTicks monotonic_time,
+ TargetProperty::Type target_property,
+ int group) override {}
+ void NotifyAnimationFinished(base::TimeTicks monotonic_time,
+ TargetProperty::Type target_property,
+ int group) override;
+ void NotifyAnimationAborted(base::TimeTicks monotonic_time,
+ TargetProperty::Type target_property,
+ int group) override {}
+ void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
+ TargetProperty::Type target_property,
+ double animation_start_time,
+ std::unique_ptr<AnimationCurve> curve) override {
+ }
+
+ private:
+ void ReattachScrollOffsetPlayerIfNeeded(ElementId element_id);
+
+ AnimationHost* animation_host_;
+ scoped_refptr<AnimationTimeline> scroll_offset_timeline_;
+
+ // We have just one player for impl-only scroll offset animations.
+ // I.e. only one element can have an impl-only scroll offset animation at
+ // any given time.
+ scoped_refptr<AnimationPlayer> scroll_offset_animation_player_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimationsImpl);
+};
+
+} // namespace cc
+
+#endif // CC_ANIMATION_SCROLL_OFFSET_ANIMATIONS_IMPL_H_
diff --git a/cc/cc.gyp b/cc/cc.gyp
index b3b0e78..9cc3bd9 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -56,6 +56,8 @@
'animation/keyframed_animation_curve.h',
'animation/scroll_offset_animation_curve.cc',
'animation/scroll_offset_animation_curve.h',
+ 'animation/scroll_offset_animations_impl.cc',
+ 'animation/scroll_offset_animations_impl.h',
'animation/target_property.cc',
'animation/target_property.h',
'animation/timing_function.cc',