Skip to content

Commit

Permalink
Bug 1305889 - Part 2: Using VRControllerInfo as the parameter for Add…
Browse files Browse the repository at this point in the history
…Gamepad; r=kip

MozReview-Commit-ID: Coye62hZxRs

--HG--
extra : rebase_source : d4166395794a55c565f37b803099682c9e075d8b
  • Loading branch information
daoshengmu committed Feb 6, 2017
1 parent 8a2e76e commit 3e9c86d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 67 deletions.
6 changes: 5 additions & 1 deletion gfx/vr/VRManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp)
const double kVRDisplayRefreshMaxDuration = 5000; // milliseconds

bool bHaveEventListener = false;
bool bHaveControllerListener = false;

for (auto iter = mVRManagerParents.Iter(); !iter.Done(); iter.Next()) {
VRManagerParent *vmp = iter.Get()->GetKey();
if (mVRDisplays.Count()) {
Unused << vmp->SendNotifyVSync();
}
bHaveEventListener |= vmp->HaveEventListener();
bHaveControllerListener |= vmp->HaveControllerListener();
}

for (auto iter = mVRDisplays.Iter(); !iter.Done(); iter.Next()) {
Expand All @@ -180,7 +182,9 @@ VRManager::NotifyVsync(const TimeStamp& aVsyncTimestamp)
if (mLastRefreshTime.IsNull()) {
// This is the first vsync, must refresh VR displays
RefreshVRDisplays();
RefreshVRControllers();
if (bHaveControllerListener) {
RefreshVRControllers();
}
mLastRefreshTime = TimeStamp::Now();
} else {
// We don't have to do this every frame, so check if we
Expand Down
13 changes: 8 additions & 5 deletions gfx/vr/gfxVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ VRFieldOfView::ConstructProjectionMatrix(float zNear, float zFar,
}

void
VRSystemManager::AddGamepad(const char* aID, dom::GamepadMappingType aMapping,
dom::GamepadHand aHand, uint32_t aNumButtons, uint32_t aNumAxes)
VRSystemManager::AddGamepad(const VRControllerInfo& controllerInfo)
{
dom::GamepadAdded a(NS_ConvertUTF8toUTF16(nsDependentCString(aID)), mControllerCount,
aMapping, aHand, dom::GamepadServiceType::VR, aNumButtons,
aNumAxes);
dom::GamepadAdded a(NS_ConvertUTF8toUTF16(controllerInfo.GetControllerName()),
mControllerCount,
controllerInfo.GetMappingType(),
controllerInfo.GetHand(),
dom::GamepadServiceType::VR,
controllerInfo.GetNumButtons(),
controllerInfo.GetNumAxes());

VRManager* vm = VRManager::Get();
MOZ_ASSERT(vm);
Expand Down
66 changes: 34 additions & 32 deletions gfx/vr/gfxVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,39 @@ struct VRHMDSensorState {
}
};

struct VRControllerInfo
{
VRDeviceType GetType() const { return mType; }
uint32_t GetControllerID() const { return mControllerID; }
const nsCString& GetControllerName() const { return mControllerName; }
dom::GamepadMappingType GetMappingType() const { return mMappingType; }
dom::GamepadHand GetHand() const { return mHand; }
uint32_t GetNumButtons() const { return mNumButtons; }
uint32_t GetNumAxes() const { return mNumAxes; }

uint32_t mControllerID;
VRDeviceType mType;
nsCString mControllerName;
dom::GamepadMappingType mMappingType;
dom::GamepadHand mHand;
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 &&
mHand == other.mHand &&
mNumButtons == other.mNumButtons &&
mNumAxes == other.mNumAxes;
}

bool operator!=(const VRControllerInfo& other) const {
return !(*this == other);
}
};

class VRSystemManager {
public:
static uint32_t AllocateDisplayID();
Expand All @@ -224,8 +257,7 @@ class VRSystemManager {
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, dom::GamepadMappingType aMapping,
dom::GamepadHand aHand, uint32_t aNumButtons, uint32_t aNumAxes);
void AddGamepad(const VRControllerInfo& controllerInfo);
void RemoveGamepad(uint32_t aIndex);

protected:
Expand All @@ -244,36 +276,6 @@ class VRSystemManager {
VRControllerHost* aController) = 0;
};

struct VRControllerInfo
{
VRDeviceType GetType() const { return mType; }
uint32_t GetControllerID() const { return mControllerID; }
const nsCString& GetControllerName() const { return mControllerName; }
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;
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 &&
mNumButtons == other.mNumButtons &&
mNumAxes == other.mNumAxes;
}

bool operator!=(const VRControllerInfo& other) const {
return !(*this == other);
}
};

} // namespace gfx
} // namespace mozilla

Expand Down
60 changes: 31 additions & 29 deletions gfx/vr/gfxVROpenVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,34 @@ VRDisplayOpenVR::NotifyVSync()
PollEvents();
}

