diff --git a/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs index d4d6d476..c44ccee0 100644 --- a/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs +++ b/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs @@ -71,7 +71,7 @@ internal static unsafe class ICanvasDeviceExtensions else { // Otherwise, just use the input device context - ComPtr.WriteTo(d2D1DeviceContext, out *d2D1DeviceContextEffective); + *d2D1DeviceContextEffective = new ComPtr(d2D1DeviceContext).Get(); } } } \ No newline at end of file diff --git a/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs b/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs index 58d6a1be..319b21e0 100644 --- a/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs +++ b/src/ComputeSharp.Win32.D3D12/ComPtr`1.cs @@ -13,74 +13,6 @@ using static ComputeSharp.Win32.S; namespace ComputeSharp.Win32; -/// -/// Extensions for to operate on raw pointers as well. -/// -internal static unsafe class ComPtr -{ - /// - /// Disposes a target COM object, if it's not . - /// - /// The type of COM objects to work with. - /// The COM object to potentially release. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dispose(T* other) - where T : unmanaged - { - if (other is not null) - { - _ = ((IUnknown*)other)->Release(); - } - } - - /// - /// Copies a given COM object into a target destination, incrementing reference counts where needed. - /// - /// The type of COM objects to work with. - /// The input COM object to copy. - /// The target destination for the COM object. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void CopyTo(T* obj, ref T* other) - where T : unmanaged - { - // We specifically need to increment the reference count on the source object before releasing the - // target object, to avoid issues in case source and destination were pointers to the same object - // (which can be the case even if the two pointers are not identical). To double check, a full check - // through an IUnknown* cast would be needed, but to avoid the extra QueryInterface call on both objects, - // we can just always do one AddRef call which avoids issues in all cases as well. The situation we need - // to avoid is that without a temporary copy, releasing the target object might actually destroy the - // object, causing the following AddRef call to AV. - if (obj is not null) - { - _ = ((IUnknown*)obj)->AddRef(); - } - - T* pointer = other; - - if (pointer is not null) - { - _ = ((IUnknown*)pointer)->Release(); - } - - other = obj; - } - - /// - /// Writes a given COM object into a target (assumed uninitialized) destination, incrementing reference counts where needed. - /// - /// The type of COM objects to work with. - /// The input COM object to copy. - /// The target destination for the COM object. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void WriteTo(T* obj, out T* other) - where T : unmanaged - { - _ = ((IUnknown*)obj)->AddRef(); - - other = obj; - } -} - /// A type that allows working with pointers to COM objects more securely. /// The type to wrap in the current instance. /// While this type is not marked as so that it can also be used in fields, make sure to keep the reference counts properly tracked if you do store instances on the heap.