Skip to content

Commit

Permalink
Merge branch 'main' into metal-tfm
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Mar 29, 2024
2 parents 33057c3 + 510e738 commit d0cde3d
Show file tree
Hide file tree
Showing 18 changed files with 1,239 additions and 3,057 deletions.
2,834 changes: 0 additions & 2,834 deletions .github/fabricbot.json

This file was deleted.

562 changes: 562 additions & 0 deletions .github/policies/resourceManagement.yml

Large diffs are not rendered by default.

130 changes: 85 additions & 45 deletions binding/SkiaSharp/SKRunBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#nullable disable

using System;
using System.ComponentModel;

namespace SkiaSharp
{
// Base

public unsafe class SKRunBuffer
{
internal readonly SKRunBufferInternal internalBuffer;
Expand All @@ -17,103 +18,142 @@ internal SKRunBuffer (SKRunBufferInternal buffer, int size)

public int Size { get; }

public Span<ushort> GetGlyphSpan () =>
new Span<ushort> (internalBuffer.glyphs, internalBuffer.glyphs == null ? 0 : Size);
public Span<ushort> Glyphs => new (internalBuffer.glyphs, Size);

public void SetGlyphs (ReadOnlySpan<ushort> glyphs) => glyphs.CopyTo (Glyphs);

public void SetGlyphs (ReadOnlySpan<ushort> glyphs) =>
glyphs.CopyTo (GetGlyphSpan ());
[Obsolete ("Use Glyphs instead.")]
public Span<ushort> GetGlyphSpan () => Glyphs;
}

public sealed unsafe class SKHorizontalRunBuffer : SKRunBuffer
{
internal SKHorizontalRunBuffer (SKRunBufferInternal buffer, int count)
: base (buffer, count)
internal SKHorizontalRunBuffer (SKRunBufferInternal buffer, int size)
: base (buffer, size)
{
}

public Span<float> GetPositionSpan () =>
new Span<float> (internalBuffer.pos, internalBuffer.pos == null ? 0 : Size);
public Span<float> Positions => new (internalBuffer.pos, Size);

public void SetPositions (ReadOnlySpan<float> positions) =>
positions.CopyTo (GetPositionSpan ());
public void SetPositions (ReadOnlySpan<float> positions) => positions.CopyTo (Positions);

[Obsolete ("Use Positions instead.")]
public Span<float> GetPositionSpan () => Positions;
}

public sealed unsafe class SKPositionedRunBuffer : SKRunBuffer
{
internal SKPositionedRunBuffer (SKRunBufferInternal buffer, int count)
: base (buffer, count)
internal SKPositionedRunBuffer (SKRunBufferInternal buffer, int size)
: base (buffer, size)
{
}

public Span<SKPoint> GetPositionSpan () =>
new Span<SKPoint> (internalBuffer.pos, internalBuffer.pos == null ? 0 : Size);
public Span<SKPoint> Positions => new (internalBuffer.pos, Size);

public void SetPositions (ReadOnlySpan<SKPoint> positions) => positions.CopyTo (Positions);

public void SetPositions (ReadOnlySpan<SKPoint> positions) =>
positions.CopyTo (GetPositionSpan ());
[Obsolete ("Use Positions instead.")]
public Span<SKPoint> GetPositionSpan () => Positions;
}

public sealed unsafe class SKRotationScaleRunBuffer : SKRunBuffer
{
internal SKRotationScaleRunBuffer (SKRunBufferInternal buffer, int count)
: base (buffer, count)
internal SKRotationScaleRunBuffer (SKRunBufferInternal buffer, int size)
: base (buffer, size)
{
}

public Span<SKRotationScaleMatrix> GetRotationScaleSpan () =>
new Span<SKRotationScaleMatrix> (internalBuffer.pos, Size);
public Span<SKRotationScaleMatrix> Positions => new (internalBuffer.pos, Size);

public void SetRotationScale (ReadOnlySpan<SKRotationScaleMatrix> positions) =>
positions.CopyTo (GetRotationScaleSpan ());
public void SetPositions (ReadOnlySpan<SKRotationScaleMatrix> positions) => positions.CopyTo (Positions);

[Obsolete ("Use Positions instead.")]
public Span<SKRotationScaleMatrix> GetRotationScaleSpan () => Positions;

[Obsolete ("Use SetPositions instead.")]
public void SetRotationScale (ReadOnlySpan<SKRotationScaleMatrix> positions) => SetPositions (positions);
}

// Text

public unsafe class SKTextRunBuffer : SKRunBuffer
{
internal SKTextRunBuffer (SKRunBufferInternal buffer, int count, int textSize)
: base (buffer, count)
internal SKTextRunBuffer (SKRunBufferInternal buffer, int size, int textSize)
: base (buffer, size)
{
TextSize = textSize;
}

public int TextSize { get; }

public Span<byte> GetTextSpan () =>
new Span<byte> (internalBuffer.utf8text, internalBuffer.utf8text == null ? 0 : TextSize);
public Span<byte> Text => new (internalBuffer.utf8text, TextSize);

public Span<uint> GetClusterSpan () =>
new Span<uint> (internalBuffer.clusters, internalBuffer.clusters == null ? 0 : Size);
public Span<uint> Clusters => new (internalBuffer.clusters, Size);

public void SetText (ReadOnlySpan<byte> text) =>
text.CopyTo (GetTextSpan ());
public void SetText (ReadOnlySpan<byte> text) => text.CopyTo (Text);

public void SetClusters (ReadOnlySpan<uint> clusters) =>
clusters.CopyTo (GetClusterSpan ());
public void SetClusters (ReadOnlySpan<uint> clusters) => clusters.CopyTo (Clusters);
}

public sealed unsafe class SKHorizontalTextRunBuffer : SKTextRunBuffer
{
internal SKHorizontalTextRunBuffer (SKRunBufferInternal buffer, int count, int textSize)
: base (buffer, count, textSize)
internal SKHorizontalTextRunBuffer (SKRunBufferInternal buffer, int size, int textSize)
: base (buffer, size, textSize)
{
}

public Span<float> GetPositionSpan () =>
new Span<float> (internalBuffer.pos, internalBuffer.pos == null ? 0 : Size);
public Span<float> Positions => new (internalBuffer.pos, Size);

public void SetPositions (ReadOnlySpan<float> positions) =>
positions.CopyTo (GetPositionSpan ());
public void SetPositions (ReadOnlySpan<float> positions) => positions.CopyTo (Positions);
}

public sealed unsafe class SKPositionedTextRunBuffer : SKTextRunBuffer
{
internal SKPositionedTextRunBuffer (SKRunBufferInternal buffer, int count, int textSize)
: base (buffer, count, textSize)
internal SKPositionedTextRunBuffer (SKRunBufferInternal buffer, int size, int textSize)
: base (buffer, size, textSize)
{
}

public Span<SKPoint> GetPositionSpan () =>
new Span<SKPoint> (internalBuffer.pos, internalBuffer.pos == null ? 0 : Size);
public Span<SKPoint> Positions => new (internalBuffer.pos, Size);

public void SetPositions (ReadOnlySpan<SKPoint> positions) => positions.CopyTo (Positions);
}

public sealed unsafe class SKRotationScaleTextRunBuffer : SKTextRunBuffer
{
internal SKRotationScaleTextRunBuffer (SKRunBufferInternal buffer, int size, int textSize)
: base (buffer, size, textSize)
{
}

public Span<SKRotationScaleMatrix> Positions => new (internalBuffer.pos, Size);

public void SetPositions (ReadOnlySpan<SKRotationScaleMatrix> positions) => positions.CopyTo (Positions);
}

// Raw / Struct

public unsafe readonly struct SKRawRunBuffer<T>
{
internal readonly SKRunBufferInternal buffer;
private readonly int size;
private readonly int posSize;
private readonly int textSize;

internal SKRawRunBuffer (SKRunBufferInternal buffer, int size, int posSize, int textSize)
{
this.buffer = buffer;
this.size = size;
this.posSize = posSize;
this.textSize = textSize;
}

public Span<ushort> Glyphs => new (buffer.glyphs, size);

public Span<T> Positions => new (buffer.pos, posSize);

public Span<byte> Text => new (buffer.utf8text, textSize);

public void SetPositions (ReadOnlySpan<SKPoint> positions) =>
positions.CopyTo (GetPositionSpan ());
public Span<uint> Clusters => new (buffer.clusters, size);
}
}
Loading

0 comments on commit d0cde3d

Please sign in to comment.