Exemplo n.º 1
0
        private void OnPaintSurface(object sender, SKNativePaintGLSurfaceEventArgs e)
        {
            var controller = Element as ISKGLViewController;

            // the control is being repainted, let the user know
            controller?.OnPaintSurface(new SKPaintGLSurfaceEventArgs(e.Surface, e.RenderTarget));
        }
Exemplo n.º 2
0
        protected override void OnPaintSurface(SkiaSharp.Views.Android.SKPaintGLSurfaceEventArgs e)
        {
            //
            // Start drawing
            //
            var del = Content;

            if (del == null)
            {
                return;
            }

            var startT = DateTime.Now;

            var _graphics = new SkiaGraphics(e.Surface);

            _graphics.SaveState();
            _graphics.Scale(Zoom, Zoom);


            //
            // Draw
            //
            del.Frame = new RectangleF(0, 0, Width / Zoom, Height / Zoom);
            try {
                del.Draw(_graphics);
            }
            catch (Exception) {
            }

            _graphics.RestoreState();

            var endT = DateTime.Now;

            _drawTime += (endT - startT).TotalSeconds;
            _drawCount++;

            //
            // Throttle
            //
            if (_running && _drawCount > 2 && (DateTime.Now - _lastThrottleTime) >= ThrottleInterval)
            {
                _lastThrottleTime = DateTime.Now;

                var maxfps = 1.0 / (_drawTime / _drawCount);
                _drawTime  = 0;
                _drawCount = 0;

                var fps = ClampUpdateFreq((int)(maxfps * CpuUtilization));

                if (Math.Abs(fps - _fps) > 1)
                {
                    _fps = fps;
                    Start();
                }
            }

            //
            // Notify
            //
            DrewFrame?.Invoke(this, EventArgs.Empty);
        }