Browse Source

Merge pull request #10341 from MrJul/lazy-pointerinfo

Lazy initialized Win32 pointer info buffers
pull/10358/head
Max Katz 3 years ago
committed by GitHub
parent
commit
b2ce977dda
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
  2. 8
      src/Windows/Avalonia.Win32/WindowImpl.cs

5
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

@ -793,6 +793,7 @@ namespace Avalonia.Win32
if (info.pointerType == PointerInputType.PT_TOUCH)
{
s_historyTouchInfos ??= new POINTER_TOUCH_INFO[MaxPointerHistorySize];
if (GetPointerTouchInfoHistory(info.pointerId, ref historyCount, s_historyTouchInfos))
{
for (int i = historyCount - 1; i >= 1; i--)
@ -804,6 +805,7 @@ namespace Avalonia.Win32
}
else if (info.pointerType == PointerInputType.PT_PEN)
{
s_historyPenInfos ??= new POINTER_PEN_INFO[MaxPointerHistorySize];
if (GetPointerPenInfoHistory(info.pointerId, ref historyCount, s_historyPenInfos))
{
for (int i = historyCount - 1; i >= 1; i--)
@ -815,6 +817,7 @@ namespace Avalonia.Win32
}
else
{
s_historyInfos ??= new POINTER_INFO[MaxPointerHistorySize];
// Currently Windows does not return history info for mouse input, but we handle it just for case.
if (GetPointerInfoHistory(info.pointerId, ref historyCount, s_historyInfos))
{
@ -837,6 +840,8 @@ namespace Avalonia.Win32
// To understand some of this code, please check MS docs:
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmousemovepointsex#remarks
s_mouseHistoryInfos ??= new MOUSEMOVEPOINT[64];
fixed (MOUSEMOVEPOINT* movePoints = s_mouseHistoryInfos)
{
var movePointCopy = movePoint;

8
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -100,10 +100,10 @@ namespace Avalonia.Win32
private const int MaxPointerHistorySize = 512;
private static readonly PooledList<RawPointerPoint> s_intermediatePointsPooledList = new();
private static readonly POINTER_TOUCH_INFO[] s_historyTouchInfos = new POINTER_TOUCH_INFO[MaxPointerHistorySize];
private static readonly POINTER_PEN_INFO[] s_historyPenInfos = new POINTER_PEN_INFO[MaxPointerHistorySize];
private static readonly POINTER_INFO[] s_historyInfos = new POINTER_INFO[MaxPointerHistorySize];
private static readonly MOUSEMOVEPOINT[] s_mouseHistoryInfos = new MOUSEMOVEPOINT[64];
private static POINTER_TOUCH_INFO[]? s_historyTouchInfos;
private static POINTER_PEN_INFO[]? s_historyPenInfos;
private static POINTER_INFO[]? s_historyInfos;
private static MOUSEMOVEPOINT[]? s_mouseHistoryInfos;
public WindowImpl()
{

Loading…
Cancel
Save