fix: NativeImage.getScaleFactors returns correct scales #25832
Merged
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.
Description of Change
Extracting part of #25727 which is safer (though doesn't fix everything that #25727 does).
gfx::ImageSkia::GetSupportedScales()
is a static method that always returns the same values, regardless of the properties of the image.Fixing this necessitated changing the
CreateFromPNG
function to callAddImageSkiaRepFromPNG
instead ofCreateFrom1xPNGBytes
. The reason is thatgfx::Image
has some functionality for lazily decoding PNG images on an as-needed basis. When agfx::Image
is created with a PNG source, it will only materialize a representation (pixel buffer) for that image when a specific scale factor is requested. So asking for "what scale factors does this image have?" of an image created in this way, when no scale factors have already been requested, would return an empty list.This has the downside that we now eagerly decode PNGs instead of lazily decoding them. Unfortunately, there is no way to detect the "lazy-decoding" state through the API that
gfx::Image
decodes. This PR chooses correctness over performance.Checklist
npm test
passesRelease Notes
Notes: Fixed NativeImage.getScaleFactors() always returning the same value.