using System.Runtime.CompilerServices; using TerraFX.Interop.Windows; namespace ComputeSharp.D2D1.Extensions; /// /// Helper methods for working with the type. /// /// Trimmed down version of the same file in ComputeSharp. internal static class ComPtrExtensions { /// /// Gets the address of the current instance as a raw double pointer. /// /// The type to wrap in the current instance. /// The input instance to get the address for. /// The raw pointer to the input instance. /// This method is only valid when the current instance is on the stack or pinned. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe void** GetVoidAddressOf(this in ComPtr ptr) where T : unmanaged { return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr)); } /// /// Moves the current instance and resets it without releasing the reference. /// /// The type to wrap in the current instance. /// The input instance to move. /// The moved instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe ComPtr Move(this in ComPtr ptr) where T : unmanaged { ComPtr copy = default; Unsafe.AsRef(in ptr).Swap(ref copy); return copy; } }