Repository navigation
[web] Unify ui.Shader between CanvasKit and Skwasm - #191232
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the web engine's shader architecture by introducing unified EngineShader classes and abstract backend interfaces (BackendShader, BackendGradient, etc.) to decouple the frontend API from specific renderer implementations (CanvasKit and Skwasm). Feedback on these changes highlights potential memory leaks in both CanvasKit and Skwasm fragment shader samplers due to undisposed child image shaders, a missing filterQuality parameter forwarding in EngineFragmentShader.setImageSampler, and the compilation-out of color stop validations in release mode due to being wrapped in assert statements.
| assert(() { | ||
| _validateColorStops(colors, colorStops); | ||
| return true; | ||
| }()); |
There was a problem hiding this comment.
Redundant and Assert-Only Validation of Color Stops\n\nWrapping _validateColorStops in an assert means that this validation is completely compiled out in release mode.\n\nIn Flutter mobile, _validateColorStops is called unconditionally in Gradient factories to throw an ArgumentError if the inputs are invalid. Disabling this on the web in release mode causes a behavioral divergence between mobile and web, and could lead to silent failures or obscure native crashes in CanvasKit/Skia.\n\nPlease call _validateColorStops unconditionally.
_validateColorStops(colors, colorStops);References
- Check for potential regressions: Look for changes that might break existing functionality or introduce unexpected behavior in related areas. (link)
There was a problem hiding this comment.
This is how the native engine does it, so it should be fine to do it here as well.
There was a problem hiding this comment.
The native engine doesn't wrap this in an assert. See:
flutter/engine/src/flutter/lib/ui/painting.dart
Lines 5237 to 5242 in ff6ef7f
There was a problem hiding this comment.
Oops, you're right. I changed it.
27766e4 to
92564fc
Compare
Part of flutter#175630. Refactors `ui.Shader` (including `Gradient` and `ImageShader`) to share core business logic between CanvasKit and Skwasm through the `EngineShader` layer. Backend-specific implementations are intentionally kept minimal, with both backends now only implementing `BackendShader` to provide the final native calls.
92564fc to
342c9d6
Compare
|
CI had a failure that stopped further tests from running. We need to investigate to determine the root cause. SHA at time of execution: 342c9d6. Possible causes:
A blank commit, or merging to head, will be required to resume running CI for this PR. Error Details: Stack trace: |
| assert(() { | ||
| _validateColorStops(colors, colorStops); | ||
| return true; | ||
| }()); |
There was a problem hiding this comment.
The native engine doesn't wrap this in an assert. See:
flutter/engine/src/flutter/lib/ui/painting.dart
Lines 5237 to 5242 in ff6ef7f
|
Thanks @mdebbar, PTAL! |
|
autosubmit label was removed for flutter/flutter/191232, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |

Refactors
ui.Shader(includingGradientandImageShader) to share core business logic between CanvasKit and Skwasm through theEngineShaderlayer. Backend-specific implementations are intentionally kept minimal, with both backends now only implementingBackendShaderto provide the final native calls.Part of #175630.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.