Rent device context to create DPI compensaton effect

このコミットが含まれているのは:
Sergio Pedri committed 2023-02-24 00:56:26 +01:00
1 親 303246fffd
コミット 00d171cdb0
6ファイル変更
+17 -36

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

+10 -10
ファイルの表示
@@ -37,22 +37,22 @@ internal static unsafe class ICanvasDeviceExtensions
}
/// <summary>
/// Creates a new <see cref="ID2D1DeviceContext"/> from an input <see cref="ICanvasDevice"/>.
/// Gets a new <see cref="ID2D1DeviceContextLease"/> from an input <see cref="ICanvasDevice"/>.
/// </summary>
/// <param name="canvasDevice">The input <see cref="ICanvasDevice"/> object.</param>
/// <param name="d2D1DeviceContext">The resulting <see cref="ID2D1DeviceContext"/> object.</param>
/// <param name="d2D1DeviceContextLease">The resulting <see cref="ID2D1DeviceContextLease"/> object.</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
public static HRESULT CreateD2DDeviceContext(this ref ICanvasDevice canvasDevice, ID2D1DeviceContext** d2D1DeviceContext)
public static HRESULT GetD2DDeviceContextLease(this ref ICanvasDevice canvasDevice, ID2D1DeviceContextLease** d2D1DeviceContextLease)
{
using ComPtr<ID2D1Device1> d2D1Device1 = default;
using ComPtr<ID2D1DeviceContextPool> d2D1DeviceContextPool = default;
// Get the underlying ID2D1Device1 object
canvasDevice.GetD2DDevice(d2D1Device1.GetAddressOf()).Assert();
// Get the ID2D1DeviceContextLease interface reference
canvasDevice.QueryInterface(
riid: Win32.__uuidof<ID2D1DeviceContextPool>(),
ppvObject: d2D1DeviceContextPool.GetVoidAddressOf()).Assert();
// Create the new device context
HRESULT hresult = d2D1Device1.Get()->CreateDeviceContext(
options: D2D1_DEVICE_CONTEXT_OPTIONS.D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
deviceContext: d2D1DeviceContext);
// Create the new lease
HRESULT hresult = d2D1DeviceContextPool.Get()->GetDeviceContextLease(d2D1DeviceContextLease);
return hresult;
}
+1 -1
ファイルの表示
@@ -19,7 +19,7 @@ internal static class ResourceManager
/// <summary>
/// Gets or creates an <see cref="IGraphicsEffectSource"/> instance for a native resource.
/// </summary>
/// <param name="device">The input canvas device (as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
/// <param name="device">The input canvas device (as a marshalled <see cref="Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
/// <param name="resource">The input native resource to create a wrapper for.</param>
/// <param name="dpi">The realization DPIs for <paramref name="resource"/></param>
/// <returns>The resulting <see cref="IGraphicsEffectSource"/> wrapper instance.</returns>
+6 -1
ファイルの表示
@@ -299,13 +299,18 @@ unsafe partial class PixelShaderEffect<T>
// Create an ID2D1Effect for the DPI compensation, if there isn't one already
if (!sourceReference.HasDpiCompensationEffect)
{
using ComPtr<ID2D1DeviceContextLease> d2D1DeviceContextLease = default;
using ComPtr<ID2D1DeviceContext> d2D1DeviceContextEffective = default;
// We need to create a DPI compensation effect, so a device context must be available.
// If there is no input device context, just create a new one from the realization device.
if (d2D1DeviceContext is null)
{
this.canvasDevice.Get()->CreateD2DDeviceContext(d2D1DeviceContextEffective.GetAddressOf()).Assert();
// Get the ID2D1DeviceContextLease interface from the input device
this.canvasDevice.Get()->GetD2DDeviceContextLease(d2D1DeviceContextLease.GetAddressOf()).Assert();
// Rent a new device context from the lease (this is much faster than creating a new device context)
d2D1DeviceContextLease.Get()->GetD2DDeviceContext(d2D1DeviceContextEffective.GetAddressOf()).Assert();
}
else
{
-16
ファイルの表示
@@ -1,16 +0,0 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
// Ported from um/d2d1_1.h in the Windows SDK for Windows 10.0.22621.0
// Original source is Copyright © Microsoft. All rights reserved.
using System;
namespace TerraFX.Interop.DirectX;
[Flags]
internal enum D2D1_DEVICE_CONTEXT_OPTIONS : uint
{
D2D1_DEVICE_CONTEXT_OPTIONS_NONE = 0,
D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS = 1,
D2D1_DEVICE_CONTEXT_OPTIONS_FORCE_DWORD = 0xffffffff,
}
-7
ファイルの表示
@@ -49,11 +49,4 @@ internal unsafe partial struct ID2D1Device1
{
((delegate* unmanaged[Stdcall]<ID2D1Device1*, ID2D1Factory**, void>)(lpVtbl[3]))((ID2D1Device1*)Unsafe.AsPointer(ref this), factory);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(4)]
public HRESULT CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext** deviceContext)
{
return ((delegate* unmanaged[Stdcall]<ID2D1Device1*, D2D1_DEVICE_CONTEXT_OPTIONS, ID2D1DeviceContext**, int>)(lpVtbl[4]))((ID2D1Device1*)Unsafe.AsPointer(ref this), options, deviceContext);
}
}
-1
ファイルの表示
@@ -35,7 +35,6 @@
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\ID2D1Image.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_CHANNEL_DEPTH.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_BUFFER_PRECISION.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_DEVICE_CONTEXT_OPTIONS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_PROPERTY.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_PROPERTY_TYPE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1CommandList.cs" />