Initial implementation port of ICanvasImageInterop from Win2D

このコミットが含まれているのは:
Sergio Pedri committed 2022-12-22 10:56:03 -08:00
1 親 7a51426988
コミット 139ad8ed62
9ファイル変更
+347 -44

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

+38
ファイルの表示
@@ -0,0 +1,38 @@
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using Win32 = TerraFX.Interop.Windows.Windows;
namespace ComputeSharp.D2D1.Uwp.Extensions;
/// <summary>
/// A <see langword="class"/> with extensions for the <see cref="ICanvasDevice"/> type.
/// </summary>
internal static unsafe class ICanvasDeviceExtensions
{
/// <summary>
/// Gets the underlying <see cref="ID2D1Device1"/> object from an <see cref="ICanvasDevice"/> object.
/// </summary>
/// <param name="canvasDevice">The input <see cref="ICanvasDevice"/> object.</param>
/// <param name="d2D1Device1">The underlying <see cref="ID2D1Device1"/> object for <paramref name="canvasDevice"/>.</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
public static HRESULT GetD2DDevice(this ref ICanvasDevice canvasDevice, ID2D1Device1** d2D1Device1)
{
using ComPtr<ICanvasResourceWrapperNative> canvasDeviceResourceWrapperNative = default;
// Get the ICanvasResourceWrapperNative wrapper around the input device
canvasDevice.QueryInterface(
riid: Win32.__uuidof<ICanvasResourceWrapperNative>(),
ppvObject: (void**)canvasDeviceResourceWrapperNative.GetAddressOf()).Assert();
// Get the underlying ID2D1Device1 instance in use
HRESULT hresult = canvasDeviceResourceWrapperNative.Get()->GetNativeResource(
device: null,
dpi: 0,
iid: Win32.__uuidof<ID2D1Device1>(),
resource: (void**)d2D1Device1);
return hresult;
}
}
+60
ファイルの表示
@@ -0,0 +1,60 @@
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
namespace ComputeSharp.D2D1.Uwp.Extensions;
/// <summary>
/// A <see langword="class"/> with extensions for the <see cref="ID2D1DeviceContext"/> type.
/// </summary>
internal static unsafe class ID2D1DeviceContextExtensions
{
/// <summary>
/// Checks whether a given <see cref="ID2D1DeviceContext"/> has an <see cref="ID2D1CommandList"/> as render target.
/// </summary>
/// <param name="deviceContext">The input <see cref="ID2D1DeviceContext"/> instance to check.</param>
/// <returns>Whether the target of <paramref name="deviceContext"/> is an <see cref="ID2D1CommandList"/>.</returns>
public static bool HasCommandListTarget(this ref ID2D1DeviceContext deviceContext)
{
using ComPtr<ID2D1Image> d2D1Image = default;
// First get the target and check that it is not null
deviceContext.GetTarget(d2D1Image.GetAddressOf());
if (d2D1Image.Get() is null)
{
return false;
}
using ComPtr<ID2D1CommandList> d2D1CommandList = default;
// If there is a target, check if it is an ID2D1CommandList
HRESULT hresult = d2D1Image.CopyTo(d2D1CommandList.GetAddressOf());
// Special case E_NOINTERFACE: this should return false and it's not an error
if (hresult == E.E_NOINTERFACE)
{
return false;
}
// Throw for any other failure
hresult.Assert();
return true;
}
/// <summary>
/// Reads the DPI value from a target <see cref="ID2D1DeviceContext"/> object.
/// </summary>
/// <param name="deviceContext">The input <see cref="ID2D1DeviceContext"/> instance.</param>
/// <returns>The DPIs from <paramref name="deviceContext"/>.</returns>
public static float GetDpi(this ref ID2D1DeviceContext deviceContext)
{
float dpiX;
float dpiY;
deviceContext.GetDpi(&dpiX, &dpiY);
return dpiX;
}
}