Skip to content

Progressive AVIF tests - #62764

Open
jakearchibald wants to merge 1 commit into
masterfrom
jakearchibald/progressive-avif
Open

jakearchibald wants to merge 1 commit into
masterfrom
jakearchibald/progressive-avif

Conversation

@jakearchibald

Copy link
Copy Markdown
Contributor

This tests progressive rendering support for AVIF. Chrome correctly passes, and Firefox/Safari correctly fail.

@wpt-pr-bot

Copy link
Copy Markdown
Collaborator

There are no reviewers for this pull request. Please reach out on the chat room to get help with this. Thank you!

Comment on lines +22 to +37
// A second image, requested after the one under test, whose completion is
// the signal to screenshot.
//
// The question this answers is "have the bytes of the layer under test been
// delivered yet", and a barrier resource answers it causally rather than by
// guessing at a wall-clock duration.
//
// It is a plain unlayered AVIF, so completing it means the image decoding
// pipeline has taken in and finished a resource queued *after* the one under
// test.
//
// It is trickled like the image under test so that both travel the same
// wptserve pipe machinery rather than one taking a different path through
// the server, and because trickle sets no-store, so the barrier stays a real
// network fetch on every test instead of an instant cache hit.
const kBarrierSrc = "/images/green.avif?pipe=trickle(d0)";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth thinking about. I couldn't come up with a better way to decide "the browser would have done a progressive render now if it could". The alternative would be a timeout, but this seems less flaky. I tested it under CPU load locally and Chrome still correctly passes.

@FrankGalligan

Copy link
Copy Markdown

So I ran some AI on this PR and it highlighted two potential issues.

  1. The test uses a "race" instead of a real finish line (streaming-image-reftest.js)

There are three reasons that doesn't actually work:

  • Separate highway lanes: Browsers don't download images single-file in one line—they open multiple parallel connections at once. Even though image Apple's submission #2 starts ~16 milliseconds later with fetchpriority="low", it's tiny and in its own lane, so it can easily arrive before image Aryeh's submission #1's partial chunk gets processed.
  • Chrome's 1-second cooldown timer: In Chrome (image_resource.cc), as soon as the browser reads the very start of the file (which says "this image is 100×100"), Chrome doesn't immediately redraw the screen for every new trickle of bytes—it uses a 1-second cooldown (kFlushDelay) before handing more partial bytes to the decoder. Meanwhile, image Apple's submission #2 finishes in ~50–80 milliseconds! So the screenshot can get snapped while image Aryeh's submission #1's pixel bytes are still sitting in a waiting room.
  • "Downloaded" ≠ "painted": Image Apple's submission #2's load event only proves image Apple's submission #2 finished downloading—it doesn't wait for background worker threads to finish decoding and painting image Aryeh's submission #1 onto the screen.
  1. A solid single-color box can't catch blending or stretching bugs (progressive-streaming-scaled-layer-alpha.html)

Why this test misses those bugs:

Every pixel is identical: The 25×25 preview layer in both scaled tests is completely solid blue (and completely uniform 50% see-through in the alpha test). Think of averaging two numbers: (10 + 10) / 2 = 10. If every pixel next to every other pixel has the exact same color and transparency, you can't tell whether the blending math between neighboring pixels is broken! While a solid 50%-transparent box would still catch one bug (like accidentally multiplying by 50% twice and washing out the color), it won't catch wrong color/alpha weighting across edges—and a solid blue box also won't catch if the decoder cropped, flipped, distorted, or stretched pixels unevenly inside the 100×100 square.
Too much wiggle room: The tests allow every single one of the 10,000 pixels (totalPixels=0-10000) to be off by ±2 in color, with no explanation why—especially on the non-transparent solid blue test, where pure blue stretched to pure blue shouldn't drift in the middle at all.

How to fix it:
Make the small preview layer a simple multi-part pattern (for example, 4 colored corners, and semi-transparent blue right next to completely invisible pixels) so resizing actually has different neighbors to blend and geometry to preserve, and tighten/explain the allowed pixel difference.

@jakearchibald

Copy link
Copy Markdown
Contributor Author

I'm open to solutions to the race. It seems to work ok now. The AI response doesn't offer a suggestion unless I'm missing something.

@FrankGalligan

Copy link
Copy Markdown

I asked for one for the race. This is what I got back:
How to fix it:
Wait long enough for that 1-second redraw cooldown to expire (e.g., ~1.1 seconds with setTimeout plus a couple animation frames) before taking the screenshot, instead of using a second image as a fake traffic cop.

@jakearchibald

Copy link
Copy Markdown
Contributor Author

Hmmmmm I'm not sure folks are keen on tests that take seconds to fail. That's exactly what I was trying to avoid.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants