diff --git a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs
index 0a671c36..f1990f56 100644
--- a/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs
+++ b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs
@@ -90,6 +90,25 @@ internal static unsafe class ResourceManager
canvasFactoryNative.Get()->UnregisterWrapper(resource).Assert();
}
+ ///
+ /// Registers a factory of wrappers for custom effect with a given effect id.
+ ///
+ /// The id of the effects to register a factory for.
+ /// The input factory to create wrappers of native effects.
+ public static void RegisterEffectFactory(Guid effectId, ICanvasEffectFactoryNative.Interface factory)
+ {
+ using ComPtr canvasFactoryNative = default;
+
+ GetActivationFactory(canvasFactoryNative.GetAddressOf());
+
+ using ComPtr canvasEffectFactoryNative = default;
+
+ RcwMarshaller.GetNativeInterface(factory, canvasEffectFactoryNative.GetAddressOf()).Assert();
+
+ // Register the factory for the current effect from the activation factory
+ canvasFactoryNative.Get()->RegisterEffectFactory(&effectId, canvasEffectFactoryNative.Get()).Assert();
+ }
+
///
/// Gets the activation factory.
///
diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.EffectFactoryManager.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.EffectFactoryManager.cs
index ac335191..73d2d2ba 100644
--- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.EffectFactoryManager.cs
+++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.EffectFactoryManager.cs
@@ -1,6 +1,7 @@
using System;
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Extensions;
+using ComputeSharp.D2D1.Interop.Effects;
#if WINDOWS_UWP
using ComputeSharp.D2D1.Uwp.Extensions;
using ComputeSharp.D2D1.Uwp.Helpers;
@@ -48,13 +49,16 @@ unsafe partial class PixelShaderEffect
///
public static EffectFactoryManager Instance { get; } = new();
+ ///
+ /// Ensures an effect factory is registered in Win2D for the current effect type, or registers one otherwise.
+ ///
public void EnsureEffectFactoryIsRegistered()
{
lock (this.lockObject)
{
if (!this.isEffectFactoryRegistered)
{
- // TODO
+ ResourceManager.RegisterEffectFactory(PixelShaderEffect.For.Instance.Id, this);
this.isEffectFactoryRegistered = true;
}