Merge pull request #467 from Sergio0694/dev/get-device-extension
Add new WIN2D_GET_DEVICE_ASSOCIATION_TYPE support for ICanvasImageInterop
このコミットが含まれているのは:
7ファイル変更
+96
-23
検索条件に一致するファイルはありません
@@ -22,13 +22,14 @@ internal unsafe struct ICanvasImageInterop
|
||||
/// <summary>
|
||||
/// Gets the device that the effect is currently realized on, if any.
|
||||
/// </summary>
|
||||
/// <param name="device">The resulting device, if available ((as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>)).</param>
|
||||
/// <param name="device">The resulting device, if available (as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
|
||||
/// <param name="type">The <see cref="WIN2D_GET_DEVICE_ASSOCIATION_TYPE"/> value describing the returned instance.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT GetDevice(ICanvasDevice** device)
|
||||
public HRESULT GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasImageInterop*, ICanvasDevice**, int>)this.lpVtbl[3])((ICanvasImageInterop*)Unsafe.AsPointer(ref this), device);
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasImageInterop*, ICanvasDevice**, WIN2D_GET_DEVICE_ASSOCIATION_TYPE*, int>)this.lpVtbl[3])((ICanvasImageInterop*)Unsafe.AsPointer(ref this), device, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,7 +89,7 @@ internal unsafe struct ICanvasImageInterop
|
||||
/// <inheritdoc cref="ICanvasImageInterop.GetDevice"/>
|
||||
[PreserveSig]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
int GetDevice(ICanvasDevice** device);
|
||||
int GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type);
|
||||
|
||||
/// <inheritdoc cref="ICanvasImageInterop.GetD2DImage"/>
|
||||
[PreserveSig]
|
||||
|
||||
@@ -46,5 +46,5 @@ internal enum WIN2D_GET_D2D_IMAGE_FLAGS : uint
|
||||
/// <summary>
|
||||
/// Ignored.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_FORCE_DWORD = 0xffffffff
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_FORCE_DWORD = 0xFFFFFFFF
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Options for fine-tuning the behavior of <see cref="ICanvasImageInterop.Interface.GetDevice"/>.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
internal enum WIN2D_GET_DEVICE_ASSOCIATION_TYPE : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// No device info is available, callers will handle the returned device with their own logic.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_UNSPECIFIED = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The returned device is the one the image is currently realized on, if any.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_REALIZATION_DEVICE = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The returned device is the one that created the image resource, and cannot change.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_CREATION_DEVICE = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Ignored.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_FORCE_DWORD = 0xFFFFFFFF
|
||||
}
|
||||
@@ -41,13 +41,13 @@ unsafe partial class CanvasEffect
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device)
|
||||
unsafe int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasImageInterop(canvasImageInterop.GetAddressOf());
|
||||
|
||||
return canvasImageInterop.Get()->GetDevice(device);
|
||||
return canvasImageInterop.Get()->GetDevice(device, type);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Win2D.uwp" Version="1.27.0-preview1" />
|
||||
<PackageReference Include="Win2D.uwp" Version="1.27.0-preview2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -12,6 +12,8 @@ using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Graphics.Effects;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_DEVICE_ASSOCIATION_TYPE;
|
||||
using Win32 = TerraFX.Interop.Windows.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
@@ -19,8 +21,18 @@ namespace ComputeSharp.D2D1.Uwp;
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device)
|
||||
int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
// Validate all input parameters
|
||||
if (device is null || type is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// Set parameters to default values
|
||||
*device = null;
|
||||
*type = WIN2D_GET_DEVICE_ASSOCIATION_TYPE_UNSPECIFIED;
|
||||
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().TryGetLease(out bool leaseTaken);
|
||||
|
||||
// Check for disposal
|
||||
@@ -40,15 +52,25 @@ unsafe partial class PixelShaderEffect<T>
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
HRESULT hresult;
|
||||
|
||||
try
|
||||
{
|
||||
// Copy the device over to the target
|
||||
return this.canvasDevice.CopyTo(device);
|
||||
hresult = this.canvasDevice.CopyTo(device);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(this.lockObject);
|
||||
}
|
||||
|
||||
// Set the association type if the copy was successful
|
||||
if (Win32.SUCCEEDED(hresult))
|
||||
{
|
||||
*type = WIN2D_GET_DEVICE_ASSOCIATION_TYPE_REALIZATION_DEVICE;
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -60,6 +82,15 @@ unsafe partial class PixelShaderEffect<T>
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage)
|
||||
{
|
||||
// The device and resulting image pointers cannot be null
|
||||
if (device is null || ppImage is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// Set the resulting image to null
|
||||
*ppImage = null;
|
||||
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().TryGetLease(out bool leaseTaken);
|
||||
|
||||
// Check for disposal
|
||||
@@ -124,8 +155,6 @@ unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
if (!Realize(flags, targetDpi, deviceContext))
|
||||
{
|
||||
*ppImage = null;
|
||||
|
||||
return E.E_FAIL;
|
||||
}
|
||||
}
|
||||
@@ -146,12 +175,6 @@ unsafe partial class PixelShaderEffect<T>
|
||||
return S.S_OK;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
*ppImage = null;
|
||||
|
||||
return e.HResult;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Ensure that reset this flag so that this method can be called again
|
||||
|
||||
@@ -11,6 +11,7 @@ using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Graphics.Effects;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_DEVICE_ASSOCIATION_TYPE;
|
||||
using static TerraFX.Interop.DirectX.D2D1_BORDER_MODE;
|
||||
using static TerraFX.Interop.DirectX.D2D1_DPICOMPENSATION_INTERPOLATION_MODE;
|
||||
using static TerraFX.Interop.DirectX.D2D1_DPICOMPENSATION_PROP;
|
||||
@@ -158,12 +159,30 @@ unsafe partial class PixelShaderEffect<T>
|
||||
|
||||
using ComPtr<ICanvasDevice> sourceCanvasDevice = default;
|
||||
|
||||
// Get the canvas device the source is realized on, if any
|
||||
canvasImageInterop.Get()->GetDevice(sourceCanvasDevice.GetAddressOf()).Assert();
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE sourceCanvasDeviceType = WIN2D_GET_DEVICE_ASSOCIATION_TYPE_UNSPECIFIED;
|
||||
|
||||
// If a device was retrieved, it must be the same as the input one. If the source has no device,
|
||||
// that is fine, as it just means that its underlying D2D image has not been realized yet.
|
||||
if (sourceCanvasDevice.Get() is not null && !this.canvasDevice.Get()->IsSameInstance(sourceCanvasDevice.Get()))
|
||||
// Get the canvas device the source is realized on, if any, and its association type
|
||||
canvasImageInterop.Get()->GetDevice(sourceCanvasDevice.GetAddressOf(), &sourceCanvasDeviceType).Assert();
|
||||
|
||||
// If the specified source is bound to a creation device, validate that this matches the one we are realized on.
|
||||
// A "creation device" is a canvas device that is used to create the native resources in a given canvas image
|
||||
// implementation, such that the canvas device and the canvas image are bound for the entire lifetime of the
|
||||
// canvas image itself. This applies to eg. CanvasBitmap, which directly wraps some native memory allocated on
|
||||
// a specific device. In these cases, if the associated device doesn't match the one this effect is currently
|
||||
// realized on, that is an error and the source is invalid.
|
||||
//
|
||||
// Otherwise, the device returned here will depend on the specific implementation of this external effect. That is,
|
||||
// it could be null for an unrealized effect, it could be null for a lazily initialized device-bound resource, or it
|
||||
// could also be an already instantiated resource tied to a specific device.
|
||||
//
|
||||
// The only case where the device has to be an exact match is if the device is an owning device for the canvas image.
|
||||
// In all other cases (including when the device is null), we can proceed to resolve the effects graph normally. This
|
||||
// will allow sources to either just work in case the device matches, or unrealize and re-realize themselves on the
|
||||
// new device if they were already realized on a different device (so that things would just work fine if someone was
|
||||
// trying to draw a reused effect after a device lost event, for instance). In the niche scenario where a given source
|
||||
// was some lazily-initialized instance that doesn't allow changing device after that, then the call to Get2D2Image
|
||||
// on that specific source will just fail during the recursive traversal, but that couldn't be checked from here anyway.
|
||||
if (sourceCanvasDeviceType == WIN2D_GET_DEVICE_ASSOCIATION_TYPE_CREATION_DEVICE && !this.canvasDevice.Get()->IsSameInstance(sourceCanvasDevice.Get()))
|
||||
{
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする