Repository navigation
fix: Apply Opacity to SKCanvasElement content - #25394
morning4coffe-dev wants to merge 3 commits into
Conversation
SKCanvasVisual drew the user's SkiaSharp content straight onto the frame canvas and ignored the accumulated opacity of the paint session, so Opacity on the element or any ancestor had no effect. The drawing is now composited as a layer when the session opacity is below 1.
|
Claude finished @morning4coffe-dev's task in 20s —— View job Review summaryVerdict: ship (approve-quality). The root cause is fixed in Issues: 0 blocking, 0 major, 1 minor (inline comment on the fallback path). Cross-cutting notes
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25394/wasm-skia-net9/index.html |
|
The build 239209 found UI Test snapshots differences: Details
|
|
|
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Claude finished @morning4coffe-dev's task in 14s —— View job Review summaryVerdict: ship. The root cause is fixed in Issues: 0 blocking, 0 major, 0 minor. I posted no inline comments. Cross-cutting notes
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25394/wasm-skia-net9/index.html |
|
The build 239676 found UI Test snapshots differences: Details
|
|
Tick the box to add this pull request to the merge queue (same as
|
# Conflicts: # src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Controls/Given_SKCanvasElement.skia.cs
|
Claude finished @morning4coffe-dev's task in 9s —— View job Review summaryVerdict: ship. Issues: 0 blocking, 0 major, 0 minor. I posted no inline comments. Cross-cutting notes
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 246601 found UI Test snapshots differences: Details
|
MartinZikmund
left a comment
There was a problem hiding this comment.
@morning4coffe-dev The SKCanvas path looks right to me. session.Opacity is already the product of the ancestor chain (Visual.CreateLocalSession), and nothing else in the pipeline adds a layer, so this applies opacity exactly once and nested opacity comes out right. The layer is bounded to the element's rect and only created below 1. Paint also only runs when the visual is re-recorded: an Opacity change hits InvalidateSubtreePaint, so the SKPaint is allocated per re-record, not per frame. No perf concerns.
One thing before merging: the software-surface fallback (backends without an SKCanvas, e.g. WebGPU when the GL island isn't available) still ignores opacity, so #24367 stays half-open there. Fixing it is one line (see inline).
| canvas.Restore(); | ||
| canvas.RestoreToCount(saveCount); | ||
| } | ||
| else |
There was a problem hiding this comment.
The software fallback below still drops opacity: PaintSoftware ends with session.DrawImage(texture, 0f, 0f). IDrawingSession.DrawImage(ITexture, float, float, float opacity = 1f) already takes an opacity, and both the Skia and WebGPU sessions implement it. So passing session.Opacity into PaintSoftware and forwarding it to DrawImage fixes that path without needing a layer. It would be nice to cover it in When_Opacity too, if the software surface can be forced in a test.
GitHub Issue: closes #24367
PR Type:
🐞 Bugfix
What changed? 🚀
SKCanvasVisualdrew the user's SkiaSharp content straight onto the frame canvas and ignored the accumulated opacity of the paint session, soOpacityset on anSKCanvasElement(or on any ancestor) had no effect: a 50% opaque blue canvas rendered as pure blue.The other visuals fold the session opacity into their own paints, which user code can't do, so
SKCanvasVisualnow draws the content into a layer (SaveLayer) with the session opacity as its alpha when it is below 1, and restores the canvas to its saved state afterwards. Background and border are unchanged (they already honoured opacity). The GL island / software fallback paths are not touched.Validated at runtime on Skia desktop (macOS):
Given_SKCanvasElement.When_Opacity(opacity on the element, and on an ancestor) passes with the fix and fails without it (centre pixel#0000FFinstead of#8080FF).PR Checklist ✅
Screenshots Compare Test Runresults.