Repository navigation
perf(image-asset): keep encoded images encoded; decode pixels on demand - #194
Merged
Merged
Conversation
An image loaded from a file, URL or encoded bytes kept its whole decoded RGBA buffer for its lifetime, even though 2D draws from the GPU copy. It now keeps Skia's lazy image over the encoded bytes, as Chrome keeps images: - loading still decodes once, so a broken image fails at load as before, then drops the pixels - 2D draws the lazy image: Skia decodes it to upload, then draws from the GPU copy - readers of bytes (WebGL and WebGPU uploads, ImageBitmap, getters) decode for the call - writers turn it into owned pixels first - images from raw pixels keep their pixels as before The encoded bytes are now copied (Data::new_copy): the lazy image decodes from them long after the caller's buffer is gone. In apps/demo-leak on an Android emulator: 8192 sprites from two sheets ended at 69.6 MB of native heap instead of 85.0 MB (PSS 176.7 vs 195.3 MB); 121 three.js texture reloads ended at 60.6 MB native. Rendering: opaque images draw the same pixels as before. Semi-transparent images drawn scaled are now filtered premultiplied, as Chrome draws them, which removes a dark halo the unpremultiplied raster showed at their edges. Images with an embedded color profile are now color-managed when drawn in 2D. Byte readers are unchanged: unpremultiplied RGBA with no color conversion.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An image loaded from a file, URL or encoded bytes kept its whole decoded RGBA buffer for its lifetime, although 2D draws from the GPU copy. It now keeps Skia's lazy image over the encoded bytes:
ImageBitmap, the getters) decode for the call. Writers turn it into owned pixels first.Data::new_copy), because the lazy image decodes from them long after the caller's buffer is gone.Measured
Android emulator (API 37, arm64), native heap and PSS in MB:
Rendering changes
Screenshots of a fixed frame, compared pixel by pixel:
Byte readers are unchanged: unpremultiplied RGBA with no color conversion.
Noticed, not changed
canvas-2dhas no2dfeature, so the#[cfg(feature = "2d")]raster_image()path indrawing_imagesnever compiles. EverydrawImage(asset)goes throughwith_skia_image_bytes, which this PR keeps from decoding for lazy images.Tested on an Android emulator only.