Skip to content

Commit 9bdb07f

Browse files
committed
Added doc comments
1 parent e6202d8 commit 9bdb07f

File tree

11 files changed

+346
-15
lines changed

11 files changed

+346
-15
lines changed

ScreenCapture/DirectX/DX11ScreenCapture.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Runtime.InteropServices;
55
using System.Threading;
6-
using ScreenCapture.Events;
76
using SharpGen.Runtime;
87
using Vortice.Direct3D;
98
using Vortice.Direct3D11;
@@ -15,6 +14,10 @@
1514

1615
namespace ScreenCapture
1716
{
17+
/// <summary>
18+
/// Represents a ScreenCapture using DirectX 11 desktop duplicaton.
19+
/// https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
20+
/// </summary>
1821
// ReSharper disable once InconsistentNaming
1922
public sealed class DX11ScreenCapture : IScreenCapture
2023
{
@@ -36,8 +39,14 @@ public sealed class DX11ScreenCapture : IScreenCapture
3639

3740
private int _indexCounter = 0;
3841

42+
/// <inheritdoc />
3943
public Display Display { get; }
4044

45+
/// <summary>
46+
/// Gets or sets the timeout in ms used for screen-capturing. (default 1000ms)
47+
/// This is used in <see cref="CaptureScreen"/> https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-idxgioutputduplication-acquirenextframe
48+
/// </summary>
49+
// ReSharper disable once MemberCanBePrivate.Global
4150
public int Timeout { get; set; } = 1000;
4251

4352
private readonly IDXGIFactory1 _factory;
@@ -54,12 +63,18 @@ public sealed class DX11ScreenCapture : IScreenCapture
5463

5564
#region Events
5665

66+
/// <inheritdoc />
5767
public event EventHandler<ScreenCaptureUpdatedEventArgs>? Updated;
5868

5969
#endregion
6070

6171
#region Constructors
6272

73+
/// <summary>
74+
/// Initializes a new instance of the <see cref="DX11ScreenCapture"/> class.
75+
/// </summary>
76+
/// <param name="factory">The <see cref="IDXGIFactory1"/> used to create underlying objects.</param>
77+
/// <param name="display">The <see cref="Display"/> to duplicate.</param>
6378
public DX11ScreenCapture(IDXGIFactory1 factory, Display display)
6479
{
6580
this._factory = factory;
@@ -72,6 +87,7 @@ public DX11ScreenCapture(IDXGIFactory1 factory, Display display)
7287

7388
#region Methods
7489

90+
/// <inheritdoc />
7591
public bool CaptureScreen()
7692
{
7793
bool result = false;
@@ -171,6 +187,7 @@ private void UpdateZones()
171187
}
172188
}
173189

190+
/// <inheritdoc />
174191
public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel = 0)
175192
{
176193
if (_device == null) throw new ApplicationException("ScreenCapture isn't initialized.");
@@ -209,6 +226,7 @@ public CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int
209226
return captureZone;
210227
}
211228

229+
/// <inheritdoc />
212230
public bool UnregisterCaptureZone(CaptureZone captureZone)
213231
{
214232
lock (_captureZones)
@@ -268,6 +286,7 @@ private void InitializeCaptureZone(in CaptureZone captureZone)
268286
_captureZones[captureZone] = (stagingTexture, scalingTexture, scalingTextureView);
269287
}
270288

289+
/// <inheritdoc />
271290
public void Restart()
272291
{
273292
lock (_captureLock)
@@ -312,6 +331,7 @@ public void Restart()
312331
}
313332
}
314333

334+
/// <inheritdoc />
315335
public void Dispose() => Dispose(true);
316336

317337
private void Dispose(bool removeCaptureZones)

ScreenCapture/DirectX/DX11ScreenCaptureService.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Vortice.DXGI;
34

45
namespace ScreenCapture
56
{
7+
/// <summary>
8+
///
9+
/// </summary>
610
public class DX11ScreenCaptureService : IScreenCaptureService
711
{
812
#region Properties & Fields
@@ -15,6 +19,9 @@ public class DX11ScreenCaptureService : IScreenCaptureService
1519

1620
#region Constructors
1721

22+
/// <summary>
23+
///
24+
/// </summary>
1825
public DX11ScreenCaptureService()
1926
{
2027
DXGI.CreateDXGIFactory1(out _factory).CheckError();
@@ -24,6 +31,7 @@ public DX11ScreenCaptureService()
2431

2532
#region Methods
2633

34+
/// <inheritdoc />
2735
public IEnumerable<GraphicsCard> GetGraphicsCards()
2836
{
2937
int i = 0;
@@ -35,6 +43,7 @@ public IEnumerable<GraphicsCard> GetGraphicsCards()
3543
}
3644
}
3745

46+
/// <inheritdoc />
3847
public IEnumerable<Display> GetDisplays(GraphicsCard graphicsCard)
3948
{
4049
using IDXGIAdapter1? adapter = _factory.GetAdapter1(graphicsCard.Index);
@@ -50,20 +59,24 @@ public IEnumerable<Display> GetDisplays(GraphicsCard graphicsCard)
5059
}
5160
}
5261

62+
/// <inheritdoc />
5363
public IScreenCapture GetScreenCapture(Display display)
5464
{
5565
if (!_screenCaptures.TryGetValue(display, out DX11ScreenCapture? screenCapture))
5666
_screenCaptures.Add(display, screenCapture = new DX11ScreenCapture(_factory, display));
5767
return screenCapture;
5868
}
5969

70+
/// <inheritdoc />
6071
public void Dispose()
6172
{
6273
foreach (DX11ScreenCapture screenCapture in _screenCaptures.Values)
6374
screenCapture.Dispose();
6475
_screenCaptures.Clear();
6576

6677
_factory.Dispose();
78+
79+
GC.SuppressFinalize(this);
6780
}
6881

6982
#endregion

ScreenCapture/Events/ScreenCaptureUpdatedEventArgs.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
using System;
1+
// ReSharper disable MemberCanBePrivate.Global
2+
using System;
23

3-
namespace ScreenCapture.Events
4+
namespace ScreenCapture
45
{
6+
/// <inheritdoc />
7+
/// <summary>
8+
/// Represents the information supplied with an <see cref="E:ScreenCapture.IDX11ScreenCapture.Updated" />-event.
9+
/// </summary>
510
public class ScreenCaptureUpdatedEventArgs : EventArgs
611
{
712
#region Properties & Fields
813

14+
/// <summary>
15+
/// <c>true</c> if the update was successful; otherwise, <c>false</c>.
16+
/// </summary>
917
public bool IsSuccessful { get; set; }
1018

1119
#endregion
1220

1321
#region Constructors
1422

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="ScreenCaptureUpdatedEventArgs"/> class.
25+
/// </summary>
26+
/// <param name="isSuccessful">Indicates if the last update was successful.</param>
1527
public ScreenCaptureUpdatedEventArgs(bool isSuccessful)
1628
{
1729
this.IsSuccessful = isSuccessful;

ScreenCapture/Helper/DPIAwareness.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// ReSharper disable InconsistentNaming
2+
// ReSharper disable MemberCanBePrivate.Global
23
using System.Runtime.InteropServices;
34

45
namespace ScreenCapture
56
{
7+
/// <summary>
8+
/// Helper-class for DPI-related WIN-API calls.
9+
/// </summary>
610
public static class DPIAwareness
711
{
812
[DllImport("user32.dll", SetLastError = true)]
@@ -29,9 +33,9 @@ internal enum DPI_AWARENESS_CONTEXT
2933
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 34
3034
}
3135

32-
public static void Initalize()
33-
{
34-
SetProcessDpiAwarenessContext((int)DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
35-
}
36+
/// <summary>
37+
/// Sets the DPI-Awareness-Context to V2. This is needed to prevent issues when using desktop duplication.
38+
/// </summary>
39+
public static void Initalize() => SetProcessDpiAwarenessContext((int)DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
3640
}
3741
}

ScreenCapture/IScreenCapture.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,48 @@
22

33
namespace ScreenCapture
44
{
5+
/// <summary>
6+
/// Represents the duplication of a single display.
7+
/// </summary>
58
public interface IScreenCapture : IDisposable
69
{
10+
/// <summary>
11+
/// Gets the <see cref="Display"/> this capture is duplicating.
12+
/// </summary>
713
Display Display { get; }
814

15+
/// <summary>
16+
/// Occurs when the <see cref="IScreenCapture"/> is updated.
17+
/// </summary>
18+
event EventHandler<ScreenCaptureUpdatedEventArgs>? Updated;
19+
20+
/// <summary>
21+
/// Attemts to capture the current frame showed on the <see cref="Display"/>.
22+
/// </summary>
23+
/// <returns><c>true</c> if the current frame was captures successfully; otherwise, <c>false</c>.</returns>
924
bool CaptureScreen();
25+
26+
/// <summary>
27+
/// Creates a new <see cref="CaptureScreen"/> for this <see cref="IScreenCapture"/>.
28+
/// </summary>
29+
/// <param name="x">The x-location of the region to capture (must be &gt;= 0 and &lt; screen-width).</param>
30+
/// <param name="y">The x-location of the region to capture (must be &gt;= 0 and &lt; screen-height).</param>
31+
/// <param name="width">The width of the region to capture (must be &gt;= 0 and this + x must be &lt;= screen-width).</param>
32+
/// <param name="height">The height of the region to capture (must be &gt;= 0 and this + y must be &lt;= screen-height).</param>
33+
/// <param name="downscaleLevel">The level of downscaling applied to the image of this region before copying to local memory. The calculation is (width and height)/2^downscaleLevel.</param>
34+
/// <returns>The new <see cref="CaptureScreen"/>.</returns>
1035
CaptureZone RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel = 0);
36+
37+
/// <summary>
38+
/// Removes the given <see cref="CaptureScreen"/> from the <see cref="IScreenCapture"/>.
39+
/// </summary>
40+
/// <param name="captureZone">The previosly registered <see cref="CaptureScreen"/>.</param>
41+
/// <returns><c>true</c> if the <see cref="CaptureScreen"/> was successfully removed; otherwise, <c>false</c>.</returns>
1142
bool UnregisterCaptureZone(CaptureZone captureZone);
43+
44+
/// <summary>
45+
/// Restarts the <see cref="IScreenCapture"/>.
46+
/// </summary>
1247
void Restart();
1348
}
1449
}

ScreenCapture/IScreenCaptureService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,29 @@
33

44
namespace ScreenCapture
55
{
6+
/// <summary>
7+
///
8+
/// </summary>
69
public interface IScreenCaptureService : IDisposable
710
{
11+
/// <summary>
12+
/// Gets a enumerable of all available graphics-cards.
13+
/// </summary>
14+
/// <returns>A enumerable of all available graphics-cards.</returns>
815
IEnumerable<GraphicsCard> GetGraphicsCards();
16+
17+
/// <summary>
18+
/// Gets a enumerable of all display connected to the given graphics-cards.
19+
/// </summary>
20+
/// <param name="graphicsCard">The graphics-card to get the displays from.</param>
21+
/// <returns>A enumerable of all display connected to the given graphics-cards.</returns>
922
IEnumerable<Display> GetDisplays(GraphicsCard graphicsCard);
23+
24+
/// <summary>
25+
/// Creates a <see cref="IScreenCapture"/> for the given display.
26+
/// </summary>
27+
/// <param name="display">The display to duplicate.</param>
28+
/// <returns>The <see cref="IScreenCapture"/> for the give display.</returns>
1029
IScreenCapture GetScreenCapture(Display display);
1130
}
1231
}

ScreenCapture/Model/BlackBarDetection.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1-
using System;
1+
// ReSharper disable MemberCanBePrivate.Global
2+
using System;
23

34
namespace ScreenCapture
45
{
6+
/// <summary>
7+
/// Represents the configuration for the detection and removal of black bars around the screen image.
8+
/// </summary>
59
public sealed class BlackBarDetection
610
{
711
#region Properties & Fields
812

913
private readonly CaptureZone _captureZone;
1014

1115
private int? _top;
16+
/// <summary>
17+
/// Gets the size of the detected black bar at the top of the image.
18+
/// </summary>
1219
public int Top => _top ??= CalculateTop();
1320

1421
private int? _bottom;
22+
/// <summary>
23+
/// Gets the size of the detected black bar at the bottom of the image.
24+
/// </summary>
1525
public int Bottom => _bottom ??= CalculateBottom();
1626

1727
private int? _left;
28+
/// <summary>
29+
/// Gets the size of the detected black bar at the left of the image.
30+
/// </summary>
1831
public int Left => _left ??= CalculateLeft();
1932

2033
private int? _right;
34+
/// <summary>
35+
/// Gets the size of the detected black bar at the right of the image.
36+
/// </summary>
2137
public int Right => _right ??= CalculateRight();
2238

2339
private int _theshold = 0;
40+
/// <summary>
41+
/// Gets or sets the threshold of "blackness" used to detect black bars. (e. g. Threshold 5 will consider a pixel of color [5,5,5] as black.) (default 0)
42+
/// </summary>
2443
public int Threshold
2544
{
2645
get => _theshold;
@@ -35,7 +54,7 @@ public int Threshold
3554

3655
#region Constructors
3756

38-
public BlackBarDetection(CaptureZone captureZone)
57+
internal BlackBarDetection(CaptureZone captureZone)
3958
{
4059
this._captureZone = captureZone;
4160
}
@@ -44,6 +63,9 @@ public BlackBarDetection(CaptureZone captureZone)
4463

4564
#region Methods
4665

66+
/// <summary>
67+
/// Invalidates the cached values and recalculates <see cref="Top"/>, <see cref="Bottom"/>, <see cref="Left"/> and <see cref="Right"/>.
68+
/// </summary>
4769
public void InvalidateCache()
4870
{
4971
_top = null;

0 commit comments

Comments
 (0)