Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A signal for when an image (img) is decoded enough to paint #3271

Open
annevk opened this issue Dec 5, 2017 · 8 comments
Open

A signal for when an image (img) is decoded enough to paint #3271

annevk opened this issue Dec 5, 2017 · 8 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: img

Comments

@annevk
Copy link
Member

annevk commented Dec 5, 2017

See the discussion starting at #1920 (comment) for context.

The idea is to extend the img element with an event, overload decode() somehow, or introduce a another signal not suggested thus far that indicates when it's ready to be displayed to users. While at the same time not making it a high priority relative to painting and hitting 60 FPS and such.

I hope I summarized that correctly.

cc @dbaron @smfr @othermaciej @vmpstr @aghassemi @cramforce @chrishtr

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: img labels Dec 5, 2017
@othermaciej
Copy link

I think this needs to be a mode of decode() or a new method along similar lines, because an image may never be decoded enough to paint if the author don’t ask for it. Examples: if it’s not in the DOM, if it’s offscreen, if it’s currently display: none, (hypothetically) if the layout engine detects that no part of it is visible due to opacity, visibility or occlusion. Because of this, an event is not sufficient. This is essentially the same reason decode() had to be a promise-returning method instead of an event.

@cramforce
Copy link

An argument to decode seems fine to me. I don't have a good naming suggestion :)

@annevk
Copy link
Member Author

annevk commented Dec 5, 2017

To bikeshed: decode({ priority:"low" }); defaults to "high".

@cramforce
Copy link

Ah, I read this more as decode({progressive: true}) (So, try to do a progressive decode if applicable). This might just be a different concern from what you wanted to address @annevk.

@annevk
Copy link
Member Author

annevk commented Dec 5, 2017

Ah, I think there might indeed be two different use cases lurking in that thread:

  1. Please let me know when I can paint this complete image, but don't let decoding it take priority over other things (keep it asynchronous, etc.).
  2. Please let me know when I can paint anything from this image.

@smfr
Copy link

smfr commented Dec 5, 2017

Please let me know when I can paint this complete image, but don't let decoding it take priority over other things (keep it asynchronous, etc.).

This is already covered by decoding=async and decode(), right? Unless you meant to write incomplete, or want some kind of decoding prioritization.

Please let me know when I can paint anything from this image.

I guess this is the incomplete case that we're focusing on here. decode({progressive: true}) would make sense.

@annevk
Copy link
Member Author

annevk commented Dec 6, 2017

@smfr I see, I thought invoking decode() put more priority on decoding than would otherwise be the case (in a scenario where the conditions @othermaciej listed do not apply, e.g., it's visible to the user).

@othermaciej
Copy link

othermaciej commented Dec 6, 2017

Current decode() will initiate decoding of an image even if decoding would not start otherwise, but, at least in WebKit’s implementation, will not make it higher priority than other decoding.

{progressive: true} is close to the right concept, but a little off I think. It doesn’t get across the idea that the promise will be resolved at a different time. Also, regular decode doesn’t prevent progressive decoding necessarily in the case where the image would otherwise paint anyway.

Some examples of syntax that would focus on the issue of the promise firing at a different time:

  • decode({firstFrameOnly: true}
  • decode({minimallyPaintable: true}
  • decode({full: false} (with the default being true)
  • decode({notifyWhen: “paintable”}) (with the default being {notifyWhen: “complete”})

I kind of like the last option , though it is a bit wordy. I could think of a boolean version that is equally clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: img
Development

No branches or pull requests

4 participants