Bug 1318839 - Add polling interval for direct input polling r=qDot
authorChih-Yi Leu <cleu@mozilla.com>
Mon, 28 Nov 2016 18:52:00 +0100
changeset 324662 313bd77f09009341a35b45bc75866a57f02907b9
parent 324661 ea48aaafb70a4cb5b4513c2c1eb0dda09a56e9e6
child 324663 577914241a79fcd9fb18230d7b0f9c528f57c89c
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersqDot
bugs1318839
milestone53.0a1
Bug 1318839 - Add polling interval for direct input polling r=qDot
dom/gamepad/windows/WindowsGamepad.cpp
--- a/dom/gamepad/windows/WindowsGamepad.cpp
+++ b/dom/gamepad/windows/WindowsGamepad.cpp
@@ -41,19 +41,20 @@ const unsigned kFirstAxis = 0x30;
 const unsigned kDesktopUsagePage = 0x1;
 const unsigned kButtonUsagePage = 0x9;
 
 // Multiple devices-changed notifications can be sent when a device
 // is connected, because USB devices consist of multiple logical devices.
 // Therefore, we wait a bit after receiving one before looking for
 // device changes.
 const uint32_t kDevicesChangedStableDelay = 200;
-// XInput is a purely polling-driven API, so we need to
-// poll it periodically. 50ms is arbitrarily chosen.
-const uint32_t kXInputPollInterval = 50;
+// Both DirectInput and XInput are polling-driven here,
+// so we need to poll it periodically.
+// 50ms is arbitrarily chosen.
+const uint32_t kWindowsGamepadPollInterval = 50;
 
 const UINT kRawInputError = (UINT)-1;
 
 #ifndef XUSER_MAX_COUNT
 #define XUSER_MAX_COUNT 4
 #endif
 
 const struct {
@@ -409,17 +410,17 @@ WindowsGamepadService::XInputMessageLoop
                                                      void* aService)
 {
   MOZ_ASSERT(aService);
   WindowsGamepadService* self = static_cast<WindowsGamepadService*>(aService);
   self->PollXInput();
   if (self->mIsXInputMonitoring) {
     aTimer->Cancel();
     aTimer->InitWithFuncCallback(XInputMessageLoopOnceCallback, self,
-                                 kXInputPollInterval, nsITimer::TYPE_ONE_SHOT);
+                                 kWindowsGamepadPollInterval, nsITimer::TYPE_ONE_SHOT);
   }
 }
 
 // static
 void
 WindowsGamepadService::DevicesChangeCallback(nsITimer *aTimer, void* aService)
 {
   MOZ_ASSERT(aService);
@@ -496,17 +497,17 @@ WindowsGamepadService::ScanForDevices()
   if (mHID) {
     ScanForRawInputDevices();
   }
   if (mXInput) {
     mXInputTimer->Cancel();
     if (ScanForXInputDevices()) {
       mIsXInputMonitoring = true;
       mXInputTimer->InitWithFuncCallback(XInputMessageLoopOnceCallback, this,
-                                         kXInputPollInterval,
+                                         kWindowsGamepadPollInterval,
                                          nsITimer::TYPE_ONE_SHOT);
     } else {
       mIsXInputMonitoring = false;
     }
   }
 
   // Look for devices that are no longer present and remove them.
   for (int i = mGamepads.Length() - 1; i >= 0; i--) {
@@ -971,17 +972,19 @@ public:
   {
     MOZ_ASSERT(NS_GetCurrentThread() == gMonitorThread);
     MSG msg;
     while (PeekMessageW(&msg, sHWnd, 0, 0, PM_REMOVE) > 0) {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
     }
     if (!sIsShutdown) {
-      NS_DispatchToCurrentThread(new WindowGamepadMessageLoopOnceRunnable());
+      nsCOMPtr<nsIRunnable> runnable = new WindowGamepadMessageLoopOnceRunnable();
+      NS_DelayedDispatchToCurrentThread(runnable.forget(),
+                                        kWindowsGamepadPollInterval);
     }
     return NS_OK;
   }
 private:
   ~WindowGamepadMessageLoopOnceRunnable() {}
 };
 
 class StartWindowsGamepadServiceRunnable final : public Runnable