From 41c2159aaab900fe59bac30796a7e9ca2dc2e53d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 21 Oct 2018 17:51:21 +0200 Subject: [PATCH 1/9] Use features that are now available in netstandard. Various features were moved into `IRuntimePlatform` because they weren't available on netstandard 1.x. They're now available in netstandard 2 so use them directly. --- src/Avalonia.Base/Platform/IRuntimePlatform.cs | 3 --- src/Avalonia.Controls/AppBuilderBase.cs | 2 +- src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs | 4 ++-- src/Linux/Avalonia.LinuxFramebuffer/Mice.cs | 2 +- .../PortableXaml/AvaloniaRuntimeTypeProvider.cs | 4 +--- src/Shared/PlatformSupport/AssetLoader.cs | 2 +- src/Shared/PlatformSupport/StandardRuntimePlatform.cs | 4 ---- 7 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Avalonia.Base/Platform/IRuntimePlatform.cs b/src/Avalonia.Base/Platform/IRuntimePlatform.cs index 9adb98e689..a0d5d611b3 100644 --- a/src/Avalonia.Base/Platform/IRuntimePlatform.cs +++ b/src/Avalonia.Base/Platform/IRuntimePlatform.cs @@ -5,10 +5,7 @@ namespace Avalonia.Platform { public interface IRuntimePlatform { - Assembly[] GetLoadedAssemblies(); - void PostThreadPoolItem(Action cb); IDisposable StartSystemTimer(TimeSpan interval, Action tick); - string GetStackTrace(); RuntimePlatformInfo GetRuntimeInfo(); IUnmanagedBlob AllocBlob(int size); } diff --git a/src/Avalonia.Controls/AppBuilderBase.cs b/src/Avalonia.Controls/AppBuilderBase.cs index 9561282274..376714b20b 100644 --- a/src/Avalonia.Controls/AppBuilderBase.cs +++ b/src/Avalonia.Controls/AppBuilderBase.cs @@ -222,7 +222,7 @@ namespace Avalonia.Controls private void SetupAvaloniaModules() { - var moduleInitializers = from assembly in AvaloniaLocator.Current.GetService().GetLoadedAssemblies() + var moduleInitializers = from assembly in AppDomain.CurrentDomain.GetAssemblies() from attribute in assembly.GetCustomAttributes() where attribute.ForWindowingSubsystem == "" || attribute.ForWindowingSubsystem == WindowingSubsystemName diff --git a/src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs b/src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs index bae97f503d..fe791e156b 100644 --- a/src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs +++ b/src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs @@ -55,7 +55,7 @@ namespace Avalonia LoadAssembliesInDirectory(); - var windowingSubsystemAttribute = (from assembly in RuntimePlatform.GetLoadedAssemblies() + var windowingSubsystemAttribute = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from attribute in assembly.GetCustomAttributes() where attribute.RequiredOS == os && CheckEnvironment(attribute.EnvironmentChecker) orderby attribute.Priority ascending @@ -65,7 +65,7 @@ namespace Avalonia throw new InvalidOperationException("No windowing subsystem found. Are you missing assembly references?"); } - var renderingSubsystemAttribute = (from assembly in RuntimePlatform.GetLoadedAssemblies() + var renderingSubsystemAttribute = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from attribute in assembly.GetCustomAttributes() where attribute.RequiredOS == os && CheckEnvironment(attribute.EnvironmentChecker) where attribute.RequiresWindowingSubsystem == null diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Mice.cs b/src/Linux/Avalonia.LinuxFramebuffer/Mice.cs index 291374a75e..4fa57dbf00 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Mice.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Mice.cs @@ -22,7 +22,7 @@ namespace Avalonia.LinuxFramebuffer _height = height; } - public void Start() => AvaloniaLocator.Current.GetService().PostThreadPoolItem(Worker); + public void Start() => ThreadPool.UnsafeQueueUserWorkItem(_ => Worker(), null); private void Worker() { diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs index cdb5fc3416..eb52e317b8 100644 --- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs +++ b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaRuntimeTypeProvider.cs @@ -91,9 +91,7 @@ namespace Avalonia.Markup.Xaml.Context private void ScanNewAssemblies() { - IEnumerable assemblies = AvaloniaLocator.Current - .GetService() - ?.GetLoadedAssemblies(); + IEnumerable assemblies = AppDomain.CurrentDomain.GetAssemblies(); if (assemblies != null) { diff --git a/src/Shared/PlatformSupport/AssetLoader.cs b/src/Shared/PlatformSupport/AssetLoader.cs index d73c98415e..3392baee0a 100644 --- a/src/Shared/PlatformSupport/AssetLoader.cs +++ b/src/Shared/PlatformSupport/AssetLoader.cs @@ -157,7 +157,7 @@ namespace Avalonia.Shared.PlatformSupport AssemblyDescriptor rv; if (!AssemblyNameCache.TryGetValue(name, out rv)) { - var loadedAssemblies = AvaloniaLocator.Current.GetService().GetLoadedAssemblies(); + var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); var match = loadedAssemblies.FirstOrDefault(a => a.GetName().Name == name); if (match != null) { diff --git a/src/Shared/PlatformSupport/StandardRuntimePlatform.cs b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs index beed847539..613cf2baf6 100644 --- a/src/Shared/PlatformSupport/StandardRuntimePlatform.cs +++ b/src/Shared/PlatformSupport/StandardRuntimePlatform.cs @@ -13,15 +13,11 @@ namespace Avalonia.Shared.PlatformSupport { internal partial class StandardRuntimePlatform : IRuntimePlatform { - public void PostThreadPoolItem(Action cb) => ThreadPool.UnsafeQueueUserWorkItem(_ => cb(), null); - public Assembly[] GetLoadedAssemblies() => AppDomain.CurrentDomain.GetAssemblies(); public IDisposable StartSystemTimer(TimeSpan interval, Action tick) { return new Timer(_ => tick(), null, interval, interval); } - public string GetStackTrace() => Environment.StackTrace; - public IUnmanagedBlob AllocBlob(int size) => new UnmanagedBlob(this, size); class UnmanagedBlob : IUnmanagedBlob From da55b4b3eddf6613323cada6767a5a46f16b7f90 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 21 Oct 2018 17:53:26 +0200 Subject: [PATCH 2/9] Don't pinvoke to compare threads. This was implemented in native code for netstandard 1, but now we can do it in managed code. Much faster. --- src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs | 3 --- src/Windows/Avalonia.Win32/Win32Platform.cs | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index c3c867d3fb..f0e2c1f689 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -751,9 +751,6 @@ namespace Avalonia.Win32.Interop [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string lpModuleName); - [DllImport("kernel32.dll")] - public static extern uint GetCurrentThreadId(); - [DllImport("user32.dll")] public static extern int GetSystemMetrics(SystemMetric smIndex); diff --git a/src/Windows/Avalonia.Win32/Win32Platform.cs b/src/Windows/Avalonia.Win32/Win32Platform.cs index 33bee4a82a..4b9c0efde7 100644 --- a/src/Windows/Avalonia.Win32/Win32Platform.cs +++ b/src/Windows/Avalonia.Win32/Win32Platform.cs @@ -41,7 +41,7 @@ namespace Avalonia.Win32 class Win32Platform : IPlatformThreadingInterface, IPlatformSettings, IWindowingPlatform, IPlatformIconLoader { private static readonly Win32Platform s_instance = new Win32Platform(); - private static uint _uiThread; + private static Thread _uiThread; private UnmanagedMethods.WndProc _wndProcDelegate; private IntPtr _hwnd; private readonly List _delegates = new List(); @@ -93,7 +93,7 @@ namespace Avalonia.Win32 .Bind().ToConstant(s_instance); Win32GlManager.Initialize(); UseDeferredRendering = deferredRendering; - _uiThread = UnmanagedMethods.GetCurrentThreadId(); + _uiThread = Thread.CurrentThread; if (OleContext.Current != null) AvaloniaLocator.CurrentMutable.Bind().ToSingleton(); @@ -157,7 +157,7 @@ namespace Avalonia.Win32 new IntPtr(SignalL)); } - public bool CurrentThreadIsLoopThread => _uiThread == UnmanagedMethods.GetCurrentThreadId(); + public bool CurrentThreadIsLoopThread => _uiThread == Thread.CurrentThread; public event Action Signaled; From ae08c0032940ff66dde8fed95d601c4f4e034703 Mon Sep 17 00:00:00 2001 From: Benedikt Schroeder Date: Fri, 26 Oct 2018 15:39:20 +0200 Subject: [PATCH 3/9] Uses the system's default font if a font can't be found --- src/Skia/Avalonia.Skia/TypefaceCache.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Skia/Avalonia.Skia/TypefaceCache.cs b/src/Skia/Avalonia.Skia/TypefaceCache.cs index cf862f3400..92d6f514dc 100644 --- a/src/Skia/Avalonia.Skia/TypefaceCache.cs +++ b/src/Skia/Avalonia.Skia/TypefaceCache.cs @@ -12,7 +12,7 @@ namespace Avalonia.Skia /// internal static class TypefaceCache { - public static SKTypeface Default = SKTypeface.FromFamilyName(FontFamily.Default.Name); + public static SKTypeface Default = CreateDefaultTypeface(); static readonly Dictionary> Cache = new Dictionary>(); struct FontKey @@ -49,6 +49,13 @@ namespace Avalonia.Skia // Equals and GetHashCode ommitted } + private static SKTypeface CreateDefaultTypeface() + { + var defaultTypeface = SKTypeface.FromFamilyName(FontFamily.Default.Name) ?? SKTypeface.FromFamilyName(null); + + return defaultTypeface; + } + private static SKTypeface GetTypeface(string name, FontKey key) { var familyKey = name; @@ -62,7 +69,7 @@ namespace Avalonia.Skia { typeface = SKTypeface.FromFamilyName(familyKey, key.Weight, SKFontStyleWidth.Normal, key.Slant); - if (typeface.FamilyName != name) + if (typeface?.FamilyName != name) { typeface = Default; } From bb2b7863cad0707a4624fdc1c240b1347ad48348 Mon Sep 17 00:00:00 2001 From: Benedikt Schroeder Date: Fri, 26 Oct 2018 16:16:56 +0200 Subject: [PATCH 4/9] Add support for font alias in case FontConfig is used in the backend. --- src/Skia/Avalonia.Skia/TypefaceCache.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Skia/Avalonia.Skia/TypefaceCache.cs b/src/Skia/Avalonia.Skia/TypefaceCache.cs index 92d6f514dc..94b9e89962 100644 --- a/src/Skia/Avalonia.Skia/TypefaceCache.cs +++ b/src/Skia/Avalonia.Skia/TypefaceCache.cs @@ -67,12 +67,8 @@ namespace Avalonia.Skia if (!entry.TryGetValue(key, out var typeface)) { - typeface = SKTypeface.FromFamilyName(familyKey, key.Weight, SKFontStyleWidth.Normal, key.Slant); - - if (typeface?.FamilyName != name) - { - typeface = Default; - } + typeface = SKTypeface.FromFamilyName(familyKey, key.Weight, SKFontStyleWidth.Normal, key.Slant) + ?? Default; entry[key] = typeface; } From 0f5643da88824e6baf360307f7e196111386f9cf Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 26 Oct 2018 15:33:29 +0100 Subject: [PATCH 5/9] gpu rendering is the defaults on gtk and avalonia native both these platforms will fallback to SW render if GPU not available. --- src/Avalonia.Native/AvaloniaNativePlatform.cs | 2 +- src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Native/AvaloniaNativePlatform.cs b/src/Avalonia.Native/AvaloniaNativePlatform.cs index 0b5d71039d..091a4ad285 100644 --- a/src/Avalonia.Native/AvaloniaNativePlatform.cs +++ b/src/Avalonia.Native/AvaloniaNativePlatform.cs @@ -120,7 +120,7 @@ namespace Avalonia.Native { public AvaloniaNativeMacOptions MacOptions { get; set; } public bool UseDeferredRendering { get; set; } = true; - public bool UseGpu { get; set; } = false; + public bool UseGpu { get; set; } = true; internal AvaloniaNativeOptions(IAvaloniaNativeFactory factory) { var mac = factory.GetMacOptions(); diff --git a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs index 8444e509fd..7bb8facaf5 100644 --- a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs +++ b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs @@ -148,8 +148,8 @@ namespace Avalonia.Gtk3 public class Gtk3PlatformOptions { - public bool? UseDeferredRendering { get; set; } - public bool? UseGpuAcceleration { get; set; } + public bool? UseDeferredRendering { get; set; } = true; + public bool? UseGpuAcceleration { get; set; } = true; public ICustomGtk3NativeLibraryResolver CustomResolver { get; set; } } } From 7add17a39b4e72da26c5126527ee52c48e94b3c6 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 26 Oct 2018 17:02:26 +0100 Subject: [PATCH 6/9] dont enable gpu by default on gtk --- src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs index 7bb8facaf5..13b610c062 100644 --- a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs +++ b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs @@ -149,7 +149,7 @@ namespace Avalonia.Gtk3 public class Gtk3PlatformOptions { public bool? UseDeferredRendering { get; set; } = true; - public bool? UseGpuAcceleration { get; set; } = true; + public bool? UseGpuAcceleration { get; set; }; public ICustomGtk3NativeLibraryResolver CustomResolver { get; set; } } } From 821606455d34fc354b8dffa49fbfd91fef194255 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 26 Oct 2018 19:50:09 +0100 Subject: [PATCH 7/9] fix gtk3 default settings --- src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs index 13b610c062..8444e509fd 100644 --- a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs +++ b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs @@ -148,8 +148,8 @@ namespace Avalonia.Gtk3 public class Gtk3PlatformOptions { - public bool? UseDeferredRendering { get; set; } = true; - public bool? UseGpuAcceleration { get; set; }; + public bool? UseDeferredRendering { get; set; } + public bool? UseGpuAcceleration { get; set; } public ICustomGtk3NativeLibraryResolver CustomResolver { get; set; } } } From 195944aa1a5721666e480195702437f6d5062506 Mon Sep 17 00:00:00 2001 From: danwalmsley Date: Fri, 26 Oct 2018 19:58:12 +0100 Subject: [PATCH 8/9] Update readme.md --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 6be9d30f50..9d113cf2ef 100644 --- a/readme.md +++ b/readme.md @@ -2,9 +2,9 @@ # Avalonia -| Gitter Chat | Build Status | Windows Build Status | Linux/Mac Build Status | Open Collective | -|---|---|---|---|---| -| [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/AvaloniaUI/Avalonia?utm_campaign=pr-badge&utm_content=badge&utm_medium=badge&utm_source=badge) | [![Build Status](https://dev.azure.com/AvaloniaUI/AvaloniaUI/_apis/build/status/AvaloniaUI.Avalonia)](https://dev.azure.com/AvaloniaUI/AvaloniaUI/_build/latest?definitionId=4) | [![Build status](https://ci.appveyor.com/api/projects/status/hubk3k0w9idyibfg/branch/master?svg=true)](https://ci.appveyor.com/project/AvaloniaUI/Avalonia/branch/master) | [![Build Status](https://travis-ci.org/AvaloniaUI/Avalonia.svg?branch=master)](https://travis-ci.org/AvaloniaUI/Avalonia) | [![Backers on Open Collective](https://opencollective.com/Avalonia/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/Avalonia/sponsors/badge.svg)](#sponsors) | +| Gitter Chat | Build Status (Win, Linux, OSX) | Appveyor Build Status | Open Collective | +|---|---|---|---| +| [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/AvaloniaUI/Avalonia?utm_campaign=pr-badge&utm_content=badge&utm_medium=badge&utm_source=badge) | [![Build Status](https://dev.azure.com/AvaloniaUI/AvaloniaUI/_apis/build/status/AvaloniaUI.Avalonia)](https://dev.azure.com/AvaloniaUI/AvaloniaUI/_build/latest?definitionId=4) | [![Build status](https://ci.appveyor.com/api/projects/status/hubk3k0w9idyibfg/branch/master?svg=true)](https://ci.appveyor.com/project/AvaloniaUI/Avalonia/branch/master) | [![Backers on Open Collective](https://opencollective.com/Avalonia/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/Avalonia/sponsors/badge.svg)](#sponsors) | ## About From 81585b055c3ed527adf61b9b0960e1d7d9046563 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 26 Oct 2018 20:42:02 +0100 Subject: [PATCH 9/9] add a condition so it doesnt publish artifacts for forks. --- azure-pipelines.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1eb7e226c8..480c49814d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -57,10 +57,13 @@ jobs: inputs: pathToPublish: '$(Build.SourcesDirectory)/Build/Products/Release/' artifactName: 'Avalonia.Native.OSX' + condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false)) + - task: PublishBuildArtifacts@1 inputs: pathToPublish: '$(Build.SourcesDirectory)/artifacts/bin' artifactName: 'BinariesOSX' + condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false)) - job: Windows pool: @@ -79,11 +82,14 @@ jobs: inputs: pathtoPublish: '$(Build.SourcesDirectory)/artifacts/nuget' artifactName: 'NuGet' + condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false)) - task: PublishBuildArtifacts@1 inputs: pathToPublish: '$(Build.SourcesDirectory)/artifacts/zip' artifactName: 'Samples' + condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false)) - task: PublishBuildArtifacts@1 inputs: pathToPublish: '$(Build.SourcesDirectory)/artifacts/bin' artifactName: 'BinariesWindows' + condition: and(succeeded(), eq(variables['system.pullrequest.isfork'], false))