Skip to content

Commit

Permalink
Initial d2d1 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosnhatred committed Aug 24, 2022
1 parent 35e529a commit 440a541
Show file tree
Hide file tree
Showing 14 changed files with 1,333 additions and 200 deletions.
87 changes: 48 additions & 39 deletions Patchwork.Framework.Dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platform", "Platform", "{CF
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2E0F2A5F-45F7-4023-BF7A-143D0031B90E}"
ProjectSection(SolutionItems) = preProject
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
CODESTYLE.md = CODESTYLE.md
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
CONTRIBUTING.md = CONTRIBUTING.md
Directory.Build.props = Directory.Build.props
src\FodyWeavers.xml = src\FodyWeavers.xml
Expand Down Expand Up @@ -96,44 +96,6 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsApp-Net6", "samples\WindowsApp-Net6\WindowsApp-Net6.csproj", "{B870805D-46D1-4690-8EDA-2B3624B1D1C1}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Platform\Patchwork.Framework.DirectX\Patchwork.Framework.DirectX.projitems*{1b5d1859-9372-45dd-a5e9-830b392418d2}*SharedItemsImports = 13
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{2a7c3663-0cb2-45dd-a52d-55ff3a6ab949}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Mobile\Patchwork.Framework.Mobile.projitems*{2fef6f21-fca7-4282-8fed-cea9b0261a83}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Android\Patchwork.Framework.Android.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Mobile\Patchwork.Framework.Mobile.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Android\Patchwork.Framework.Android.projitems*{5cd3f1a7-43d7-4fb2-bec0-81ff1ee8704b}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{6e5462b8-0293-4944-8229-df5d4fdf1183}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{6f55f2da-a116-422e-8468-f8c8947f6064}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{8262adec-5c8c-4270-996f-b352ad34d163}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Linux\Patchwork.Framework.Linux.projitems*{c6806c4e-c4e9-4736-ac25-300cd08b244c}*SharedItemsImports = 13
src\System.Drawing\System.Drawing.projitems*{dc0efc52-d116-4c15-a296-2eca1a62479e}*SharedItemsImports = 13
src\Patchwork.Framework\Patchwork.Framework.projitems*{dff5f575-ace9-41ce-89a9-e82d0dc8ca6c}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.DirectX\Patchwork.Framework.DirectX.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{e3bb4d7b-fda8-4f9d-b4e9-1613506f1e2e}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{e4609d0b-3a70-4ae1-9462-042a72263376}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{f81b5c8f-475f-466c-b028-d7e248c05897}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Android = Debug|Android
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -297,4 +259,51 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A53841F6-1E2B-46A5-82DE-2A2FF30168E4}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Platform\Patchwork.Framework.DirectX\Patchwork.Framework.DirectX.projitems*{1b5d1859-9372-45dd-a5e9-830b392418d2}*SharedItemsImports = 13
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{2a7c3663-0cb2-45dd-a52d-55ff3a6ab949}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.DirectX\Patchwork.Framework.DirectX.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{2c888852-e914-4ab4-904d-4ee959200233}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Mobile\Patchwork.Framework.Mobile.projitems*{2fef6f21-fca7-4282-8fed-cea9b0261a83}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Android\Patchwork.Framework.Android.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Mobile\Patchwork.Framework.Mobile.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{40991e61-4ee1-4d67-8bc9-abd05ab21d70}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Android\Patchwork.Framework.Android.projitems*{5cd3f1a7-43d7-4fb2-bec0-81ff1ee8704b}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{659ffa04-d773-41e6-907a-e12fcbeb82f1}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{6e5462b8-0293-4944-8229-df5d4fdf1183}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{6f55f2da-a116-422e-8468-f8c8947f6064}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{8262adec-5c8c-4270-996f-b352ad34d163}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Linux\Patchwork.Framework.Linux.projitems*{c6806c4e-c4e9-4736-ac25-300cd08b244c}*SharedItemsImports = 13
src\System.Drawing\System.Drawing.projitems*{dc0efc52-d116-4c15-a296-2eca1a62479e}*SharedItemsImports = 13
src\Patchwork.Framework\Patchwork.Framework.projitems*{dff5f575-ace9-41ce-89a9-e82d0dc8ca6c}*SharedItemsImports = 13
src\Patchwork.Framework.Display\Patchwork.Framework.Display.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework.Rendering\Patchwork.Framework.Rendering.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework\Patchwork.Framework.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Desktop\Patchwork.Framework.Desktop.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.DirectX\Patchwork.Framework.DirectX.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Gdi\Patchwork.Framework.Gdi.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{e369dda2-26d2-4558-943d-303306f80a53}*SharedItemsImports = 5
src\Patchwork.Framework.Windowing\Patchwork.Framework.Windowing.projitems*{e3bb4d7b-fda8-4f9d-b4e9-1613506f1e2e}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Windows\Patchwork.Framework.Windows.projitems*{e4609d0b-3a70-4ae1-9462-042a72263376}*SharedItemsImports = 13
src\Platform\Patchwork.Framework.Skia\Patchwork.Framework.Skia.projitems*{f81b5c8f-475f-466c-b028-d7e248c05897}*SharedItemsImports = 13
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\NRenderTarget.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\RenderLevel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\RenderPriority.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\NRenderResourceFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Windowing\INWindow.Rendering.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\INWindowRenderer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Windowing\IWindowDataCache.Rendering.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using Shin.Framework;
using Shin.Framework.Collections.Concurrent;
using Shin.Framework.IoC.DependencyInjection;

