pcerman
pcerman

Reputation: 51

SkiaSharp and GPU acceleration

I am evaluating SkiaSharp library (from nuget, version 1.59.3). Everything is rendered well. But it seems Skia is not using GPU for accelerated rendering. Windows 10 Task Manager doesn't detect any uses of GPU for my testing application. I am using next commands to create SKCanvas:

 using (SKBitmap bitmap = new SKBitmap(gWidth, gHeight, SKColorType.Bgra8888, alphaType))
 using (SKCanvas canvas = new SKCanvas(bitmap))
 { ... }

Does GPU acceleration requires some special way to initialize SkiaSharp ?

I have tried next command:

GRContext context = GRContext.Create(GRBackend.OpenGL);

but it returns null.

Upvotes: 5

Views: 5924

Answers (1)

Matthew
Matthew

Reputation: 5222

Ah, GPU.

You need to be in an existing OpenGL/ANGLE context.

I am doing this: https://github.com/mono/SkiaSharp/blob/master/source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKSwapChainPanel.cs

But, before I actually initialize SkiaSharp, I first have to manually create the ANGLE context: https://github.com/mono/SkiaSharp/blob/master/source/SkiaSharp.Views/SkiaSharp.Views.UWP/AngleSwapChainPanel.cs

This is the same for all platforms, first set up the OpenGL/ANGLE context, and then when it is the current context, start the SkiaSharp GRContext.

This is something that I do for my unit tests as well: https://github.com/mono/SkiaSharp/blob/master/tests/Tests/GlContexts/Wgl/WglContext.cs

This is not always the nicest code to write if you aren't a fan of all this setup-y code, but you could use some other library to do all the boilerplate code. As long as there is a valid OpenGL/ANGLE context, you are good.

Upvotes: 4

Related Questions