in source/SkiaSharp.Views/SkiaSharp.Views/Platform/iOS/SKGLLayer.cs [50:114]
public virtual void Render()
{
if (glContext == null)
{
PrepareGLContexts();
}
EAGLContext.SetCurrentContext(glContext);
// get the new surface size
var newSize = lastSize;
if (recreateSurface)
{
Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_WIDTH, out var bufferWidth);
Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_HEIGHT, out var bufferHeight);
newSize = new SKSizeI(bufferWidth, bufferHeight);
}
// manage the drawing surface
if (recreateSurface || renderTarget == null || lastSize != newSize || !renderTarget.IsValid)
{
// create or update the dimensions
lastSize = newSize;
// read the info from the buffer
Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out var framebuffer);
Gles.glGetIntegerv(Gles.GL_STENCIL_BITS, out var stencil);
Gles.glGetIntegerv(Gles.GL_SAMPLES, out var samples);
var maxSamples = context.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(context, renderTarget, surfaceOrigin, colorType);
canvas = surface.Canvas;
}
using (new SKAutoCanvasRestore(canvas, true))
{
// start drawing
var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType);
OnPaintSurface(e);
}
// flush the SkiaSharp context to the GL context
canvas.Flush();
context.Flush();
// present the GL buffers
glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER);
EAGLContext.SetCurrentContext(null);
}