Skip to content

Commit bcb92eb

Browse files
committed
Added some missing doc-comments
1 parent a1a43dd commit bcb92eb

File tree

19 files changed

+406
-45
lines changed

19 files changed

+406
-45
lines changed

ScreenCapture.NET.DX11/DX11ScreenCapture.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public sealed class DX11ScreenCapture : AbstractScreenCapture<ColorBGRA>
6868
/// <param name="factory">The <see cref="IDXGIFactory1"/> used to create underlying objects.</param>
6969
/// <param name="display">The <see cref="Display"/> to duplicate.</param>
7070
/// <param name="useNewDuplicationAdapter">Indicates if the DuplicateOutput1 interface should be used instead of the older DuplicateOutput. Currently there's no real use in setting this to true.</param>
71-
public DX11ScreenCapture(IDXGIFactory1 factory, Display display, bool useNewDuplicationAdapter = false)
71+
internal DX11ScreenCapture(IDXGIFactory1 factory, Display display, bool useNewDuplicationAdapter = false)
7272
: base(display)
7373
{
7474
this._factory = factory;
@@ -81,6 +81,7 @@ public DX11ScreenCapture(IDXGIFactory1 factory, Display display, bool useNewDupl
8181

8282
#region Methods
8383

84+
/// <inheritdoc />
8485
protected override bool PerformScreenCapture()
8586
{
8687
bool result = false;
@@ -133,6 +134,7 @@ protected override bool PerformScreenCapture()
133134
return result;
134135
}
135136

137+
/// <inheritdoc />
136138
protected override void PerformCaptureZoneUpdate(CaptureZone<ColorBGRA> captureZone, in Span<byte> buffer)
137139
{
138140
if (_context == null) return;
@@ -299,6 +301,7 @@ public override void UpdateCaptureZone(CaptureZone<ColorBGRA> captureZone, int?
299301
}
300302
}
301303

304+
/// <inheritdoc />
302305
protected override void ValidateCaptureZoneAndThrow(int x, int y, int width, int height, int downscaleLevel)
303306
{
304307
if (_device == null) throw new ApplicationException("ScreenCapture isn't initialized.");
@@ -429,10 +432,13 @@ public override void Restart()
429432
}
430433
}
431434

435+
/// <inheritdoc />
432436
protected override void Dispose(bool disposing)
433437
{
434438
base.Dispose(disposing);
435-
DisposeDX();
439+
440+
lock (_captureLock)
441+
DisposeDX();
436442
}
437443

438444
private void DisposeDX()

ScreenCapture.NET.DX9/DX9ScreenCapture.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
namespace ScreenCapture.NET;
1010

1111
/// <summary>
12-
/// Represents a ScreenCapture using DirectX 11 desktop duplicaton.
13-
/// https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
12+
/// Represents a ScreenCapture using DirectX 9.
13+
/// https://learn.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9-getfrontbufferdata
1414
/// </summary>
1515
// ReSharper disable once InconsistentNaming
1616
public sealed class DX9ScreenCapture : AbstractScreenCapture<ColorBGRA>
@@ -32,8 +32,9 @@ public sealed class DX9ScreenCapture : AbstractScreenCapture<ColorBGRA>
3232
/// <summary>
3333
/// Initializes a new instance of the <see cref="DX9ScreenCapture"/> class.
3434
/// </summary>
35+
/// <param name="direct3D9">The D3D9 instance used.</param>
3536
/// <param name="display">The <see cref="Display"/> to duplicate.</param>
36-
public DX9ScreenCapture(IDirect3D9 direct3D9, Display display)
37+
internal DX9ScreenCapture(IDirect3D9 direct3D9, Display display)
3738
: base(display)
3839
{
3940
this._direct3D9 = direct3D9;
@@ -45,6 +46,7 @@ public DX9ScreenCapture(IDirect3D9 direct3D9, Display display)
4546

4647
#region Methods
4748

49+
/// <inheritdoc />
4850
protected override bool PerformScreenCapture()
4951
{
5052
bool result = false;
@@ -89,6 +91,7 @@ protected override bool PerformScreenCapture()
8991
return result;
9092
}
9193

94+
/// <inheritdoc />
9295
protected override void PerformCaptureZoneUpdate(CaptureZone<ColorBGRA> captureZone, in Span<byte> buffer)
9396
{
9497
if (_buffer == null) return;
@@ -195,10 +198,13 @@ public override void Restart()
195198
}
196199
}
197200

201+
/// <inheritdoc />
198202
protected override void Dispose(bool disposing)
199203
{
200204
base.Dispose(disposing);
201-
DisposeDX();
205+
206+
lock (_captureLock)
207+
DisposeDX();
202208
}
203209

204210
private void DisposeDX()

ScreenCapture.NET.DX9/Downscale/SamplerInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ internal readonly ref struct SamplerInfo<T>
4343
/// <summary>
4444
/// Initializes a new instance of the <see cref="SamplerInfo{T}" /> class.
4545
/// </summary>
46+
/// <param name="x">The X-location of the region the data comes from.</param>
47+
/// <param name="y">The Y-location of the region the data comes from.</param>
4648
/// <param name="width">The width of the region the data comes from.</param>
4749
/// <param name="height">The height of region the data comes from.</param>
50+
/// <param name="stride">The number of pixels in a row of data.</param>
51+
/// <param name="dataPerPixel">The number of {T} representing a single pixel.</param>
4852
/// <param name="data">The data to sample.</param>
4953
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan<T> data)
5054
{

ScreenCapture.NET.X11/Downscale/SamplerInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ internal readonly ref struct SamplerInfo<T>
4343
/// <summary>
4444
/// Initializes a new instance of the <see cref="SamplerInfo{T}" /> class.
4545
/// </summary>
46+
/// <param name="x">The X-location of the region the data comes from.</param>
47+
/// <param name="y">The Y-location of the region the data comes from.</param>
4648
/// <param name="width">The width of the region the data comes from.</param>
4749
/// <param name="height">The height of region the data comes from.</param>
50+
/// <param name="stride">The number of pixels in a row of data.</param>
51+
/// <param name="dataPerPixel">The number of {T} representing a single pixel.</param>
4852
/// <param name="data">The data to sample.</param>
4953
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan<T> data)
5054
{

ScreenCapture.NET.X11/X11ScreenCapture.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ScreenCapture.NET;
77

88
/// <summary>
99
/// Represents a ScreenCapture using libX11.
10-
/// https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
10+
/// https://x.org/releases/current/doc/libX11/libX11/libX11.html#XGetImage
1111
/// </summary>
1212
// ReSharper disable once InconsistentNaming
1313
public sealed class X11ScreenCapture : AbstractScreenCapture<ColorBGRA>
@@ -31,7 +31,7 @@ public sealed class X11ScreenCapture : AbstractScreenCapture<ColorBGRA>
3131
/// Initializes a new instance of the <see cref="X11ScreenCapture"/> class.
3232
/// </summary>
3333
/// <param name="display">The <see cref="Display"/> to duplicate.</param>
34-
public X11ScreenCapture(Display display)
34+
internal X11ScreenCapture(Display display)
3535
: base(display)
3636
{
3737
Restart();
@@ -41,6 +41,7 @@ public X11ScreenCapture(Display display)
4141

4242
#region Methods
4343

44+
/// <inheritdoc />
4445
protected override bool PerformScreenCapture()
4546
{
4647
lock (_captureLock)
@@ -57,6 +58,7 @@ protected override bool PerformScreenCapture()
5758
}
5859
}
5960

61+
/// <inheritdoc />
6062
protected override void PerformCaptureZoneUpdate(CaptureZone<ColorBGRA> captureZone, in Span<byte> buffer)
6163
{
6264
using IDisposable @lock = captureZone.Lock();
@@ -158,6 +160,7 @@ public override void Restart()
158160
}
159161
}
160162

163+
/// <inheritdoc />
161164
protected override void Dispose(bool disposing)
162165
{
163166
base.Dispose(disposing);

ScreenCapture.NET.X11/X11ScreenCaptureService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public IEnumerable<Display> GetDisplays(GraphicsCard graphicsCard)
7575

7676
/// <inheritdoc />
7777
IScreenCapture IScreenCaptureService.GetScreenCapture(Display display) => GetScreenCapture(display);
78+
79+
/// <inheritdoc cref="IScreenCaptureService.GetScreenCapture"/>
7880
public X11ScreenCapture GetScreenCapture(Display display)
7981
{
8082
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);

ScreenCapture.NET/Generic/AbstractScreenCapture.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,37 @@
44

55
namespace ScreenCapture.NET;
66

7+
/// <inheritdoc />
78
public abstract class AbstractScreenCapture<TColor> : IScreenCapture
89
where TColor : struct, IColor
910
{
1011
#region Properties & Fields
1112

1213
private bool _isDisposed;
1314

15+
/// <summary>
16+
/// Gets a list of <see cref="CaptureZone{TColol}"/> registered on this ScreenCature.
17+
/// </summary>
1418
protected HashSet<CaptureZone<TColor>> CaptureZones { get; } = new();
1519

20+
/// <inheritdoc />
1621
public Display Display { get; }
1722

1823
#endregion
1924

2025
#region Events
2126

27+
/// <inheritdoc />
2228
public event EventHandler<ScreenCaptureUpdatedEventArgs>? Updated;
2329

2430
#endregion
2531

2632
#region Constructors
2733

34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="AbstractScreenCapture{T}"/> class.
36+
/// </summary>
37+
/// <param name="display">The <see cref="Display"/> to duplicate.</param>
2838
protected AbstractScreenCapture(Display display)
2939
{
3040
this.Display = display;
@@ -36,6 +46,7 @@ protected AbstractScreenCapture(Display display)
3646

3747
#region Methods
3848

49+
/// <inheritdoc />
3950
public virtual bool CaptureScreen()
4051
{
4152
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
@@ -67,10 +78,23 @@ public virtual bool CaptureScreen()
6778
return result;
6879
}
6980

81+
/// <summary>
82+
/// Performs the actual screen capture.
83+
/// </summary>
84+
/// <returns><c>true</c> if the screen was captured sucessfully; otherwise, <c>false</c>.</returns>
7085
protected abstract bool PerformScreenCapture();
7186

87+
/// <summary>
88+
/// Performs an update of the given capture zone.
89+
/// </summary>
90+
/// <param name="captureZone">The capture zone to update.</param>
91+
/// <param name="buffer">The buffer containing the current pixel-data of the capture zone.</param>
7292
protected abstract void PerformCaptureZoneUpdate(CaptureZone<TColor> captureZone, in Span<byte> buffer);
7393

94+
/// <summary>
95+
/// Raises the <see cref="Updated"/>-event.
96+
/// </summary>
97+
/// <param name="result">A bool indicating whether the update was successful or not.</param>
7498
protected virtual void OnUpdated(bool result)
7599
{
76100
try
@@ -80,7 +104,10 @@ protected virtual void OnUpdated(bool result)
80104
catch { /**/ }
81105
}
82106

107+
/// <inheritdoc />
83108
ICaptureZone IScreenCapture.RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel) => RegisterCaptureZone(x, y, width, height, downscaleLevel);
109+
110+
/// <inheritdoc cref="IScreenCapture.RegisterCaptureZone" />
84111
public virtual CaptureZone<TColor> RegisterCaptureZone(int x, int y, int width, int height, int downscaleLevel = 0)
85112
{
86113
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
@@ -100,6 +127,15 @@ public virtual CaptureZone<TColor> RegisterCaptureZone(int x, int y, int width,
100127
}
101128
}
102129

130+
/// <summary>
131+
/// Validates the given values of a capture zone.
132+
/// </summary>
133+
/// <param name="x">The X-location of the zone.</param>
134+
/// <param name="y">The Y-location of the zone.</param>
135+
/// <param name="width">The width of the zone.</param>
136+
/// <param name="height">The height of the zone.</param>
137+
/// <param name="downscaleLevel">The downscale-level of the zone.</param>
138+
/// <exception cref="ArgumentException">Throws if some of the provided data is not valid.</exception>
103139
protected virtual void ValidateCaptureZoneAndThrow(int x, int y, int width, int height, int downscaleLevel)
104140
{
105141
if (x < 0) throw new ArgumentException("x < 0");
@@ -110,6 +146,13 @@ protected virtual void ValidateCaptureZoneAndThrow(int x, int y, int width, int
110146
if ((y + height) > Display.Height) throw new ArgumentException("y + height > Display height");
111147
}
112148

149+
/// <summary>
150+
/// Calculates the actual size when downscaling is used.
151+
/// </summary>
152+
/// <param name="width">The original width.</param>
153+
/// <param name="height">The original height.</param>
154+
/// <param name="downscaleLevel">The level of downscaling to be used.</param>
155+
/// <returns>A tuple containing the scaled width, the scaled height and the downscale-level used. (This can be smaller then the one provided if the image is not big enough to scale down that often.)</returns>
113156
protected virtual (int width, int height, int downscaleLevel) CalculateScaledSize(int width, int height, int downscaleLevel)
114157
{
115158
if (downscaleLevel > 0)
@@ -131,16 +174,22 @@ protected virtual (int width, int height, int downscaleLevel) CalculateScaledSiz
131174
return (width, height, downscaleLevel);
132175
}
133176

177+
/// <inheritdoc />
134178
bool IScreenCapture.UnregisterCaptureZone(ICaptureZone captureZone) => UnregisterCaptureZone(captureZone as CaptureZone<TColor> ?? throw new ArgumentException("Invalid capture-zone."));
179+
180+
/// <inheritdoc cref="IScreenCapture.UnregisterCaptureZone" />
135181
public virtual bool UnregisterCaptureZone(CaptureZone<TColor> captureZone)
136182
{
137183
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
138184

139185
return CaptureZones.Remove(captureZone);
140186
}
141187

188+
/// <inheritdoc />
142189
void IScreenCapture.UpdateCaptureZone(ICaptureZone captureZone, int? x, int? y, int? width, int? height, int? downscaleLevel)
143190
=> UpdateCaptureZone(captureZone as CaptureZone<TColor> ?? throw new ArgumentException("Invalid capture-zone."), x, y, width, height, downscaleLevel);
191+
192+
/// <inheritdoc cref="IScreenCapture.UpdateCaptureZone" />
144193
public virtual void UpdateCaptureZone(CaptureZone<TColor> captureZone, int? x = null, int? y = null, int? width = null, int? height = null, int? downscaleLevel = null)
145194
{
146195
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
@@ -169,6 +218,7 @@ public virtual void UpdateCaptureZone(CaptureZone<TColor> captureZone, int? x =
169218
}
170219
}
171220

221+
/// <inheritdoc />
172222
public virtual void Restart()
173223
{
174224
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
@@ -190,6 +240,7 @@ public void Dispose()
190240
_isDisposed = true;
191241
}
192242

243+
/// <inheritdoc cref="Dispose" />
193244
protected virtual void Dispose(bool disposing) { }
194245

195246
#endregion

0 commit comments

Comments
 (0)