Skip to content

Commit

Permalink
D2D1: Svg improvements and remove some legacy code.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Mar 29, 2023
1 parent a97d350 commit fc1540a
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 280 deletions.
150 changes: 150 additions & 0 deletions src/Vortice.Direct2D1/ID2D1SvgElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Collections;

namespace Vortice.Direct2D1;

public unsafe partial class ID2D1SvgElement : IEnumerable<ID2D1SvgElement>
{
public string TextValue
{
get
{
int length = GetTextValueLength();
char* chars = stackalloc char[length + 1];
GetTextValue(chars, length + 1).CheckError();
return new string(chars, 0, length);
}
}

public string TagName
{
get
{
int length = GetTagNameLength();
char* chars = stackalloc char[length + 1];
GetTagName(chars, length + 1).CheckError();
return new string(chars, 0, length);
}
}

public IEnumerator<ID2D1SvgElement> GetEnumerator()
{
ID2D1SvgElement? child = GetFirstChild();
while (child != null)
{
yield return child;
child = child.GetNextChild(child);
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public IEnumerable<ID2D1SvgElement> DescendantsAndSelf()
{
yield return this;
foreach (ID2D1SvgElement child in this)
{
foreach (ID2D1SvgElement descendant in child.DescendantsAndSelf())
{
yield return descendant;
}
}
}

public IEnumerable<ID2D1SvgElement> Descendants()
{
foreach (ID2D1SvgElement child in this)
{
yield return child;
foreach (ID2D1SvgElement grandchild in child.Descendants())
{
yield return grandchild;
}
}
}

public Result SetAttributeValue(string name, float value)
{
return SetAttributeValue(name, SvgAttributePodType.Float, &value, sizeof(float));
}

public Result SetAttributeValue(string name, Color4 value)
{
return SetAttributeValue(name, SvgAttributePodType.Color, (float*)&value, sizeof(Color4));
}

public Result SetAttributeValue(string name, FillMode value)
{
return SetAttributeValue(name, SvgAttributePodType.FillMode, &value, sizeof(FillMode));
}

public Result SetAttributeValue(string name, SvgDisplay value)
{
return SetAttributeValue(name, SvgAttributePodType.Display, &value, sizeof(SvgDisplay));
}

public Result SetAttributeValue(string name, SvgOverflow value)
{
return SetAttributeValue(name, SvgAttributePodType.Overflow, &value, sizeof(SvgOverflow));
}

public Result SetAttributeValue(string name, SvgLineJoin value)
{
return SetAttributeValue(name, SvgAttributePodType.LineJoin, &value, sizeof(SvgLineJoin));
}

public Result SetAttributeValue(string name, SvgLineCap value)
{
return SetAttributeValue(name, SvgAttributePodType.LineCap, &value, sizeof(SvgLineCap));
}

public Result SetAttributeValue(string name, SvgVisibility value)
{
return SetAttributeValue(name, SvgAttributePodType.Visibility, &value, sizeof(SvgVisibility));
}

public Result SetAttributeValue(string name, Matrix3x2 value)
{
return SetAttributeValue(name, SvgAttributePodType.Matrix, (float*)&value, sizeof(Matrix3x2));
}

public Result SetAttributeValue(string name, SvgUnitType value)
{
return SetAttributeValue(name, SvgAttributePodType.UnitType, &value, sizeof(SvgUnitType));
}

public Result SetAttributeValue(string name, ExtendMode value)
{
return SetAttributeValue(name, SvgAttributePodType.ExtendMode, &value, sizeof(ExtendMode));
}

public Result SetAttributeValue(string name, SvgPreserveAspectRatio value)
{
return SetAttributeValue(name, SvgAttributePodType.PreserveAspectRatio, &value, sizeof(SvgPreserveAspectRatio));
}

public Result SetAttributeValue(string name, SvgViewbox value)
{
return SetAttributeValue(name, SvgAttributePodType.Viewbox, &value, sizeof(SvgViewbox));
}

public Result SetAttributeValue(string name, SvgLength value)
{
return SetAttributeValue(name, SvgAttributePodType.Length, &value, sizeof(SvgLength));
}

public Result SetAttributeValue<T>(string name, SvgAttributePodType type, in T value) where T : unmanaged
{
fixed (T* pValue = &value)
{
return SetAttributeValue(name, type, (IntPtr)pValue, sizeof(T));
}
}

private Result SetAttributeValue(string name, SvgAttributePodType type, void* value, int valueSizeInBytes)
{
return SetAttributeValue(name, type, (IntPtr)value, valueSizeInBytes);
}
}
14 changes: 14 additions & 0 deletions src/Vortice.Direct2D1/Mappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<bind from="VORTICE_COLOR4" to="Vortice.Mathematics.Color4" />
<bind from="LOGFONTW" to="Vortice.Gdi.LogFont"/>
<bind from="FONTSIGNATURE" to="Vortice.Gdi.FontSignature" />
<bind from="D3DCOLORVALUE" to="Vortice.Mathematics.Color4" override="true" />
</bindings>

<naming>
Expand Down Expand Up @@ -483,6 +484,19 @@
<map param="ID2D1Properties::GetValue::data" type="void" keep-pointers="true"/>
<map param="ID2D1Properties::SetValue::data" type="void" keep-pointers="true"/>

<!-- ID2D1SvgElement -->
<map method="ID2D1SvgElement::GetDocument" persist="true"/>

<map method="ID2D1SvgElement::GetTagNameLength" visibility="private" property="false" />
<map method="ID2D1SvgElement::GetTagName" visibility="private" hresult="true" check="false" />
<map param="ID2D1SvgElement::GetTagName::name" type="void" keep-pointers="true"/>

<map method="ID2D1SvgElement::GetTextValueLength" visibility="private" property="false" />
<map method="ID2D1SvgElement::GetTextValue" visibility="private" hresult="true" check="false" />
<map param="ID2D1SvgElement::GetTextValue::name" type="void" keep-pointers="true"/>

<map method="ID2D1SvgElement::SetAttributeValue" hresult="true" check="false" />

<!--IWICStream-->
<map method="IWICStream::InitializeFrom.*" visibility="internal" hresult="true" check="false" />
<map param="IWICStream::InitializeFromMemory::pbBuffer" type="void" keep-pointers="true"/>
Expand Down
18 changes: 18 additions & 0 deletions src/Vortice.Direct2D1/SvgLength.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Drawing;

namespace Vortice.Direct2D1;

public partial struct SvgLength
{
/// <summary>
/// Initializes a new instance of the <see cref="SvgLength"/> struct.
/// </summary>
public SvgLength(float value, SvgLengthUnits units)
{
Value = value;
Units = units;
}
}
19 changes: 19 additions & 0 deletions src/Vortice.Direct2D1/SvgPreserveAspectRatio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Drawing;

namespace Vortice.Direct2D1;

public partial struct SvgPreserveAspectRatio
{
/// <summary>
/// Initializes a new instance of the <see cref="SvgLength"/> struct.
/// </summary>
public SvgPreserveAspectRatio(bool defer, SvgAspectAlign align, SvgAspectScaling meetOrSlice)
{
Defer = defer;
Align = align;
MeetOrSlice = meetOrSlice;
}
}
20 changes: 20 additions & 0 deletions src/Vortice.Direct2D1/SvgViewbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using System.Drawing;

namespace Vortice.Direct2D1;

public partial struct SvgViewbox
{
/// <summary>
/// Initializes a new instance of the <see cref="SvgViewbox"/> struct.
/// </summary>
public SvgViewbox(float x, float y, float width, float height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
}
4 changes: 0 additions & 4 deletions src/Vortice.Direct3D11/BlendDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ public partial struct RenderTarget__FixedBuffer
[UnscopedRef]
public Span<RenderTargetBlendDescription> AsSpan()
{
#if NET6_0_OR_GREATER
return MemoryMarshal.CreateSpan(ref e0, 8);
#else
return UnsafeUtilities.CreateSpan(ref e0, 8);
#endif
}
}
}
8 changes: 0 additions & 8 deletions src/Vortice.Direct3D11/D3D11.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public static partial class D3D11
/// <typeparam name="T">Type of IDirect3DDevice.</typeparam>
/// <param name="dxgiDevice"></param>
/// <returns></returns>
#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public static T CreateDirect3D11DeviceFromDXGIDevice<T>(IDXGIDevice dxgiDevice)
{
CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice, out IntPtr graphicsDevicePtr).CheckError();
Expand All @@ -25,9 +23,7 @@ public static T CreateDirect3D11DeviceFromDXGIDevice<T>(IDXGIDevice dxgiDevice)
return graphicsDevice;
}

