Browse Source

Add the ability to resize a GL context

repro-window-close
Nelson Carrillo 8 years ago
parent
commit
776b6c6b4b
  1. 1
      src/Avalonia.Gpu/IGpuContext.cs
  2. 8
      src/Avalonia.Windowing/Bindings/GlWindow.cs
  3. 16
      src/Avalonia.Windowing/WIndowingPlatform.cs
  4. 4
      src/Avalonia.Windowing/WindowImpl.cs
  5. 8
      src/Skia/Avalonia.Skia/GlRenderTarget.cs

1
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);
}
}

8
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);
}
}
}

16
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<IMouseDevice>().ToConstant(new MouseDevice())
.Bind<IPlatformIconLoader>().ToConstant(new IconLoader())
.Bind<IStandardCursorFactory>().ToConstant(new CursorFactory())
.Bind<IPlatformSettings>().ToConstant(new PlatformSettings())
.Bind<IPlatformThreadingInterface>().ToConstant(this);
}

4
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);;
}

8
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
}));

Loading…
Cancel
Save