[vector_graphics] Moved color and colorFilter effects into the raster cache to reduce rendering overhead.
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.
Note: This PR is proposed separately from flutter/packages#8932, which introduced a new auto strategy. Although related in purpose (performance improvements), this fix is independent and directly targets the saveLayer overhead problem.
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
- [x] I read the Contributor Guide and followed the process outlined there for submitting PRs.
- [x] I read the Tree Hygiene page, which explains my responsibilities.
- [x] I read and followed the relevant style guides and ran the auto-formatter.
- [x] I signed the CLA.
- [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g.
[shared_preferences] - [x] I linked to at least one issue that this PR fixes in the description above.
- [x] I updated
pubspec.yamlwith 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]. - [x] I updated
CHANGELOG.mdto 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]. - [x] I updated/added any relevant documentation (doc comments with
///). - [x] I added new tests to check the change I am making, or I have commented below to indicate which test exemption this PR falls under[^1].
- [x] All existing and new tests are passing.