Bug 1315896 - Part 3: Remove MOZ_GAMEPAD in VR module; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Thu, 08 Dec 2016 13:01:11 -1000
changeset 450569 7afc961dafc3983672ae2af002050785084e3aa7
parent 450568 98df1d5ce763927fb085e49422db3f7af436aec8
child 539791 a025412fa442cc1cad91b5d09776686285056f6b
push id38902
push userbmo:dmu@mozilla.com
push dateSat, 17 Dec 2016 00:19:00 +0000
reviewerskip
bugs1315896
milestone53.0a1
Bug 1315896 - Part 3: Remove MOZ_GAMEPAD in VR module; r?kip MozReview-Commit-ID: I9vJvxgFgIh
gfx/vr/gfxVR.cpp
gfx/vr/gfxVR.h
gfx/vr/gfxVROpenVR.cpp
gfx/vr/ipc/VRManagerChild.cpp
--- a/gfx/vr/gfxVR.cpp
+++ b/gfx/vr/gfxVR.cpp
@@ -1,20 +1,18 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <math.h>
 
 #include "gfxVR.h"
-#ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadEventTypes.h"
 #include "mozilla/dom/GamepadBinding.h"
-#endif
 
 #ifndef M_PI
 # define M_PI 3.14159265358979323846
 #endif
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
@@ -63,18 +61,18 @@ VRFieldOfView::ConstructProjectionMatrix
 
 /* static */ uint32_t
 VRControllerManager::AllocateControllerID()
 {
   return ++sControllerBase;
 }
 
 void
-VRControllerManager::AddGamepad(const char* aID, uint32_t aMapping, uint32_t aHand,
-                                uint32_t aNumButtons, uint32_t aNumAxes)
+VRControllerManager::AddGamepad(const char* aID, dom::GamepadMappingType aMapping,
+                                dom::GamepadHand aHand, uint32_t aNumButtons, uint32_t aNumAxes)
 {
   dom::GamepadAdded a(NS_ConvertUTF8toUTF16(nsDependentCString(aID)), mControllerCount,
                      aMapping, aHand, dom::GamepadServiceType::VR, aNumButtons,
                      aNumAxes);
 
   VRManager* vm = VRManager::Get();
   MOZ_ASSERT(vm);
   vm->NotifyGamepadChange<dom::GamepadAdded>(a);
--- a/gfx/vr/gfxVR.h
+++ b/gfx/vr/gfxVR.h
@@ -17,16 +17,17 @@
 #include "mozilla/TypedEnumBits.h"
 
 namespace mozilla {
 namespace layers {
 class PTextureParent;
 }
 namespace dom {
 enum class GamepadMappingType : uint32_t;
+enum class GamepadHand : uint32_t;
 struct GamepadPoseState;
 }
 namespace gfx {
 class VRLayerParent;
 class VRDisplayHost;
 class VRControllerHost;
 
 enum class VRDeviceType : uint16_t {
@@ -214,24 +215,24 @@ protected:
   virtual ~VRDisplayManager() { }
 };
 
 struct VRControllerInfo
 {
   VRDeviceType GetType() const { return mType; }
   uint32_t GetControllerID() const { return mControllerID; }
   const nsCString& GetControllerName() const { return mControllerName; }
-  uint32_t GetMappingType() const { return mMappingType; }
+  dom::GamepadMappingType GetMappingType() const { return mMappingType; }
   uint32_t GetNumButtons() const { return mNumButtons; }
   uint32_t GetNumAxes() const { return mNumAxes; }
 
   uint32_t mControllerID;
   VRDeviceType mType;
   nsCString mControllerName;
-  uint32_t mMappingType;
+  dom::GamepadMappingType mMappingType;
   uint32_t mNumButtons;
   uint32_t mNumAxes;
 
   bool operator==(const VRControllerInfo& other) const {
     return mType == other.mType &&
            mControllerID == other.mControllerID &&
            mControllerName == other.mControllerName &&
            mMappingType == other.mMappingType &&
@@ -253,18 +254,18 @@ public:
   virtual void Destroy() = 0;
   virtual void HandleInput() = 0;
   virtual void GetControllers(nsTArray<RefPtr<VRControllerHost>>& aControllerResult) = 0;
   virtual void ScanForDevices() = 0;
   virtual void RemoveDevices() = 0;
   void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
   void NewAxisMove(uint32_t aIndex, uint32_t aAxis, double aValue);
   void NewPoseState(uint32_t aIndex, const dom::GamepadPoseState& aPose);
-  void AddGamepad(const char* aID, uint32_t aMapping, uint32_t aHand,
-                  uint32_t aNumButtons, uint32_t aNumAxes);
+  void AddGamepad(const char* aID, dom::GamepadMappingType aMapping,
+                  dom::GamepadHand aHand, uint32_t aNumButtons, uint32_t aNumAxes);
   void RemoveGamepad(uint32_t aIndex);
 
 protected:
   VRControllerManager() : mInstalled(false), mControllerCount(0) {}
   virtual ~VRControllerManager() {}
 
   bool mInstalled;
   uint32_t mControllerCount;
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -20,20 +20,18 @@
 #endif // XP_WIN
 
 #include "gfxVROpenVR.h"
 
 #include "nsServiceManagerUtils.h"
 #include "nsIScreenManager.h"
 #include "openvr/openvr.h"
 
-#ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadEventTypes.h"
 #include "mozilla/dom/GamepadBinding.h"
-#endif
 
 #ifndef M_PI
 # define M_PI 3.14159265358979323846
 #endif
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::gfx::impl;
@@ -485,19 +483,17 @@ VRDisplayManagerOpenVR::GetHMDs(nsTArray
   }
 }
 
 VRControllerOpenVR::VRControllerOpenVR()
   : VRControllerHost(VRDeviceType::OpenVR)
 {
   MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
   mControllerInfo.mControllerName.AssignLiteral("OpenVR HMD");
-#ifdef MOZ_GAMEPAD
-  mControllerInfo.mMappingType = static_cast<uint32_t>(GamepadMappingType::_empty);
-#endif
+  mControllerInfo.mMappingType = GamepadMappingType::_empty;
   mControllerInfo.mNumButtons = gNumOpenVRButtonMask;
   mControllerInfo.mNumAxes = gNumOpenVRAxis;
 }
 
 VRControllerOpenVR::~VRControllerOpenVR()
 {
   MOZ_COUNT_DTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
 }
@@ -739,45 +735,40 @@ VRControllerManagerOpenVR::ScanForDevice
       RemoveGamepad(mOpenVRController[i]->GetIndex());
     }
     mControllerCount = 0;
     mOpenVRController.Clear();
 
     // Re-adding controllers to VRControllerManager.
     for (vr::TrackedDeviceIndex_t i = 0; i < newControllerCount; ++i) {
       vr::TrackedDeviceIndex_t trackedDevice = trackedIndexArray[i];
-  #ifdef MOZ_GAMEPAD
       vr::ETrackedControllerRole role =
       mVRSystem->GetControllerRoleForTrackedDeviceIndex(trackedDevice);
       GamepadHand hand;
 
       switch(role) {
         case vr::ETrackedControllerRole::TrackedControllerRole_Invalid:
           hand = GamepadHand::_empty;
           break;
         case vr::ETrackedControllerRole::TrackedControllerRole_LeftHand:
           hand = GamepadHand::Left;
           break;
         case vr::ETrackedControllerRole::TrackedControllerRole_RightHand:
           hand = GamepadHand::Right;
           break;
       }
-  #endif
       RefPtr<VRControllerOpenVR> openVRController = new VRControllerOpenVR();
       openVRController->SetIndex(mControllerCount);
       openVRController->SetTrackedIndex(trackedDevice);
       mOpenVRController.AppendElement(openVRController);
 
-  // Only in MOZ_GAMEPAD platform, We add gamepads.
-  #ifdef MOZ_GAMEPAD
       // Not already present, add it.
-       AddGamepad("OpenVR Gamepad", static_cast<uint32_t>(GamepadMappingType::_empty),
-               static_cast<uint32_t>(hand), gNumOpenVRButtonMask, gNumOpenVRAxis);
+      AddGamepad("OpenVR Gamepad", GamepadMappingType::_empty,
+                 hand, gNumOpenVRButtonMask, gNumOpenVRAxis);
       ++mControllerCount;
-  #endif
     }
   }
 }
 
 void
 VRControllerManagerOpenVR::RemoveDevices()
 {
   mOpenVRController.Clear();
--- a/gfx/vr/ipc/VRManagerChild.cpp
+++ b/gfx/vr/ipc/VRManagerChild.cpp
@@ -12,20 +12,17 @@
 #include "mozilla/StaticPtr.h"
 #include "mozilla/layers/CompositorThread.h" // for CompositorThread
 #include "mozilla/dom/Navigator.h"
 #include "mozilla/dom/VREventObserver.h"
 #include "mozilla/dom/WindowBinding.h" // for FrameRequestCallback
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/layers/TextureClient.h"
 #include "nsContentUtils.h"
-
-#ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadManager.h"
-#endif
 
 using layers::TextureClient;
 
 namespace {
 const nsTArray<RefPtr<dom::VREventObserver>>::index_type kNoIndex =
   nsTArray<RefPtr<dom::VREventObserver> >::NoIndex;
 } // namespace
 
@@ -474,27 +471,25 @@ VRManagerChild::RecvNotifyVRVSync(const 
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 VRManagerChild::RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent)
 {
-#ifdef MOZ_GAMEPAD
   // VRManagerChild could be at other processes, but GamepadManager
   // only exists at the content process or the same process
   // in non-e10s mode.
   MOZ_ASSERT(XRE_IsContentProcess() || IsSameProcess());
 
   RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
   if (gamepadManager) {
     gamepadManager->Update(aGamepadEvent);
   }
-#endif
 
   return IPC_OK();
 }
 
 void
 VRManagerChild::RunFrameRequestCallbacks()
 {
   TimeStamp nowTime = TimeStamp::Now();