зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1323328 - Part 2: Implement VRServiceTest backend at VRManager; r=kip
MozReview-Commit-ID: EpW7BqeICLo --HG-- extra : rebase_source : 6274d1ed704b6dae7b06a71e357b189c97cfbde3
This commit is contained in:
Родитель
6021ede12b
Коммит
cfca85c8aa
|
@ -62,6 +62,15 @@ parent:
|
|||
// GetControllers synchronously returns the VR controllers that have already been
|
||||
// enumerated by RefreshVRControllers() but does not enumerate new ones.
|
||||
sync GetControllers() returns(VRControllerInfo[] aControllerInfo);
|
||||
async CreateVRServiceTestDisplay(nsCString aID, uint32_t aPromiseID);
|
||||
async CreateVRServiceTestController(nsCString aID, uint32_t aPromiseID);
|
||||
async SetDisplayInfoToMockDisplay(uint32_t aDeviceID, VRDisplayInfo aDisplayInfo);
|
||||
async SetSensorStateToMockDisplay(uint32_t aDeviceID, VRHMDSensorState aSensorState);
|
||||
async NewButtonEventToMockController(uint32_t aDeviceID, long aButton,
|
||||
bool aPressed);
|
||||
async NewAxisMoveEventToMockController(uint32_t aDeviceID, long aAxis,
|
||||
double aValue);
|
||||
async NewPoseMoveToMockController(uint32_t aDeviceID, GamepadPoseState aPose);
|
||||
|
||||
child:
|
||||
|
||||
|
@ -76,6 +85,10 @@ child:
|
|||
async NotifyVSync();
|
||||
async NotifyVRVSync(uint32_t aDisplayID);
|
||||
async GamepadUpdate(GamepadChangeEvent aGamepadEvent);
|
||||
async ReplyCreateVRServiceTestDisplay(nsCString aID, uint32_t aPromiseID,
|
||||
uint32_t aDeviceID);
|
||||
async ReplyCreateVRServiceTestController(nsCString aID, uint32_t aPromiseID,
|
||||
uint32_t aDeviceID);
|
||||
|
||||
async __delete__();
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "mozilla/layers/TextureClient.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/GamepadManager.h"
|
||||
#include "mozilla/dom/VRServiceTest.h"
|
||||
|
||||
using layers::TextureClient;
|
||||
|
||||
|
@ -43,6 +44,7 @@ VRManagerChild::VRManagerChild()
|
|||
, mMessageLoop(MessageLoop::current())
|
||||
, mFrameRequestCallbackCounter(0)
|
||||
, mBackend(layers::LayersBackend::LAYERS_NONE)
|
||||
, mPromiseID(0)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -314,6 +316,22 @@ VRManagerChild::RefreshVRDisplaysWithCallback(uint64_t aWindowId)
|
|||
return success;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::CreateVRServiceTestDisplay(const nsCString& aID, dom::Promise* aPromise)
|
||||
{
|
||||
SendCreateVRServiceTestDisplay(aID, mPromiseID);
|
||||
mPromiseList.Put(mPromiseID, aPromise);
|
||||
++mPromiseID;
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::CreateVRServiceTestController(const nsCString& aID, dom::Promise* aPromise)
|
||||
{
|
||||
SendCreateVRServiceTestController(aID, mPromiseID);
|
||||
mPromiseList.Put(mPromiseID, aPromise);
|
||||
++mPromiseID;
|
||||
}
|
||||
|
||||
int
|
||||
VRManagerChild::GetInputFrameID()
|
||||
{
|
||||
|
@ -491,6 +509,36 @@ VRManagerChild::RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent)
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerChild::RecvReplyCreateVRServiceTestDisplay(const nsCString& aID,
|
||||
const uint32_t& aPromiseID,
|
||||
const uint32_t& aDeviceID)
|
||||
{
|
||||
RefPtr<dom::Promise> p;
|
||||
if (!mPromiseList.Get(aPromiseID, getter_AddRefs(p))) {
|
||||
MOZ_CRASH("We should always have a promise.");
|
||||
}
|
||||
|
||||
p->MaybeResolve(new VRMockDisplay(aID, aDeviceID));
|
||||
mPromiseList.Remove(aPromiseID);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerChild::RecvReplyCreateVRServiceTestController(const nsCString& aID,
|
||||
const uint32_t& aPromiseID,
|
||||
const uint32_t& aDeviceID)
|
||||
{
|
||||
RefPtr<dom::Promise> p;
|
||||
if (!mPromiseList.Get(aPromiseID, getter_AddRefs(p))) {
|
||||
MOZ_CRASH("We should always have a promise.");
|
||||
}
|
||||
|
||||
p->MaybeResolve(new VRMockController(aID, aDeviceID));
|
||||
mPromiseList.Remove(aPromiseID);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
void
|
||||
VRManagerChild::RunFrameRequestCallbacks()
|
||||
{
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
int GetInputFrameID();
|
||||
bool GetVRDisplays(nsTArray<RefPtr<VRDisplayClient> >& aDisplays);
|
||||
bool RefreshVRDisplaysWithCallback(uint64_t aWindowId);
|
||||
void CreateVRServiceTestDisplay(const nsCString& aID, dom::Promise* aPromise);
|
||||
void CreateVRServiceTestController(const nsCString& aID, dom::Promise* aPromise);
|
||||
|
||||
static void InitSameProcess();
|
||||
static void InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint);
|
||||
|
@ -117,6 +119,12 @@ protected:
|
|||
virtual mozilla::ipc::IPCResult RecvNotifyVSync() override;
|
||||
virtual mozilla::ipc::IPCResult RecvNotifyVRVSync(const uint32_t& aDisplayID) override;
|
||||
virtual mozilla::ipc::IPCResult RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) override;
|
||||
virtual mozilla::ipc::IPCResult RecvReplyCreateVRServiceTestDisplay(const nsCString& aID,
|
||||
const uint32_t& aPromiseID,
|
||||
const uint32_t& aDeviceID) override;
|
||||
virtual mozilla::ipc::IPCResult RecvReplyCreateVRServiceTestController(const nsCString& aID,
|
||||
const uint32_t& aPromiseID,
|
||||
const uint32_t& aDeviceID) override;
|
||||
|
||||
// ShmemAllocator
|
||||
|
||||
|
@ -177,6 +185,8 @@ private:
|
|||
|
||||
layers::LayersBackend mBackend;
|
||||
RefPtr<layers::SyncObject> mSyncObject;
|
||||
uint32_t mPromiseID;
|
||||
nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(VRManagerChild);
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "mozilla/layers/CompositorThread.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "VRManager.h"
|
||||
#include "gfxVRPuppet.h"
|
||||
|
||||
namespace mozilla {
|
||||
using namespace layers;
|
||||
|
@ -21,6 +22,8 @@ namespace gfx {
|
|||
|
||||
VRManagerParent::VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild)
|
||||
: HostIPCAllocator()
|
||||
, mDisplayTestID(0)
|
||||
, mControllerTestID(0)
|
||||
, mHaveEventListener(false)
|
||||
, mHaveControllerListener(false)
|
||||
, mIsContentChild(aIsContentChild)
|
||||
|
@ -326,6 +329,129 @@ VRManagerParent::RecvGetControllers(nsTArray<VRControllerInfo> *aControllers)
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint32_t& aPromiseID)
|
||||
{
|
||||
nsTArray<VRDisplayInfo> displayInfoArray;
|
||||
impl::VRDisplayPuppet* displayPuppet = nullptr;
|
||||
VRManager* vm = VRManager::Get();
|
||||
vm->RefreshVRDisplays();
|
||||
|
||||
// Get VRDisplayPuppet from VRManager
|
||||
vm->GetVRDisplayInfo(displayInfoArray);
|
||||
for (auto& displayInfo : displayInfoArray) {
|
||||
if (displayInfo.GetType() == VRDeviceType::Puppet) {
|
||||
displayPuppet = static_cast<impl::VRDisplayPuppet*>(
|
||||
vm->GetDisplay(displayInfo.GetDisplayID()).get());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(displayPuppet);
|
||||
MOZ_ASSERT(!mDisplayTestID); // We have only one display in VRSystemManagerPuppet.
|
||||
|
||||
if (!mVRDisplayTests.Get(mDisplayTestID, nullptr)) {
|
||||
mVRDisplayTests.Put(mDisplayTestID, displayPuppet);
|
||||
}
|
||||
|
||||
if (SendReplyCreateVRServiceTestDisplay(aID, aPromiseID, mDisplayTestID)) {
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
return IPC_FAIL(this, "SendReplyCreateVRServiceTestController fail");
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvCreateVRServiceTestController(const nsCString& aID, const uint32_t& aPromiseID)
|
||||
{
|
||||
uint32_t controllerIdx = 0;
|
||||
nsTArray<VRControllerInfo> controllerInfoArray;
|
||||
impl::VRControllerPuppet* controllerPuppet = nullptr;
|
||||
VRManager* vm = VRManager::Get();
|
||||
|
||||
// Get VRControllerPuppet from VRManager
|
||||
vm->GetVRControllerInfo(controllerInfoArray);
|
||||
for (auto& controllerInfo : controllerInfoArray) {
|
||||
if (controllerInfo.GetType() == VRDeviceType::Puppet) {
|
||||
if (controllerIdx == mControllerTestID) {
|
||||
controllerPuppet = static_cast<impl::VRControllerPuppet*>(
|
||||
vm->GetController(controllerInfo.GetControllerID()).get());
|
||||
break;
|
||||
}
|
||||
++controllerIdx;
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(controllerPuppet);
|
||||
MOZ_ASSERT(mControllerTestID < 2); // We have only two controllers in VRSystemManagerPuppet.
|
||||
|
||||
if (!mVRControllerTests.Get(mControllerTestID, nullptr)) {
|
||||
mVRControllerTests.Put(mControllerTestID, controllerPuppet);
|
||||
}
|
||||
|
||||
if (SendReplyCreateVRServiceTestController(aID, aPromiseID, mControllerTestID)) {
|
||||
++mControllerTestID;
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
return IPC_FAIL(this, "SendReplyCreateVRServiceTestController fail");
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvSetDisplayInfoToMockDisplay(const uint32_t& aDeviceID,
|
||||
const VRDisplayInfo& aDisplayInfo)
|
||||
{
|
||||
RefPtr<impl::VRDisplayPuppet> displayPuppet;
|
||||
MOZ_ASSERT(mVRDisplayTests.Get(mDisplayTestID,
|
||||
getter_AddRefs(displayPuppet)));
|
||||
displayPuppet->SetDisplayInfo(aDisplayInfo);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvSetSensorStateToMockDisplay(const uint32_t& aDeviceID,
|
||||
const VRHMDSensorState& aSensorState)
|
||||
{
|
||||
RefPtr<impl::VRDisplayPuppet> displayPuppet;
|
||||
MOZ_ASSERT(mVRDisplayTests.Get(mControllerTestID,
|
||||
getter_AddRefs(displayPuppet)));
|
||||
displayPuppet->SetSensorState(aSensorState);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvNewButtonEventToMockController(const uint32_t& aDeviceID, const long& aButton,
|
||||
const bool& aPressed)
|
||||
{
|
||||
RefPtr<impl::VRControllerPuppet> controllerPuppet;
|
||||
MOZ_ASSERT(mVRControllerTests.Get(mControllerTestID,
|
||||
getter_AddRefs(controllerPuppet)));
|
||||
controllerPuppet->SetButtonPressState(aButton, aPressed);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvNewAxisMoveEventToMockController(const uint32_t& aDeviceID, const long& aAxis,
|
||||
const double& aValue)
|
||||
{
|
||||
RefPtr<impl::VRControllerPuppet> controllerPuppet;
|
||||
MOZ_ASSERT(mVRControllerTests.Get(mControllerTestID,
|
||||
getter_AddRefs(controllerPuppet)));
|
||||
controllerPuppet->SetAxisMoveState(aAxis, aValue);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
VRManagerParent::RecvNewPoseMoveToMockController(const uint32_t& aDeviceID,
|
||||
const GamepadPoseState& pose)
|
||||
{
|
||||
RefPtr<impl::VRControllerPuppet> controllerPuppet;
|
||||
MOZ_ASSERT(mVRControllerTests.Get(mControllerTestID,
|
||||
getter_AddRefs(controllerPuppet)));
|
||||
controllerPuppet->SetPoseMoveState(pose);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
bool
|
||||
VRManagerParent::SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent)
|
||||
{
|
||||
|
|
|
@ -22,6 +22,11 @@ namespace gfx {
|
|||
|
||||
class VRManager;
|
||||
|
||||
namespace impl {
|
||||
class VRDisplayPuppet;
|
||||
class VRControllerPuppet;
|
||||
} // namespace impl
|
||||
|
||||
class VRManagerParent final : public PVRManagerParent
|
||||
, public HostIPCAllocator
|
||||
, public ShmemAllocator
|
||||
|
@ -89,6 +94,17 @@ protected:
|
|||
virtual mozilla::ipc::IPCResult RecvControllerListenerAdded() override;
|
||||
virtual mozilla::ipc::IPCResult RecvControllerListenerRemoved() override;
|
||||
virtual mozilla::ipc::IPCResult RecvGetControllers(nsTArray<VRControllerInfo> *aControllers) override;
|
||||
virtual mozilla::ipc::IPCResult RecvCreateVRServiceTestDisplay(const nsCString& aID, const uint32_t& aPromiseID) override;
|
||||
virtual mozilla::ipc::IPCResult RecvCreateVRServiceTestController(const nsCString& aID, const uint32_t& aPromiseID) override;
|
||||
virtual mozilla::ipc::IPCResult RecvSetDisplayInfoToMockDisplay(const uint32_t& aDeviceID,
|
||||
const VRDisplayInfo& aDisplayInfo) override;
|
||||
virtual mozilla::ipc::IPCResult RecvSetSensorStateToMockDisplay(const uint32_t& aDeviceID,
|
||||
const VRHMDSensorState& aSensorState) override;
|
||||
virtual mozilla::ipc::IPCResult RecvNewButtonEventToMockController(const uint32_t& aDeviceID, const long& aButton,
|
||||
const bool& aPressed) override;
|
||||
virtual mozilla::ipc::IPCResult RecvNewAxisMoveEventToMockController(const uint32_t& aDeviceID, const long& aAxis,
|
||||
const double& aValue) override;
|
||||
virtual mozilla::ipc::IPCResult RecvNewPoseMoveToMockController(const uint32_t& aDeviceID, const GamepadPoseState& pose) override;
|
||||
|
||||
private:
|
||||
void RegisterWithManager();
|
||||
|
@ -109,6 +125,10 @@ private:
|
|||
|
||||
// Keep the VRManager alive, until we have destroyed ourselves.
|
||||
RefPtr<VRManager> mVRManagerHolder;
|
||||
nsRefPtrHashtable<nsUint32HashKey, impl::VRDisplayPuppet> mVRDisplayTests;
|
||||
nsRefPtrHashtable<nsUint32HashKey, impl::VRControllerPuppet> mVRControllerTests;
|
||||
uint32_t mDisplayTestID;
|
||||
uint32_t mControllerTestID;
|
||||
bool mHaveEventListener;
|
||||
bool mHaveControllerListener;
|
||||
bool mIsContentChild;
|
||||
|
|
Загрузка…
Ссылка в новой задаче