Skip to content

fix: Apply Opacity to SKCanvasElement content - #25394

Open
morning4coffe-dev wants to merge 3 commits into
masterfrom
dev/morning4coffe-dev/skcanvaselement-opacity
Open

morning4coffe-dev wants to merge 3 commits into
masterfrom
dev/morning4coffe-dev/skcanvaselement-opacity

Conversation

@morning4coffe-dev

Copy link
Copy Markdown
Member

GitHub Issue: closes #24367

PR Type:

🐞 Bugfix

What changed? 🚀

SKCanvasVisual drew the user's SkiaSharp content straight onto the frame canvas and ignored the accumulated opacity of the paint session, so Opacity set on an SKCanvasElement (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 SKCanvasVisual now 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 #0000FF instead of #8080FF).

PR Checklist ✅

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.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @morning4coffe-dev's task in 20s —— View job


Review summary

Verdict: ship (approve-quality). The root cause is fixed in SKCanvasVisual: the user's SkiaSharp drawing now goes through a SaveLayer carrying the session opacity.

Issues: 0 blocking, 0 major, 1 minor (inline comment on the fallback path).

Cross-cutting notes

  • RestoreToCount(saveCount) correctly unwinds both the clip and the layer.
  • The test covers opacity on the element and on an ancestor. It was reported as failing before the fix and passing after, which meets the red/fix/green bar.
  • One SKPaint is allocated per frame, and only when opacity is below 1. That is acceptable.
  • Validation was done on Skia desktop (macOS) only. I did not build or run anything myself, so this is a code review.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 239209 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ImageBrushAlignmentXY.png-dark
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • Accessibility_ScreenReader.png-dark
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png-dark
    • Application_DispatcherShutdownMode.png-dark
    • AppWindowFeatures.png-dark
    • AppWindowPresenters.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_FontSize_Changing.png-dark
    • Attributed_text_Simple.png-dark
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithbottommargin.png-dark
    • AutoBorderStretchwithrightmargin.png
    • AutomationPropertiesExtensions_Role.png
    • AutomationProperties_Name.png-dark
    • AutoSuggestBox_BitmapIcon.png
    • AutoSizedPathCentered.png
    • AutoSuggestBox_SoftKeboard.png-dark
    • AutoSizedTopLeft.png-dark
    • AutoSuggestBox_SoftKeboard.png

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 239209 has failed on Uno.UI - CI.

Copilot AI balanced review requested due to automatic review settings October 15, 2026 07:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @morning4coffe-dev's task in 14s —— View job


Review summary

Verdict: ship. The root cause is fixed in SKCanvasVisual.Paint. User SkiaSharp content now goes through a SaveLayer that carries the session opacity. RestoreToCount(saveCount) unwinds both the clip and the layer.

Issues: 0 blocking, 0 major, 0 minor. I posted no inline comments.

Cross-cutting notes

  • Fallback paths: the GL island and software fallback paths still ignore session opacity. The PR description says this is intentional, but it leaves a follow-up gap on backends without an SKCanvas, such as WebGPU. A follow-up issue would be worth filing.
  • Allocation: one SKPaint is allocated per frame, and only when opacity is below 1. That is acceptable. If this becomes hot, the paint could be cached on the visual.
  • Tests: Given_SKCanvasElement.When_Opacity covers opacity on the element and on an ancestor. The PR reports it failing before the fix and passing after.
  • CI: the screenshot comparison diffs (118 on Linux, 2458 on Windows) and the failed Uno.UI CI build are far too broad to come from this two-file change. They look like baseline or infrastructure noise, but please confirm by re-running or checking the build logs. I did not investigate them.
  • Validation: this is a code review only. I did not build or run anything.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 239676 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • ClipboardTests.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • ApplicationViewSizing.png
    • AppWindowFeatures.png
    • Arrange_Performance01.png
    • Attributed_text_Supserscript.png
    • AutoBorderStretchwithrightmargin.png
    • AutomationProperties_Name.png
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBox_Icons.png-dark
    • AutoSuggestBox_Icons.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • BorderTopwithmargins.png-dark
    • BorderTopwithmargins.png
    • Border_AntiAlias.png-dark
    • Border_AntiAlias.png
    • Border_CornerRadius_Alignments.png-dark
    • Border_CornerRadius_Alignments.png

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

# Conflicts:
#	src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Controls/Given_SKCanvasElement.skia.cs
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @morning4coffe-dev's task in 9s —— View job


Review summary

Verdict: ship. SKCanvasVisual.Paint now draws the user's SkiaSharp content through a SaveLayer that carries the session opacity, so the root cause is fixed. RestoreToCount(saveCount) unwinds both the clip and the layer.

Issues: 0 blocking, 0 major, 0 minor. I posted no inline comments.

Cross-cutting notes

  • Fallback paths: the GL island and software fallback paths still ignore session opacity. The PR description says this is intentional. A follow-up issue is worth filing for backends without an SKCanvas.
  • Allocation: one SKPaint is allocated per frame, and only when opacity is below 1. That is acceptable.
  • Tests: Given_SKCanvasElement.When_Opacity covers opacity on the element and on an ancestor. It uses an opaque white backdrop, so the expected #8080FF is deterministic. The PR reports it failing before the fix and passing after.
  • CI: the screenshot diffs (118 on Linux, 2458 on Windows) and the failed Uno.UI CI build are far too broad to come from this two-file change. They look like baseline or infrastructure noise. Please confirm by re-running or checking the build logs. I did not investigate them.
  • Validation: this is a code review only. I did not build or run anything.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 246601 found UI Test snapshots differences: skia-linux-screenshots: 231, skia-windows-screenshots: 293

Details
  • skia-linux-screenshots: 231 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • Accessibility_Showcase.png
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png
    • AnimatedVisualsTestbedPage.png-dark
    • AppWindowTitleBar Properties.png
    • AutomationProperties_AutomationId.png
    • AutomationProperties_AutomationId.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • Basics.png-dark
    • BenchmarkDotNet.png-dark
    • Basics.png
    • BenchmarkDotNet.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
  • skia-windows-screenshots: 293 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • BenchmarkDotNet.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png-dark
    • AnimatedVisualsTestbedPage.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_Showcase.png-dark
    • BasicAcrylicBrushTest2.png-dark

@MartinZikmund MartinZikmund left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UIElement.Opacity has no effect on SKCanvasElement content

5 participants