Complete D2D1DrawInfoUpdateContextImpl implementation

このコミットが含まれているのは:
Sergio Pedri committed 2022-11-29 22:34:05 +01:00
1 親 6fbf37c3cf
コミット 2481bc7e0a
6ファイル変更
+112 -12

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

+8 -5
ファイルの表示
@@ -131,16 +131,19 @@ unsafe partial struct PixelShaderEffect
return E.E_INVALIDARG;
}
// Reuse the existing buffer if there is one, otherwise allocate a new one
if (@this->constantBuffer is not null)
{
NativeMemory.Free(@this->constantBuffer);
Buffer.MemoryCopy(data, @this->constantBuffer, dataSize, dataSize);
}
else
{
void* buffer = NativeMemory.Alloc(dataSize);
void* buffer = NativeMemory.Alloc(dataSize);
Buffer.MemoryCopy(data, buffer, dataSize, dataSize);
Buffer.MemoryCopy(data, buffer, dataSize, dataSize);
@this->constantBuffer = (byte*)buffer;
@this->constantBuffer = (byte*)buffer;
}
return S.S_OK;
}
@@ -84,7 +84,17 @@ partial struct D2D1DrawInfoUpdateContextImpl
[UnmanagedCallersOnly]
public static int GetConstantBufferSize(D2D1DrawInfoUpdateContextImpl* @this, uint* size)
{
// TODO
if (@this->d2D1DrawInfo is null)
{
return RO.RO_E_CLOSED;
}
if (size is null)
{
return E.E_POINTER;
}
*size = (uint)@this->constantBufferSize;
return S.S_OK;
}
@@ -93,7 +103,30 @@ partial struct D2D1DrawInfoUpdateContextImpl
[UnmanagedCallersOnly]
public static int GetConstantBuffer(D2D1DrawInfoUpdateContextImpl* @this, byte* buffer, uint bufferCount)
{
// TODO
if (@this->d2D1DrawInfo is null)
{
return RO.RO_E_CLOSED;
}
if (buffer is null)
{
return E.E_POINTER;
}
if (bufferCount < @this->constantBufferSize)
{
return E.E_NOT_SUFFICIENT_BUFFER;
}
if (@this->constantBuffer is null)
{
return E.E_NOT_VALID_STATE;
}
if (@this->constantBufferSize > 0)
{
Buffer.MemoryCopy(@this->constantBuffer, buffer, bufferCount, @this->constantBufferSize);
}
return S.S_OK;
}
@@ -102,7 +135,34 @@ partial struct D2D1DrawInfoUpdateContextImpl
[UnmanagedCallersOnly]
public static int SetConstantBuffer(D2D1DrawInfoUpdateContextImpl* @this, byte* buffer, uint bufferCount)
{
// TODO
if (@this->d2D1DrawInfo is null)
{
return RO.RO_E_CLOSED;
}
if (buffer is null)
{
return E.E_POINTER;
}
if (bufferCount != (uint)@this->constantBufferSize)
{
return E.E_INVALIDARG;
}
// Reuse the existing buffer if there is one, otherwise allocate a new one
if (@this->constantBuffer is not null)
{
Buffer.MemoryCopy(buffer, @this->constantBuffer, bufferCount, bufferCount);
}
else
{
void* constantBuffer = NativeMemory.Alloc(bufferCount);
Buffer.MemoryCopy(buffer, constantBuffer, bufferCount, bufferCount);
@this->constantBuffer = (byte*)constantBuffer;
}
return S.S_OK;
}
@@ -74,7 +74,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
{
@this = (D2D1DrawInfoUpdateContextImpl*)&((void**)@this)[-1];
// TODO
@this->d2D1DrawInfo = null;
return S.S_OK;
}
@@ -2,6 +2,7 @@ using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#if NET6_0_OR_GREATER
using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers;
@@ -96,11 +97,33 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
/// </summary>
private volatile int referenceCount;
/// <summary>
/// The constant buffer data, if set.
/// </summary>
private byte* constantBuffer;
/// <summary>
/// The size of <see cref="constantBuffer"/>.
/// </summary>
private int constantBufferSize;
/// <summary>
/// The <see cref="ID2D1DrawInfo"/> instance currently in use.
/// </summary>
private ID2D1DrawInfo* d2D1DrawInfo;
/// <summary>
/// The factory method for <see cref="D2D1DrawInfoUpdateContextImpl"/> instances.
/// </summary>
/// <param name="drawInfoUpdateContext">The resulting draw info update context instance.</param>
public static void Factory(D2D1DrawInfoUpdateContextImpl** drawInfoUpdateContext)
/// <param name="constantBuffer">The constant buffer data, if set.</param>
/// <param name="constantBufferSize">The size of <paramref name="constantBuffer"/>.</param>
/// <param name="d2D1DrawInfo">The <see cref="ID2D1DrawInfo"/> instance currently in use.</param>
public static void Factory(
D2D1DrawInfoUpdateContextImpl** drawInfoUpdateContext,
byte* constantBuffer,
int constantBufferSize,
ID2D1DrawInfo* d2D1DrawInfo)
{
D2D1DrawInfoUpdateContextImpl* @this = (D2D1DrawInfoUpdateContextImpl*)NativeMemory.Alloc((nuint)sizeof(D2D1DrawInfoUpdateContextImpl));
@@ -109,6 +132,9 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
@this->lpVtblForID2D1DrawInfoUpdateContex = VtblForID2D1DrawInfoUpdateContex;
@this->lpVtblForID2D1DrawInfoUpdateContexInternal = VtblForID2D1DrawInfoUpdateContexInternal;
@this->referenceCount = 1;
@this->constantBuffer = constantBuffer;
@this->constantBufferSize = constantBufferSize;
@this->d2D1DrawInfo = d2D1DrawInfo;
*drawInfoUpdateContext = @this;
}
@@ -160,8 +186,6 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
if (referenceCount == 0)
{
// TODO
NativeMemory.Free(Unsafe.AsPointer(ref this));
}
+1
ファイルの表示
@@ -63,6 +63,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows\shared\windef\RECT.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows\shared\winerror\D2DERR.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows\shared\winerror\E.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows\shared\winerror\RO.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows\shared\winerror\Windows.cs" />
</ItemGroup>
</Project>
+12
ファイルの表示
@@ -0,0 +1,12 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
// Ported from shared/winerror.h in the Windows SDK for Windows 10.0.22621.0
// Original source is Copyright © Microsoft. All rights reserved.
namespace TerraFX.Interop.Windows;
internal static partial class RO
{
[NativeTypeName("#define RO_E_CLOSED _HRESULT_TYPEDEF_(0x80000013L)")]
public const int RO_E_CLOSED = unchecked((int)(0x80000013));
}