-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAvaloniaFramebufferReference.cs
More file actions
49 lines (38 loc) · 1.84 KB
/
Copy pathAvaloniaFramebufferReference.cs
File metadata and controls
49 lines (38 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using Avalonia.Platform;
using MarcusW.VncClient.Rendering;
namespace MarcusW.VncClient.Avalonia.Adapters.Rendering
{
/// <inheritdoc />
public sealed class AvaloniaFramebufferReference : IFramebufferReference
{
private ILockedFramebuffer? _lockedFramebuffer;
private readonly Action _invalidateVisual;
/// <inheritdoc />
public IntPtr Address => _lockedFramebuffer?.Address ?? throw new ObjectDisposedException(nameof(AvaloniaFramebufferReference));
/// <inheritdoc />
public Size Size => Conversions.GetSize(_lockedFramebuffer?.Size ?? throw new ObjectDisposedException(nameof(AvaloniaFramebufferReference)));
/// <inheritdoc />
public PixelFormat Format => Conversions.GetPixelFormat(_lockedFramebuffer?.Format ?? throw new ObjectDisposedException(nameof(AvaloniaFramebufferReference)));
/// <inheritdoc />
public double HorizontalDpi => _lockedFramebuffer?.Dpi.X ?? throw new ObjectDisposedException(nameof(AvaloniaFramebufferReference));
/// <inheritdoc />
public double VerticalDpi => _lockedFramebuffer?.Dpi.Y ?? throw new ObjectDisposedException(nameof(AvaloniaFramebufferReference));
internal AvaloniaFramebufferReference(ILockedFramebuffer lockedFramebuffer, Action invalidateVisual)
{
_lockedFramebuffer = lockedFramebuffer;
_invalidateVisual = invalidateVisual;
}
/// <inheritdoc />
public void Dispose()
{
ILockedFramebuffer? lockedFramebuffer = _lockedFramebuffer;
_lockedFramebuffer = null;
if (lockedFramebuffer == null)
return;
lockedFramebuffer.Dispose();
// Dispose gets called, when rendering is finished, so invalidate the visual now
_invalidateVisual();
}
}
}