Platforms: Win32 Use Message Time for WinTab events #116114

Open
Harley Acheson wants to merge 1 commits from Harley/blender:WinTabMessageTimes into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

WinTab events are all created in result of windows messages, so for
these use the last message time, rather than supplied time, to ensure
the times are consistent with other event times.


In the Wacom reference page the say that the "pkTime" is "In absolute mode, specifies the system time at which the event was posted. In relative mode, specifies the elapsed time in milliseconds since the last packet". This second format is not compatible with blender event times. https://developer-docs.wacom.com/docs/icbt/windows/wintab/wintab-reference/

WinTab events are all created in result of windows messages, so for these use the last message time, rather than supplied time, to ensure the times are consistent with other event times. --- In the Wacom reference page the say that the "pkTime" is "In absolute mode, specifies the system time at which the event was posted. In relative mode, specifies the elapsed time in milliseconds since the last packet". This second format is not compatible with blender event times. https://developer-docs.wacom.com/docs/icbt/windows/wintab/wintab-reference/
Harley Acheson added 1 commit 2023-12-12 23:26:38 +01:00
446b2c18e1 Platforms: Win32 Use Message Time for WinTab events
WinTab events are all created in result of windows messages, so for
these use the last message time, rather than supplied time, to ensure
the times are consistent with other event times.
Harley Acheson requested review from Ray molenkamp 2023-12-12 23:44:34 +01:00
Harley Acheson added this to the Platforms, Builds Tests & Devices project 2023-12-12 23:44:43 +01:00
Member

I Vaguely remember @PrototypeNM1 fighting with this, and i'd like to get his opinion before making changes here

I Vaguely remember @PrototypeNM1 fighting with this, and i'd like to get his opinion before making changes here

The GetMessageTime() API only has a resolution of 16ms (62.5 fps). For smooth strokes from tablets we want as much resolution as we can get. And the potential issue is not just that we'd only get 16ms resolution, but that by rounding the native tablet frequency to another frequency that points would be poorly spaced as well.

I think we want to get the time from the tablet API. If some offsets needs to be applied to make it match other times, perhaps that offset could be computed at the start of the stroke (i.e. pen/mouse down) and stay fixed for the duration.

The `GetMessageTime()` API only has a resolution of 16ms (62.5 fps). For smooth strokes from tablets we want as much resolution as we can get. And the potential issue is not just that we'd only get 16ms resolution, but that by rounding the native tablet frequency to another frequency that points would be poorly spaced as well. I think we want to get the time from the tablet API. If some offsets needs to be applied to make it match other times, perhaps that offset could be computed at the start of the stroke (i.e. pen/mouse down) and stay fixed for the duration.

I vaguely remember that we can limit reading the Wintab packets constrained to those associated to the current WT_PACKET Windows message, currently I believe we drain the whole Wintab packet queue. If we're going to use the message origination time we will probably want to limit what we read to have closer timestamps.

I also wonder if e.g. stroke smoothing or similar operations take time between INBETWEEN_MOUSEMOVEs into consideration? If so this could cause a regression from timestamps not differing.

I vaguely remember that we can limit reading the Wintab packets constrained to those associated to the current `WT_PACKET` Windows message, currently I believe we drain the whole Wintab packet queue. If we're going to use the message origination time we will probably want to limit what we read to have closer timestamps. I also wonder if e.g. stroke smoothing or similar operations take time between `INBETWEEN_MOUSEMOVE`s into consideration? If so this could cause a regression from timestamps not differing.
Author
Member

The GetMessageTime() API only has a resolution of 16ms (62.5 fps)....

Its more complicated than that. Our general "get tick count" routine uses a high performance timer with a resolution of <1us. The getMilliSeconds might appear to fallback to using GetTickCount if there is no high res timer, but that can no longer happen as such a timer is guaranteed since Windows XP. We convert this value to milliseconds though so the resolution is 1ms.

Our new getMessageTime uses this timer's value and subtracts the difference between the 32-bit GetMessageTime and GetTickCount. So we end up with a 64 timer with good accuracy that doesn't roll over. But the portion of this time value from when a windows message is delivered to when we collect it has a resolution of 16ms.

but that by rounding the native tablet frequency to another frequency that points would be poorly spaced as well.

Do we really space the points using time and not just position?

AFAIK with this change we will receive the same number of messages from Wintab and send the same number of events to Blender at the same time they always have. With the only change being our own timestamp in the Blender events will be of a format that matches the format of other event times. We use detect double-click by comparing subsequent values, but not sure we use it anywhere else yet.

> The `GetMessageTime()` API only has a resolution of 16ms (62.5 fps).... Its more complicated than that. Our general "get tick count" routine uses a high performance timer with a resolution of <1us. The `getMilliSeconds` might appear to fallback to using `GetTickCount` if there is no high res timer, but that can no longer happen as such a timer is [guaranteed since Windows XP](https://learn.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancefrequency). We convert this value to milliseconds though so the resolution is 1ms. Our new `getMessageTime` uses this timer's value and subtracts the difference between the 32-bit `GetMessageTime` and `GetTickCount`. So we end up with a 64 timer with good accuracy that doesn't roll over. But the portion of this time value from when a windows message is delivered to when we collect it has a resolution of 16ms. > but that by rounding the native tablet frequency to another frequency that points would be poorly spaced as well. Do we really space the points using _time_ and not just position? AFAIK with this change we will receive the same number of messages from Wintab and send the same number of events to Blender at the same time they always have. With the only change being our own timestamp in the Blender events will be of a format that matches the format of other event times. We use detect double-click by comparing subsequent values, but not sure we use it anywhere else yet.

Its more complicated than that. Our general "get tick count" routine uses a high performance timer with a resolution of <1us. The getMilliSeconds might appear to fallback to using GetTickCount if there is no high res timer, but that can no longer happen as such a timer is guaranteed since Windows XP. We convert this value to milliseconds though so the resolution is 1ms.

GetTickCount is the time the event is being processed, not the time the event happened. Its accuracy does not help because it's not measuring the right thing.

With high frequency tablet events you will end up processing a few events together every time, and then you'll have clumps of events that have nearly the same time because they happened to be processed together.

Do we really space the points using time and not just position?

We indeed do not seem to be using it in the brush code. If it was accurate we could use it for the airbrush, to properly match position and time.

If it's not trivial to keep the accuracy I guess it's to lose it. But I would like to see a comment noting the loss of accuracy and that it's okay because it's only used for double click checking.

> Its more complicated than that. Our general "get tick count" routine uses a high performance timer with a resolution of <1us. The `getMilliSeconds` might appear to fallback to using `GetTickCount` if there is no high res timer, but that can no longer happen as such a timer is [guaranteed since Windows XP](https://learn.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancefrequency). We convert this value to milliseconds though so the resolution is 1ms. `GetTickCount` is the time the event is being processed, not the time the event happened. Its accuracy does not help because it's not measuring the right thing. With high frequency tablet events you will end up processing a few events together every time, and then you'll have clumps of events that have nearly the same time because they happened to be processed together. > Do we really space the points using _time_ and not just position? We indeed do not seem to be using it in the brush code. If it was accurate we could use it for the airbrush, to properly match position and time. If it's not trivial to keep the accuracy I guess it's to lose it. But I would like to see a comment noting the loss of accuracy and that it's okay because it's only used for double click checking.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u WinTabMessageTimes:Harley-WinTabMessageTimes
git checkout Harley-WinTabMessageTimes
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#116114
No description provided.