From f3f612aca8a961713d0fc5633d061a0fe3cc3201 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 31 Oct 2023 15:13:31 -0700 Subject: [PATCH] Retain an AnimationClock per-document instead of per-page Since each document coarsens timestamps differently, having a clock for each makes more sense than having one per the all page and then coarsening when retrieving the time. Coarsening on the getter was causing a performance regression, so coarsening at the start of the frame when setting the clock fixes it, but requires a separate clock per document. We still keep the page clock for things like SVG images and intersection stability, though that can be removed in the future. This also matches the spec more closely, where time is coarsened when updating the rendering rather than in DocumentTimeline.currentTime. Bug: 1496136 Change-Id: Ifbd4ca03471232598585db9ee38208c00bcead99 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4981913 Reviewed-by: Robert Flack Commit-Queue: Noam Rosenthal Cr-Commit-Position: refs/heads/main@{#1217900} --- hr-time/raf-coarsened-time.https.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hr-time/raf-coarsened-time.https.html b/hr-time/raf-coarsened-time.https.html index c7cc723da6f4ec..e649d91c16311e 100644 --- a/hr-time/raf-coarsened-time.https.html +++ b/hr-time/raf-coarsened-time.https.html @@ -22,10 +22,13 @@ for (let i = 0; i < 32; ++i) { const timestamp = await new Promise(resolve => requestAnimationFrame(ts => resolve(ts))); const coarse_timestamp = Math.round(timestamp / COARSE_RESOLUTION) * COARSE_RESOLUTION; - assert_approx_equals(timestamp, coarse_timestamp, FLOATING_POINT_ERROR_EPSILON); - assert_approx_equals(timestamp, document.timeline.currentTime, FLOATING_POINT_ERROR_EPSILON); + assert_approx_equals(timestamp, coarse_timestamp, FLOATING_POINT_ERROR_EPSILON, + "timestamp should be coarsened"); + assert_approx_equals(timestamp, document.timeline.currentTime, FLOATING_POINT_ERROR_EPSILON, + "document.timeline.currentTimeline should be the same as the rAF callback"); assert_approx_equals(customTimeline.currentTime + CUSTOM_TIMELINE_DELTA, - timestamp, FLOATING_POINT_ERROR_EPSILON); + timestamp, FLOATING_POINT_ERROR_EPSILON, + "originTime for custom timeline should not be coarsened"); } });