[vector_graphics] Moved color and colorFilter effects into the raster cache to reduce rendering overhead. #9398
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 addresses a performance issue in the VectorGraphic widget when using the raster rendering strategy. Specifically, it moves the color and colorFilter effects into the raster cache stage, avoiding the need to apply them via saveLayer during every frame of rendering.
This issue was highlighted in flutter/flutter#166184, where rendering multiple SVGs in raster mode led to excessive overhead due to the use of saveLayer. Rather than being applied during drawing time, these effects can be baked into the cached image once, resulting in faster and more efficient rendering.
Before this PR
With the current behavior, SVGs using raster mode with color or colorFilter incur significant rendering costs. For example, rendering 20 SVGs may trigger many sub render passes caused by saveLayer:
After this PR
The effects are applied once at caching time. As a result, runtime rendering becomes a simple drawImage call, with no subpasses introduced:
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 under[^1].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 under[^1].///
).