Browse Source

Merge pull request #7424 from AvaloniaUI/fixes/wasm-init

fix stability of wasm init.
pull/7430/head
Dan Walmsley 4 years ago
committed by GitHub
parent
commit
f9bc43af3a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      src/Web/Avalonia.Web.Blazor/AvaloniaView.razor.cs

56
src/Web/Avalonia.Web.Blazor/AvaloniaView.razor.cs

@ -287,17 +287,22 @@ namespace Avalonia.Web.Blazor
_topLevelImpl.SetSurface(_context, _jsGlInfo, ColorType,
new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi);
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
_initialised = true;
_topLevel.Prepare();
_topLevel.Renderer.Start();
Invalidate();
_sizeWatcher = await SizeWatcherInterop.ImportAsync(Js, _htmlCanvas, OnSizeChanged);
_dpiWatcher = await DpiWatcherInterop.ImportAsync(Js, OnDpiChanged);
Threading.Dispatcher.UIThread.Post(async () =>
{
_interop.RequestAnimationFrame(true);
_sizeWatcher = await SizeWatcherInterop.ImportAsync(Js, _htmlCanvas, OnSizeChanged);
_dpiWatcher = await DpiWatcherInterop.ImportAsync(Js, OnDpiChanged);
_topLevel.Prepare();
_topLevel.Renderer.Start();
});
}
}
@ -336,37 +341,30 @@ namespace Avalonia.Web.Blazor
private void OnDpiChanged(double newDpi)
{
_dpi = newDpi;
if (Math.Abs(_dpi - newDpi) > 0.0001)
{
_dpi = newDpi;
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
_topLevelImpl.SetClientSize(_canvasSize, _dpi);
ForceBlit();
_topLevelImpl.SetClientSize(_canvasSize, _dpi);
Invalidate();
ForceBlit();
}
}
private void OnSizeChanged(SKSize newSize)
{
_canvasSize = newSize;
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
_topLevelImpl.SetClientSize(_canvasSize, _dpi);
if (_canvasSize != newSize)
{
_canvasSize = newSize;
ForceBlit();
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
Invalidate();
}
_topLevelImpl.SetClientSize(_canvasSize, _dpi);
public void Invalidate()
{
if (!_initialised || _jsGlInfo == null)
{
Console.WriteLine("invalidate ignored");
return;
ForceBlit();
}
_interop.RequestAnimationFrame(true);
}
public void SetActive(bool active)

Loading…
Cancel
Save