From aa1069310e180d8fa8cb41795ba605b79f7db416 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 24 Nov 2021 20:57:41 +0100 Subject: [PATCH] Changed default duplication to old dxgi1_2 headers to prevent problems with capturing in WPF-threads and remove the need to set the dpiawareness --- ScreenCapture.NET/DirectX/DX11ScreenCapture.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ScreenCapture.NET/DirectX/DX11ScreenCapture.cs b/ScreenCapture.NET/DirectX/DX11ScreenCapture.cs index dd54a7e..d0434b8 100644 --- a/ScreenCapture.NET/DirectX/DX11ScreenCapture.cs +++ b/ScreenCapture.NET/DirectX/DX11ScreenCapture.cs @@ -38,6 +38,7 @@ namespace ScreenCapture.NET private readonly object _captureLock = new(); + private readonly bool _useNewDuplicationAdapter; private int _indexCounter = 0; /// @@ -74,12 +75,17 @@ namespace ScreenCapture.NET /// /// Initializes a new instance of the class. /// + /// + /// Note that setting useNewDuplicationAdapter to true requires to call DPIAwareness.Initalize(); and prevents the capture from running in a WPF-thread. + /// /// The used to create underlying objects. /// The to duplicate. - public DX11ScreenCapture(IDXGIFactory1 factory, Display display) + /// Indicates if the DuplicateOutput1 interface should be used instead of the older DuplicateOutput. Currently there's no real use in setting this to true. + public DX11ScreenCapture(IDXGIFactory1 factory, Display display, bool useNewDuplicationAdapter = false) { this._factory = factory; this.Display = display; + this._useNewDuplicationAdapter = useNewDuplicationAdapter; Restart(); } @@ -325,8 +331,11 @@ namespace ScreenCapture.NET foreach (CaptureZone captureZone in captureZones) InitializeCaptureZone(captureZone); } - - _duplicatedOutput = output.DuplicateOutput1(_device, Format.B8G8R8A8_UNorm); // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth + + if (_useNewDuplicationAdapter) + _duplicatedOutput = output.DuplicateOutput1(_device, Format.B8G8R8A8_UNorm); // DarthAffe 27.02.2021: This prepares for the use of 10bit color depth + else + _duplicatedOutput = output.DuplicateOutput(_device); } catch { Dispose(false); } }