Cached drawing


I did my search and I'm hoping this is a question that's not already answered somewhere else.

I'm making some real-time drawings based on touch events, using skiasharp on xamarin.forms/PCL. My graphics concept requires the view to be completely redrawn each time. Since these redrawings start with a Clear(), they cause some flickers at the view. So I decided to use a cache, on which to draw first, away from user's sight, and then copy resulting image to the view.

In order to achieve this, one method that seemed best to me, is to create a cache surface having same dimensions with the view's surface, make drawings on cache surface, and then at the view use SKCanvas.DrawSurface method to copy cache surface content to view's surface, showing it to user by a single command, making sure there will be no flickers.

Do you think this is the most reasonable approach, or do you recommend another method for cached drawing?



  • mattleibowmattleibow ZAXamarin Team Xamurai
    This should be fine.

    About the flicker, I am interested in looking into this as it shouldn't really happen... Most platforms already have a buffer - possibly not on iOS. What platforms do you see the flicker and is it possible to share some code?

    If this is really the case and not a bug, I can implement a DoubleBuffered property like with WinForms.
  • Hello Matthew,

    Thank you for the answer. About the flicker, I did some progress in graphics code without trying to get rid of flicker, and now I cannot reproduce it. I think that flicker was because of some conditional drawing code I had put for debugging purposes. Now, even if I put some temporary "Task.Delay(100).Wait();" after Clear&Flush, I cannot see any bit of flicker, on UWP desktop and android device. So this was a false question, sorry. If I experience any flicker on ios, I will leave a notification here.

    Btw, while trying to reproduce flicker, it seemed to me that, Touch events are not being fired/queued while PaintSurface handler is drawing (my Touch handler calls InvalidateSurface()). Is this the case?


  • mattleibowmattleibow ZAXamarin Team Xamurai

    That is correct. The drawing and the touch events are happening on the same thread - the UI thread. Thus, only one thing can occur at a time. This is an aspect of the OS though, SkiaSharp just fits into native draw and touch lifecycle.

  • OK, thank you for clarification =)

Sign In or Register to comment.