unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.75k stars 706 forks source link

Incorrect Implementation of GetIntermediatePoints Method in UNO Framework #17527

Open lindexi opened 1 month ago

lindexi commented 1 month ago

Current behavior

I have discovered an issue with the implementation of the GetIntermediatePoints method in the UNO Framework.

In the design of WinUI or UWP, developers can use GetIntermediatePoints to obtain historical input point data. This is particularly useful when the UI is busy, as it means that when the UI is unable to process input points in time, the accumulated input points will be added to the historical input point data, preventing a large number of input triggers from further slowing down the UI.

However, in the UNO Framework, the GetIntermediatePoints method is not implemented correctly. Instead of returning historical input point data, it only returns the current point. This means that in the UNO Framework, when the UI is too busy to process input, it will continuously trigger input events or lose input data. On the X11 platform, this will exacerbate UI lag by continuously triggering input events. On the WPF platform, this will result in lost input data.

Expected behavior

I would like to see the GetIntermediatePoints method in the UNO Framework implemented in the same way as in WinUI, where input points are collected and added to the historical input point data when the UI is too busy. This would reduce the triggering of input events when the UI thread is unable to process input data in time.

How to reproduce it (as minimally and precisely as possible)

  1. Create an empty UNO project.
  2. Add the PointerMoved handler.
  3. Call the GetIntermediatePoints and make the UI busy.

Run the project between WinUI and UNO. And you can find the count of GetIntermediatePoints will always be one.

You can find my demo code in https://github.com/lindexi/lindexi_gd/tree/1111c23e4c76a3aa7e3418db8ff7b6661cd0d1d2/UnoDemo/NeejabaykugoWerjekeeja

Workaround

No response

Works on UWP/WinUI

Yes

Environment

No response

NuGet package version(s)

gloabl.json

{
  // To update the version of Uno please update the version of the Uno.Sdk here. See https://aka.platform.uno/upgrade-uno-packages for more information.
  "msbuild-sdks": 
  {
    "Uno.Sdk": "5.2.175"
  }
}

Affected platforms

Skia (WPF), Skia (Linux X11), Skia (macOS), Skia (Linux Framebuffer), Skia (GTK)

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

https://github.com/unoplatform/uno/blob/9079a087aa7a8cb9077aef7b120f09a240336a7a/src/Uno.UWP/UI/Core/PointerEventArgs.cs#L21-L22

https://github.com/unoplatform/uno/blob/9079a087aa7a8cb9077aef7b120f09a240336a7a/src/Uno.UI/UI/Xaml/Input/PointerRoutedEventArgs.cs#L49-L50

lindexi commented 1 month ago

Furthering the issue, I believe it's an unsound design within the UNO framework to bifurcate threads into X11 threads and the UNO main thread. It's also unreasonable to have a design where each window has an X11 thread. When the UI thread fails to process input messages in a timely manner, it results in message accumulation. Even with the correct implementation of the GetIntermediatePoints function, due to input messages being scheduled to the UI thread with higher priority, rendering messages can't be pushed promptly, leading to a halt in interface rendering.