Commit 3698e89b authored by Majid Valipour's avatar Majid Valipour Committed by Commit Bot

[animation-worklet] Do not tick worklet animations on main thread

We should not tick cc:WorkletAnimation on main thread. The local
time is actually not updated on main thread so the produced value
is incorrect and more importantly causes superfluous commits.


Note: We may decide to avoid ticking all animations on main thread
(See http://crbug.com/762717) in which case we can remove this.


TEST: cc/animation/worklet_animation_unittest.cc
Bug: 839555

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I3335bfd452cc284a585e84a87b8912207b843813
Reviewed-on: https://chromium-review.googlesource.com/1042875
Commit-Queue: Majid Valipour <majidvp@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556256}
parent e5132b72
......@@ -11,11 +11,13 @@ namespace cc {
WorkletAnimation::WorkletAnimation(
int id,
const std::string& name,
std::unique_ptr<ScrollTimeline> scroll_timeline)
std::unique_ptr<ScrollTimeline> scroll_timeline,
bool is_controlling_instance)
: SingleKeyframeEffectAnimation(id),
name_(name),
scroll_timeline_(std::move(scroll_timeline)),
last_current_time_(base::nullopt) {}
last_current_time_(base::nullopt),
is_impl_instance_(is_controlling_instance) {}
WorkletAnimation::~WorkletAnimation() = default;
......@@ -24,7 +26,7 @@ scoped_refptr<WorkletAnimation> WorkletAnimation::Create(
const std::string& name,
std::unique_ptr<ScrollTimeline> scroll_timeline) {
return WrapRefCounted(
new WorkletAnimation(id, name, std::move(scroll_timeline)));
new WorkletAnimation(id, name, std::move(scroll_timeline), false));
}
scoped_refptr<Animation> WorkletAnimation::CreateImplInstance() const {
......@@ -33,7 +35,7 @@ scoped_refptr<Animation> WorkletAnimation::CreateImplInstance() const {
impl_timeline = scroll_timeline_->CreateImplInstance();
return WrapRefCounted(
new WorkletAnimation(id(), name(), std::move(impl_timeline)));
new WorkletAnimation(id(), name(), std::move(impl_timeline), true));
}
void WorkletAnimation::SetLocalTime(base::TimeDelta local_time) {
......@@ -42,6 +44,10 @@ void WorkletAnimation::SetLocalTime(base::TimeDelta local_time) {
}
void WorkletAnimation::Tick(base::TimeTicks monotonic_time) {
// Do not tick worklet animations on main thread. This should be removed if we
// skip ticking all animations on main thread in http://crbug.com/762717.
if (!is_impl_instance_)
return;
// As the output of a WorkletAnimation is driven by a script-provided local
// time, we don't want the underlying effect to participate in the normal
// animations lifecycle. To avoid this we pause the underlying keyframe effect
......
......@@ -23,7 +23,8 @@ class CC_ANIMATION_EXPORT WorkletAnimation final
public:
WorkletAnimation(int id,
const std::string& name,
std::unique_ptr<ScrollTimeline> scroll_timeline);
std::unique_ptr<ScrollTimeline> scroll_timeline,
bool is_controlling_instance);
static scoped_refptr<WorkletAnimation> Create(
int id,
const std::string& name,
......@@ -66,6 +67,8 @@ class CC_ANIMATION_EXPORT WorkletAnimation final
base::TimeDelta local_time_;
base::Optional<double> last_current_time_;
bool is_impl_instance_;
};
} // namespace cc
......
......@@ -75,6 +75,10 @@ TEST_F(WorkletAnimationTest, LocalTimeIsUsedWithAnimations) {
worklet_animation_impl_->SetLocalTime(local_time);
TickAnimationsTransferEvents(base::TimeTicks(), 0u);
TestLayer* layer =
client_.FindTestLayer(element_id_, ElementListType::ACTIVE);
EXPECT_FALSE(layer->is_property_mutated(TargetProperty::OPACITY));
client_impl_.ExpectOpacityPropertyMutated(
element_id_, ElementListType::ACTIVE, expected_opacity);
}
......
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