Browse Source

Avalonia / Skia expect pixels in physical units rather than logical ones. Hard code DPI values for now.

repro-window-close
Nelson Carrillo 8 years ago
parent
commit
8623e6cc2a
  1. 20
      src/Avalonia.Windowing/Bindings/GlWindow.cs
  2. 2
      src/Avalonia.Windowing/Bindings/IWindowWrapper.cs
  3. 10
      src/Avalonia.Windowing/Bindings/Window.cs
  4. 1
      src/Avalonia.Windowing/WIndowingPlatform.cs
  5. 31
      src/Avalonia.Windowing/WindowImpl.cs
  6. 15
      src/Skia/Avalonia.Skia/GlRenderTarget.cs

20
src/Avalonia.Windowing/Bindings/GlWindow.cs

@ -25,9 +25,15 @@ namespace Avalonia.Windowing.Bindings
[DllImport("winit_wrapper")] [DllImport("winit_wrapper")]
private static extern LogicalSize winit_gl_window_get_size(IntPtr handle); private static extern LogicalSize winit_gl_window_get_size(IntPtr handle);
[DllImport("winit_wrapper")]
private static extern LogicalPosition winit_gl_window_get_position(IntPtr handle);
[DllImport("winit_wrapper")] [DllImport("winit_wrapper")]
private static extern void winit_gl_window_present(IntPtr handle); private static extern void winit_gl_window_present(IntPtr handle);
[DllImport("winit_wrapper")]
private static extern void winit_gl_window_show(IntPtr handle);
[DllImport("winit_wrapper")] [DllImport("winit_wrapper")]
private static extern IntPtr winit_gl_window_get_proc_addr(IntPtr handle, string symbol); private static extern IntPtr winit_gl_window_get_proc_addr(IntPtr handle, string symbol);
@ -64,15 +70,23 @@ namespace Avalonia.Windowing.Bindings
public (double, double) GetSize() { public (double, double) GetSize() {
var size = winit_gl_window_get_size(_handle); var size = winit_gl_window_get_size(_handle);
return (size.Width, size.Height); return (size.Width, size.Height);
} }
public (double, double) GetFramebufferSize() public (double, double) GetFramebufferSize()
{ {
var size = winit_gl_window_get_size(_handle); return GetSize();
}
return (size.Width, size.Height); public (double, double) GetPosition()
{
var position = winit_gl_window_get_position(_handle);
return (position.X, position.Y);
}
public void Show()
{
winit_gl_window_show(_handle);
} }
} }
} }

2
src/Avalonia.Windowing/Bindings/IWindowWrapper.cs

@ -9,5 +9,7 @@ namespace Avalonia.Windowing.Bindings
void SetTitle(string title); void SetTitle(string title);
void SetSize(double width, double height); void SetSize(double width, double height);
(double, double) GetSize(); (double, double) GetSize();
(double, double) GetPosition();
void Show();
} }
} }

10
src/Avalonia.Windowing/Bindings/Window.cs

@ -36,5 +36,15 @@ namespace Avalonia.Windowing.Bindings
{ {
return (0, 0); return (0, 0);
} }
public (double, double) GetPosition()
{
return (0, 0);
}
public void Show()
{
}
} }
} }

1
src/Avalonia.Windowing/WIndowingPlatform.cs

@ -82,6 +82,7 @@ namespace Avalonia.Windowing
public void Signal(DispatcherPriority priority) public void Signal(DispatcherPriority priority)
{ {
// We need to run some sort of callback on wakeup don't we?
_eventsLoop.Wakeup(); _eventsLoop.Wakeup();
} }

31
src/Avalonia.Windowing/WindowImpl.cs

