Browse Source

Benchmarks: option to use Skia for text layout

pull/10047/head
Julien Lebosquain 3 years ago
parent
commit
7a1f74a3d3
  1. 1
      src/Skia/Avalonia.Skia/Avalonia.Skia.csproj
  2. 1
      tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj
  3. 32
      tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs
  4. 10
      tests/Avalonia.UnitTests/MockGlyphRun.cs

1
src/Skia/Avalonia.Skia/Avalonia.Skia.csproj

@ -23,6 +23,7 @@
<ItemGroup Label="InternalsVisibleTo">
<InternalsVisibleTo Include="Avalonia.Skia.RenderTests, PublicKey=$(AvaloniaPublicKey)" />
<InternalsVisibleTo Include="Avalonia.Skia.UnitTests, PublicKey=$(AvaloniaPublicKey)" />
<InternalsVisibleTo Include="Avalonia.Benchmarks, PublicKey=$(AvaloniaPublicKey)" />
</ItemGroup>
<ItemGroup>

1
tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj

@ -10,6 +10,7 @@
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Fluent\Avalonia.Themes.Fluent.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Themes.Simple\Avalonia.Themes.Simple.csproj" />
<ProjectReference Include="..\..\src\Skia\Avalonia.Skia\Avalonia.Skia.csproj" />
<ProjectReference Include="..\Avalonia.UnitTests\Avalonia.UnitTests.csproj" />
</ItemGroup>
<ItemGroup>

32
tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs

@ -3,6 +3,7 @@ using System.Linq;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using Avalonia.Skia;
using Avalonia.UnitTests;
using BenchmarkDotNet.Attributes;
@ -13,24 +14,35 @@ namespace Avalonia.Benchmarks.Text;
[MaxWarmupCount(15)]
public class HugeTextLayout : IDisposable
{
private static readonly Random s_rand = new();
private static readonly bool s_useSkia = true;
private readonly IDisposable _app;
private string[] _manySmallStrings;
private static Random _rand = new Random();
private readonly string[] _manySmallStrings;
private static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&?%$@";
return new string(Enumerable.Repeat(chars, length).Select(s => s[_rand.Next(s.Length)]).ToArray());
return new string(Enumerable.Repeat(chars, length).Select(s => s[s_rand.Next(s.Length)]).ToArray());
}
public HugeTextLayout()
{
_manySmallStrings = Enumerable.Range(0, 1000).Select(x => RandomString(_rand.Next(2, 15))).ToArray();
_app = UnitTestApplication.Start(
TestServices.StyledWindow.With(
renderInterface: new NullRenderingPlatform(),
threadingInterface: new NullThreadingPlatform(),
standardCursorFactory: new NullCursorFactory()));
_manySmallStrings = Enumerable.Range(0, 1000).Select(_ => RandomString(s_rand.Next(2, 15))).ToArray();
var testServices = TestServices.StyledWindow.With(
renderInterface: new NullRenderingPlatform(),
threadingInterface: new NullThreadingPlatform(),
standardCursorFactory: new NullCursorFactory());
if (s_useSkia)
{
testServices = testServices.With(
textShaperImpl: new TextShaperImpl(),
fontManagerImpl: new FontManagerImpl());
}
_app = UnitTestApplication.Start(testServices);
}
private const string Text = @"Though, the objectives of the development of the prominent landmarks can be neglected in most cases, it should be realized that after the completion of the strategic decision gives rise to The Expertise of Regular Program (Carlton Cartwright in The Book of the Key Factor)

10
tests/Avalonia.UnitTests/MockGlyphRun.cs

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Avalonia.Media.TextFormatting;
using Avalonia.Platform;
@ -9,7 +8,14 @@ namespace Avalonia.UnitTests
{
public MockGlyphRun(IReadOnlyList<GlyphInfo> glyphInfos)
{
Size = new Size(glyphInfos.Sum(x=> x.GlyphAdvance), 10);
var width = 0.0;
for (var i = 0; i < glyphInfos.Count; ++i)
{
width += glyphInfos[i].GlyphAdvance;
}
Size = new Size(width, 10);
}
public Size Size { get; }

Loading…
Cancel
Save