in source/SkiaSharp.Views/SkiaSharp.Views.WPF/SKGLElement.cs [117:181]
protected virtual void OnPaint(TimeSpan e)
{
if (disposed)
{
return;
}
if (designMode)
{
return;
}
// create the contexts if not done already
if (grContext == null)
{
var glInterface = GRGlInterface.Create();
grContext = GRContext.CreateGl(glInterface);
}
// get the new surface size
var newSize = GetSize();
GL.ClearColor(Color4.Transparent);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
// manage the drawing surface
if (renderTarget == null || lastSize != newSize || !renderTarget.IsValid)
{
// create or update the dimensions
lastSize = newSize;
GL.GetInteger(GetPName.FramebufferBinding, out var framebuffer);
GL.GetInteger(GetPName.StencilBits, out var stencil);
GL.GetInteger(GetPName.Samples, out var samples);
var maxSamples = grContext.GetMaxSurfaceSampleCount(colorType);
if (samples > maxSamples)
samples = maxSamples;
glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
// destroy the old surface
surface?.Dispose();
surface = null;
canvas = null;
// re-create the render target
renderTarget?.Dispose();
renderTarget = new GRBackendRenderTarget(newSize.Width, newSize.Height, samples, stencil, glInfo);
}
// create the surface
if (surface == null)
{
surface = SKSurface.Create(grContext, renderTarget, surfaceOrigin, colorType);
canvas = surface.Canvas;
}
using (new SKAutoCanvasRestore(canvas, true))
{
// start drawing
OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType));
}
// update the control
canvas.Flush();
}