Add RCW support to D2D1ResourceTextureManager
このコミットが含まれているのは:
1 親
4764e285c7
コミット
8c59086ee7
3ファイル変更
+414
-109
検索条件に一致するファイルはありません
@@ -2,6 +2,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
@@ -41,11 +42,22 @@ namespace ComputeSharp.D2D1.Interop;
|
||||
/// These can be used to create resource textures, pass them to effects, and also share resources among different effects.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For details of how these work, <c>Initialize</c> maps to <c>ID2D1EffectContext::CreateResourceTexture</c>, whereas
|
||||
/// <c>Update</c> maps to <c>ID2D1ResourceTexture::Update</c>. The same behavior and parameters as those methods is used.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This interface is implemented by ComputeSharp.D2D1, and it can be used through the APIs in <see cref="D2D1ResourceTextureManager"/>.
|
||||
/// That is, <see cref="Create"/> is first use to create an <c>ID2D1ResourceTextureManager</c> instance. Then,
|
||||
/// <see cref="Initialize"/> can be used to initialize the resource texture held by the manager. The manager can also be
|
||||
/// assigned to an effect at any time, using the available property indices from <see cref="D2D1PixelShaderEffectProperty"/>.
|
||||
/// The <see cref="Update"/> API can also be used to update texture data after the initial creation.
|
||||
/// That is, <see cref="Create"/> is first use to create an <c>ID2D1ResourceTextureManager</c> instance. Then, <see cref="Initialize"/>
|
||||
/// can be used to initialize the resource texture held by the manager. The manager can also be assigned to an effect at any time,
|
||||
/// using the available property indices from <see cref="D2D1PixelShaderEffectProperty"/>. To update texture data after its initial
|
||||
/// creation, <see cref="Update(void*, ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{byte})"/> can be used.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// An RCW (runtime callable wrapper, see <see href="https://docs.microsoft.com/dotnet/standard/native-interop/runtime-callable-wrapper"/>),
|
||||
/// is also available for all of these APIs, implemented by the same <see cref="D2D1PixelShaderEffect"/>. In this case, the constructor can
|
||||
/// be used to create an initialize an instance (equivalent to calling <see cref="Create"/> and <see cref="Initialize"/>, and then
|
||||
/// <see cref="Update(ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{byte})"/> is available for texture data updates.
|
||||
/// The instance implements <see cref="ICustomQueryInterface"/>, which can be used in advanced scenarios to retrieve the underlying COM object.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The <c>ID2D1ResourceTextureManager</c> contract allows callers to create a resource texture at any time even before the effect
|
||||
@@ -65,9 +77,270 @@ namespace ComputeSharp.D2D1.Interop;
|
||||
/// };
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Note that due to the fact <c>ID2D1EffectContext</c> and <c>ID2D1ResourceTexture</c> are not thread safe, they are only
|
||||
/// safe to use without additional synchronization when <c>SetEffectContext</c> and <c>GetResourceTexture</c> are called.
|
||||
/// This happens from the internal <c>ID2D1EffectImpl</c> object, which is invoked by D2D, which will handle taking the
|
||||
/// necessary lock before invoking these APIs. Due to the fact the context has to be stored internally, custom implementations
|
||||
/// have to make sure to retrieve the right <c>ID2D1Multithread</c> instance from the input context and use that to synchronize
|
||||
/// all accesses to those two objects from all APIs (including those exposed by <c>ID2D1ResourceTextureManager</c>). The
|
||||
/// built-in implementation of these two interfaces provided by <see cref="D2D1ResourceTextureManager"/> takes care of all this.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static unsafe class D2D1ResourceTextureManager
|
||||
public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManagerImpl"/> object wrapped by the current instance.
|
||||
/// </summary>
|
||||
private readonly D2D1ResourceTextureManagerImpl* d2D1ResourceManagerImpl;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes)
|
||||
{
|
||||
fixed (D2D1ResourceTextureManagerImpl** d2D1ResourceManagerImpl = &this.d2D1ResourceManagerImpl)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl.Factory(d2D1ResourceManagerImpl);
|
||||
}
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
{
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES d2D1ResourceTextureProperties;
|
||||
d2D1ResourceTextureProperties.extents = pExtents;
|
||||
d2D1ResourceTextureProperties.dimensions = (uint)extents.Length;
|
||||
d2D1ResourceTextureProperties.bufferPrecision = (D2D1_BUFFER_PRECISION)bufferPrecision;
|
||||
d2D1ResourceTextureProperties.channelDepth = (D2D1_CHANNEL_DEPTH)channelDepth;
|
||||
d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter;
|
||||
d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes;
|
||||
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
resourceId: null,
|
||||
resourceTextureProperties: &d2D1ResourceTextureProperties,
|
||||
data: null,
|
||||
strides: null,
|
||||
dataSize: 0);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="resourceId">The resource id for the resource to create.</param>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
Guid resourceId,
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes)
|
||||
{
|
||||
fixed (D2D1ResourceTextureManagerImpl** d2D1ResourceManagerImpl = &this.d2D1ResourceManagerImpl)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl.Factory(d2D1ResourceManagerImpl);
|
||||
}
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
{
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES d2D1ResourceTextureProperties;
|
||||
d2D1ResourceTextureProperties.extents = pExtents;
|
||||
d2D1ResourceTextureProperties.dimensions = (uint)extents.Length;
|
||||
d2D1ResourceTextureProperties.bufferPrecision = (D2D1_BUFFER_PRECISION)bufferPrecision;
|
||||
d2D1ResourceTextureProperties.channelDepth = (D2D1_CHANNEL_DEPTH)channelDepth;
|
||||
d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter;
|
||||
d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes;
|
||||
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
resourceId: &resourceId,
|
||||
resourceTextureProperties: &d2D1ResourceTextureProperties,
|
||||
data: null,
|
||||
strides: null,
|
||||
dataSize: 0);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <param name="data">The data to load in the resource to create.</param>
|
||||
/// <param name="strides">The strides for the data supplied for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes,
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
{
|
||||
fixed (D2D1ResourceTextureManagerImpl** d2D1ResourceManagerImpl = &this.d2D1ResourceManagerImpl)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl.Factory(d2D1ResourceManagerImpl);
|
||||
}
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
fixed (byte* pData = data)
|
||||
fixed (uint* pStrides = strides)
|
||||
{
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES d2D1ResourceTextureProperties;
|
||||
d2D1ResourceTextureProperties.extents = pExtents;
|
||||
d2D1ResourceTextureProperties.dimensions = (uint)extents.Length;
|
||||
d2D1ResourceTextureProperties.bufferPrecision = (D2D1_BUFFER_PRECISION)bufferPrecision;
|
||||
d2D1ResourceTextureProperties.channelDepth = (D2D1_CHANNEL_DEPTH)channelDepth;
|
||||
d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter;
|
||||
d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes;
|
||||
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
resourceId: null,
|
||||
resourceTextureProperties: &d2D1ResourceTextureProperties,
|
||||
data: pData,
|
||||
strides: pStrides,
|
||||
dataSize: (uint)data.Length);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="resourceId">The resource id for the resource to create.</param>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <param name="data">The data to load in the resource to create.</param>
|
||||
/// <param name="strides">The strides for the data supplied for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
Guid resourceId,
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes,
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
{
|
||||
fixed (D2D1ResourceTextureManagerImpl** d2D1ResourceManagerImpl = &this.d2D1ResourceManagerImpl)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl.Factory(d2D1ResourceManagerImpl);
|
||||
}
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
fixed (byte* pData = data)
|
||||
fixed (uint* pStrides = strides)
|
||||
{
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES d2D1ResourceTextureProperties;
|
||||
d2D1ResourceTextureProperties.extents = pExtents;
|
||||
d2D1ResourceTextureProperties.dimensions = (uint)extents.Length;
|
||||
d2D1ResourceTextureProperties.bufferPrecision = (D2D1_BUFFER_PRECISION)bufferPrecision;
|
||||
d2D1ResourceTextureProperties.channelDepth = (D2D1_CHANNEL_DEPTH)channelDepth;
|
||||
d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter;
|
||||
d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes;
|
||||
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
resourceId: &resourceId,
|
||||
resourceTextureProperties: &d2D1ResourceTextureProperties,
|
||||
data: pData,
|
||||
strides: pStrides,
|
||||
dataSize: (uint)data.Length);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the underlying <c>ID2D1ResourceTextureManager</c> object.
|
||||
/// </summary>
|
||||
~D2D1ResourceTextureManager()
|
||||
{
|
||||
this.d2D1ResourceManagerImpl->Release();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specific resource texture inside the specific range or box using the supplied data.
|
||||
/// </summary>
|
||||
/// <param name="minimumExtents">The "left" extent of the updates if specified. If <see langword="null"/>, the entire texture is updated.</param>
|
||||
/// <param name="maximimumExtents">The "right" extent of the updates if specified. If <see langword="null"/>, the entire texture is updated.</param>
|
||||
/// <param name="strides">The stride to advance through the input data, according to dimension.</param>
|
||||
/// <param name="data">The data to be placed into the resource texture.</param>
|
||||
public void Update(
|
||||
ReadOnlySpan<uint> minimumExtents,
|
||||
ReadOnlySpan<uint> maximimumExtents,
|
||||
ReadOnlySpan<uint> strides,
|
||||
ReadOnlySpan<byte> data)
|
||||
{
|
||||
fixed (uint* pMinimumExtents = minimumExtents)
|
||||
fixed (uint* pMaximumExtents = maximimumExtents)
|
||||
fixed (uint* pStrides = strides)
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Update(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
minimumExtents: pMinimumExtents,
|
||||
maximimumExtents: pMaximumExtents,
|
||||
strides: pStrides,
|
||||
dimensions: (uint)(strides.Length + 1),
|
||||
data: pData,
|
||||
dataCount: (uint)data.Length);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out IntPtr ppv)
|
||||
{
|
||||
fixed (Guid* pIid = &iid)
|
||||
fixed (IntPtr* pPpv = &ppv)
|
||||
{
|
||||
int hresult = this.d2D1ResourceManagerImpl->QueryInterface(pIid, (void**)pPpv);
|
||||
|
||||
return hresult switch
|
||||
{
|
||||
S.S_OK => CustomQueryInterfaceResult.Handled,
|
||||
_ => CustomQueryInterfaceResult.Failed
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>ID2D1ResourceTextureManager</c> instance.
|
||||
/// </summary>
|
||||
@@ -104,8 +377,6 @@ public static unsafe class D2D1ResourceTextureManager
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
{
|
||||
// TODO: validate argument and return
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
fixed (byte* pData = data)
|
||||
@@ -136,19 +407,15 @@ public static unsafe class D2D1ResourceTextureManager
|
||||
/// <param name="resourceTextureManager">A pointer to the <c>ID2D1ResourceTextureManager</c> instance to use.</param>
|
||||
/// <param name="minimumExtents">The "left" extent of the updates if specified (if empty, the entire texture is updated).</param>
|
||||
/// <param name="maximimumExtents">The "right" extent of the updates if specified (if empty, the entire texture is updated).</param>
|
||||
/// <param name="strides">The stride to advance through the input data, according to dimension.</param>
|
||||
/// <param name="dimensions">The number of dimensions in the resource texture. This must match the number used to load the texture.</param>
|
||||
/// <param name="strides">The stride to advance through the input data.</param>
|
||||
/// <param name="data">The data to be placed into the resource texture.</param>
|
||||
public static void Update(
|
||||
void* resourceTextureManager,
|
||||
ReadOnlySpan<uint> minimumExtents,
|
||||
ReadOnlySpan<uint> maximimumExtents,
|
||||
ReadOnlySpan<uint> strides,
|
||||
uint dimensions,
|
||||
ReadOnlySpan<byte> data)
|
||||
{
|
||||
// TODO: validate argument and return
|
||||
|
||||
fixed (uint* pMinimumExtents = minimumExtents)
|
||||
fixed (uint* pMaximumExtents = maximimumExtents)
|
||||
fixed (uint* pStrides = strides)
|
||||
@@ -158,7 +425,7 @@ public static unsafe class D2D1ResourceTextureManager
|
||||
minimumExtents: pMinimumExtents,
|
||||
maximimumExtents: pMaximumExtents,
|
||||
strides: pStrides,
|
||||
dimensions: dimensions,
|
||||
dimensions: (uint)(strides.Length + 1),
|
||||
data: pData,
|
||||
dataCount: (uint)data.Length);
|
||||
|
||||
|
||||
+132
-94
@@ -9,12 +9,125 @@ using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.In
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial struct D2D1ResourceTextureManagerImpl
|
||||
unsafe partial struct D2D1ResourceTextureManagerImpl
|
||||
{
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Initialize"/>
|
||||
public static int Initialize(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
// Return E_POINTER if any input pointer is null
|
||||
if (resourceTextureProperties is null ||
|
||||
data is null ||
|
||||
resourceTextureProperties->extents is null ||
|
||||
resourceTextureProperties->extendModes is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
// If the method has already been called, fail
|
||||
if (@this->d2D1ResourceTexture is not null ||
|
||||
@this->data is not null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If the method has already been called, just forward the call
|
||||
if (@this->d2D1EffectContext is not null)
|
||||
{
|
||||
@this->d2D1Multithread->Enter();
|
||||
|
||||
// Create the resource after taking a D2D lock
|
||||
int hresult = @this->d2D1EffectContext->CreateResourceTexture(
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: resourceTextureProperties,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize,
|
||||
resourceTexture: &@this->d2D1ResourceTexture);
|
||||
|
||||
@this->d2D1Multithread->Leave();
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Initialize into a staging buffer
|
||||
return ID2D1ResourceTextureManagerMethods.InitializeWithStagingBuffer(
|
||||
@this: @this,
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: resourceTextureProperties,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Update"/>
|
||||
public static int Update(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
uint* strides,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint dataCount)
|
||||
{
|
||||
if (minimumExtents is null ||
|
||||
maximimumExtents is null ||
|
||||
data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
if (@this->d2D1ResourceTexture is null &&
|
||||
@this->data is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If a resource texture already exists, just forward the call
|
||||
if (@this->d2D1ResourceTexture is not null)
|
||||
{
|
||||
@this->d2D1Multithread->Enter();
|
||||
|
||||
// Take a D2D lock here too to ensure thread safety
|
||||
int hresult = @this->d2D1ResourceTexture->Update(
|
||||
minimumExtents: minimumExtents,
|
||||
maximimumExtents: maximimumExtents,
|
||||
strides: strides,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
dataCount: dataCount);
|
||||
|
||||
@this->d2D1Multithread->Leave();
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Otherwise update the staging buffer
|
||||
return ID2D1ResourceTextureManagerMethods.UpdateWithStagingBuffer(
|
||||
@this: @this,
|
||||
minimumExtents: minimumExtents,
|
||||
maximimumExtents: maximimumExtents,
|
||||
strides: strides,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
dataCount: dataCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The implementation for <c>ID2D1ResourceTextureManager</c>.
|
||||
/// </summary>
|
||||
private static unsafe class ID2D1ResourceTextureManagerMethods
|
||||
private static class ID2D1ResourceTextureManagerMethods
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
/// <inheritdoc cref="Initialize"/>
|
||||
@@ -95,52 +208,13 @@ partial struct D2D1ResourceTextureManagerImpl
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
// Return E_POINTER if any input pointer is null
|
||||
if (resourceTextureProperties is null ||
|
||||
data is null ||
|
||||
resourceTextureProperties->extents is null ||
|
||||
resourceTextureProperties->extendModes is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
// If the method has already been called, fail
|
||||
if (@this->d2D1ResourceTexture is not null ||
|
||||
@this->data is not null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If the method has already been called, just forward the call
|
||||
if (@this->d2D1EffectContext is not null)
|
||||
{
|
||||
@this->d2D1Multithread->Enter();
|
||||
|
||||
// Create the resource after taking a D2D lock
|
||||
int hresult = @this->d2D1EffectContext->CreateResourceTexture(
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: resourceTextureProperties,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize,
|
||||
resourceTexture: &@this->d2D1ResourceTexture);
|
||||
|
||||
@this->d2D1Multithread->Leave();
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Initialize into a staging buffer
|
||||
return InitializeWithStagingBuffer(
|
||||
@this: @this,
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: resourceTextureProperties,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize);
|
||||
}
|
||||
return D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this,
|
||||
resourceId,
|
||||
resourceTextureProperties,
|
||||
data,
|
||||
strides,
|
||||
dataSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Update"/>
|
||||
@@ -154,54 +228,18 @@ partial struct D2D1ResourceTextureManagerImpl
|
||||
byte* data,
|
||||
uint dataCount)
|
||||
{
|
||||
if (minimumExtents is null ||
|
||||
maximimumExtents is null ||
|
||||
data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
if (@this->d2D1ResourceTexture is null &&
|
||||
@this->data is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If a resource texture already exists, just forward the call
|
||||
if (@this->d2D1ResourceTexture is not null)
|
||||
{
|
||||
@this->d2D1Multithread->Enter();
|
||||
|
||||
// Take a D2D lock here too to ensure thread safety
|
||||
int hresult = @this->d2D1ResourceTexture->Update(
|
||||
minimumExtents: minimumExtents,
|
||||
maximimumExtents: maximimumExtents,
|
||||
strides: strides,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
dataCount: dataCount);
|
||||
|
||||
@this->d2D1Multithread->Leave();
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Otherwise update the staging buffer
|
||||
return UpdateWithStagingBuffer(
|
||||
@this: @this,
|
||||
minimumExtents: minimumExtents,
|
||||
maximimumExtents: maximimumExtents,
|
||||
strides: strides,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
dataCount: dataCount);
|
||||
}
|
||||
return D2D1ResourceTextureManagerImpl.Update(
|
||||
@this,
|
||||
minimumExtents,
|
||||
maximimumExtents,
|
||||
strides,
|
||||
dimensions,
|
||||
data,
|
||||
dataCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Initialize"/>
|
||||
private static int InitializeWithStagingBuffer(
|
||||
public static int InitializeWithStagingBuffer(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
@@ -308,7 +346,7 @@ partial struct D2D1ResourceTextureManagerImpl
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Update"/>
|
||||
private static int UpdateWithStagingBuffer(
|
||||
public static int UpdateWithStagingBuffer(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
|
||||
+2
-2
@@ -173,7 +173,7 @@ internal unsafe partial struct D2D1ResourceTextureManagerImpl
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
private int QueryInterface(Guid* riid, void** ppvObject)
|
||||
public int QueryInterface(Guid* riid, void** ppvObject)
|
||||
{
|
||||
if (ppvObject is null)
|
||||
{
|
||||
@@ -213,7 +213,7 @@ internal unsafe partial struct D2D1ResourceTextureManagerImpl
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
private uint Release()
|
||||
public uint Release()
|
||||
{
|
||||
uint referenceCount = (uint)Interlocked.Decrement(ref this.referenceCount);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする