in my project (WinUi 3) i draw some polylines to plot some "real time" datas with Skiasharp. I saw the GPU-load is very high. So i tryed, what happens when less datas are drawn. ....the GPU load is still the same. Only if i change the size of the "SKXamlCanvas" it reduces the GPU load. (but the plot shout have a certain size...) So i tryed to render my chart in a bitmap with a lower resolution and scale it. But still it needs the same recources.
Is there any possibility to reduce the basic GPU-load? (as example an possibility to render in a lower resolution and scale it afterwords)
Example Application (.net 6.0 Winui-3) (Installed Modules: SkiaSharp, Skiasharp.Views.Winui) XAML:
x:Class="skEfficientDraw.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:skEfficientDraw"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:skia="using:SkiaSharp.Views.Windows"
mc:Ignorable="d">
<Grid>
<skia:SKXamlCanvas x:Name="skCanvas" PaintSurface="skCanvas_PaintSurface" />
</Grid>
C#:
public sealed partial class MainWindow : Window
{
SKPaint linePaint = new SKPaint
{
Color = SKColor.Parse("#003366"),
StrokeWidth = 5,
IsAntialias = true,
Style = SKPaintStyle.Stroke
};
public MainWindow()
{
this.InitializeComponent();
DispatcherTimer DrawTimer;
DrawTimer = new DispatcherTimer();
DrawTimer.Tick += DrawTimer_Tick;
DrawTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
DrawTimer.Start();
}
private void DrawTimer_Tick(object sender, object e)
{
skCanvas.Invalidate();
}
private void skCanvas_PaintSurface(object sender, SkiaSharp.Views.Windows.SKPaintSurfaceEventArgs e)
{
///
/// - The GPU load is very high, also if lineCount is 0
/// - Is there a possibility to reduce the GPU-load? Maybe rendering the "skCanvas" in a lower resolution?
///
SKImageInfo info = e.Info;
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
int lineCount = 5;
Random rand = new Random();
for (int i = 0; i < lineCount; i++)
{
int x1 = rand.Next(info.Width);
int y1 = rand.Next(info.Height);
int x2 = rand.Next(info.Width);
int y2 = rand.Next(info.Height);
canvas.DrawLine(x1, y1, x2, y2, linePaint);
}
}
}