Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SkiaVisual #15166

Closed
jeromelaban opened this issue Jan 22, 2024 · 7 comments · Fixed by #16621 or #18181
Closed

Add support for SkiaVisual #15166

jeromelaban opened this issue Jan 22, 2024 · 7 comments · Fixed by #16621 or #18181
Assignees
Labels
area/skia ✏️ Categorizes an issue or PR as relevant to Skia difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/enhancement New feature or request project/core-tools 🛠️ Categorizes an issue or PR as relevant to core and tools

Comments

@jeromelaban
Copy link
Member

jeromelaban commented Jan 22, 2024

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.

@jeromelaban jeromelaban added kind/enhancement New feature or request triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. area/skia ✏️ Categorizes an issue or PR as relevant to Skia project/core-tools 🛠️ Categorizes an issue or PR as relevant to core and tools and removed triage/untriaged Indicates an issue requires triaging or verification labels Jan 22, 2024
@lindexi
Copy link
Contributor

lindexi commented Jan 23, 2024

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)

@jeromelaban
Copy link
Member Author

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.

@lindexi
Copy link
Contributor

lindexi commented Sep 6, 2024

Good job!

@agneszitte
Copy link
Contributor

agneszitte commented Sep 6, 2024

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

@jeromelaban
Copy link
Member Author

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

@ramezgerges
Copy link
Contributor

ramezgerges commented Sep 6, 2024

@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.

@ramezgerges ramezgerges reopened this Sep 6, 2024
@agneszitte
Copy link
Contributor

agneszitte commented Sep 6, 2024

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

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 difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/enhancement New feature or request project/core-tools 🛠️ Categorizes an issue or PR as relevant to core and tools
Projects
None yet
4 participants