Skip to content

Conversation

@auggie2lbcf
Copy link

sync Mode

  • The Spec: "Image decoding is said to be synchronous if it prevents presentation of other content until it is finished. Typically, this has an effect of atomically presenting
    the image and any other content at the same time. However, this presentation is delayed by the amount of time it takes to perform the decode."
  • The Implementation: The code path for decoding="sync" uses Core::EventLoop::current().spin_until([...]). This call effectively blocks the main thread, halting further script
    execution and rendering updates. It waits in a tight loop until the image decoding process, running on a separate thread, completes (either successfully or with a failure).
    This blocking behavior directly matches the specification's requirement to "prevent presentation of other content until it is finished," thereby achieving an atomic
    presentation.

async Mode

  • The Spec: "Image decoding is said to be asynchronous if it does not prevent presentation of other content. This has an effect of presenting non-image content faster. However,
    the image content is missing on screen until the decode finishes."
  • The Implementation: The code path for decoding="async" queues a microtask to perform the work. The actual decoding is initiated via
    Web::Platform::ImageCodecPlugin::the().decode_image(), which is an asynchronous operation. Callbacks are attached to this operation to resolve or reject the promise when the
    decoding is complete. This entire process does not block the main thread, allowing the browser's rendering engine to continue processing and displaying other content on the
    page. This aligns perfectly with the spec's definition of asynchronous decoding.

auto Mode

  • The Spec: "Indicates no preference in decoding mode (the default)." The user agent is free to choose the most appropriate decoding strategy.
  • The Implementation: The implementation treats the auto mode identically to the async mode. This is a valid and common interpretation of the spec. By defaulting to asynchronous
    decoding, the implementation prioritizes a non-blocking user experience, which is generally preferred for web performance.

@ladybird-bot
Copy link
Collaborator

Hello!

One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

This commit implements the 'decoding' attribute for HTMLImageElement,
including parsing the attribute and implementing the decoding logic.

The 'decoding' attribute can be set to 'auto', 'sync', or 'async'
to control the image decoding behavior. This implementation respects
the chosen mode, with 'sync' blocking the main thread and 'async'
using a background task.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants