title: The most efficient way to draw in SkiaSharp without using PaintSurface event
body: <p>An extension of this <a href="https://forums.xamarin.com/discussion/99300/is-there-a-way-to-access-a-sksurface-outside-of-the-paintsurface-event" rel="nofollow noreferrer">question</a>. I'm using <code>SkiaSharp</code> to draw shapes with <code>OpenGL</code>. Most of code samples for WPF suggest using <code>SKElement</code> control and get reference to the drawing surface inside <code>PaintSurface</code> event. I need reference to drawing surface al the time, not only inside of this event, so I'm using <code>SKBitmap</code> and <code>SKCanvas</code> and send the output to <code>Image</code> control in WPF.</p>
  <p><strong>XAML</strong></p>
  <pre><code>&lt;Canvas x:Name=&quot;ScreenControl&quot; /&gt;
  </code></pre>
  <p><strong>CS</strong></p>
  <pre><code>var bmp = new SKBitmap((int)ScreenControl.ActualWidth, (int)ScreenControl.ActualHeight);
  var canvas = new SKCanvas(bmp);
  var image = new Image
  {
    Stretch = Stretch.Fill
  };
  
  canvas.DrawText(&quot;Demo&quot;, new SKPoint(20, 20), new SKPaint { TextSize = 20 });
  
  var index = 0;
  var clock = new Timer();
  var wrt = bmp.ToWriteableBitmap();
  
  image.Source = wrt;
  
  clock.Interval = 100;
  clock.Elapsed += (object sender, ElapsedEventArgs e) =&gt;
  {
    Application.Current.Dispatcher.BeginInvoke(new Action(() =&gt;
    {
      var wrt = bmp.ToWriteableBitmap(); // Potentially slow line #1
  
      canvas.Clear();
      canvas.DrawText((index++).ToString(), new SKPoint(20, 20), new SKPaint { TextSize = 20 });
      image.Source = wrt;                // Potentially slow line #2
      image.InvalidateVisual();
    }));
  };
  clock.Start();
  
  ScreenControl.Children.Clear();
  ScreenControl.Children.Add(image);
  
  </code></pre>
  <p><strong>Project</strong></p>
  <pre><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;OutputType&gt;WinExe&lt;/OutputType&gt;
      &lt;TargetFramework&gt;net5.0-windows&lt;/TargetFramework&gt;
      &lt;UseWPF&gt;true&lt;/UseWPF&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;SkiaSharp.Views.WPF&quot; Version=&quot;2.80.3-preview.18&quot; /&gt;
    &lt;/ItemGroup&gt;
  
  &lt;/Project&gt;
  </code></pre>
  <p><strong>Question</strong></p>
  <p>Is there a way to draw faster, specifically, without recreating bitmap <code>bmp.ToWriteableBitmap()</code> and without changing image source every time <code>image.Source = wrt</code>? Back buffer or something related?</p>