[vector_graphics] Fix raster cache size calculation and incorporate ColorFilter/Opacity effects into cache #9082
+183
−70
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.
This PR fixes the bugs mentioned in #8932.
The raster cache size generated by
vector_graphics
takesBoxFit
into account but does not consider the impact of theTransform
widget. In practice, the raster cache size can be derived directly from the canvas's scale, which naturally reflects all visual transformations—including BoxFit, Transform, and any other factors affecting the final display size of the component. This PR replaces the previous size calculation with one based on the canvas scale.Currently, the raster cache does not include
ColorFilter
orOpacity,
meaning that rendering overhead remains high when either is present, due to the need for additional offscreen rendering passes. However, in real-world scenarios—especially when using SVG assets—it's very common to applyColorFilter
for tinting. This PR incorporatesColorFilter
andOpacity
effects into the raster cache, reducing the overall rendering cost.Of course, this PR also aims to address issue #166184.
Regarding point 2, before applying the fix, the trace output was as follows:

At that time, two SVGs were causing two vkQueueSubmit calls, resulting in two offscreen renderings, which took approximately 2ms.
After the fix, the trace output is as follows:
The vkQueueSubmit calls are no longer present, and the processing time has decreased to 0.6ms.
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3