forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirectCompositedWindow.cs
More file actions
63 lines (51 loc) · 1.84 KB
/
DirectCompositedWindow.cs
File metadata and controls
63 lines (51 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Threading;
using Avalonia.Controls;
using Avalonia.OpenGL.Egl;
using Avalonia.Reactive;
using MicroCom.Runtime;
namespace Avalonia.Win32.DComposition;
internal class DirectCompositedWindow : IDisposable
{
private readonly DirectCompositionShared _shared;
public EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo WindowInfo { get; }
private readonly IDCompositionVisual _container;
private readonly IDCompositionTarget _target;
private readonly IDCompositionDevice2 _device;
public void Dispose()
{
lock (_shared.SyncRoot)
{
_container.Dispose();
_target.Dispose();
_device.Dispose();
}
}
public DirectCompositedWindow(EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo info, DirectCompositionShared shared)
{
WindowInfo = info;
_shared = shared;
_device = shared.Device.CloneReference();
using var desktopTarget = shared.Device.CreateTargetForHwnd(WindowInfo.Handle, false);
_target = desktopTarget.QueryInterface<IDCompositionTarget>();
using var container = shared.Device.CreateVisual();
_container = container.CloneReference();
_target.SetRoot(container);
}
public void SetSurface(IDCompositionSurface surface) => _container.SetContent(surface);
public IDisposable BeginTransaction()
{
Monitor.Enter(_shared.SyncRoot);
return Disposable.Create(() =>
{
_device.Commit();
Monitor.Exit(_shared.SyncRoot);
});
}
public bool IsTransparency => _transparencyLevel != WindowTransparencyLevel.None;
public void SetTransparencyLevel(WindowTransparencyLevel transparencyLevel)
{
_transparencyLevel = transparencyLevel;
}
private WindowTransparencyLevel _transparencyLevel;
}