@ -21,7 +21,19 @@ namespace Avalonia.Windowing
public WindowState WindowState { get; set; } public WindowState WindowState { get; set; }
public Action<WindowState> WindowStateChanged { get; set; } public Action<WindowState> WindowStateChanged { get; set; }
public Func<bool> Closing { get; set; } public Func<bool> Closing { get; set; }
public Point Position { get; set; } public Point Position
{
get
{
var (x, y) = _windowWrapper.GetPosition();
return new Point(x, y);
}
set
{
var x = value;
}
}
public Action<Point> PositionChanged { get; set; } public Action<Point> PositionChanged { get; set; }
public Action Deactivated { get; set; } public Action Deactivated { get; set; }
public Action Activated { get; set; } public Action Activated { get; set; }
@ -36,11 +48,11 @@ namespace Avalonia.Windowing
get get
{ {
var (width, height) = _windowWrapper.GetSize(); var (width, height) = _windowWrapper.GetSize();
return new Size(width, height); return new Size(width * 2, height * 2);
} }
} }
public double Scaling => 1.0; public double Scaling => 192 / 96;
public IEnumerable<object> Surfaces => new List<object>() { _windowWrapper }; public IEnumerable<object> Surfaces => new List<object>() { _windowWrapper };
@ -89,18 +101,24 @@ namespace Avalonia.Windowing
public Point PointToClient(Point point) public Point PointToClient(Point point)
{ {
return point; point = point.WithY(ClientSize.Height - point.Y);
var (x, y) = _windowWrapper.GetPosition();
return new Point(point.X + x, point.Y + y);
} }
public Point PointToScreen(Point point) public Point PointToScreen(Point point)
{ {
return point; point = point.WithY(ClientSize.Height - point.Y);
var (x, y) = _windowWrapper.GetPosition();
return new Point(point.X - x, point.Y - y);;
} }
public void Resize(Size clientSize) public void Resize(Size clientSize)
{ {
// This is where we size the window accordingly.. // This is where we size the window accordingly..
_windowWrapper.SetSize(clientSize.Width, clientSize.Height); _windowWrapper.SetSize(clientSize.Width / Scaling, clientSize.Height / Scaling);
// TODO: Move this to when we receive the Resized message.
Resized(clientSize); Resized(clientSize);
} }
@ -135,6 +153,7 @@ namespace Avalonia.Windowing
public void Show() public void Show()
{ {
_windowWrapper.Show();
} }
public IDisposable ShowDialog() public IDisposable ShowDialog()

15
src/Skia/Avalonia.Skia/GlRenderTarget.cs

@ -31,14 +31,14 @@ namespace Avalonia.Skia
{ {
// TODO: These are hard coded for now. Don't do that. // TODO: These are hard coded for now. Don't do that.
// TODO: Recreate the surface when the size changes. // TODO: Recreate the surface when the size changes.
// if (_surface == null) if (_surface == null)
// { {
var (width, height) = _context.GetFramebufferSize(); var (width, height) = _context.GetFramebufferSize();
_surface = SKSurface.Create(_grContext, new GRBackendRenderTargetDesc _surface = SKSurface.Create(_grContext, new GRBackendRenderTargetDesc
{ {
Height = (int)height, Height = (int)height * 2,
Width = (int)width, Width = (int)width * 2,
SampleCount = 1, SampleCount = 1,
StencilBits = 8, StencilBits = 8,
Config = GRPixelConfig.Bgra8888, Config = GRPixelConfig.Bgra8888,
@ -47,12 +47,15 @@ namespace Avalonia.Skia
}); });
_canvas = _surface.Canvas; _canvas = _surface.Canvas;
// } }
_canvas.RestoreToCount(-1);
_canvas.ResetMatrix();
var createInfo = new DrawingContextImpl.CreateInfo var createInfo = new DrawingContextImpl.CreateInfo
{ {
Canvas = _canvas, Canvas = _canvas,
Dpi = new Vector(96, 96), Dpi = new Vector(192, 192),
VisualBrushRenderer = visualBrushRenderer, VisualBrushRenderer = visualBrushRenderer,
DisableTextLcdRendering = true DisableTextLcdRendering = true
}; };

Loading…
Cancel
Save