Skip to content

Commit

Permalink
First go at a zero-allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Apr 27, 2020
1 parent 354d85d commit c7162db
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions source/SkiaSharp.Views/SkiaSharp.Views.UWP/SKSwapChainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class SKSwapChainPanel : AngleSwapChainPanel

private SKSizeI lastSize;

private SKPaintGLSurfaceEventArgs lastPaintEventArgs;
private bool reusePaintEventArgsInstance = true;

public SKSwapChainPanel()
{
}
Expand Down Expand Up @@ -80,14 +83,18 @@ protected override void OnRenderFrame(Rect rect)
{
surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
canvas = surface.Canvas;
}

using (new SKAutoCanvasRestore(canvas, true))
{
// start drawing
OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType, glInfo));
// reset the args
lastPaintEventArgs = null;
}

// start drawing
if (!reusePaintEventArgsInstance || lastPaintEventArgs == null)
lastPaintEventArgs = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType, glInfo);

OnPaintSurface(lastPaintEventArgs);
canvas.RestoreToCount(0);

// update the control
canvas.Flush();
context.Flush();
Expand All @@ -97,6 +104,7 @@ protected override void OnDestroyingContext()
{
base.OnDestroyingContext();

lastPaintEventArgs = null;
lastSize = default;

canvas?.Dispose();
Expand Down

0 comments on commit c7162db

Please sign in to comment.