#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public static Result CreateDirect3D11DeviceFromDXGIDevice<T>(IDXGIDevice dxgiDevice, out T? graphicsDevice)
{
Result result = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice, out IntPtr graphicsDevicePtr);
Expand All @@ -48,9 +44,7 @@ public static Result CreateDirect3D11DeviceFromDXGIDevice<T>(IDXGIDevice dxgiDev
/// <typeparam name="T">Type of IDirect3DSurface class.</typeparam>
/// <param name="dgxiSurface"></param>
/// <returns></returns>
#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public static T CreateDirect3D11SurfaceFromDXGISurface<T>(IDXGISurface dgxiSurface)
{
CreateDirect3D11SurfaceFromDXGISurface(dgxiSurface, out IntPtr graphicsSurfacePtr).CheckError();
Expand All @@ -59,9 +53,7 @@ public static T CreateDirect3D11SurfaceFromDXGISurface<T>(IDXGISurface dgxiSurfa
return graphicsSurface;
}

#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public static Result CreateDirect3D11SurfaceFromDXGISurface<T>(IDXGISurface dgxiSurface, out T? graphicsSurface)
{
Result result = CreateDirect3D11SurfaceFromDXGISurface(dgxiSurface, out IntPtr graphicsSurfacePtr);
Expand Down
4 changes: 0 additions & 4 deletions src/Vortice.Direct3D12/BlendDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ public partial struct RenderTarget__FixedBuffer
[UnscopedRef]
public Span<RenderTargetBlendDescription> AsSpan()
{
#if NET6_0_OR_GREATER
return MemoryMarshal.CreateSpan(ref e0, 8);
#else
return UnsafeUtilities.CreateSpan(ref e0, 8);
#endif
}
}
}
7 changes: 0 additions & 7 deletions src/Vortice.Direct3D9/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,4 @@ public static int ToBgra(in Color color)

return (int)value;
}

