8internal sealed class BlazorLogicalResolutionBinding : IDisposable
10 private readonly RenderSurfaceAdapterBase _adapter;
11 private readonly Action<float> _applyScale;
12 private readonly
int _logicalWidth;
13 private readonly
int _logicalHeight;
14 private bool _established;
15 private bool _disposed;
22 internal BlazorLogicalResolutionBinding(
23 RenderSurfaceAdapterBase adapter,
26 Action<float> applyScale)
28 ArgumentNullException.ThrowIfNull(adapter);
29 ArgumentNullException.ThrowIfNull(applyScale);
30 ArgumentOutOfRangeException.ThrowIfNegativeOrZero(logicalWidth);
31 ArgumentOutOfRangeException.ThrowIfNegativeOrZero(logicalHeight);
34 _logicalWidth = logicalWidth;
35 _logicalHeight = logicalHeight;
36 _applyScale = applyScale;
39 _adapter.Resized += OnResized;
42 TryEstablish(_adapter.Width, _adapter.Height);
46 _adapter.Resized -= OnResized;
53 private void OnResized(RenderSurfaceAdapterResizedEventArgs args)
54 => TryEstablish(args.NewWidth, args.NewHeight);
59 private void TryEstablish(
int width,
int height)
62 if (_disposed || _established || width <= 1 || height <= 1)
66 float scale = Math.Max((
float)_logicalWidth / width, (
float)_logicalHeight / height);
69 _adapter.Resized -= OnResized;
79 _adapter.Resized -= OnResized;