Example #1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            Title = $"(Vsync: {VSync}) FPS: {1f / e.Time:0}";

            var props = new SKSurfaceProperties(SKSurfacePropsFlags.None, SKPixelGeometry.BgrHorizontal);

            using (var surface = SKSurface.Create(_context, _renderTarget, SKColorType.Bgra8888, props))
            {
                if (surface != null)
                {
                    Debug.Assert(surface != null);
                    Debug.Assert(surface.Handle != IntPtr.Zero);

                    var canvas = surface.Canvas;

                    canvas.Flush();

                    var info = this._renderTarget;

                    PaintSurface?.Invoke(this, new SKPaintGLSurfaceEventArgs(surface, _renderTarget));

                    canvas.Flush();
                }
                else
                {
                }
            }

            this._context.Flush();
            SwapBuffers();
        }
Example #2
0
        public void CanCreateSurfaceFromExistingMemory()
        {
            var info  = new SKImageInfo(100, 100);
            var props = new SKSurfaceProperties(SKPixelGeometry.Unknown);

            var memory = Marshal.AllocCoTaskMem(info.BytesSize);

            using (var surface = SKSurface.Create(info, memory, info.RowBytes, props))
            {
                Assert.NotNull(surface);
            }

            Marshal.FreeCoTaskMem(memory);
        }
Example #3
0
        public void SimpleSurfaceWithPropertiesIsCorrect()
        {
            var info  = new SKImageInfo(100, 100);
            var props = new SKSurfaceProperties(SKSurfacePropsFlags.UseDeviceIndependentFonts, SKPixelGeometry.RgbVertical);

            using (var surface = SKSurface.Create(info, props))
            {
                Assert.NotNull(surface);

                Assert.Equal(SKPixelGeometry.RgbVertical, surface.SurfaceProperties.PixelGeometry);
                Assert.Equal(SKSurfacePropsFlags.UseDeviceIndependentFonts, surface.SurfaceProperties.Flags);

                Assert.Equal(props.PixelGeometry, surface.SurfaceProperties.PixelGeometry);
                Assert.Equal(props.Flags, surface.SurfaceProperties.Flags);
            }
        }
Example #4
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            var wndclass = new User32.WNDCLASSEX();

            wndclass.cbSize    = Marshal.SizeOf <User32.WNDCLASSEX>();
            wndclass.style     = 0;
            wndclass.hInstance = Kernel32.GetModuleHandle(null).DangerousGetHandle();
            User32.RegisterClassEx(ref wndclass);
            var windowHandle = User32.CreateWindowEx((User32.WindowStylesEx)WS_EX_NOREDIRECTIONBITMAP, "static", "", User32.WindowStyles.WS_CHILD | User32.WindowStyles.WS_CLIPCHILDREN | User32.WindowStyles.WS_VISIBLE, 0, 0, (int)Width, (int)Height, hwndParent.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            User32.SetWindowPos(windowHandle, hwndParent.Handle, 0, 0, (int)Width, (int)Height, User32.SetWindowPosFlags.SWP_SHOWWINDOW);
            ANGLE.InitializeContext((int)Width, (int)Height, true, windowHandle, User32.GetDC(windowHandle).DangerousGetHandle());
            var angleInterface = GRGlInterface.CreateAngle(ANGLE.AngleGetProcAddress);
            var grContext      = GRContext.CreateGl(angleInterface);
            var buffer         = ANGLE.GetFrameBuffer();
            var fbinfo         = new GRGlFramebufferInfo(buffer, ANGLE.GetFramebufferFormat());
            var backendRT      = new GRBackendRenderTarget((int)Width, (int)Height, 4, 8, fbinfo);
            var surfaceprops   = new SKSurfaceProperties(SKSurfacePropsFlags.UseDeviceIndependentFonts, SKPixelGeometry.Unknown);
            var surface        = SKSurface.Create(grContext, backendRT, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888, null, surfaceprops);
            var canvas         = surface.Canvas;

            canvas.Clear(SKColor.Empty);
            SKPaint paint = new SKPaint();

            paint.Style       = SKPaintStyle.Fill;
            paint.IsAntialias = true;
            paint.StrokeWidth = 4;
            paint.Color       = new SKColor(0xff4285f4);
            SKRect rect = SKRect.Create(10, 10, 100, 160);

            canvas.DrawRect(rect, paint);
            SKRoundRect oval = new SKRoundRect();

            oval.SetOval(rect);
            oval.Offset(40, 80);
            paint.Color = new SKColor(0xffdb4437);
            canvas.DrawRoundRect(oval, paint);
            paint.Color = new SKColor(0xff0f9d58);
            canvas.DrawCircle(180, 50, 25, paint);
            rect.Offset(80, 50);
            paint.Color = new SKColor(0xfff4b400);
            paint.Style = SKPaintStyle.Stroke;
            canvas.DrawRoundRect(rect, 10, 10, paint);
            canvas.Flush();
            ANGLE.Swap();
            return(new HandleRef(this, windowHandle));
        }
Example #5
0
        public void CanCreateSurfaceFromExistingMemoryUsingReleaseDelegate()
        {
            var hasReleased = false;

            var info  = new SKImageInfo(100, 100);
            var props = new SKSurfaceProperties(SKPixelGeometry.Unknown);

            var memory = Marshal.AllocCoTaskMem(info.BytesSize);

            using (var surface = SKSurface.Create(info, memory, info.RowBytes, OnRelease, "Hello", props))
            {
                Assert.NotNull(surface);
            }

            Assert.True(hasReleased);

            void OnRelease(IntPtr address, object context)
            {
                Marshal.FreeCoTaskMem(memory);
                hasReleased = true;

                Assert.Equal("Hello", context);
            }
        }