Refactor ComPtr<T>.IsSameInstance extension
このコミットが含まれているのは:
1 親
e2550a2b54
コミット
d6cd052791
3ファイル変更
+44
-42
検索条件に一致するファイルはありません
@@ -1,41 +0,0 @@
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for working with the <see cref="ComPtr{T}"/> type.
|
||||
/// </summary>
|
||||
internal static class ComPtrExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks whether two <see cref="ComPtr{T}"/> values have the same underlying COM object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the first value to check.</typeparam>
|
||||
/// <typeparam name="U">The type of the second value to check.</typeparam>
|
||||
/// <param name="left">The first <see cref="ComPtr{T}"/> object to compare.</param>
|
||||
/// <param name="right">The second <see cref="ComPtr{T}"/> 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 in ComPtr<T> left, in ComPtr<U> right)
|
||||
where T : unmanaged
|
||||
where U : unmanaged
|
||||
{
|
||||
if (left.Get() == right.Get())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (left.Get() is null || right.Get() is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using ComPtr<IUnknown> leftUnknown = default;
|
||||
using ComPtr<IUnknown> rightUnknown = default;
|
||||
|
||||
left.CopyTo(leftUnknown.GetAddressOf()).Assert();
|
||||
right.CopyTo(rightUnknown.GetAddressOf()).Assert();
|
||||
|
||||
return leftUnknown.Get() == rightUnknown.Get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Win32 = TerraFX.Interop.Windows.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for working with the <see cref="IUnknown"/> type.
|
||||
/// </summary>
|
||||
internal static class IUnknownExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks whether two <see cref="IUnknown"/> values have the same underlying COM object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the first value to check.</typeparam>
|
||||
/// <typeparam name="U">The type of the second value to check.</typeparam>
|
||||
/// <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)
|
||||
where T : unmanaged // IUnknown
|
||||
where U : unmanaged // IUnknown
|
||||
{
|
||||
if (Unsafe.AreSame(ref left, ref *(T*)right))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Unsafe.IsNullRef(ref left) || right is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using ComPtr<IUnknown> leftUnknown = default;
|
||||
using ComPtr<IUnknown> rightUnknown = default;
|
||||
|
||||
((IUnknown*)Unsafe.AsPointer(ref left))->QueryInterface(Win32.__uuidof<T>(), (void**)leftUnknown.GetAddressOf()).Assert();
|
||||
((IUnknown*)right)->QueryInterface(Win32.__uuidof<T>(), (void**)rightUnknown.GetAddressOf()).Assert();
|
||||
|
||||
return leftUnknown.Get() == rightUnknown.Get();
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
|
||||
// Check that the input D2D device is the same instance as the current realization device, if any.
|
||||
// If not and the effect has already been realized, unrealize it and store the new device to use.
|
||||
if (!d2D1Device1.IsSameInstance(in this.d2D1RealizationDevice))
|
||||
if (!d2D1Device1.Get()->IsSameInstance(this.d2D1RealizationDevice.Get()))
|
||||
{
|
||||
Unrealize();
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする