public override void DrawRect()

in source/SkiaSharp.Views/SkiaSharp.Views/Platform/macOS/SKGLView.cs [108:176]


		public override void DrawRect(CGRect dirtyRect)
		{
			// Track if the scale of the display has changed and if so force the SKGLView to reshape itself.
			// If this is not done, the output will scale correctly when the window is dragged from a non-retina to a retina display.
			if (Window != null && lastBackingScaleFactor != Window.BackingScaleFactor)
			{
				bool isFirstDraw = lastBackingScaleFactor == 0;
				lastBackingScaleFactor = Window.BackingScaleFactor;
				if (!isFirstDraw)
				{
					Reshape();
					// A redraw will also be necessary. Invoke later or the request will be ignored
					Invoke(() => {
						NeedsDisplay = true;
					}, 0);
					// do not proceed at the wrong scale
					return;
				}
			}

			base.DrawRect(dirtyRect);

			Gles.glClear(Gles.GL_COLOR_BUFFER_BIT | Gles.GL_DEPTH_BUFFER_BIT | Gles.GL_STENCIL_BUFFER_BIT);

			// create the render target
			if (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 contents to GL
			canvas.Flush();
			context.Flush();

			OpenGLContext.FlushBuffer();
		}