Implement ICanvasImage public APIs
このコミットが含まれているのは:
1 親
f6366343a0
コミット
b6f739ca9d
2ファイル変更
+67
-4
検索条件に一致するファイルはありません
@@ -0,0 +1,27 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Native APIs from <c>Microsoft.Graphics.Canvas</c> (ie. Win2D).
|
||||
/// </summary>
|
||||
internal static unsafe class Win2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Calculates the bounds for a given <see cref="ICanvasImageInterop"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceCreator">The <see cref="ICanvasResourceCreator"/> object in use.</param>
|
||||
/// <param name="image">The input <see cref="ICanvasImageInterop"/> instance to compute the bounds for.</param>
|
||||
/// <param name="transform">The transform to use (optional).</param>
|
||||
/// <param name="rect">The resulting bounds.</param>
|
||||
/// <returns>The <see cref="TerraFX.Interop.Windows.HRESULT"/> for the operation.</returns>
|
||||
[DllImport("Microsoft.Graphics.Canvas.dll", PreserveSig = true, ExactSpelling = true)]
|
||||
public static extern int GetBoundsForICanvasImageInterop(
|
||||
ICanvasResourceCreator* resourceCreator,
|
||||
ICanvasImageInterop* image,
|
||||
[NativeTypeName("Windows::Foundation::Numerics::Matrix3x2 const*")] Matrix3x2* transform,
|
||||
Rect* rect);
|
||||
}
|
||||
@@ -1,22 +1,58 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Foundation;
|
||||
using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class PixelShaderEffect<T>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
return GetBounds(resourceCreator, null);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2 transform)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
return GetBounds(resourceCreator, &transform);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ICanvasImage.GetBounds(ICanvasResourceCreator, Matrix3x2)"/>
|
||||
private Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2* transform)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
using ComPtr<IUnknown> canvasResourceCreatorUnknown = default;
|
||||
using ComPtr<IUnknown> canvasImageInteropUnknown = default;
|
||||
|
||||
// Get the IUnknown* references for the ICanvasResourceCreator and ICanvasImageInterop objects
|
||||
canvasResourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator));
|
||||
canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this));
|
||||
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator> canvasResourceCreator = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
// Get the ICanvasResourceCreator* and ICanvasImageInterop* pointers
|
||||
canvasResourceCreatorUnknown.CopyTo(canvasResourceCreator.GetAddressOf()).Assert();
|
||||
canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert();
|
||||
|
||||
Rect bounds;
|
||||
|
||||
// Forward the actual logic to Win2D to compute the image bounds (it needs the internal context)
|
||||
Win2D.GetBoundsForICanvasImageInterop(
|
||||
resourceCreator: canvasResourceCreator.Get(),
|
||||
image: canvasImageInterop.Get(),
|
||||
transform: transform,
|
||||
rect: &bounds).Assert();
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする