Browse Source

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

fix stability of wasm init.
pull/7430/head
Dan Walmsley 5 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, _topLevelImpl.SetSurface(_context, _jsGlInfo, ColorType,
new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi); new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi);
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
_initialised = true; _initialised = true;
_topLevel.Prepare(); Threading.Dispatcher.UIThread.Post(async () =>
{
_topLevel.Renderer.Start(); _interop.RequestAnimationFrame(true);
Invalidate(); _sizeWatcher = await SizeWatcherInterop.ImportAsync(Js, _htmlCanvas, OnSizeChanged);
_dpiWatcher = await DpiWatcherInterop.ImportAsync(Js, OnDpiChanged);
_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) 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); _topLevelImpl.SetClientSize(_canvasSize, _dpi);
ForceBlit();
Invalidate(); ForceBlit();
}
} }
private void OnSizeChanged(SKSize newSize) private void OnSizeChanged(SKSize newSize)
{ {
_canvasSize = newSize; if (_canvasSize != newSize)
{
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi)); _canvasSize = newSize;
_topLevelImpl.SetClientSize(_canvasSize, _dpi);
ForceBlit(); _interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
Invalidate(); _topLevelImpl.SetClientSize(_canvasSize, _dpi);
}
public void Invalidate() ForceBlit();
{
if (!_initialised || _jsGlInfo == null)
{
Console.WriteLine("invalidate ignored");
return;
} }
_interop.RequestAnimationFrame(true);
} }
public void SetActive(bool active) public void SetActive(bool active)

Loading…
Cancel
Save