Commit d358adee authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Animation Worklet: Use the correct time in WorkletAnimation::GetTimeForKeyframeModel

This code used to assume that the local_time_ was equivalent to the
active time, but that isn't true. Active time is local time - start
delay, so the start delay (time_offset_) shouldn't be removed when
converting local_time_ to 'real' time.

Bug: 824782
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I3cc570c4054843bf31cdba0f58917f4566ccd8b1
Reviewed-on: https://chromium-review.googlesource.com/1008062
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarMajid Valipour <majidvp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550766}
parent 2ed0db6e
......@@ -152,8 +152,8 @@ bool KeyframeModel::InEffect(base::TimeTicks monotonic_time) const {
(fill_mode_ == FillMode::BOTH || fill_mode_ == FillMode::BACKWARDS);
}
base::TimeTicks KeyframeModel::ConvertFromActiveTime(
base::TimeDelta active_time) const {
base::TimeTicks KeyframeModel::ConvertLocalTimeToMonotonicTime(
base::TimeDelta local_time) const {
// When waiting on receiving a start time, then our global clock is 'stuck' at
// the initial state.
if ((run_state_ == STARTING && !has_set_start_time()) ||
......@@ -162,9 +162,9 @@ base::TimeTicks KeyframeModel::ConvertFromActiveTime(
// If we're paused, time is 'stuck' at the pause time.
if (run_state_ == PAUSED)
return pause_time_ - time_offset_;
return pause_time_;
return active_time - time_offset_ + start_time_ + total_paused_time_;
return local_time + start_time_ + total_paused_time_;
}
base::TimeDelta KeyframeModel::ConvertToActiveTime(
......
......@@ -140,7 +140,8 @@ class CC_ANIMATION_EXPORT KeyframeModel {
base::TimeDelta TrimTimeToCurrentIteration(
base::TimeTicks monotonic_time) const;
base::TimeTicks ConvertFromActiveTime(base::TimeDelta active_time) const;
base::TimeTicks ConvertLocalTimeToMonotonicTime(
base::TimeDelta local_time) const;
std::unique_ptr<KeyframeModel> CloneAndInitialize(
RunState initial_run_state) const;
......
......@@ -68,9 +68,10 @@ bool WorkletAnimation::NeedsUpdate(base::TimeTicks monotonic_time,
base::TimeTicks WorkletAnimation::GetTimeForKeyframeModel(
const KeyframeModel& keyframe_model) const {
// Animation local time is equivalent to animation active time. So we have to
// convert it from active time to monotonic time.
return keyframe_model.ConvertFromActiveTime(local_time_);
// The local time set by the script has to be converted to monotonic time;
// largely this means it is offset from the start time and includes any time
// the animation spent paused.
return keyframe_model.ConvertLocalTimeToMonotonicTime(local_time_);
}
void WorkletAnimation::PushPropertiesTo(Animation* animation_impl) {
......
<!DOCTYPE html>
<style>
.box {
width: 100px;
height: 100px;
background-color: #00ff00;
}
</style>
<div class="box"></div>
<div style="transform: translateX(100px);" class="box"></div>
<!DOCTYPE html>
<style>
.box {
width: 100px;
height: 100px;
background-color: #00ff00;
}
</style>
<div id="t0" class="box"></div>
<div id="t1" class="box"></div>
<script id="visual_update" type="text/worklet">
registerAnimator("t0_animator", class {
animate(currentTime, effect) {
effect.localTime = 500;
}
});
registerAnimator("t1_animator", class {
animate(currentTime, effect) {
effect.localTime = 5500;
}
});
</script>
<script src="resources/animation-worklet-tests.js"></script>
<script>
if (window.testRunner) {
testRunner.waitUntilDone();
}
runInAnimationWorklet(
document.getElementById('visual_update').textContent
).then(()=>{
const keyframes = [
{ transform: 'translateX(0)' },
{ transform: 'translateX(200px)' }
];
const options = {
duration: 1000,
delay: 5000,
};
const $t0 = document.getElementById('t0');
const $t0_effect = new KeyframeEffect($t0, keyframes, options);
const $t0_animation = new WorkletAnimation('t0_animator', [$t0_effect], document.timeline, {});
const $t1 = document.getElementById('t1');
const $t1_effect = new KeyframeEffect($t1, keyframes, options);
const $t1_animation = new WorkletAnimation('t1_animator', [$t1_effect], document.timeline, {});
$t0_animation.play();
$t1_animation.play();
if (window.testRunner) {
waitTwoAnimationFrames(_ => {
testRunner.notifyDone();
});
}
});
</script>
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