-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
IFramebufferPlatformSurface.cs
86 lines (71 loc) · 2.45 KB
/
IFramebufferPlatformSurface.cs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using Avalonia.Metadata;
using Avalonia.Platform;
namespace Avalonia.Controls.Platform.Surfaces
{
[Unstable]
public interface IFramebufferPlatformSurface
{
IFramebufferRenderTarget CreateFramebufferRenderTarget();
}
[Unstable]
public interface IFramebufferRenderTarget : IDisposable
{
/// <summary>
/// Provides a framebuffer descriptor for drawing.
/// </summary>
/// <remarks>
/// Contents should be drawn on actual window after disposing
/// </remarks>
ILockedFramebuffer Lock();
}
[PrivateApi]
public interface IFramebufferRenderTargetWithProperties : IFramebufferRenderTarget
{
/// <summary>
/// Provides a framebuffer descriptor for drawing.
/// </summary>
/// <remarks>
/// Contents should be drawn on actual window after disposing
/// </remarks>
ILockedFramebuffer Lock(out FramebufferLockProperties properties);
bool RetainsFrameContents { get; }
}
[PrivateApi]
public record struct FramebufferLockProperties(bool PreviousFrameIsRetained);
/// <summary>
/// For simple cases when framebuffer is always available
/// </summary>
public class FuncFramebufferRenderTarget : IFramebufferRenderTarget
{
private readonly Func<ILockedFramebuffer> _lockFramebuffer;
public FuncFramebufferRenderTarget(Func<ILockedFramebuffer> lockFramebuffer)
{
_lockFramebuffer = lockFramebuffer;
}
public void Dispose()
{
// No-op
}
public ILockedFramebuffer Lock() => _lockFramebuffer();
}
internal class FuncRetainedFramebufferRenderTarget : IFramebufferRenderTargetWithProperties
{
public delegate ILockedFramebuffer LockDelegate(out FramebufferLockProperties properties);
private readonly LockDelegate _lockFramebuffer;
public FuncRetainedFramebufferRenderTarget(LockDelegate lockFramebuffer)
{
_lockFramebuffer = lockFramebuffer;
}
public void Dispose()
{
// No-op
}
public ILockedFramebuffer Lock() => _lockFramebuffer(out _);
public ILockedFramebuffer Lock(out FramebufferLockProperties properties)
{
return _lockFramebuffer(out properties);
}
public bool RetainsFrameContents => true;
}
}