From efe3e4f0233d86a31ef1773de96112a8e628dfb8 Mon Sep 17 00:00:00 2001 From: Nicholas Rishel Date: Mon, 25 May 2020 20:45:26 -0700 Subject: Save Wintab packets to a local queue as WT_PACKET events arrive or when handling mouse input. This Wintab to mouse synchronization issues, and likely prevents queue exhaustion for some Wintab implmenetations. Signed-off-by: Nicholas Rishel --- intern/ghost/intern/GHOST_SystemWin32.cpp | 8 +++++ intern/ghost/intern/GHOST_SystemWin32.h | 2 ++ intern/ghost/intern/GHOST_WindowWin32.cpp | 55 ++++++++++++++++++++++++++++--- intern/ghost/intern/GHOST_WindowWin32.h | 6 ++++ 4 files changed, 66 insertions(+), 5 deletions(-) (limited to 'intern') diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index a4fdcc24ed8..e40934dd1ad 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -234,6 +234,11 @@ GHOST_SystemWin32::~GHOST_SystemWin32() toggleConsole(1); } +GHOST_TUns64 GHOST_SystemWin32::millisSinceStart(__int64 ms) const +{ + return (GHOST_TUns64)(ms - m_start * 1000 / m_freq); +} + GHOST_TUns64 GHOST_SystemWin32::performanceCounterToMillis(__int64 perf_ticks) const { // Calculate the time passed since system initialization. @@ -1591,6 +1596,9 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, window->processWintabProximityEvent(inRange); break; } + case WT_PACKET: + window->updatePendingWintabEvents(); + break; //////////////////////////////////////////////////////////////////////// // Pointer events, processed //////////////////////////////////////////////////////////////////////// diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h index 68aef3e3b30..1f9b28bb7ce 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.h +++ b/intern/ghost/intern/GHOST_SystemWin32.h @@ -64,6 +64,8 @@ class GHOST_SystemWin32 : public GHOST_System { ** Time(r) functionality ***************************************************************************************/ + GHOST_TUns64 millisSinceStart(__int64 ms) const; + /** * This method converts performance counter measurements into milliseconds since the start of the * system process. diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp index c5fe38ee678..f09be8ed6d0 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cpp +++ b/intern/ghost/intern/GHOST_WindowWin32.cpp @@ -1045,6 +1045,7 @@ void GHOST_WindowWin32::initializeWintab() lc.lcPktData = PACKETDATA; lc.lcPktMode = PACKETMODE; lc.lcMoveMask = PACKETDATA; + lc.lcOptions |= CXO_MESSAGES; // Wacom maps y origin to the tablet's bottom // Invert to match Windows y origin mapping to the screen top lc.lcOutExtY = -lc.lcOutExtY; @@ -1298,12 +1299,16 @@ GHOST_TSuccess GHOST_WindowWin32::getWintabInfo(std::vectorgetMilliSeconds(); + GHOST_TUns64 timeout = 300; + while (!pendingEvents.empty()) { + GHOST_TUns64 pktTime = system->millisSinceStart(pendingEvents.front().pkTime); + if (currTime - pktTime > timeout) { + pendingEvents.pop(); + } + else { + break; + } + } + + // Get new packets. + const int numPackets = m_wintab.packetsGet( + m_wintab.context, m_wintab.pkts.size(), m_wintab.pkts.data()); + + int i = 0; + // Don't queue outdated packets, such events can include packets that occurred before the current + // window lost and regained focus. + for (; i < numPackets; i++) { + GHOST_TUns64 pktTime = system->millisSinceStart(m_wintab.pkts[i].pkTime); + if (currTime - pktTime < timeout) { + break; + } + } + for (; i < numPackets; i++) { + pendingEvents.push(m_wintab.pkts[i]); + } +} + GHOST_TUns16 GHOST_WindowWin32::getDPIHint() { if (m_user32) { diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h index 3cf7417e4c1..88b6e19c69d 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.h +++ b/intern/ghost/intern/GHOST_WindowWin32.h @@ -35,6 +35,7 @@ #endif #include +#include #include // PACKETDATA and PACKETMODE modify structs in pktdef.h, so make sure they come first @@ -482,6 +483,10 @@ class GHOST_WindowWin32 : public GHOST_Window { */ GHOST_TSuccess getWintabInfo(std::vector &outWintabInfo); + /** + */ + void updatePendingWintabEvents(); + GHOST_TSuccess beginFullScreen() const { return GHOST_kFailure; @@ -625,6 +630,7 @@ class GHOST_WindowWin32 : public GHOST_Window { LONG maxAzimuth = 0, maxAltitude = 0; /* Queue size doesn't change once set, so reuse the same buffer */ std::vector pkts; + std::queue pendingEvents; } m_wintab; /** -- cgit v1.2.3