#if !NET6_0_OR_GREATER
public static unsafe Span<T> CreateSpan<T>(ref T value, int length)
{
return new(Unsafe.AsPointer(ref value), length);
}
#endif
}
4 changes: 0 additions & 4 deletions src/Vortice.Direct3D9/Luid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace Vortice.Direct3D9;
/// A locally unique identifier for a graphics device.
/// </summary>
public readonly struct Luid : IEquatable<Luid>
#if NET6_0_OR_GREATER
, ISpanFormattable
#endif
{
/// <summary>
/// The low bits of the luid.
Expand Down Expand Up @@ -74,7 +72,6 @@ public override string ToString()
return (((long)HighPart) << 32 | LowPart).ToString();
}

#if NET6_0_OR_GREATER
/// <inheritdoc/>
[Pure]
public string ToString(string? format, IFormatProvider? formatProvider)
Expand All @@ -87,7 +84,6 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
{
return (((long)HighPart) << 32 | LowPart).TryFormat(destination, out charsWritten, format, provider);
}
#endif

/// <summary>
/// Check whether two <see cref="Luid"/> values are equal.
Expand Down
2 changes: 0 additions & 2 deletions src/Vortice.DirectML/DML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Vortice.DirectML;
public static partial class DML
{

#if NET6_0_OR_GREATER
public static event DllImportResolver? ResolveLibrary;

static DML()
Expand Down Expand Up @@ -109,7 +108,6 @@ private static bool TryResolveLibrary(string libraryName, System.Reflection.Asse
nativeLibrary = IntPtr.Zero;
return false;
}
#endif

public static IDMLDevice DMLCreateDevice(ID3D12Device d3d12Device, CreateDeviceFlags createDeviceFlags)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Vortice.DirectStorage/DirectStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Vortice.DirectStorage;

public static partial class DirectStorage
{
#if NET6_0_OR_GREATER
public static event DllImportResolver? ResolveLibrary;

static DirectStorage()
Expand Down Expand Up @@ -92,7 +91,6 @@ private static bool TryResolveLibrary(string libraryName, System.Reflection.Asse
nativeLibrary = IntPtr.Zero;
return false;
}
#endif

/// <summary>
/// Returns the static DStorage factory object used to create DStorage queues,
Expand Down
4 changes: 0 additions & 4 deletions src/Vortice.DirectX/Luid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace Vortice;
/// A locally unique identifier for a graphics device.
/// </summary>
public readonly struct Luid : IEquatable<Luid>
#if NET6_0_OR_GREATER
, ISpanFormattable
#endif
{
/// <summary>
/// The low bits of the luid.
Expand Down Expand Up @@ -74,7 +72,6 @@ public override string ToString()
return (((long)HighPart) << 32 | LowPart).ToString();
}

#if NET6_0_OR_GREATER
/// <inheritdoc/>
[Pure]
public string ToString(string? format, IFormatProvider? formatProvider)
Expand All @@ -87,7 +84,6 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
{
return (((long)HighPart) << 32 | LowPart).TryFormat(destination, out charsWritten, format, provider);
}
#endif

/// <summary>
/// Check whether two <see cref="Luid"/> values are equal.
Expand Down
Loading

0 comments on commit fc1540a

Please sign in to comment.