Fix a memory leak with the realization ICanvasDevice object

このコミットが含まれているのは:
Sergio Pedri committed 2022-12-22 10:56:03 -08:00
1 親 222737e479
コミット b37e735e06
2ファイル変更
+17 -8

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

+16 -2
ファイルの表示
@@ -8,7 +8,7 @@ namespace ComputeSharp.D2D1.Uwp.Extensions;
/// <summary>
/// Helper methods for working with the <see cref="IUnknown"/> type.
/// </summary>
internal static class IUnknownExtensions
internal static unsafe class IUnknownExtensions
{
/// <summary>
/// Checks whether two <see cref="IUnknown"/> values have the same underlying COM object.
@@ -18,7 +18,7 @@ internal static class IUnknownExtensions
/// <param name="left">The first <see cref="IUnknown"/> object to compare.</param>
/// <param name="right">The second <see cref="IUnknown"/> object to compare.</param>
/// <returns>Whether <paramref name="left"/> and <paramref name="right"/> point to the same COM object.</returns>
public static unsafe bool IsSameInstance<T, U>(this ref T left, U* right)
public static bool IsSameInstance<T, U>(this ref T left, U* right)
where T : unmanaged // IUnknown
where U : unmanaged // IUnknown
{
@@ -40,4 +40,18 @@ internal static class IUnknownExtensions
return leftUnknown.Get() == rightUnknown.Get();
}
/// <summary>
/// Copies the source <see cref="IUnknown"/> object onto a target <see cref="ComPtr{T}"/> destination.
/// </summary>
/// <typeparam name="T">The type of object being copied.</typeparam>
/// <param name="source">The source <see cref="IUnknown"/> object.</param>
/// <param name="destination">The destination <see cref="ComPtr{T}"/> location.</param>
public static void CopyTo<T>(this ref T source, ref ComPtr<T> destination)
where T : unmanaged // IUnknown
{
destination.Dispose();
destination = new ComPtr<T>((T*)Unsafe.AsPointer(ref source));
}
}
+1 -6
ファイルの表示
@@ -12,7 +12,6 @@ using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using Windows.Graphics.Effects;
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS;
using Win32 = TerraFX.Interop.Windows.Windows;
namespace ComputeSharp.D2D1.Uwp;
@@ -117,11 +116,7 @@ unsafe partial class PixelShaderEffect<T>
// Store the input realization device and canvas device for future uses
d2D1Device1.CopyTo(ref this.d2D1RealizationDevice).Assert();
fixed (ICanvasDevice** canvasDevice = this.canvasDevice)
{
device->QueryInterface(Win32.__uuidof<ICanvasDevice>(), (void**)canvasDevice).Assert();
}
device->CopyTo(ref this.canvasDevice);
}
// Create the effect, if it doesn't exist already