diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs index 94857be8..5be9f5a0 100644 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs +++ b/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs @@ -37,22 +37,22 @@ internal static unsafe class ICanvasDeviceExtensions } /// - /// Creates a new from an input . + /// Gets a new from an input . /// /// The input object. - /// The resulting object. + /// The resulting object. /// The for the operation. - public static HRESULT CreateD2DDeviceContext(this ref ICanvasDevice canvasDevice, ID2D1DeviceContext** d2D1DeviceContext) + public static HRESULT GetD2DDeviceContextLease(this ref ICanvasDevice canvasDevice, ID2D1DeviceContextLease** d2D1DeviceContextLease) { - using ComPtr d2D1Device1 = default; + using ComPtr d2D1DeviceContextPool = default; - // Get the underlying ID2D1Device1 object - canvasDevice.GetD2DDevice(d2D1Device1.GetAddressOf()).Assert(); + // Get the ID2D1DeviceContextLease interface reference + canvasDevice.QueryInterface( + riid: Win32.__uuidof(), + ppvObject: d2D1DeviceContextPool.GetVoidAddressOf()).Assert(); - // Create the new device context - HRESULT hresult = d2D1Device1.Get()->CreateDeviceContext( - options: D2D1_DEVICE_CONTEXT_OPTIONS.D2D1_DEVICE_CONTEXT_OPTIONS_NONE, - deviceContext: d2D1DeviceContext); + // Create the new lease + HRESULT hresult = d2D1DeviceContextPool.Get()->GetDeviceContextLease(d2D1DeviceContextLease); return hresult; } diff --git a/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs index 77dd939a..bd37235c 100644 --- a/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs @@ -19,7 +19,7 @@ internal static class ResourceManager /// /// Gets or creates an instance for a native resource. /// - /// The input canvas device (as a marshalled ). + /// The input canvas device (as a marshalled ). /// The input native resource to create a wrapper for. /// The realization DPIs for /// The resulting wrapper instance. diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs index 2f524503..3e06cb86 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs @@ -299,13 +299,18 @@ unsafe partial class PixelShaderEffect // Create an ID2D1Effect for the DPI compensation, if there isn't one already if (!sourceReference.HasDpiCompensationEffect) { + using ComPtr d2D1DeviceContextLease = default; using ComPtr d2D1DeviceContextEffective = default; // We need to create a DPI compensation effect, so a device context must be available. // If there is no input device context, just create a new one from the realization device. if (d2D1DeviceContext is null) { - this.canvasDevice.Get()->CreateD2DDeviceContext(d2D1DeviceContextEffective.GetAddressOf()).Assert(); + // Get the ID2D1DeviceContextLease interface from the input device + this.canvasDevice.Get()->GetD2DDeviceContextLease(d2D1DeviceContextLease.GetAddressOf()).Assert(); + + // Rent a new device context from the lease (this is much faster than creating a new device context) + d2D1DeviceContextLease.Get()->GetD2DDeviceContext(d2D1DeviceContextEffective.GetAddressOf()).Assert(); } else { diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_DEVICE_CONTEXT_OPTIONS.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_DEVICE_CONTEXT_OPTIONS.cs deleted file mode 100644 index bd22e599..00000000 --- a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/D2D1_DEVICE_CONTEXT_OPTIONS.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/d2d1_1.h in the Windows SDK for Windows 10.0.22621.0 -// Original source is Copyright © Microsoft. All rights reserved. - -using System; - -namespace TerraFX.Interop.DirectX; - -[Flags] -internal enum D2D1_DEVICE_CONTEXT_OPTIONS : uint -{ - D2D1_DEVICE_CONTEXT_OPTIONS_NONE = 0, - D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS = 1, - D2D1_DEVICE_CONTEXT_OPTIONS_FORCE_DWORD = 0xffffffff, -} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_2/ID2D1Device1.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_2/ID2D1Device1.cs index 1a374296..193e8b8c 100644 --- a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_2/ID2D1Device1.cs +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_2/ID2D1Device1.cs @@ -49,11 +49,4 @@ internal unsafe partial struct ID2D1Device1 { ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((ID2D1Device1*)Unsafe.AsPointer(ref this), factory); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [VtblIndex(4)] - public HRESULT CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext** deviceContext) - { - return ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((ID2D1Device1*)Unsafe.AsPointer(ref this), options, deviceContext); - } } \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems index 51cb9906..cfa82c7b 100644 --- a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems +++ b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems @@ -35,7 +35,6 @@ -