namespace Patchwork.Framework.Platform.Rendering
{
public abstract class NRenderResourceFactory : Initializable, INResourceFactory
{
protected IContainer m_iocContainer;
protected ConcurrentList<Type> m_supportedResources;

public NRenderResourceFactory(IContainer iocContainer)
{
m_iocContainer = iocContainer.CreateChildContainer();
}

/// <inheritdoc />
public event EventHandler OnCreate;

/// <inheritdoc />
public event EventHandler OnDestroy;

/// <inheritdoc />
public IEnumerable<Type> SupportedResources
{
get { return m_supportedResources; }
}

/// <inheritdoc />
protected override void InitializeResources()
{
base.InitializeResources();

m_supportedResources = new ConcurrentList<Type>();
RegisterResources();
foreach (var resource in m_supportedResources)
m_iocContainer.Register(resource);
}

protected abstract void RegisterResources();

/// <inheritdoc />
public virtual T Create<T>(params object[] parameters) where T : INResource
{
Throw.If(!m_supportedResources.Contains(typeof(T))).InvalidOperationException();
var r = m_iocContainer.Resolve<T>(null, parameters);
if (m_isInitialized)
r.Create();

return r;
}

/// <inheritdoc />
public virtual void Destroy<T>(T instance) where T : INResource
{
Throw.If(!m_supportedResources.Contains(typeof(T))).InvalidOperationException();
instance.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<Import_RootNamespace>Patchwork.Framework</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\D2D1RenderAdapter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\D2D1RenderDevice.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\D2D1Adapter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\D2D1Device.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\D2D1ResourceFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\D2D1WindowRenderer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Platform\Rendering\Resources\D2D1RenderTarget.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Patchwork.Framework.Platform.Rendering
{
public class D2D1RenderAdapter : NRenderAdapter
public class D2D1Adapter : NRenderAdapter
{
/// <inheritdoc />
protected override void PlatformFlush()
Expand All @@ -18,5 +18,8 @@ protected override void PlatformSwapBuffers()
{
throw new NotImplementedException();
}

/// <inheritdoc />
public D2D1Adapter(INRenderDevice device, INResourceFactory factory) : base(device, factory) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
using Patchwork.Framework.Platform.Windowing;
using Shin.Framework.IoC.DependencyInjection;

namespace Patchwork.Framework.Platform.Rendering
{
public class D2D1Device : NRenderDevice<D2D1Adapter>
{
/// <inheritdoc />
protected override void RegisterRenderers()
{
m_iocContainer.Register<INRenderDevice>(this);
m_iocContainer.Register<INRenderAdapter, D2D1Adapter>();
m_iocContainer.Register<INResourceFactory, D2D1ResourceFactory>();
m_iocContainer.Register<INWindowRenderer, D2D1WindowRenderer>(false);
m_supportedRenderers.Add(typeof(D2D1WindowRenderer));
}

/// <inheritdoc />
protected override void PlatformSetFrameBuffer(NFrameBuffer buffer)
{
return;
}

/// <inheritdoc />
protected override void PlatformGetDpi(INWindow window)
{
return;
}

/// <inheritdoc />
public D2D1Device(IContainer iocContainer) : base(iocContainer) { }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;
using Patchwork.Framework.Platform.Rendering.Resources;
using SharpGen.Runtime;
using Shin.Framework;
using Shin.Framework.IoC.DependencyInjection;
using Vortice.Direct2D1;
using D2D1 = Vortice.Direct2D1.D2D1;

namespace Patchwork.Framework.Platform.Rendering
{
public sealed class D2D1ResourceFactory : NRenderResourceFactory
{
private ID2D1Factory2 m_d2D1Factory;

/// <inheritdoc />
public D2D1ResourceFactory(IContainer iocContainer) : base(iocContainer) { }

/// <inheritdoc />
protected override void InitializeResources()
{
base.InitializeResources();

var res = D2D1.D2D1CreateFactory(FactoryType.MultiThreaded, out m_d2D1Factory);
Throw.If(res != Result.Ok).InvalidOperationException();
m_iocContainer.Register(m_d2D1Factory);
}

/// <inheritdoc />
protected override void DisposeManagedResources()
{
m_d2D1Factory.Dispose();

base.DisposeManagedResources();
}


/// <inheritdoc />
protected override void RegisterResources()
{
m_supportedResources.Add(typeof(D2D1RenderTarget));
}
}
}
Loading

0 comments on commit 440a541

Please sign in to comment.