More code refactoring and style tweaks

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-07 20:28:19 +02:00
1 親 2022a73754
コミット cfbfc2886b
4ファイル変更
+37 -17

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

@@ -310,13 +310,8 @@ partial struct PixelShaderEffect
try
{
// Free the previous ID2D1DrawInfo object, if present
ComPtr<ID2D1DrawInfo>.Release(@this->d2D1DrawInfo);
// Store the new ID2D1DrawInfo object
_ = drawInfo->AddRef();
@this->d2D1DrawInfo = drawInfo;
ComPtr<ID2D1DrawInfo>.CopyTo(drawInfo, ref @this->d2D1DrawInfo);
Guid shaderId = @this->GetGlobals().EffectId;
D2D1PixelOptions pixelOptions = @this->GetGlobals().PixelOptions;
@@ -114,13 +114,8 @@ internal unsafe partial struct PixelShaderEffect
// If loading the bytecode succeeded, set the transform node
transformGraph->SetSingleTransformNode((ID2D1TransformNode*)&@this->lpVtblForID2D1DrawTransform).Assert();
// Free the previous ID2D1EffectContext object, if present
ComPtr<ID2D1EffectContext>.Release(@this->d2D1EffectContext);
// Store the new ID2D1EffectContext object
_ = effectContext->AddRef();
@this->d2D1EffectContext = effectContext;
ComPtr<ID2D1EffectContext>.CopyTo(effectContext, ref @this->d2D1EffectContext);
return S.S_OK;
}
@@ -124,9 +124,8 @@ partial struct D2D1ResourceTextureManagerImpl
// Now, the effect context can actually be stored safely while holding the lock.
// This is guaranteed to be the case here, as this method is only called (as per
// contact of the COM interface) from ID2D1EffectImpl, which holds the D2D lock.
_ = effectContext->AddRef();
ComPtr<ID2D1EffectContext>.WriteTo(effectContext, out @this->d2D1EffectContext);
@this->d2D1EffectContext = effectContext;
@this->d2D1Multithread = d2D1Multithread.Detach();
}
@@ -162,9 +161,7 @@ partial struct D2D1ResourceTextureManagerImpl
// If the texture has already been created, just return it
if (@this->d2D1ResourceTexture is not null)
{
_ = @this->d2D1ResourceTexture->AddRef();
*resourceTexture = @this->d2D1ResourceTexture;
ComPtr<ID2D1ResourceTexture>.WriteTo(@this->d2D1ResourceTexture, out *resourceTexture);
return S.S_OK;
}
+33
ファイルの表示
@@ -51,6 +51,39 @@ internal unsafe struct ComPtr<T> : IDisposable
}
}
/// <summary>
/// Copies a given COM object into a target destination.
/// </summary>
/// <param name="obj">The input COM object to copy.</param>
/// <param name="other">The target destination for the COM object.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CopyTo(T* obj, ref T* other)
{
T* pointer = other;
if (pointer is not null)
{
_ = ((IUnknown*)pointer)->Release();
}
_ = ((IUnknown*)obj)->AddRef();
other = obj;
}
/// <summary>
/// Writes a given COM object into a target (assumed uninitialized) destination.
/// </summary>
/// <param name="obj">The input COM object to copy.</param>
/// <param name="other">The target destination for the COM object.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteTo(T* obj, out T* other)
{
_ = ((IUnknown*)obj)->AddRef();
other = obj;
}
/// <summary>Converts a raw pointer to a new <see cref="ComPtr{T}"/> instance and increments the ref count.</summary>
/// <param name="other">The raw pointer to wrap.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]