зеркало из https://github.com/mono/SkiaSharp.git
Add some tests
This commit is contained in:
Родитель
46a6728db3
Коммит
6cf79eac14
|
@ -4,13 +4,18 @@ using System.Text;
|
|||
|
||||
namespace SkiaSharp
|
||||
{
|
||||
public class GRD3DBackendContext
|
||||
public class GRD3DBackendContext : IDisposable
|
||||
{
|
||||
public nint Adapter { get; set; }
|
||||
public nint Device { get; set; }
|
||||
public nint Queue { get; set; }
|
||||
public bool ProtectedContext { get; set; }
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
// NOTE: for the future
|
||||
}
|
||||
|
||||
internal GrD3DBackendContextNative ToNative ()
|
||||
{
|
||||
return new GrD3DBackendContextNative {
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace SkiaSharp
|
|||
private IDXGIAdapter1 _adapter;
|
||||
public new IDXGIAdapter1 Adapter { get => _adapter; set { _adapter = value; base.Adapter = value?.NativePointer ?? default; } }
|
||||
|
||||
private ID3D12Device2 _device;
|
||||
public new ID3D12Device2 Device { get => _device; set { _device = value; base.Device = value?.NativePointer ?? default; } }
|
||||
private ID3D12Device _device;
|
||||
public new ID3D12Device Device { get => _device; set { _device = value; base.Device = value?.NativePointer ?? default; } }
|
||||
|
||||
private ID3D12CommandQueue _queue;
|
||||
public new ID3D12CommandQueue Queue { get => _queue; set { _queue = value; base.Queue = value?.NativePointer ?? default; } }
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using Vortice.Direct3D12;
|
||||
using Vortice.DXGI;
|
||||
|
||||
namespace SkiaSharp.Tests
|
||||
{
|
||||
public class Direct3DContext : IDisposable
|
||||
{
|
||||
public virtual IDXGIAdapter1 Adapter { get; protected set; }
|
||||
|
||||
public virtual ID3D12Device Device { get; protected set; }
|
||||
|
||||
public virtual ID3D12CommandQueue Queue { get; protected set; }
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
Queue.Dispose();
|
||||
Device.Dispose();
|
||||
Adapter.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
using Vortice.Direct3D;
|
||||
using Vortice.Direct3D12;
|
||||
using Vortice.DXGI;
|
||||
|
||||
namespace SkiaSharp.Tests;
|
||||
|
||||
public class Win32Direct3DContext : Direct3DContext
|
||||
{
|
||||
public Win32Direct3DContext()
|
||||
{
|
||||
// Create the device
|
||||
var factory = DXGI.CreateDXGIFactory1<IDXGIFactory4>();
|
||||
Adapter = GetHardwareAdapter(factory);
|
||||
Device = D3D12.D3D12CreateDevice<ID3D12Device>(Adapter, FeatureLevel.Level_11_0);
|
||||
|
||||
// Create the command queue
|
||||
var queueDesc = new CommandQueueDescription(CommandListType.Direct);
|
||||
Queue = Device.CreateCommandQueue(queueDesc);
|
||||
}
|
||||
|
||||
private static IDXGIAdapter1 GetHardwareAdapter(IDXGIFactory4 pFactory)
|
||||
{
|
||||
for (var adapterIndex = 0; ; adapterIndex++)
|
||||
{
|
||||
// No more adapters to enumerate.
|
||||
if (pFactory.EnumAdapters1(adapterIndex, out var pAdapter).Failure)
|
||||
break;
|
||||
|
||||
// Check to see if the adapter supports Direct3D 12.
|
||||
if (D3D12.IsSupported(pAdapter, FeatureLevel.Level_11_0))
|
||||
return pAdapter;
|
||||
|
||||
pAdapter.Release();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using SkiaSharp.Tests;
|
||||
using Xunit;
|
||||
|
||||
namespace SkiaSharp.Direct3D.Tests
|
||||
{
|
||||
public class Direct3DTest : SKTest
|
||||
{
|
||||
protected Direct3DContext CreateDirect3DContext()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsWindows)
|
||||
throw new PlatformNotSupportedException();
|
||||
|
||||
return new Win32Direct3DContext();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new SkipException($"Unable to create Direct3D context: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
using SkiaSharp.Tests;
|
||||
|
||||
namespace SkiaSharp.Direct3D.Tests;
|
||||
|
||||
public class GRContextTest : Direct3DTest
|
||||
{
|
||||
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
|
||||
[SkippableFact]
|
||||
public void CreateD3DContextIsValid()
|
||||
{
|
||||
using var ctx = CreateDirect3DContext();
|
||||
|
||||
using var grD3DBackendContext = new GRDirect3DBackendContext
|
||||
{
|
||||
Adapter = ctx.Adapter,
|
||||
Device = ctx.Device,
|
||||
Queue = ctx.Queue,
|
||||
ProtectedContext = false
|
||||
};
|
||||
|
||||
Assert.NotNull(grD3DBackendContext);
|
||||
|
||||
using var grContext = GRContext.CreateDirect3D(grD3DBackendContext);
|
||||
|
||||
Assert.NotNull(grContext);
|
||||
}
|
||||
|
||||
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
|
||||
[SkippableFact]
|
||||
public void CreateVkContextWithOptionsIsValid()
|
||||
{
|
||||
using var ctx = CreateDirect3DContext();
|
||||
|
||||
using var grD3DBackendContext = new GRDirect3DBackendContext
|
||||
{
|
||||
Adapter = ctx.Adapter,
|
||||
Device = ctx.Device,
|
||||
Queue = ctx.Queue,
|
||||
ProtectedContext = false
|
||||
};
|
||||
|
||||
Assert.NotNull(grD3DBackendContext);
|
||||
|
||||
var options = new GRContextOptions();
|
||||
|
||||
using var grContext = GRContext.CreateDirect3D(grD3DBackendContext, options);
|
||||
|
||||
Assert.NotNull(grContext);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
// using Xunit;
|
||||
// using SkiaSharp.Tests;
|
||||
|
||||
// namespace SkiaSharp.Direct3D.Tests
|
||||
// {
|
||||
// public class SharpVkBackendContextTest : Direct3DTest
|
||||
// {
|
||||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
|
||||
// [SkippableFact]
|
||||
// public void VkGpuSurfaceIsCreatedSharpVkTypes()
|
||||
// {
|
||||
// using var ctx = CreateVkContext();
|
||||
// using var grVkBackendContext = new GRSharpVkBackendContext
|
||||
// {
|
||||
// VkInstance = ctx.Instance,
|
||||
// VkPhysicalDevice = ctx.PhysicalDevice,
|
||||
// VkDevice = ctx.Device,
|
||||
// VkQueue = ctx.GraphicsQueue,
|
||||
// GraphicsQueueIndex = ctx.GraphicsFamily,
|
||||
// GetProcedureAddress = ctx.SharpVkGetProc,
|
||||
// VkPhysicalDeviceFeatures = ctx.PhysicalDevice.GetFeatures(),
|
||||
// };
|
||||
// Assert.NotNull(grVkBackendContext);
|
||||
|
||||
// var baseType = grVkBackendContext as GRVkBackendContext;
|
||||
// Assert.NotNull(baseType);
|
||||
|
||||
// Assert.Equal(ctx.Instance.RawHandle.ToUInt64(), (ulong)baseType.VkInstance);
|
||||
// Assert.Equal(ctx.PhysicalDevice.RawHandle.ToUInt64(), (ulong)baseType.VkPhysicalDevice);
|
||||
// Assert.Equal(ctx.Device.RawHandle.ToUInt64(), (ulong)baseType.VkDevice);
|
||||
// Assert.Equal(ctx.GraphicsQueue.RawHandle.ToUInt64(), (ulong)baseType.VkQueue);
|
||||
// Assert.NotEqual(0, (long)baseType.VkPhysicalDeviceFeatures);
|
||||
// }
|
||||
|
||||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
|
||||
// [SkippableFact]
|
||||
// public void PropertyIsSetAndUnset()
|
||||
// {
|
||||
// using var grVkBackendContext = new GRSharpVkBackendContext();
|
||||
// var baseType = grVkBackendContext as GRVkBackendContext;
|
||||
|
||||
// Assert.Equal(0, (long)baseType.VkPhysicalDeviceFeatures);
|
||||
|
||||
// grVkBackendContext.VkPhysicalDeviceFeatures = new global::SharpVk.PhysicalDeviceFeatures();
|
||||
// Assert.NotEqual(0, (long)baseType.VkPhysicalDeviceFeatures);
|
||||
|
||||
// grVkBackendContext.VkPhysicalDeviceFeatures = null;
|
||||
// Assert.Equal(0, (long)baseType.VkPhysicalDeviceFeatures);
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -0,0 +1,73 @@
|
|||
// using System;
|
||||
// using Xunit;
|
||||
// using SkiaSharp.Tests;
|
||||
|
||||
// namespace SkiaSharp.Direct3D.Tests
|
||||
// {
|
||||
// public class SKSurfaceTest : Direct3DTest
|
||||
// {
|
||||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
|
||||
// [SkippableFact]
|
||||
// public void VkGpuSurfaceIsCreated()
|
||||
// {
|
||||
// using var ctx = CreateVkContext();
|
||||
|
||||
// using var grVkBackendContext = new GRVkBackendContext
|
||||
// {
|
||||
// VkInstance = (IntPtr)ctx.Instance.RawHandle.ToUInt64(),
|
||||
// VkPhysicalDevice = (IntPtr)ctx.PhysicalDevice.RawHandle.ToUInt64(),
|
||||
// VkDevice = (IntPtr)ctx.Device.RawHandle.ToUInt64(),
|
||||
// VkQueue = (IntPtr)ctx.GraphicsQueue.RawHandle.ToUInt64(),
|
||||
// GraphicsQueueIndex = ctx.GraphicsFamily,
|
||||
// GetProcedureAddress = ctx.GetProc
|
||||
// };
|
||||
|
||||
// Assert.NotNull(grVkBackendContext);
|
||||
|
||||
// using var grContext = GRContext.CreateVulkan(grVkBackendContext);
|
||||
|
||||
// using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
|
||||
|
||||
// Assert.NotNull(surface);
|
||||
|
||||
// var canvas = surface.Canvas;
|
||||
// Assert.NotNull(canvas);
|
||||
|
||||
// canvas.Clear(SKColors.Transparent);
|
||||
|
||||
// canvas.Flush();
|
||||
// }
|
||||
|
||||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)]
|
||||
// [SkippableFact]
|
||||
// public void VkGpuSurfaceIsCreatedSharpVkTypes()
|
||||
// {
|
||||
// using var ctx = CreateVkContext();
|
||||
|
||||
// using var grVkBackendContext = new GRSharpVkBackendContext
|
||||
// {
|
||||
// VkInstance = ctx.Instance,
|
||||
// VkPhysicalDevice = ctx.PhysicalDevice,
|
||||
// VkDevice = ctx.Device,
|
||||
// VkQueue = ctx.GraphicsQueue,
|
||||
// GraphicsQueueIndex = ctx.GraphicsFamily,
|
||||
// GetProcedureAddress = ctx.SharpVkGetProc
|
||||
// };
|
||||
|
||||
// Assert.NotNull(grVkBackendContext);
|
||||
|
||||
// using var grContext = GRContext.CreateVulkan(grVkBackendContext);
|
||||
|
||||
// using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));
|
||||
|
||||
// Assert.NotNull(surface);
|
||||
|
||||
// var canvas = surface.Canvas;
|
||||
// Assert.NotNull(canvas);
|
||||
|
||||
// canvas.Clear(SKColors.Transparent);
|
||||
|
||||
// canvas.Flush();
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -0,0 +1,44 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||
<RootNamespace>SkiaSharp.Direct3D.Tests</RootNamespace>
|
||||
<AssemblyName>SkiaSharp.Direct3D.Tests</AssemblyName>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<SkipGenerateAssemblyVersionInfo>true</SkipGenerateAssemblyVersionInfo>
|
||||
<SkipMDocGenerateDocs>true</SkipMDocGenerateDocs>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
|
||||
<PackageReference Include="XunitXml.TestLogger" Version="3.0.78" />
|
||||
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
|
||||
<PackageReference Include="Vortice.Direct3D12" Version="3.5.0" />
|
||||
<PackageReference Include="coverlet.msbuild" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\binding\HarfBuzzSharp\HarfBuzzSharp.csproj" />
|
||||
<ProjectReference Include="..\..\binding\SkiaSharp\SkiaSharp.csproj" />
|
||||
<ProjectReference Include="..\..\binding\SkiaSharp.SceneGraph\SkiaSharp.SceneGraph.csproj" />
|
||||
<ProjectReference Include="..\..\binding\SkiaSharp.Skottie\SkiaSharp.Skottie.csproj" />
|
||||
<ProjectReference Include="..\..\source\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz.csproj" />
|
||||
<ProjectReference Include="..\..\source\SkiaSharp.Direct3D\SkiaSharp.Direct3D.Vortice\SkiaSharp.Direct3D.Vortice.csproj" />
|
||||
<ProjectReference Include="..\SkiaSharp.Tests.Console\SkiaSharp.Tests.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Direct3DTests\**\*.cs" Link="%(RecursiveDir)%(FileName)%(Extension)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Content\**\*" Link="%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="Always" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\..\binding\IncludeNativeAssets.SkiaSharp.targets" />
|
||||
<Import Project="..\..\binding\IncludeNativeAssets.HarfBuzzSharp.targets" />
|
||||
|
||||
</Project>
|
|
@ -23,6 +23,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Skottie", "..\bin
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "source", "source", "{9FAA974B-A671-40BC-82EA-8EF77F463ECB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Direct3D.Vortice", "..\source\SkiaSharp.Direct3D\SkiaSharp.Direct3D.Vortice\SkiaSharp.Direct3D.Vortice.csproj", "{E8AACE39-87A4-4BA7-9988-4847C4A80947}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Direct3D.Tests.Console", "SkiaSharp.Direct3D.Tests.Console\SkiaSharp.Direct3D.Tests.Console.csproj", "{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -141,6 +145,30 @@ Global
|
|||
{D35696BA-3038-41F2-9BE9-181439E6EF9E}.Release|x64.Build.0 = Release|Any CPU
|
||||
{D35696BA-3038-41F2-9BE9-181439E6EF9E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D35696BA-3038-41F2-9BE9-181439E6EF9E}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947}.Release|x86.Build.0 = Release|Any CPU
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Debug|x64.Build.0 = Debug|x64
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Debug|x86.Build.0 = Debug|x86
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Release|x64.ActiveCfg = Release|x64
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Release|x64.Build.0 = Release|x64
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Release|x86.ActiveCfg = Release|x86
|
||||
{229FC9FB-F2F6-4B08-9770-2F04FB3AA983}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -153,6 +181,7 @@ Global
|
|||
{978AD2C6-E592-4F5E-B565-26C357877B2C} = {9FAA974B-A671-40BC-82EA-8EF77F463ECB}
|
||||
{AD2C6978-4F5E-E592-B565-26C357877B2C} = {9FAA974B-A671-40BC-82EA-8EF77F463ECB}
|
||||
{D35696BA-3038-41F2-9BE9-181439E6EF9E} = {9FAA974B-A671-40BC-82EA-8EF77F463ECB}
|
||||
{E8AACE39-87A4-4BA7-9988-4847C4A80947} = {9FAA974B-A671-40BC-82EA-8EF77F463ECB}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8355B800-A642-459B-8675-B545839DE6C7}
|
||||
|
|
Загрузка…
Ссылка в новой задаче