Use ActivationFactory.Get() for ICanvasFactoryNative

このコミットが含まれているのは:
Sergio Pedri committed 2024-06-28 15:36:25 -07:00
1 親 f1fc6a8410
コミット 8c53714c29
2ファイル変更
+32 -30

検索条件に一致するファイルはありません

+26 -26
ファイルの表示
@@ -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;
/// </summary>
[NativeTypeName("class ICanvasFactoryNative : public IInspectable")]
[NativeInheritance("IInspectable")]
internal unsafe struct ICanvasFactoryNative
internal unsafe struct ICanvasFactoryNative : IComObject
{
/// <inheritdoc/>
public static Guid* IID
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ReadOnlySpan<byte> 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;
/// <inheritdoc cref="IUnknown.QueryInterface"/>
@@ -144,25 +165,4 @@ internal unsafe struct ICanvasFactoryNative
(ICanvasFactoryNative*)Unsafe.AsPointer(ref this),
effectId);
}
/// <summary>
/// The managed interface for <see cref="ICanvasFactoryNative"/>.
/// </summary>
[Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")]
[WindowsRuntimeType]
[WindowsRuntimeHelperType(typeof(Interface))]
public interface Interface
{
/// <summary>
/// The vtable type for <see cref="Interface"/>.
/// </summary>
[Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")]
public readonly struct Vftbl
{
/// <summary>
/// Allows CsWinRT to retrieve a pointer to the projection vtable (the name is hardcoded by convention).
/// </summary>
public static readonly IntPtr AbiToProjectionVftablePtr = IUnknownVftbl.AbiToProjectionVftblPtr;
}
}
}
+6 -4
ファイルの表示
@@ -107,12 +107,14 @@ internal static unsafe class ResourceManager
/// <param name="factoryNative">A pointer to the resulting activation factory.</param>
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<I>() 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<ICanvasFactoryNative.Interface>();
using IObjectReference canvasDeviceActivationFactory = ActivationFactory.Get(ActivatableClassId, *ICanvasFactoryNative.IID);
*factoryNative = (ICanvasFactoryNative*)MarshalInterface<ICanvasFactoryNative.Interface>.FromManaged(canvasDeviceActivationFactory);
*factoryNative = (ICanvasFactoryNative*)canvasDeviceActivationFactory.GetRef();
}
}