diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ComPtrExtensions.cs b/src/ComputeSharp.D2D1.Uwp/Extensions/ComPtrExtensions.cs deleted file mode 100644 index 8e51d066..00000000 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/ComPtrExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -using ComputeSharp.D2D1.Extensions; -using TerraFX.Interop.Windows; - -namespace ComputeSharp.D2D1.Uwp.Extensions; - -/// -/// Helper methods for working with the type. -/// -internal static class ComPtrExtensions -{ - /// - /// Checks whether two values have the same underlying COM object. - /// - /// The type of the first value to check. - /// The type of the second value to check. - /// The first object to compare. - /// The second object to compare. - /// Whether and point to the same COM object. - public static unsafe bool IsSameInstance(this in ComPtr left, in ComPtr right) - where T : unmanaged - where U : unmanaged - { - if (left.Get() == right.Get()) - { - return true; - } - - if (left.Get() is null || right.Get() is null) - { - return false; - } - - using ComPtr leftUnknown = default; - using ComPtr rightUnknown = default; - - left.CopyTo(leftUnknown.GetAddressOf()).Assert(); - right.CopyTo(rightUnknown.GetAddressOf()).Assert(); - - return leftUnknown.Get() == rightUnknown.Get(); - } -} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs b/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs new file mode 100644 index 00000000..75fcb82d --- /dev/null +++ b/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs @@ -0,0 +1,43 @@ +using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Extensions; +using TerraFX.Interop.Windows; +using Win32 = TerraFX.Interop.Windows.Windows; + +namespace ComputeSharp.D2D1.Uwp.Extensions; + +/// +/// Helper methods for working with the type. +/// +internal static class IUnknownExtensions +{ + /// + /// Checks whether two values have the same underlying COM object. + /// + /// The type of the first value to check. + /// The type of the second value to check. + /// The first object to compare. + /// The second object to compare. + /// Whether and point to the same COM object. + public static unsafe bool IsSameInstance(this ref T left, U* right) + where T : unmanaged // IUnknown + where U : unmanaged // IUnknown + { + if (Unsafe.AreSame(ref left, ref *(T*)right)) + { + return true; + } + + if (Unsafe.IsNullRef(ref left) || right is null) + { + return false; + } + + using ComPtr leftUnknown = default; + using ComPtr rightUnknown = default; + + ((IUnknown*)Unsafe.AsPointer(ref left))->QueryInterface(Win32.__uuidof(), (void**)leftUnknown.GetAddressOf()).Assert(); + ((IUnknown*)right)->QueryInterface(Win32.__uuidof(), (void**)rightUnknown.GetAddressOf()).Assert(); + + return leftUnknown.Get() == rightUnknown.Get(); + } +} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs index 210da512..e227672a 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -107,7 +107,7 @@ unsafe partial class PixelShaderEffect // Check that the input D2D device is the same instance as the current realization device, if any. // If not and the effect has already been realized, unrealize it and store the new device to use. - if (!d2D1Device1.IsSameInstance(in this.d2D1RealizationDevice)) + if (!d2D1Device1.Get()->IsSameInstance(this.d2D1RealizationDevice.Get())) { Unrealize();