Defer getting D2D1 factory to when realization fails
このコミットが含まれているのは:
1 親
d0490ed524
コミット
c33877d382
2ファイル変更
+25
-10
検索条件に一致するファイルはありません
@@ -57,4 +57,24 @@ internal static unsafe class ID2D1DeviceContextExtensions
|
||||
|
||||
return dpiX;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="ID2D1Factory1"/> object from a given <see cref="ID2D1DeviceContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="deviceContext">The input <see cref="ID2D1DeviceContext"/> instance.</param>
|
||||
/// <param name="d2D1Factory1">The resulting <see cref="ID2D1Factory1"/> object.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
/// <remarks>
|
||||
/// The <see cref="Interop.D2D1PixelShaderEffect"/> APIs specifically need an <see cref="ID2D1Factory1"/> (as <see cref="ID2D1Factory1.RegisterEffectFromString"/> is used).
|
||||
/// </remarks>
|
||||
public static HRESULT GetFactory1(this ref ID2D1DeviceContext deviceContext, ID2D1Factory1** d2D1Factory1)
|
||||
{
|
||||
using ComPtr<ID2D1Factory> d2D1Factory = default;
|
||||
|
||||
// Get the underlying ID2D1Factory from the input context, which can be used to register effects
|
||||
deviceContext.GetFactory(d2D1Factory.GetAddressOf());
|
||||
|
||||
// QueryInterface for the ID2D1Factory1 object (which should always be present)
|
||||
return d2D1Factory.CopyTo(d2D1Factory1);
|
||||
}
|
||||
}
|
||||
@@ -224,16 +224,6 @@ unsafe partial class PixelShaderEffect<T>
|
||||
/// <returns>Whether the effect was realized correctly.</returns>
|
||||
private bool Realize(WIN2D_GET_D2D_IMAGE_FLAGS flags, float targetDpi, ID2D1DeviceContext* deviceContext)
|
||||
{
|
||||
using ComPtr<ID2D1Factory> d2D1Factory = default;
|
||||
|
||||
// Get the underlying ID2D1Factory from the input context, so we can register and create the effect
|
||||
deviceContext->GetFactory(d2D1Factory.GetAddressOf());
|
||||
|
||||
using ComPtr<ID2D1Factory1> d2D1Factory1 = default;
|
||||
|
||||
// D2D1PixelShaderEffect APIs specifically need an ID2D1Factory1 (as ID2D1Factory1::RegisterEffectFromString is used)
|
||||
d2D1Factory.CopyTo(d2D1Factory1.GetAddressOf()).Assert();
|
||||
|
||||
fixed (ID2D1Effect** d2D1Effect = this.d2D1Effect)
|
||||
{
|
||||
Guid effectId = PixelShaderEffect.For<T>.Instance.Id;
|
||||
@@ -248,6 +238,11 @@ unsafe partial class PixelShaderEffect<T>
|
||||
if (hresult == D2DERR.D2DERR_EFFECT_IS_NOT_REGISTERED ||
|
||||
hresult == E.E_NOTFOUND)
|
||||
{
|
||||
using ComPtr<ID2D1Factory1> d2D1Factory1 = default;
|
||||
|
||||
// Get the ID2D1Factory1 object to register the effect (required by D2D1PixelShaderEffect)
|
||||
deviceContext->GetFactory1(d2D1Factory1.GetAddressOf()).Assert();
|
||||
|
||||
// Register the effect with the factory (pass the same D2D1 draw transform mapper factory that was used before)
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<T>(d2D1Factory1.Get(), out _);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする