Browse Source

Request for Feedback: Improving Startup Latency in X11 (#16033)

* Improve: X11 Startup time with asynchronous Gfx Startup

Before: 80-100
After: 66-81

* Changed: Move CursorFactory Back to its Place

* Changed: An alternative attempt with lazy cursor generation.
pull/16734/head
Sewer. 2 years ago
committed by GitHub
parent
commit
de3aa58c5c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 24
      src/Avalonia.X11/X11CursorFactory.cs
  2. 2
      src/Avalonia.X11/X11Platform.cs

24
src/Avalonia.X11/X11CursorFactory.cs

@ -1,13 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Avalonia.Controls.Platform.Surfaces; using Avalonia.Controls.Platform.Surfaces;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Platform.Internal; using Avalonia.Platform.Internal;
using Avalonia.SourceGenerator;
using Avalonia.Utilities;
#nullable enable #nullable enable
@ -50,15 +47,14 @@ namespace Avalonia.X11
{StandardCursorType.TopRightCorner, CursorFontShape.XC_top_right_corner}, {StandardCursorType.TopRightCorner, CursorFontShape.XC_top_right_corner},
}; };
[GenerateEnumValueList]
private static partial CursorFontShape[] GetAllCursorShapes();
public X11CursorFactory(IntPtr display) public X11CursorFactory(IntPtr display)
{ {
_display = display; _display = display;
_nullCursor = GetNullCursor(display); _nullCursor = GetNullCursor(display);
_cursors = GetAllCursorShapes()
.ToDictionary(id => id, id => XLib.XCreateFontCursor(_display, id)); // 78 = number of items in CursorFontShape enum
// Unlikely to change, but, do we have a Src Gen for this?
_cursors = new Dictionary<CursorFontShape, IntPtr>(78);
} }
public ICursorImpl GetCursor(StandardCursorType cursorType) public ICursorImpl GetCursor(StandardCursorType cursorType)
@ -71,8 +67,8 @@ namespace Avalonia.X11
else else
{ {
handle = s_mapping.TryGetValue(cursorType, out var shape) handle = s_mapping.TryGetValue(cursorType, out var shape)
? _cursors[shape] ? GetCursorHandleLazy(shape)
: _cursors[CursorFontShape.XC_left_ptr]; : GetCursorHandleLazy(CursorFontShape.XC_left_ptr);
} }
return new CursorImpl(handle); return new CursorImpl(handle);
} }
@ -144,6 +140,14 @@ namespace Avalonia.X11
public IFramebufferRenderTarget CreateFramebufferRenderTarget() => new FuncFramebufferRenderTarget(Lock); public IFramebufferRenderTarget CreateFramebufferRenderTarget() => new FuncFramebufferRenderTarget(Lock);
} }
private nint GetCursorHandleLazy(CursorFontShape shape)
{
if (!_cursors.TryGetValue(shape, out var handle))
_cursors[shape] = handle = XLib.XCreateFontCursor(_display, shape);
return handle;
}
} }
internal class CursorImpl : ICursorImpl internal class CursorImpl : ICursorImpl

2
src/Avalonia.X11/X11Platform.cs

@ -2,8 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using Avalonia.Controls;
using Avalonia.Controls.Platform; using Avalonia.Controls.Platform;
using Avalonia.FreeDesktop; using Avalonia.FreeDesktop;
using Avalonia.FreeDesktop.DBusIme; using Avalonia.FreeDesktop.DBusIme;

Loading…
Cancel
Save