private void _skiaView_PaintSurface(object sender, SKPaintGLSurfaceEventArgs e) { Stopwatch renderStopWatch = null; if (RenderOptions.ShowClipRects) { renderStopWatch = Stopwatch.StartNew(); } e.Surface.Canvas.Clear(new SKColor(Container.BackColor.R, Container.BackColor.G, Container.BackColor.B, Container.BackColor.A)); _root.Measure(new Primitives.Size(Container.ClientSize.Width, Container.ClientSize.Height)); _root.Arrange(new Primitives.Rect(0, 0, Container.ClientSize.Width, Container.ClientSize.Height)); _root.Render(e.Surface.Canvas); if (renderStopWatch != null) { renderStopWatch.Stop(); using (var ptRect = new SkiaSharp.SKPaint() .ApplyBrush(new SolidColorBrush(new Color(0, 0, 0)))) using (var ptText = new SkiaSharp.SKPaint() .ApplyBrush(new SolidColorBrush(new Color(255, 255, 255)))) { e.Surface.Canvas.DrawRect(Container.ClientSize.Width - 50.0f, 0.0f, 100.0f, 10.0f, ptRect); var elapsedString = renderStopWatch.ElapsedMilliseconds == 0 ? "-" : $"{(1.0 / renderStopWatch.ElapsedMilliseconds * 1000).ToString("##.00", CultureInfo.InvariantCulture)}FPS"; e.Surface.Canvas.DrawText(elapsedString, new SKPoint(Container.ClientSize.Width - 50.0f, 10.0f), ptText); } renderStopWatch.Reset(); } }
private void _skiaView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) { Stopwatch renderStopWatch = null; if (RenderOptions.ShowFrameRate) { renderStopWatch = Stopwatch.StartNew(); } //e.Surface.Canvas.Clear(new SKColor(Container.BackgroundColor.R, Container.BackgroundColor.G, Container.BackgroundColor.B, Container.BackgroundColor.A)); e.Surface.Canvas.Clear(SKColors.White); using (new SKAutoCanvasRestore(e.Surface.Canvas)) { var deviceSize = new Primitives.Size(e.Info.Width, e.Info.Height); var deviceIndSize = new Primitives.Size(_skiaView.Width, _skiaView.Height); var scaleDpi = new Primitives.Point(e.Info.Width / _skiaView.Width, e.Info.Height / _skiaView.Height); e.Surface.Canvas.Scale((float)scaleDpi.X, (float)scaleDpi.Y); _root.Measure(deviceIndSize); _root.Arrange(new Primitives.Rect(0, 0, deviceIndSize.Width, deviceIndSize.Height)); _root.Render(e.Surface.Canvas); } if (renderStopWatch != null) { renderStopWatch.Stop(); using (var ptRect = new SkiaSharp.SKPaint() .ApplyBrush(new SolidColorBrush(new Primitives.Color(0, 0, 0)))) using (var ptText = new SkiaSharp.SKPaint() .ApplyBrush(new SolidColorBrush(new Primitives.Color(255, 255, 255)))) { e.Surface.Canvas.DrawRect(e.Info.Width - 50.0f, 0.0f, 100.0f, 10.0f, ptRect); var elapsedString = renderStopWatch.ElapsedMilliseconds == 0 ? "-" : $"{(1.0 / renderStopWatch.ElapsedMilliseconds * 1000).ToString("##.00", CultureInfo.InvariantCulture)}FPS"; e.Surface.Canvas.DrawText(elapsedString, new SKPoint(e.Info.Width - 50.0f, 10.0f), ptText); } renderStopWatch.Reset(); } }