toyota-connected / ivi-homescreen

Embedded Flutter runtime targeting Embedded Linux with Wayland
Other
246 stars 33 forks source link

Change pointer event timestamp from nano to microseconds #98

Closed cmc5788 closed 1 year ago

cmc5788 commented 1 year ago

Problem

We noticed visual scroll/touch physics bugs when running on hardware, such as lack of scroll velocity. We were able to reproduce locally for the videos below. The scroll velocity issue is the most obvious problem, but this issue is likely also making other more subtle touch mechanics work unexpectedly as well (button press timing, etc).

First video without the change in this PR, showing reproduction of scroll velocity error:

Next video is with the change in this PR applied, showing scroll velocity working as expected:

Solution

The changes in this PR were arrived at by following the embedder.h doc comments, and finding that timestamps for pointer events should be in microseconds.

  /// The timestamp at which the pointer event was generated. The timestamp
  /// should be specified in microseconds and the clock should be the same as
  /// that used by `FlutterEngineGetCurrentTime`.
  size_t timestamp;

However, we're currently using the return value from FlutterEngineGetCurrentTime directly, which returns nanoseconds:

//------------------------------------------------------------------------------
/// @brief      Get the current time in nanoseconds from the clock used by the
///             flutter engine. This is the system monotonic clock.
///
/// @return     The current time in nanoseconds.
///
FLUTTER_EXPORT
uint64_t FlutterEngineGetCurrentTime();

When the docs were followed in this case, the touch bugs disappeared immediately as per the video.


Note that In order to reproduce this in a Flutter app locally with pointer events acting as drag devices as seen in the video, it's necessary to force Flutter to treat all kinds of touch devices as "drag devices" by wrapping one of the app root widgets as follows

ScrollConfiguration(
  behavior: const ScrollBehavior().copyWith(
    dragDevices: {...PointerDeviceKind.values},
  ),
  child: /* your root widgets here */,
)