diff --git a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs index 1f60788a..853052f2 100644 --- a/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs +++ b/src/ComputeSharp.D2D1.WinUI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs @@ -2,11 +2,8 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.Win32; -using WinRT; -using WinRT.Interop; -using IInspectable = ComputeSharp.Win32.IInspectable; -#pragma warning disable CS0649, IDE1006 +#pragma warning disable CS0649, IDE0055, IDE1006 namespace ABI.Microsoft.Graphics.Canvas; @@ -15,8 +12,32 @@ namespace ABI.Microsoft.Graphics.Canvas; /// [NativeTypeName("class ICanvasFactoryNative : public IInspectable")] [NativeInheritance("IInspectable")] -internal unsafe struct ICanvasFactoryNative +internal unsafe struct ICanvasFactoryNative : IComObject { + /// + public static Guid* IID + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ReadOnlySpan data = + [ + 0x0D, 0x44, 0x5C, 0x69, + 0xB3, 0x04, + 0xDD, 0x4E, + 0xBF, 0xD9, + 0x63, + 0xE5, + 0x1E, + 0x9F, + 0x72, + 0x02 + ]; + + return (Guid*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)); + } + } + public void** lpVtbl; /// @@ -144,25 +165,4 @@ internal unsafe struct ICanvasFactoryNative (ICanvasFactoryNative*)Unsafe.AsPointer(ref this), effectId); } - - /// - /// The managed interface for . - /// - [Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")] - [WindowsRuntimeType] - [WindowsRuntimeHelperType(typeof(Interface))] - public interface Interface - { - /// - /// The vtable type for . - /// - [Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")] - public readonly struct Vftbl - { - /// - /// Allows CsWinRT to retrieve a pointer to the projection vtable (the name is hardcoded by convention). - /// - public static readonly IntPtr AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftblPtr; - } - } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs index d2701fac..8b7a0846 100644 --- a/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.WinUI/Helpers/ResourceManager.cs @@ -107,12 +107,14 @@ internal static unsafe class ResourceManager /// A pointer to the resulting activation factory. private static void GetActivationFactory(ICanvasFactoryNative** factoryNative) { - // On WinUI 3, the types are not guaranteed to be registered for activation. Additionally, - // for concistency with other types, we just use the built-in T.As() method, which will + const string ActivatableClassId = "Microsoft.Graphics.Canvas.CanvasDevice"; + + // On WinUI 3, the types are not guaranteed to be registered for activation. Additionally, for + // concistency with other types, we just use the built-in ActivationFactory type, which will // automatically handle fallback logic to resolve types to activate if they're not registered. // For instance, this will ensure the following call will work fine in unpackaged apps. - ICanvasFactoryNative.Interface canvasDeviceActivationFactory = CanvasDevice.As(); + using IObjectReference canvasDeviceActivationFactory = ActivationFactory.Get(ActivatableClassId, *ICanvasFactoryNative.IID); - *factoryNative = (ICanvasFactoryNative*)MarshalInterface.FromManaged(canvasDeviceActivationFactory); + *factoryNative = (ICanvasFactoryNative*)canvasDeviceActivationFactory.GetRef(); } } \ No newline at end of file