Skip to content

Commit aa10693

Browse files
committed
Changed default duplication to old dxgi1_2 headers to prevent problems with capturing in WPF-threads and remove the need to set the dpiawareness
1 parent 9be201c commit aa10693

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ScreenCapture.NET/DirectX/DX11ScreenCapture.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public sealed class DX11ScreenCapture : IScreenCapture
3838

3939
private readonly object _captureLock = new();
4040

41+
private readonly bool _useNewDuplicationAdapter;
4142
private int _indexCounter = 0;
4243

4344
/// <inheritdoc />
@@ -74,12 +75,17 @@ public sealed class DX11ScreenCapture : IScreenCapture
7475
/// <summary>
7576
/// Initializes a new instance of the <see cref="DX11ScreenCapture"/> class.
7677
/// </summary>
78+
/// <remarks>
79+
/// Note that setting useNewDuplicationAdapter to true requires to call <c>DPIAwareness.Initalize();</c> and prevents the capture from running in a WPF-thread.
80+
/// </remarks>
7781
/// <param name="factory">The <see cref="IDXGIFactory1"/> used to create underlying objects.</param>
7882
/// <param name="display">The <see cref="Display"/> to duplicate.</param>
79-
public DX11ScreenCapture(IDXGIFactory1 factory, Display display)
83+
/// <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>
84+
public DX11ScreenCapture(IDXGIFactory1 factory, Display display, bool useNewDuplicationAdapter = false)
8085
{
8186
this._factory = factory;
8287
this.Display = display;
88+
this._useNewDuplicationAdapter = useNewDuplicationAdapter;
8389

8490
Restart();
8591
}
@@ -325,8 +331,11 @@ public void Restart()
325331
foreach (CaptureZone captureZone in captureZones)
326332
InitializeCaptureZone(captureZone);
327333
}
328-
329-
_duplicatedOutput = output.DuplicateOutput1(_device, Format.B8G8R8A8_UNorm); // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth
334+
335+
if (_useNewDuplicationAdapter)
336+
_duplicatedOutput = output.DuplicateOutput1(_device, Format.B8G8R8A8_UNorm); // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth
337+
else
338+
_duplicatedOutput = output.DuplicateOutput(_device);
330339
}
331340
catch { Dispose(false); }
332341
}

0 commit comments

Comments
 (0)