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;
43 TryEstablish(_adapter.Width, _adapter.Height);
47 _adapter.Resized -= OnResized;
54 private void OnResized(RenderSurfaceAdapterResizedEventArgs args)
55 => TryEstablish(args.NewWidth, args.NewHeight);
60 private void TryEstablish(
int width,
int height)
63 if (_disposed || _established || width <= 1 || height <= 1)
67 float scale = Math.Max((
float)_logicalWidth / width, (
float)_logicalHeight / height);
70 _adapter.Resized -= OnResized;
80 _adapter.Resized -= OnResized;