From 776b6c6b4b49ce8f8634e8a2a045431379657d8f Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Tue, 24 Jul 2018 08:30:41 -0400 Subject: [PATCH] Add the ability to resize a GL context --- src/Avalonia.Gpu/IGpuContext.cs | 1 + src/Avalonia.Windowing/Bindings/GlWindow.cs | 8 ++++++++ src/Avalonia.Windowing/WIndowingPlatform.cs | 16 +++++++--------- src/Avalonia.Windowing/WindowImpl.cs | 4 ++-- src/Skia/Avalonia.Skia/GlRenderTarget.cs | 8 ++++---- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Avalonia.Gpu/IGpuContext.cs b/src/Avalonia.Gpu/IGpuContext.cs index 1adc4952d6..d27e9c24f1 100644 --- a/src/Avalonia.Gpu/IGpuContext.cs +++ b/src/Avalonia.Gpu/IGpuContext.cs @@ -7,5 +7,6 @@ namespace Avalonia.Gpu void Present(); IntPtr GetProcAddress(string symbol); (double, double) GetFramebufferSize(); + void ResizeContext(double width, double height); } } diff --git a/src/Avalonia.Windowing/Bindings/GlWindow.cs b/src/Avalonia.Windowing/Bindings/GlWindow.cs index 3fa1a8553e..077bb62179 100644 --- a/src/Avalonia.Windowing/Bindings/GlWindow.cs +++ b/src/Avalonia.Windowing/Bindings/GlWindow.cs @@ -40,6 +40,9 @@ namespace Avalonia.Windowing.Bindings [DllImport("winit_wrapper")] private static extern IntPtr winit_gl_window_get_id(IntPtr handle); + [DllImport("winit_wrapper")] + private static extern void winit_gl_window_resize_context(IntPtr handle, double width, double height); + private IntPtr _handle; public IntPtr Id => winit_gl_window_get_id(_handle); public GlWindowWrapper(EventsLoop eventsLoop) @@ -92,5 +95,10 @@ namespace Avalonia.Windowing.Bindings { winit_gl_window_show(_handle); } + + public void ResizeContext(double width, double height) + { + winit_gl_window_resize_context(_handle, width, height); + } } } diff --git a/src/Avalonia.Windowing/WIndowingPlatform.cs b/src/Avalonia.Windowing/WIndowingPlatform.cs index fce6b148ea..5d414995fe 100644 --- a/src/Avalonia.Windowing/WIndowingPlatform.cs +++ b/src/Avalonia.Windowing/WIndowingPlatform.cs @@ -10,14 +10,10 @@ using Avalonia.Windowing.Bindings; namespace Avalonia.Windowing { - // Exposing C# Enums to Rust will again prove to be a massive PITA. - public enum WinitEventType - { - MouseMove - } - - public struct MouseMoveData + public class PlatformSettings : IPlatformSettings { + public Size DoubleClickSize => new Size(4, 4); + public TimeSpan DoubleClickTime => TimeSpan.FromMilliseconds(200); } public class DummyPlatformHandle : IPlatformHandle @@ -71,8 +67,9 @@ namespace Avalonia.Windowing private void _eventsLoop_Awakened() { - Signaled?.Invoke(DispatcherPriority.Normal); - // Dispatcher.UIThread.RunJobs(); + Signaled?.Invoke(DispatcherPriority.Input); + Signaled?.Invoke(DispatcherPriority.Layout); + Signaled?.Invoke(DispatcherPriority.Render); } @@ -89,6 +86,7 @@ namespace Avalonia.Windowing .Bind().ToConstant(new MouseDevice()) .Bind().ToConstant(new IconLoader()) .Bind().ToConstant(new CursorFactory()) + .Bind().ToConstant(new PlatformSettings()) .Bind().ToConstant(this); } diff --git a/src/Avalonia.Windowing/WindowImpl.cs b/src/Avalonia.Windowing/WindowImpl.cs index eb6a695fca..5ee1accc9f 100644 --- a/src/Avalonia.Windowing/WindowImpl.cs +++ b/src/Avalonia.Windowing/WindowImpl.cs @@ -103,14 +103,14 @@ namespace Avalonia.Windowing public Point PointToClient(Point point) { - point = point.WithY(ClientSize.Height - point.Y); + // point = point.WithY(ClientSize.Height - point.Y); var position = Position; return new Point(point.X + position.X, point.Y + position.Y); } public Point PointToScreen(Point point) { - point = point.WithY(ClientSize.Height - point.Y); + //point = point.WithY(ClientSize.Height - point.Y); var position = Position; return new Point(point.X - position.X, point.Y - position.Y);; } diff --git a/src/Skia/Avalonia.Skia/GlRenderTarget.cs b/src/Skia/Avalonia.Skia/GlRenderTarget.cs index 8a564ebedd..4c1bb8def5 100644 --- a/src/Skia/Avalonia.Skia/GlRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/GlRenderTarget.cs @@ -34,26 +34,25 @@ namespace Avalonia.Skia if (_surface == null || (_desc.Width != (int)width * 2 || _desc.Height != (int)height * 2)) { + _context.ResizeContext(width, height); _desc = new GRBackendRenderTargetDesc { Height = (int)height * 2, Width = (int)width * 2, SampleCount = 1, StencilBits = 8, - Config = GRPixelConfig.Bgra8888, + Config = GRPixelConfig.Rgba8888, Origin = GRSurfaceOrigin.BottomLeft, RenderTargetHandle = IntPtr.Zero }; _surface?.Dispose(); _surface = SKSurface.Create(_grContext, _desc); + _canvas?.Dispose(); _canvas = _surface.Canvas; } - _canvas.Clear(SKColors.Orange); - _canvas.RestoreToCount(-1); - _canvas.ResetMatrix(); var createInfo = new DrawingContextImpl.CreateInfo { @@ -65,6 +64,7 @@ namespace Avalonia.Skia return new DrawingContextImpl(createInfo, Disposable.Create(() => { + _canvas.Flush(); _grContext.Flush(); _context.Present(); // Swap Buffers }));