using System; using ComputeSharp.Interop; using System.Runtime.CompilerServices; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Helpers; #else using ComputeSharp.D2D1.WinUI.Helpers; #endif using ComputeSharp.Win32; #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; #else namespace ComputeSharp.D2D1.WinUI; #endif /// partial class PixelShaderEffect { /// /// Releases unmanaged resources and performs other cleanup operations. /// ~PixelShaderEffect() { this.referenceTracker.Dispose(); } /// public void Dispose() { this.referenceTracker.Dispose(); GC.SuppressFinalize(this); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] internal ref ReferenceTracker GetReferenceTracker() { return ref this.referenceTracker; } /// ref ReferenceTracker IReferenceTrackedObject.GetReferenceTracker() { return ref this.referenceTracker; } /// unsafe void IReferenceTrackedObject.DangerousOnDispose() { // When the effect is disposed, we also unregister it from the resource manager cache. This // is analogous to what is done when manually unrealizing the effect (eg. when using a new // device). Without this call, the resource manager would keep registered effects alive for // the entire process duration, even if their original wrappers are gone (ie. collected). if (this.d2D1Effect.Get() is not null) { ResourceManager.UnregisterWrapper((IUnknown*)this.d2D1Effect.Get()); } // Release the native D2D objects that were set during realization this.canvasDevice.Dispose(); this.d2D1RealizationDevice.Dispose(); this.d2D1Effect.Dispose(); // Also release all native resources for the used sources. The transform mapper and // resource texture managers don't need to be disposed, as those could be shared // between effects. Note that SourceReference.Dispose() will only release the native // resources (ie. D2D images and effects), but it will not also dispose the managed // wrappers (ie. IGraphicsEffectSource objects), as those can be shared as well. for (int i = 0; i < Sources.Count; i++) { Sources.Storage[i].Dispose(); } } }