Switch Win2D bindings to ICanvasImageInterop
このコミットが含まれているのは:
1 親
6143ceebd5
コミット
2362b32df0
3ファイル変更
+63
-49
検索条件に一致するファイルはありません
+3
-8
@@ -3,10 +3,10 @@ using System;
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Options for fine-tuning the behavior of ICanvasImageInternal::GetD2DImage.
|
||||
/// Options for fine-tuning the behavior of <see cref="ICanvasImageInterop.GetD2DImage"/>.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
internal enum GetImageFlags
|
||||
internal enum CanvasImageGetD2DImageFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// No options specified.
|
||||
@@ -36,10 +36,5 @@ internal enum GetImageFlags
|
||||
/// <summary>
|
||||
/// Allow partially configured effect graphs where some inputs are <see langword="null"/>.
|
||||
/// </summary>
|
||||
AllowNullEffectInputs = 16,
|
||||
|
||||
/// <summary>
|
||||
/// If an input is invalid, unrealize the effect and return <see langword="null"/> rather than throwing.
|
||||
/// </summary>
|
||||
UnrealizeOnFailure = 32
|
||||
AllowNullEffectInputs = 16
|
||||
}
|
||||
+24
-14
@@ -7,21 +7,29 @@ using TerraFX.Interop;
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Internal Win2D interface for all images and effects that can be drawn.
|
||||
/// An interop Win2D interface for all images and effects that can be drawn.
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[Guid("2F434224-053C-4978-87C4-CFAAFA2F4FAC")]
|
||||
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal unsafe interface ICanvasImageInternal
|
||||
internal unsafe interface ICanvasImageInterop
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="ID2D1Image"/> from an <see cref="ICanvasImageInternal"/> instance.
|
||||
/// Gets the device that the effect is currently realized on, if any.
|
||||
/// </summary>
|
||||
/// <param name="retBuf">A pointer to the return buffer to write the result into (needed for ABI matching).</param>
|
||||
/// <param name="device">The input canvas device (as pointer to internal interface).</param>
|
||||
/// <param name="device">The resulting device, if available ((as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>)).</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
[PreserveSig]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
int GetDevice([NativeTypeName("ICanvasDevice**")] IUnknown** device);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="ID2D1Image"/> from an <see cref="ICanvasImageInterop"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="device">The input canvas device (as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
|
||||
/// <param name="deviceContext">
|
||||
/// The device context in use. This value is is optional (but recommended), except when the
|
||||
/// <see cref="GetImageFlags.ReadDpiFromDeviceContext"/> flag is specified. This is because
|
||||
/// <see cref="CanvasImageGetD2DImageFlags.ReadDpiFromDeviceContext"/> flag is specified. This is because
|
||||
/// not all callers of <see cref="GetD2DImage"/> have easy access to a context. It is always
|
||||
/// possible to get a resource creation context from the device, but the context is only
|
||||
/// actually necessary if a new effect realization needs to be created, so it is more efficient
|
||||
@@ -31,20 +39,22 @@ internal unsafe interface ICanvasImageInternal
|
||||
/// <param name="targetDpi">
|
||||
/// The DPI of the target device context. This is used to determine when a <c>D2D1DpiCompensation</c>
|
||||
/// effect needs to be inserted. Behavior of this parameter can be overridden by the flag values
|
||||
/// <see cref="GetImageFlags.ReadDpiFromDeviceContext"/>, <see cref="GetImageFlags.AlwaysInsertDpiCompensation"/>
|
||||
/// or <see cref="GetImageFlags.NeverInsertDpiCompensation"/>
|
||||
/// <see cref="CanvasImageGetD2DImageFlags.ReadDpiFromDeviceContext"/>, <see cref="CanvasImageGetD2DImageFlags.AlwaysInsertDpiCompensation"/>
|
||||
/// or <see cref="CanvasImageGetD2DImageFlags.NeverInsertDpiCompensation"/>
|
||||
/// </param>
|
||||
/// <param name="realizeDpi">
|
||||
/// The DPI of a source bitmap, or zero if the image does not have a fixed DPI. A <c>D2D1DpiCompensation</c> effect
|
||||
/// will be inserted if <paramref name="targetDpi"/> and <paramref name="realizeDpi"/> are different (flags permitting).
|
||||
/// </param>
|
||||
/// <returns>A pointer to the resulting image (this value is the same as <paramref name="retBuf"/>).</returns>
|
||||
/// <param name="ppImage">The resulting <see cref="ID2D1Image"/> for the effect.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
[PreserveSig]
|
||||
ID2D1Image** GetD2DImage(
|
||||
ID2D1Image** retBuf,
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
int GetD2DImage(
|
||||
[NativeTypeName("ICanvasDevice*")] IUnknown* device,
|
||||
ID2D1DeviceContext* deviceContext,
|
||||
GetImageFlags flags,
|
||||
CanvasImageGetD2DImageFlags flags,
|
||||
float targetDpi,
|
||||
float* realizeDpi);
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace ComputeSharp.D2D1.Uwp;
|
||||
/// A custom <see cref="ICanvasImage"/> implementation powered by a supplied shader type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
|
||||
public sealed class PixelShaderEffect<T> : ICanvasImage, ICanvasImageInternal
|
||||
public sealed class PixelShaderEffect<T> : ICanvasImage, ICanvasImageInterop
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <summary>
|
||||
@@ -42,52 +42,61 @@ public sealed class PixelShaderEffect<T> : ICanvasImage, ICanvasImageInternal
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe ID2D1Image** ICanvasImageInternal.GetD2DImage(
|
||||
ID2D1Image** retBuf,
|
||||
unsafe int ICanvasImageInterop.GetDevice(IUnknown** device)
|
||||
{
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe int ICanvasImageInterop.GetD2DImage(
|
||||
IUnknown* device,
|
||||
ID2D1DeviceContext* deviceContext,
|
||||
GetImageFlags flags,
|
||||
CanvasImageGetD2DImageFlags flags,
|
||||
float targetDpi,
|
||||
float* realizeDpi)
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage)
|
||||
{
|
||||
if (realizeDpi is not null)
|
||||
{
|
||||
*realizeDpi = targetDpi;
|
||||
*realizeDpi = 0;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1Image> d2D1Image = default;
|
||||
|
||||
if (this.effect.Get() is null)
|
||||
try
|
||||
{
|
||||
using ComPtr<ID2D1Factory> d2D1Factory = default;
|
||||
if (this.effect.Get() is null)
|
||||
{
|
||||
using ComPtr<ID2D1Factory> d2D1Factory = default;
|
||||
|
||||
deviceContext->GetFactory(d2D1Factory.GetAddressOf());
|
||||
deviceContext->GetFactory(d2D1Factory.GetAddressOf());
|
||||
|
||||
using ComPtr<ID2D1Factory1> d2D1Factory1 = default;
|
||||
using ComPtr<ID2D1Factory1> d2D1Factory1 = default;
|
||||
|
||||
d2D1Factory.CopyTo(d2D1Factory1.GetAddressOf()).Assert();
|
||||
d2D1Factory.CopyTo(d2D1Factory1.GetAddressOf()).Assert();
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<T>(d2D1Factory1.Get(), out _);
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<T>(d2D1Factory1.Get(), out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<T>(deviceContext, (void**)d2D1Effect.GetAddressOf());
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<T>(deviceContext, (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in this.Value, d2D1Effect.Get());
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in this.Value, d2D1Effect.Get());
|
||||
|
||||
this.effect = new(d2D1Effect.Get());
|
||||
this.effect = new(d2D1Effect.Get());
|
||||
|
||||
d2D1Effect.CopyTo(d2D1Image.GetAddressOf()).Assert();
|
||||
d2D1Effect.CopyTo(ppImage).Assert();
|
||||
}
|
||||
else
|
||||
{
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in this.Value, this.effect.Get());
|
||||
|
||||
this.effect.CopyTo(ppImage).Assert();
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in this.Value, this.effect.Get());
|
||||
|
||||
this.effect.CopyTo(d2D1Image.GetAddressOf()).Assert();
|
||||
return e.HResult;
|
||||
}
|
||||
|
||||
*retBuf = d2D1Image.Detach();
|
||||
|
||||
return retBuf;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする