mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.32k stars 530 forks source link

[BUG] Draw a bitmap decoded from SKCodec performance is poor on UWP #1501

Open h82258652 opened 3 years ago

h82258652 commented 3 years ago

Description

Draw a bitmap decoded from SKCodec performance is poor on UWP, it is much slower than .net core and .net framework.

Code

var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///test.png"));
using (var stream = await file.OpenStreamForReadAsync())
{
    using (var bitmap = new SKBitmap(960, 720))
    {
        using (var canvas = new SKCanvas(bitmap))
        {
            using (var codec = SKCodec.Create(stream))
            {
                using (var decodeBitmap = new SKBitmap(codec.Info))
                {
                    var pointer = decodeBitmap.GetPixels();
                    codec.GetPixels(decodeBitmap.Info, pointer);

                    var dest = new SKRect(0, 0, 960, 720);

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    canvas.DrawBitmap(decodeBitmap, dest);

                    stopwatch.Stop();

                    await new MessageDialog($"cost {stopwatch.ElapsedMilliseconds} ms").ShowAsync();
                }
            }
        }
    }
}

Expected Behavior

The performance should be equals to run on .net core or .net framework.

Actual Behavior

It cost 200~300 ms on my computer and the .net core and .net framework version, only takes <10 ms.

Basic Information

Reproduction Link

https://github.com/h82258652/SKCodecUwpPerformanceRepo

h82258652 commented 3 years ago

I found an interesting thing. I download the 2.80.2 nuget package, extra it and then let the UWP project reference the .net standard 2.0 dll (also copy the libSkiaSharp.dll), the performance equals to run on .net core or .net framework.