Closed Bug 1775495 Opened 2 years ago Closed 2 years ago

Use of async and sync image decodes can cause duplicates in the SurfaceCache

Categories

(Core :: Graphics: ImageLib, defect, P3)

defect

Tracking

()

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: aosmond, Assigned: aosmond)

References

Details

Attachments

(1 file)

We may trigger an async decode for a raster image through the prediction logic:

https://searchfox.org/mozilla-central/rev/44d99b6b8d84abed2d20386cc2e62cd90da41cc3/layout/generic/nsImageFrame.cpp#1125

And then we may trigger a sync decode due to the decoding attribute on the image.

If the async decode hasn't produce any frame data yet, then we will enter the if block and request another frame to be decoded:

https://searchfox.org/mozilla-central/rev/44d99b6b8d84abed2d20386cc2e62cd90da41cc3/image/RasterImage.cpp#347

We should do better here. Perhaps if we could create the first frame's imgFrame immediately when the Decoder is initialized for non-metadata decodes? We should know what size we need. That would allow us to avoid the case where there is no frame data, and then we can't block on:

https://searchfox.org/mozilla-central/rev/44d99b6b8d84abed2d20386cc2e62cd90da41cc3/image/RasterImage.cpp#385

We should also consider returning TEMPORARY_ERROR or NOT_READY if we try to sync decode and we have yet to load all the data from the network. This would ensure sync decodes either return an error or return all of the pixel data.

This can also impact CI which uses sync decoding.

Blocks: wr-memory

If we do trigger a sync decode, but we don't have all the source data, we don't enter the if block for the sync path:

https://searchfox.org/mozilla-central/rev/44d99b6b8d84abed2d20386cc2e62cd90da41cc3/image/RasterImage.cpp#1114

And trigger another async path. That can exacerbate the issues mentioned in the original description, as we would not have triggered a new async decode if the sync decode was not set, but do if it is.

When we request a sync decode, there is an outstanding pending async
decode, but we don't have all the network data, we would end up
triggering an extra async decode. This patch ensures that we only
trigger sync decodes if they will actually execute as async.

Pushed by aosmond@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/19e6d96df297
Avoid trigger extra async image decodes when sync decodes are requested. r=jrmuizel
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 103 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: