Bug 1346149 - Part 1: Make button support value in VRSystemManager; r=kip
authorDaosheng Mu <daoshengmu@gmail.com>
Thu, 16 Mar 2017 15:49:46 +0800
changeset 348320 5f756281dc146040f0ec7e0b23bbec84239829fe
parent 348319 d06ce06386adb22b15fcab20df4ed13a4ee6dc20
child 348321 109db936e344c10543191aceb01a81eec1fa9f3f
push id88187
push userarchaeopteryx@coole-files.de
push dateSat, 18 Mar 2017 15:27:00 +0000
treeherdermozilla-inbound@0b1d3324cffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip
bugs1346149
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1346149 - Part 1: Make button support value in VRSystemManager; r=kip MozReview-Commit-ID: 72rqJZtIaDa
gfx/vr/gfxVR.cpp
gfx/vr/gfxVR.h
gfx/vr/gfxVROSVR.cpp
gfx/vr/gfxVROSVR.h
gfx/vr/gfxVRPuppet.cpp
gfx/vr/gfxVRPuppet.h
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -81,20 +81,20 @@ VRSystemManager::RemoveGamepad(uint32_t 
 
   VRManager* vm = VRManager::Get();
   MOZ_ASSERT(vm);
   vm->NotifyGamepadChange<dom::GamepadRemoved>(a);
 }
 
 void
 VRSystemManager::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
-                                bool aPressed)
+                                bool aPressed, double aValue)
 {
   dom::GamepadButtonInformation a(aIndex, dom::GamepadServiceType::VR,
-                                  aButton, aPressed, aPressed ? 1.0L : 0.0L);
+                                  aButton, aPressed, aValue);
 
   VRManager* vm = VRManager::Get();
   MOZ_ASSERT(vm);
   vm->NotifyGamepadChange<dom::GamepadButtonInformation>(a);
 }
 
 void
 VRSystemManager::NewAxisMove(uint32_t aIndex, uint32_t aAxis,
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -250,34 +250,25 @@ public:
 
   virtual bool Init() = 0;
   virtual void Destroy() = 0;
   virtual void GetHMDs(nsTArray<RefPtr<VRDisplayHost>>& aHMDResult) = 0;
   virtual void HandleInput() = 0;
   virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
   virtual void ScanForControllers() = 0;
   virtual void RemoveControllers() = 0;
-  void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
+  void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, double aValue);
   void NewAxisMove(uint32_t aIndex, uint32_t aAxis, double aValue);
   void NewPoseState(uint32_t aIndex, const dom::GamepadPoseState& aPose);
   void AddGamepad(const VRControllerInfo& controllerInfo);
   void RemoveGamepad(uint32_t aIndex);
 
 protected:
   VRSystemManager() : mControllerCount(0) { }
   virtual ~VRSystemManager() { }
 
   uint32_t mControllerCount;
-
-private:
-  virtual void HandleButtonPress(uint32_t aControllerIdx,
-                                 uint64_t aButtonPressed) = 0;
-  virtual void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
-                              float aValue) = 0;
-  virtual void HandlePoseTracking(uint32_t aControllerIdx,
-                                  const dom::GamepadPoseState& aPose,
-                                  VRControllerHost* aController) = 0;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif /* GFX_VR_H */
--- a/gfx/vr/gfxVROSVR.cpp
+++ b/gfx/vr/gfxVROSVR.cpp
@@ -527,35 +527,16 @@ VRSystemManagerOSVR::GetHMDs(nsTArray<Re
 }
 
 void
 VRSystemManagerOSVR::HandleInput()
 {
 }
 
 void
-VRSystemManagerOSVR::HandleButtonPress(uint32_t aControllerIdx,
-                                       uint64_t aButtonPressed)
-{
-}
-
-void
-VRSystemManagerOSVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
-                                    float aValue)
-{
-}
-
-void
-VRSystemManagerOSVR::HandlePoseTracking(uint32_t aControllerIdx,
-                                        const GamepadPoseState& aPose,
-                                        VRControllerHost* aController)
-{
-}
-
-void
 VRSystemManagerOSVR::GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult)
 {
 }
 
 void
 VRSystemManagerOSVR::ScanForControllers()
 {
 }
--- a/gfx/vr/gfxVROSVR.h
+++ b/gfx/vr/gfxVROSVR.h
@@ -92,23 +92,16 @@ protected:
   bool mInterfaceInitialized;
   RefPtr<nsIThread> mOSVRThread;
 
   OSVR_ClientContext m_ctx;
   OSVR_ClientInterface m_iface;
   OSVR_DisplayConfig m_display;
 
 private:
-  virtual void HandleButtonPress(uint32_t aControllerIdx,
-                                 uint64_t aButtonPressed) override;
-  virtual void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
-                              float aValue) override;
-  virtual void HandlePoseTracking(uint32_t aControllerIdx,
-                                  const dom::GamepadPoseState& aPose,
-                                  VRControllerHost* aController) override;
   // check if all components are initialized
   // and if not, it will try to initialize them
   void CheckOSVRStatus();
   void InitializeClientContext();
   void InitializeDisplay();
   void InitializeInterface();
 };
 
--- a/gfx/vr/gfxVRPuppet.cpp
+++ b/gfx/vr/gfxVRPuppet.cpp
@@ -342,50 +342,49 @@ VRSystemManagerPuppet::GetHMDs(nsTArray<
 }
 
 void
 VRSystemManagerPuppet::HandleInput()
 {
   RefPtr<impl::VRControllerPuppet> controller;
   for (uint32_t i = 0; i < mPuppetController.Length(); ++i) {
     controller = mPuppetController[i];
-    HandleButtonPress(i, controller->GetButtonPressState());
+    for (uint32_t j = 0; j < kNumPuppetButtonMask; ++j) {
+      HandleButtonPress(i, j, kPuppetButtonMask[i], controller->GetButtonPressState());
+    }
+    controller->SetButtonPressed(controller->GetButtonPressState());
 
     for (uint32_t j = 0; j < kNumPuppetAxis; ++j) {
       HandleAxisMove(i, j, controller->GetAxisMoveState(j));
     }
     HandlePoseTracking(i, controller->GetPoseMoveState(), controller);
   }
 }
 
 void
 VRSystemManagerPuppet::HandleButtonPress(uint32_t aControllerIdx,
+                                         uint32_t aButton,
+                                         uint64_t aButtonMask,
                                          uint64_t aButtonPressed)
 {
-  uint64_t buttonMask = 0;
   RefPtr<impl::VRControllerPuppet> controller(mPuppetController[aControllerIdx]);
   MOZ_ASSERT(controller);
-  uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
+  const uint64_t diff = (controller->GetButtonPressed() ^ aButtonPressed);
 
   if (!diff) {
     return;
   }
 
-  for (uint32_t i = 0; i < kNumPuppetButtonMask; ++i) {
-    buttonMask = kPuppetButtonMask[i];
-
-    if (diff & buttonMask) {
-      // diff & aButtonPressed would be true while a new button press
-      // event, otherwise it is an old press event and needs to notify
-      // the button has been released.
-      NewButtonEvent(aControllerIdx, i, diff & aButtonPressed);
-    }
+  if (diff & aButtonMask) {
+    // diff & aButtonPressed would be true while a new button press
+    // event, otherwise it is an old press event and needs to notify
+    // the button has been released.
+    NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed,
+                   (aButtonMask & aButtonPressed) ? 1.0L : 0.0L);
   }
-
-  controller->SetButtonPressed(aButtonPressed);
 }
 
 void
 VRSystemManagerPuppet::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
                                       float aValue)
 {
   RefPtr<impl::VRControllerPuppet> controller(mPuppetController[aControllerIdx]);
   MOZ_ASSERT(controller);
--- a/gfx/vr/gfxVRPuppet.h
+++ b/gfx/vr/gfxVRPuppet.h
@@ -94,23 +94,25 @@ public:
                               aControllerResult) override;
   virtual void ScanForControllers() override;
   virtual void RemoveControllers() override;
 
 protected:
   VRSystemManagerPuppet();
 
 private:
-  virtual void HandleButtonPress(uint32_t aControllerIndex,
-                                 uint64_t aButtonPressed) override;
-  virtual void HandleAxisMove(uint32_t aControllerIndex, uint32_t aAxis,
-                              float aValue) override;
-  virtual void HandlePoseTracking(uint32_t aControllerIndex,
-                                  const dom::GamepadPoseState& aPose,
-                                  VRControllerHost* aController) override;
+  void HandleButtonPress(uint32_t aControllerIdx,
+                         uint32_t aButton,
+                         uint64_t aButtonMask,
+                         uint64_t aButtonPressed);
+  void HandleAxisMove(uint32_t aControllerIndex, uint32_t aAxis,
+                      float aValue);
+  void HandlePoseTracking(uint32_t aControllerIndex,
+                          const dom::GamepadPoseState& aPose,
+                          VRControllerHost* aController);
 
   // there can only be one
   RefPtr<impl::VRDisplayPuppet> mPuppetHMD;
   nsTArray<RefPtr<impl::VRControllerPuppet>> mPuppetController;
 };
 
 } // namespace gfx
 } // namespace mozilla