Beispiel #1
0
        private void GlCtrl_PaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
        {
            var surface       = e.Surface;
            var canvas        = surface.Canvas;
            var surfaceWidth  = e.BackendRenderTarget.Width;
            var surfaceHeight = e.BackendRenderTarget.Height;

            canvas.Clear(Color.White.ToSKColor());

            canvas.Flush();
        }
Beispiel #2
0
        void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs skPaintSurfaceEventArgs)
        {
            TryInitializeViewport();
//            if (!Viewport.Initialized) return;

//            _viewport.SetSize(Width, Height);

            skPaintSurfaceEventArgs.Surface.Canvas.Scale(_skiaScale, _skiaScale);

            _renderer.Render(skPaintSurfaceEventArgs.Surface.Canvas,
                             Viewport, _map.Layers, _map.Widgets, _map.BackColor);
        }
Beispiel #3
0
        private void HandlePaintGLSurfaceZoom(object sender, SKPaintGLSurfaceEventArgs e)
        {
            // See https://github.com/mono/SkiaSharp/issues/920
            var control = (SKGLControl)sender;

            control.BringToFront();
            control.MakeCurrent();
            var bg = TransparencyKey.ToSKColor();

            e.Surface.Canvas.Clear(bg);
            phiddle.DrawZoomWindow(e.Surface.Canvas);
        }
Beispiel #4
0
        public RenderContext CreateContext(SKPaintGLSurfaceEventArgs e)
        {
            var context = new RenderContext
            {
                Canvas     = e.Surface.Canvas,
                Paint      = new SKPaint(),
                CanvasRect = e.BackendRenderTarget.Rect
            };

            CalculateRenderSize(context);
            return(context);
        }
Beispiel #5
0
        public virtual void Render()
        {
            if (glContext == null)
            {
                PrepareGLContexts();
            }

            EAGLContext.SetCurrentContext(glContext);

            // manage the drawing surface
            if (renderTarget == null || surface == null)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                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;
                }
                Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_WIDTH, out var bufferWidth);
                Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_HEIGHT, out var bufferHeight);
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget(bufferWidth, bufferHeight, samples, stencil, glInfo);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
                SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // flush the SkiaSharp context to the GL context
            surface.Canvas.Flush();
            context.Flush();

            // present the GL buffers
            glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER);
            EAGLContext.SetCurrentContext(null);
        }
        private void SKGlControlOnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
        {
            e.Surface.Canvas.Clear(SKColors.DarkSlateGray);
            if (_image != null)
            {
                // fit image size to 1920 x 1080
                var widthScale  = 1920 / _image.Width;
                var heightScale = 1080 / _image.Height;

                var scale = Math.Max(widthScale, heightScale);

                e.Surface.Canvas.DrawImage(_image, new SKRect(0, 0, _image.Width, _image.Height), new SKRect(0, 0, _image.Width * scale, _image.Height * scale));
            }
        }
Beispiel #7
0
        public new void DrawInRect(GLKView view, CGRect rect)
        {
            if (designMode)
            {
                return;
            }

            // create the contexts if not done already
            if (context == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // manage the drawing surface
            if (renderTarget == null || surface == null || renderTarget.Width != DrawableWidth || renderTarget.Height != DrawableHeight)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                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;
                }
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget((int)DrawableWidth, (int)DrawableHeight, samples, stencil, glInfo);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // flush the SkiaSharp contents to GL
            surface.Canvas.Flush();
            context.Flush();
        }
Beispiel #8
0
        void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs skPaintSurfaceEventArgs)
        {
            if (PixelDensity <= 0)
            {
                return;
            }

            Navigator.UpdateAnimations();

            skPaintSurfaceEventArgs.Surface.Canvas.Scale(PixelDensity, PixelDensity);

            var canvas = skPaintSurfaceEventArgs.Surface.Canvas;

            _renderer.Render(canvas, new Viewport(Viewport), _map.Layers, _map.Widgets, _map.BackColor);
        }
Beispiel #9
0
        private void OnPaint(object sender, SKPaintGLSurfaceEventArgs e)
        {
            float pixelCoordRatioX =
                (float)e.BackendRenderTarget.Width / (float)Settings.General.xAxisLength;
            float pixelCoordRatioY =
                (float)e.BackendRenderTarget.Height / (float)Settings.General.yAxisLength;
            SKCanvas canvas = e.Surface.Canvas;

            canvas.Scale(pixelCoordRatioX, pixelCoordRatioY);
            try
            {
                GameLoop();
                DrawingLoop(canvas);
            }
            finally
            {
                canvas.Scale(1 / pixelCoordRatioX, 1 / pixelCoordRatioY);
            }
        }
Beispiel #10
0
        private void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
        {
            var oldTicks = milliseconds;
            var newTicks = Environment.TickCount;

            milliseconds = newTicks;

            game.Update(TimeSpan.FromMilliseconds(newTicks - oldTicks));

            var canvas = e.Surface.Canvas;

            using (new SKAutoCanvasRestore(canvas, true))
            {
                //canvas.Scale(
                //	e.BackendRenderTarget.Width / baseSize.Width,
                //	e.BackendRenderTarget.Height / baseSize.Height);

                game.Draw(canvas);
            }
        }
Beispiel #11
0
        void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs skPaintSurfaceEventArgs)
        {
            if (!_viewportInitialized)
            {
                InitializeViewport();
            }
            if (!_viewportInitialized)
            {
                return;
            }

            _map.Viewport.Width  = _canvas.Frame.Width;
            _map.Viewport.Height = _canvas.Frame.Height;

            var scaleFactor = (float)UIScreen.MainScreen.Scale;

            skPaintSurfaceEventArgs.Surface.Canvas.Scale(scaleFactor, scaleFactor);

            _renderer.Render(skPaintSurfaceEventArgs.Surface.Canvas, _map.Viewport, _map.Layers, _map.BackColor);
        }
        private void CanvasOnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Scale((float)_canvas.ContentScaleFactor);
            canvas.Clear(SKColors.White);
            using (var path = ToPath(_originalPath.Points.Select(p => new SKPoint(p.X * _scale, p.Y * _scale))))
            {
                canvas.Translate(_center.X - path.Bounds.MidX, _center.Y - path.Bounds.MidY);
                using (var paint = new SKPaint
                {
                    Color = SKColors.Red,
                    StrokeWidth = 10,
                    Style = SKPaintStyle.StrokeAndFill
                })
                {
                    e.Surface.Canvas.DrawPath(path, paint);
                }
            }
        }
Beispiel #13
0
        private void WindowOnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Clear(ClearColor);

            var RectangleStyleFillShadowColor = new SKColor(255, 0, 0, 255);

            var RectangleStyleFillShadow = SKImageFilter.CreateDropShadow(0f, 0f, 20f, 20f,
                                                                          RectangleStyleFillShadowColor, SKDropShadowImageFilterShadowMode.DrawShadowOnly, null, null);

            var RectangleStyleFillColor = new SKColor(255, 255, 255, 255);


            canvas.DrawRect(100, 100, 800, 800, new SKPaint
            {
                Color = new SKColor(202, 157, 93),
                Style = SKPaintStyle.Fill,
//                Color = RectangleStyleFillColor,
                BlendMode   = SKBlendMode.SrcOver,
                IsAntialias = true,
                ImageFilter = SKImageFilter.CreateBlur(5, 5)
//                ImageFilter = RectangleStyleFillShadow
            });

            canvas.DrawCircle(200, 200, 50, new SKPaint
            {
                IsAntialias = true,
                Color       = new SKColor(115, 61, 19),
                ImageFilter = SKImageFilter.CreateBlur(15, 15)
            });

//            var pos = new Position
//            {
//                X = 300,
//                Y = 100
//            };
//            DrawTreeElements(canvas, Window.Document.ChildNodes.OfType<Element>().ToList(), ref pos);
//
//            _renderer.Render(canvas);
        }
Beispiel #14
0
        public virtual void Render()
        {
            if (glContext == null)
            {
                PrepareGLContexts();
            }

            EAGLContext.SetCurrentContext(glContext);

            // manage the drawing surface
            if (renderTarget == null || surface == null)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                renderTarget = SKGLDrawable.CreateRenderTarget(0, 0);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
                SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // flush the SkiaSharp context to the GL context
            surface.Canvas.Flush();
            context.Flush();

            // present the GL buffers
            glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER);
            EAGLContext.SetCurrentContext(null);
        }
Beispiel #15
0
        public new void DrawInRect(GLKView view, CGRect rect)
        {
            if (designMode)
            {
                return;
            }

            // create the contexts if not done already
            if (context == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // manage the drawing surface
            if (renderTarget == null || surface == null || renderTarget.Width != DrawableWidth || renderTarget.Height != DrawableHeight)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                renderTarget = SKGLDrawable.CreateRenderTarget((int)DrawableWidth, (int)DrawableHeight);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // flush the SkiaSharp contents to GL
            surface.Canvas.Flush();
            context.Flush();
        }