VRControllerOpenVR::VRControllerOpenVR()
: VRControllerHost(VRDeviceType::OpenVR)
{
MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
mControllerInfo.mControllerName.AssignLiteral("OpenVR Gamepad");
mControllerInfo.mMappingType = GamepadMappingType::_empty;
mControllerInfo.mHand = GamepadHand::_empty;
mControllerInfo.mNumButtons = gNumOpenVRButtonMask;
mControllerInfo.mNumAxes = gNumOpenVRAxis;
}

VRControllerOpenVR::~VRControllerOpenVR()
{
MOZ_COUNT_DTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
}

void
VRControllerOpenVR::SetTrackedIndex(uint32_t aTrackedIndex)
{
mTrackedIndex = aTrackedIndex;
}

uint32_t
VRControllerOpenVR::GetTrackedIndex()
{
return mTrackedIndex;
}

VRSystemManagerOpenVR::VRSystemManagerOpenVR()
: mVRSystem(nullptr), mOpenVRInstalled(false)
{
Expand Down Expand Up @@ -463,6 +491,7 @@ VRSystemManagerOpenVR::Destroy()
mOpenVRHMD = nullptr;
}
RemoveControllers();
mVRSystem = nullptr;
mOpenVRInstalled = false;
}
}
Expand Down Expand Up @@ -707,11 +736,11 @@ VRSystemManagerOpenVR::ScanForControllers()
RefPtr<VRControllerOpenVR> openVRController = new VRControllerOpenVR();
openVRController->SetIndex(mControllerCount);
openVRController->SetTrackedIndex(trackedDevice);
openVRController->SetHand(hand);
mOpenVRController.AppendElement(openVRController);

// Not already present, add it.
AddGamepad("OpenVR Gamepad", GamepadMappingType::_empty,
hand, gNumOpenVRButtonMask, gNumOpenVRAxis);
AddGamepad(openVRController->GetControllerInfo());
++mControllerCount;
}
}
Expand All @@ -723,30 +752,3 @@ VRSystemManagerOpenVR::RemoveControllers()
mOpenVRController.Clear();
mControllerCount = 0;
}

VRControllerOpenVR::VRControllerOpenVR()
: VRControllerHost(VRDeviceType::OpenVR)
{
MOZ_COUNT_CTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
mControllerInfo.mControllerName.AssignLiteral("OpenVR HMD");
mControllerInfo.mMappingType = GamepadMappingType::_empty;
mControllerInfo.mNumButtons = gNumOpenVRButtonMask;
mControllerInfo.mNumAxes = gNumOpenVRAxis;
}

VRControllerOpenVR::~VRControllerOpenVR()
{
MOZ_COUNT_DTOR_INHERITED(VRControllerOpenVR, VRControllerHost);
}

void
VRControllerOpenVR::SetTrackedIndex(uint32_t aTrackedIndex)
{
mTrackedIndex = aTrackedIndex;
}

uint32_t
VRControllerOpenVR::GetTrackedIndex()
{
return mTrackedIndex;
}
9 changes: 9 additions & 0 deletions gfx/vr/ipc/VRManagerParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace gfx {
VRManagerParent::VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild)
: HostIPCAllocator()
, mHaveEventListener(false)
, mHaveControllerListener(false)
, mIsContentChild(aIsContentChild)
{
MOZ_COUNT_CTOR(VRManagerParent);
Expand Down Expand Up @@ -285,6 +286,12 @@ VRManagerParent::HaveEventListener()
return mHaveEventListener;
}

bool
VRManagerParent::HaveControllerListener()
{
return mHaveControllerListener;
}

mozilla::ipc::IPCResult
VRManagerParent::RecvSetHaveEventListener(const bool& aHaveEventListener)
{
Expand All @@ -296,6 +303,7 @@ mozilla::ipc::IPCResult
VRManagerParent::RecvControllerListenerAdded()
{
VRManager* vm = VRManager::Get();
mHaveControllerListener = true;
// Ask the connected gamepads to be added to GamepadManager
vm->ScanForControllers();
return IPC_OK();
Expand All @@ -305,6 +313,7 @@ mozilla::ipc::IPCResult
VRManagerParent::RecvControllerListenerRemoved()
{
VRManager* vm = VRManager::Get();
mHaveControllerListener = false;
vm->RemoveControllers();
return IPC_OK();
}
Expand Down
2 changes: 2 additions & 0 deletions gfx/vr/ipc/VRManagerParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class VRManagerParent final : public PVRManagerParent

virtual bool IsSameProcess() const override;
bool HaveEventListener();
bool HaveControllerListener();

virtual void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override;
virtual void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override;
Expand Down Expand Up @@ -109,6 +110,7 @@ class VRManagerParent final : public PVRManagerParent
// Keep the VRManager alive, until we have destroyed ourselves.
RefPtr<VRManager> mVRManagerHolder;
bool mHaveEventListener;
bool mHaveControllerListener;
bool mIsContentChild;
};

Expand Down

0 comments on commit 3e9c86d

Please sign in to comment.