diff --git a/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj b/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj index ffe8352865..4c3cfe2ef4 100644 --- a/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj +++ b/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj @@ -23,6 +23,7 @@ + diff --git a/tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj b/tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj index 941d377a17..0ddee2ad7a 100644 --- a/tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj +++ b/tests/Avalonia.Benchmarks/Avalonia.Benchmarks.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs b/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs index 0adabc75f1..4dad8442de 100644 --- a/tests/Avalonia.Benchmarks/Text/HugeTextLayout.cs +++ b/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) diff --git a/tests/Avalonia.UnitTests/MockGlyphRun.cs b/tests/Avalonia.UnitTests/MockGlyphRun.cs index 45e7b47f62..477f34565f 100644 --- a/tests/Avalonia.UnitTests/MockGlyphRun.cs +++ b/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 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; }