Skip to content

Add support for SkiaVisual #15166

Description

@jeromelaban

What would you like to be added

Add support for a composition level SkiaVisual, which can allow third parties to use SkiaSharp in a constrained visual.

Why is this needed

Faster implementation of the SKXamlCanvas, and hardware acceleration for such controls, or custom visuals based on SkiaVisual.

For which platform

No response

Anything else we need to know?

Such an API cannot be provided at the XAML level for threading concerns.

A similar implementation for a visual is TextVisual, for which there's currently no publicly available API.

Activity

  1. added
    kind/enhancement
    triage/untriaged
    difficulty/tbd
    area/skia ✏️
    project/core-tools 🛠️
    and removed
    triage/untriaged
    on Jan 22, 2024
  2. lindexi commented on Jan 23, 2024

    @lindexi
    Contributor

    Awesome, thank you @jeromelaban . I'm looking forward to this feature


    Why not SKXamlCanvas?

    Because the SKXamlCanvas is working the hack thing. The SKXamlCanvas will render and then copy to WriteableBitmap to show.

    See https://github.com/mono/SkiaSharp/blob/9274aeec807fd17eec2a3266ad4c2475c37d8a0c/source/SkiaSharp.Views.Uno/SkiaSharp.Views.Uno.WinUI.Skia/SKXamlCanvas.Skia.cs#L27

    The SKXamlCanvas have to copy the pixel data to WriteableBitmap :

    	public partial class SKXamlCanvas : Canvas
    	{
    		private void DoInvalidate()
    		{
    			...
    
    			var info = CreateBitmap(out var unscaledSize, out var dpi);
    
    			using (var surface = SKSurface.Create(info, pixelsHandle.AddrOfPinnedObject(), info.RowBytes))
    			{
    				...
    
    				OnPaintSurface(...);
    			}
    
    			// This implementation is not fast enough, and providing the original pixel buffer
    			// is needed, yet the internal `IBufferByteAccess` interface is not yet available in Uno.
    			// Once it is, we can replace this implementation and provide the pinned array directly
    			// to skia.
    			using (var data = bitmap.PixelBuffer.AsStream())
    			{
    				data.Write(pixels, 0, pixels.Length);
    				data.Flush();
    			}
    
    			bitmap.Invalidate();
    		}
            }

    See #15097 (reply in thread)


    Before the SkiaVisual added, we can use the hack code to implemente the same functionality. The demo code: https://github.com/lindexi/lindexi_gd/tree/5db72c3d67f121becefb5c4e8a0eacd5099c4198/KefalurcilaybelJallbuderenajel

    See #15097 (reply in thread)

  3. jeromelaban commented on Jan 23, 2024

    @jeromelaban
    MemberAuthor

    Thanks for the update. The hack you're suggesting is about exposing an API that is not meant to be exposed in the first place. We need a SkiaVisual in order for Uno.WinUI to expose an API that SkiaSharp and any other animplementation can use reliably.

  4. self-assigned this
    on Jan 23, 2024
  5. added a commit that references this issue on Jun 7, 2024
  6. lindexi commented on Sep 6, 2024

    @lindexi
    Contributor

    Good job!

  7. agneszitte commented on Sep 6, 2024

    @agneszitte
    Member

    @jeromelaban, @rafael-rosa-knowcode should @jhanvi03 or @Darsh0307 test the uno samples app for this new support?

  8. jeromelaban commented on Sep 6, 2024

    @jeromelaban
    MemberAuthor

    @agneszitte yes, the uno samples app contains a new sample for WPF and X11.

  9. ramezgerges commented on Sep 6, 2024

    @ramezgerges
    Contributor

    @agneszitte @jeromelaban Not yet. The work is pretty much done but I removed it from #16621 because the PR was getting too big and we wanted to merge the GLCanvasElement work. I will open another PR for SKCanvasElement soon.

  10. agneszitte commented on Sep 6, 2024

    @agneszitte
    Member

    Thanks for the info @ramezgerges, let them know when it will be ready for QA when it will be done please

  11. github-actions commented on May 8, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.

  12. locked as resolved and limited conversation to collaborators on May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/skia ✏️difficulty/tbdkind/enhancementproject/core-tools 🛠️

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions