Beispiel #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            DpiScale = e.Graphics.DpiX / 96.0;

            // get the bitmap
            CreateBitmap();
            var data = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);

            // create the surface
            var info = new SKImageInfo(Width, Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            using (var surface = SKSurface.Create(info, data.Scan0, data.Stride))
            {
                // start drawing

                if (fsurface != null)
                {
                    fsurface.UpdateSurface(surface);
                }

                OnPaintSurface(new SKPaintSurfaceEventArgs(surface, info));

                surface.Canvas.Flush();
            }

            // write the bitmap to the graphics
            bitmap.UnlockBits(data);
            e.Graphics.DrawImage(bitmap, 0, 0);
        }
Beispiel #2
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            if (fsurface == null)
            {
                return;
            }

            var size = ConvertSizeToBacking(Bounds.Size);

            renderTarget.Width  = (int)size.Width;
            renderTarget.Height = (int)size.Height;

            Gles.glClear(Gles.GL_STENCIL_BUFFER_BIT);

            using (var surface = SKSurface.Create(context, renderTarget))
            {
                fsurface.UpdateSurface(surface);

                // draw on the surface
                DrawInSurface(surface, renderTarget);

                surface.Canvas.Flush();
            }

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

            OpenGLContext.FlushBuffer();
        }
Beispiel #3
0
        protected override void OnRenderFrame()
        {
            var rect = Allocation;

            // create the contexts if not done already
            if (grContext == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();

                if (glInterface == null)
                {
                    Console.WriteLine("Error creating OpenGL ES interface. Check if you have OpenGL ES correctly installed and configured or change the PFD Renderer to 'Software (CPU)' on the Global Settings panel.", "Error Creating OpenGL ES interface");
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                }
                else
                {
                    grContext = GRContext.Create(GRBackend.OpenGL, glInterface);
                }

                try
                {
                    renderTarget = CreateRenderTarget();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error creating OpenGL ES render target. Check if you have OpenGL ES correctly installed and configured or change the PFD Renderer to 'Software (CPU)' on the Global Settings panel.\nError message:\n" + ex.ToString());
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                }
            }

            if (grContext != null)
            {
                // update to the latest dimensions
                renderTarget.Width  = rect.Width;
                renderTarget.Height = rect.Height;

                // create the surface
                using (var surface = SKSurface.Create(grContext, renderTarget))
                {
                    surface.Canvas.Clear(SKColors.White);

                    // start drawing
                    if (fsurface != null)
                    {
                        fsurface.UpdateSurface(surface);
                    }

                    // start drawing
                    OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));

                    surface.Canvas.Flush();
                }
            }
        }
Beispiel #4
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            var rect = Allocation;

            if (rect.Width > 0 && rect.Height > 0)
            {
                var         area  = evnt.Area;
                SKColorType ctype = SKColorType.Bgra8888;
                if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
                {
                    ctype = SKColorType.Rgba8888;
                }
                using (Cairo.Context cr = Gdk.CairoHelper.Create(base.GdkWindow))
                {
                    if (cr == null)
                    {
                        Console.WriteLine("Cairo Context is null");
                    }
                    using (var bitmap = new SKBitmap(rect.Width, rect.Height, ctype, SKAlphaType.Premul))
                    {
                        if (bitmap == null)
                        {
                            Console.WriteLine("Bitmap is null");
                        }
                        IntPtr len;
                        using (var skSurface = SKSurface.Create(bitmap.Info.Width, bitmap.Info.Height, ctype, SKAlphaType.Premul, bitmap.GetPixels(out len), bitmap.Info.RowBytes))
                        {
                            if (skSurface == null)
                            {
                                Console.WriteLine("skSurface is null");
                            }
                            if (fsurface != null)
                            {
                                fsurface.UpdateSurface(skSurface);
                            }
                            skSurface.Canvas.Flush();
                            using (Cairo.Surface surface = new Cairo.ImageSurface(bitmap.GetPixels(out len), Cairo.Format.Argb32, bitmap.Width, bitmap.Height, bitmap.Width * 4))
                            {
                                surface.MarkDirty();
                                cr.SetSourceSurface(surface, 0, 0);
                                cr.Paint();
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #5
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            int    width, height;
            double dpiX = 1.0;
            double dpiY = 1.0;

            if (IgnorePixelScaling)
            {
                width  = (int)ActualWidth;
                height = (int)ActualHeight;
            }
            else
            {
                var m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
                dpiX   = m.M11;
                dpiY   = m.M22;
                width  = (int)(ActualWidth * dpiX);
                height = (int)(ActualHeight * dpiY);
            }

            var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            // reset the bitmap if the size has changed
            if (bitmap == null || info.Width != bitmap.PixelWidth || info.Height != bitmap.PixelHeight)
            {
                bitmap = new WriteableBitmap(width, height, dpiX, dpiY, PixelFormats.Pbgra32, null);
            }

            // draw on the bitmap
            bitmap.Lock();
            using (var surface = SKSurface.Create(info, bitmap.BackBuffer, bitmap.BackBufferStride))
            {
                if (fsurface != null)
                {
                    fsurface.UpdateSurface(surface);
                }
                OnPaintSurface(new SKPaintSurfaceEventArgs(surface, info));
                surface.Canvas.Flush();
            }

            // draw the bitmap to the screen
            bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            bitmap.Unlock();
            drawingContext.DrawImage(bitmap, new Rect(0, 0, ActualWidth, ActualHeight));
        }
Beispiel #6
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            if (fsurface == null)
            {
                return;
            }

            var ctx = NSGraphicsContext.CurrentContext.GraphicsPort;

            // create the skia context
            SKImageInfo info;

            var surface = drawable.CreateSurface(Bounds, 1.0f, out info);

            fsurface.UpdateSurface(surface);

            // draw the surface to the context
            drawable.DrawSurface(ctx, Bounds, info, surface);
        }
Beispiel #7
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            this.MakeCurrent();

            //base.OnPaint(e);

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

                // get initial details
                renderTarget = CreateRenderTarget();
            }

            // update to the latest dimensions
            renderTarget.Width  = Width;
            renderTarget.Height = Height;

            // create the surface
            using (var surface = SKSurface.Create(grContext, renderTarget))
            {
                surface.Canvas.Clear(SKColors.White);

                // start drawing
                if (fsurface != null)
                {
                    fsurface.UpdateSurface(surface);
                }

                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));

                surface.Canvas.Flush();
            }

            // update the control
            SwapBuffers();
        }