From 7dd77c56b166fbfb73374f68fc93ac4290f512d1 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 7 Mar 2024 14:33:00 +0100 Subject: [PATCH] Added UI thread rendering mode for X11. (#14856) Allows using UI thread render timer for X11. Makes sense for low-end X11 devices that previously used immediate renderer. --- src/Avalonia.X11/X11Platform.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.X11/X11Platform.cs b/src/Avalonia.X11/X11Platform.cs index 75e0776b5e..9e1757d4ef 100644 --- a/src/Avalonia.X11/X11Platform.cs +++ b/src/Avalonia.X11/X11Platform.cs @@ -70,10 +70,14 @@ namespace Avalonia.X11 if (options.UseDBusMenu) DBusHelper.TryInitialize(); + IRenderTimer timer = options.ShouldRenderOnUIThread + ? new UiThreadRenderTimer(60) + : new SleepLoopRenderTimer(60); + AvaloniaLocator.CurrentMutable.BindToSelf(this) .Bind().ToConstant(this) .Bind().ToConstant(new X11PlatformThreading(this)) - .Bind().ToConstant(new SleepLoopRenderTimer(60)) + .Bind().ToConstant(timer) .Bind().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control)) .Bind().ToFunc(() => KeyboardDevice) .Bind().ToConstant(new X11CursorFactory(Display)) @@ -303,7 +307,14 @@ namespace Avalonia /// public bool EnableSessionManagement { get; set; } = Environment.GetEnvironmentVariable("AVALONIA_X11_USE_SESSION_MANAGEMENT") != "0"; - + + /// + /// Render directly on the UI thread instead of using a dedicated render thread. + /// This can be usable if your device don't have multiple cores to begin with. + /// This setting is false by default. + /// + public bool ShouldRenderOnUIThread { get; set; } + public IList GlProfiles { get; set; } = new List { new GlVersion(GlProfileType.OpenGL, 4, 0),