blob: 4c9f854c8c9a16155715cf3028936694df422f09 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharpDX;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using Tango.RemoteDesktop.Utils;
using Device = SharpDX.Direct3D11.Device;
using MapFlags = SharpDX.Direct3D11.MapFlags;
namespace Tango.RemoteDesktop.CaptureMethods
{
/// <summary>
/// Represents a high performance DirectX screen capture method.
/// </summary>
/// <seealso cref="Tango.RemoteDesktop.ICaptureMethod" />
public class DirectXScreenCapture : ICaptureMethod
{
private static bool _hasInstance;
private Device device;
private Output1 output1;
private Texture2DDescription textureDesc;
private OutputDuplication duplicatedOutput;
private int monitorWidth;
private int monitorHeight;
/// <summary>
/// Gets or sets the index of the graphics adapter.
/// </summary>
public int AdapterIndex { get; set; }
/// <summary>
/// Gets or sets the index of the monitor within the graphics adapter.
/// </summary>
public int MonitorIndex { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="DirectXScreenCapture"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">An instance of the DirectX screen capture method already exists. Please dispose it before attempting to create a new one.</exception>
public DirectXScreenCapture()
{
if (_hasInstance)
{
throw new InvalidOperationException("An instance of the DirectX screen capture method already exists. Please dispose it before attempting to create a new one.");
}
// Create DXGI Factory1
var factory = new Factory1();
var adapter = factory.GetAdapter1(AdapterIndex);
// Create device from Adapter
device = new Device(adapter);
// Get DXGI.Output
var
|