csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.1 KiB
63 lines
2.1 KiB
using System;
|
|
|
|
using Avalonia.Controls;
|
|
using Avalonia.Markup.Xaml.Styling;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Styling;
|
|
using Avalonia.UnitTests;
|
|
|
|
using BenchmarkDotNet.Attributes;
|
|
|
|
namespace Avalonia.Benchmarks.Themes
|
|
{
|
|
[MemoryDiagnoser]
|
|
public class ThemeBenchmark : IDisposable
|
|
{
|
|
private IDisposable _app;
|
|
|
|
public ThemeBenchmark()
|
|
{
|
|
AssetLoader.RegisterResUriParsers();
|
|
|
|
_app = UnitTestApplication.Start(TestServices.StyledWindow.With(theme: () => null));
|
|
// Add empty style to override it later
|
|
UnitTestApplication.Current.Styles.Add(new Style());
|
|
}
|
|
|
|
[Benchmark]
|
|
[Arguments("avares://Avalonia.Themes.Fluent/FluentDark.xaml")]
|
|
[Arguments("avares://Avalonia.Themes.Fluent/FluentLight.xaml")]
|
|
public bool InitFluentTheme(string themeUri)
|
|
{
|
|
UnitTestApplication.Current.Styles[0] = new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
|
|
{
|
|
Source = new Uri(themeUri)
|
|
};
|
|
return ((IResourceHost)UnitTestApplication.Current).TryGetResource("SystemAccentColor", out _);
|
|
}
|
|
|
|
[Benchmark]
|
|
[Arguments("avares://Avalonia.Themes.Simple/Accents/BaseLight.xaml")]
|
|
[Arguments("avares://Avalonia.Themes.Simple/Accents/BaseDark.xaml")]
|
|
public bool InitDefaultTheme(string themeUri)
|
|
{
|
|
UnitTestApplication.Current.Styles[0] = new Styles
|
|
{
|
|
new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
|
|
{
|
|
Source = new Uri(themeUri)
|
|
},
|
|
new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
|
|
{
|
|
Source = new Uri("avares://Avalonia.Themes.Simple/DefaultTheme.xaml")
|
|
}
|
|
};
|
|
return ((IResourceHost)UnitTestApplication.Current).TryGetResource("ThemeAccentColor", out _);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_app.Dispose();
|
|
}
|
|
}
|
|
}
|
|
|