2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-09-17 21:23:13 +00:00
|
|
|
/* 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 "VRManagerChild.h"
|
|
|
|
#include "VRManagerParent.h"
|
2017-10-05 10:16:16 +00:00
|
|
|
#include "VRThread.h"
|
2016-02-24 23:54:50 +00:00
|
|
|
#include "VRDisplayClient.h"
|
2016-10-04 08:30:04 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
2015-09-17 21:23:13 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2016-05-16 06:39:30 +00:00
|
|
|
#include "mozilla/layers/CompositorThread.h" // for CompositorThread
|
2015-09-17 21:23:13 +00:00
|
|
|
#include "mozilla/dom/Navigator.h"
|
2016-07-04 22:46:49 +00:00
|
|
|
#include "mozilla/dom/VREventObserver.h"
|
2016-02-24 23:54:50 +00:00
|
|
|
#include "mozilla/dom/WindowBinding.h" // for FrameRequestCallback
|
2016-10-04 08:31:27 +00:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2016-07-04 22:46:49 +00:00
|
|
|
#include "nsContentUtils.h"
|
2016-11-04 07:53:01 +00:00
|
|
|
#include "mozilla/dom/GamepadManager.h"
|
2017-03-01 15:58:31 +00:00
|
|
|
#include "mozilla/dom/VRServiceTest.h"
|
2017-08-07 10:15:24 +00:00
|
|
|
#include "mozilla/layers/SyncObject.h"
|
2016-11-04 07:53:01 +00:00
|
|
|
|
2016-07-04 22:46:49 +00:00
|
|
|
namespace {
|
|
|
|
const nsTArray<RefPtr<dom::VREventObserver>>::index_type kNoIndex =
|
|
|
|
nsTArray<RefPtr<dom::VREventObserver> >::NoIndex;
|
|
|
|
} // namespace
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
static StaticRefPtr<VRManagerChild> sVRManagerChildSingleton;
|
|
|
|
static StaticRefPtr<VRManagerParent> sVRManagerParentSingleton;
|
|
|
|
|
|
|
|
void ReleaseVRManagerParentSingleton() {
|
|
|
|
sVRManagerParentSingleton = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VRManagerChild::VRManagerChild()
|
2017-09-15 00:10:15 +00:00
|
|
|
: mDisplaysInitialized(false)
|
2016-02-24 23:54:50 +00:00
|
|
|
, mMessageLoop(MessageLoop::current())
|
|
|
|
, mFrameRequestCallbackCounter(0)
|
|
|
|
, mBackend(layers::LayersBackend::LAYERS_NONE)
|
2017-03-01 15:58:31 +00:00
|
|
|
, mPromiseID(0)
|
2017-03-15 05:50:34 +00:00
|
|
|
, mVRMockDisplay(nullptr)
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-02-24 23:54:50 +00:00
|
|
|
|
|
|
|
mStartTimeStamp = TimeStamp::Now();
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VRManagerChild::~VRManagerChild()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
/*static*/ void
|
|
|
|
VRManagerChild::IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier)
|
|
|
|
{
|
|
|
|
if (sVRManagerChildSingleton) {
|
|
|
|
sVRManagerChildSingleton->mBackend = aIdentifier.mParentBackend;
|
2017-08-07 10:15:24 +00:00
|
|
|
sVRManagerChildSingleton->mSyncObject =
|
|
|
|
layers::SyncObjectClient::CreateSyncObjectClient(aIdentifier.mSyncHandle);
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layers::LayersBackend
|
|
|
|
VRManagerChild::GetBackendType() const
|
|
|
|
{
|
|
|
|
return mBackend;
|
|
|
|
}
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
/*static*/ VRManagerChild*
|
|
|
|
VRManagerChild::Get()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sVRManagerChildSingleton);
|
|
|
|
return sVRManagerChildSingleton;
|
|
|
|
}
|
|
|
|
|
2016-07-21 07:14:59 +00:00
|
|
|
/* static */ bool
|
|
|
|
VRManagerChild::IsCreated()
|
|
|
|
{
|
|
|
|
return !!sVRManagerChildSingleton;
|
|
|
|
}
|
|
|
|
|
2016-07-21 07:14:59 +00:00
|
|
|
/* static */ bool
|
|
|
|
VRManagerChild::InitForContent(Endpoint<PVRManagerChild>&& aEndpoint)
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!sVRManagerChildSingleton);
|
|
|
|
|
|
|
|
RefPtr<VRManagerChild> child(new VRManagerChild());
|
2016-09-02 20:13:50 +00:00
|
|
|
if (!aEndpoint.Bind(child)) {
|
2018-02-14 23:07:53 +00:00
|
|
|
return false;
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
sVRManagerChildSingleton = child;
|
2016-07-21 07:14:59 +00:00
|
|
|
return true;
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 08:18:50 +00:00
|
|
|
/* static */ bool
|
|
|
|
VRManagerChild::ReinitForContent(Endpoint<PVRManagerChild>&& aEndpoint)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
ShutDown();
|
|
|
|
|
|
|
|
return InitForContent(Move(aEndpoint));
|
|
|
|
}
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
/*static*/ void
|
2016-07-21 07:14:59 +00:00
|
|
|
VRManagerChild::InitSameProcess()
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
2016-07-21 07:14:59 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!sVRManagerChildSingleton);
|
2016-07-21 07:14:59 +00:00
|
|
|
|
|
|
|
sVRManagerChildSingleton = new VRManagerChild();
|
|
|
|
sVRManagerParentSingleton = VRManagerParent::CreateSameProcess();
|
|
|
|
sVRManagerChildSingleton->Open(sVRManagerParentSingleton->GetIPCChannel(),
|
2017-11-02 04:44:12 +00:00
|
|
|
VRListenerThreadHolder::Loop(),
|
2016-07-21 07:14:59 +00:00
|
|
|
mozilla::ipc::ChildSide);
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 07:14:59 +00:00
|
|
|
/* static */ void
|
|
|
|
VRManagerChild::InitWithGPUProcess(Endpoint<PVRManagerChild>&& aEndpoint)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!sVRManagerChildSingleton);
|
|
|
|
|
|
|
|
sVRManagerChildSingleton = new VRManagerChild();
|
2016-09-02 20:13:50 +00:00
|
|
|
if (!aEndpoint.Bind(sVRManagerChildSingleton)) {
|
2017-10-25 06:30:31 +00:00
|
|
|
MOZ_CRASH("Couldn't Open() Compositor channel.");
|
2016-07-21 07:14:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
/*static*/ void
|
|
|
|
VRManagerChild::ShutDown()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (sVRManagerChildSingleton) {
|
|
|
|
sVRManagerChildSingleton->Destroy();
|
|
|
|
sVRManagerChildSingleton = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
VRManagerChild::DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild)
|
|
|
|
{
|
2016-02-24 23:54:50 +00:00
|
|
|
aVRManagerChild->Close();
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::Destroy()
|
|
|
|
{
|
|
|
|
// Keep ourselves alive until everything has been shut down
|
|
|
|
RefPtr<VRManagerChild> selfRef = this;
|
|
|
|
|
|
|
|
// The DeferredDestroyVRManager task takes ownership of
|
|
|
|
// the VRManagerChild and will release it when it runs.
|
2016-04-28 00:06:05 +00:00
|
|
|
MessageLoop::current()->PostTask(
|
2017-10-27 20:39:28 +00:00
|
|
|
NewRunnableFunction("VRManagerChildDestroyRunnable",
|
|
|
|
DeferredDestroy, selfRef));
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
PVRLayerChild*
|
|
|
|
VRManagerChild::AllocPVRLayerChild(const uint32_t& aDisplayID,
|
2017-05-08 23:01:36 +00:00
|
|
|
const uint32_t& aGroup)
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2017-07-12 23:05:40 +00:00
|
|
|
return VRLayerChild::CreateIPDLActor();
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::DeallocPVRLayerChild(PVRLayerChild* actor)
|
|
|
|
{
|
2017-07-12 23:05:40 +00:00
|
|
|
return VRLayerChild::DestroyIPDLActor(actor);
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 22:52:21 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::UpdateDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayUpdates)
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2017-02-14 19:21:09 +00:00
|
|
|
nsTArray<uint32_t> disconnectedDisplays;
|
|
|
|
nsTArray<uint32_t> connectedDisplays;
|
2016-02-24 23:54:50 +00:00
|
|
|
|
|
|
|
// Check if any displays have been disconnected
|
|
|
|
for (auto& display : mDisplays) {
|
|
|
|
bool found = false;
|
|
|
|
for (auto& displayUpdate : aDisplayUpdates) {
|
|
|
|
if (display->GetDisplayInfo().GetDisplayID() == displayUpdate.GetDisplayID()) {
|
|
|
|
found = true;
|
2015-09-17 21:23:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-02-24 23:54:50 +00:00
|
|
|
if (!found) {
|
|
|
|
display->NotifyDisconnected();
|
2017-02-14 19:21:09 +00:00
|
|
|
disconnectedDisplays.AppendElement(display->GetDisplayInfo().GetDisplayID());
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
// mDisplays could be a hashed container for more scalability, but not worth
|
|
|
|
// it now as we expect < 10 entries.
|
|
|
|
nsTArray<RefPtr<VRDisplayClient>> displays;
|
2016-07-04 22:52:21 +00:00
|
|
|
for (VRDisplayInfo& displayUpdate : aDisplayUpdates) {
|
2016-02-24 23:54:50 +00:00
|
|
|
bool isNewDisplay = true;
|
2016-07-04 22:52:21 +00:00
|
|
|
for (auto& display : mDisplays) {
|
2016-02-24 23:54:50 +00:00
|
|
|
const VRDisplayInfo& prevInfo = display->GetDisplayInfo();
|
|
|
|
if (prevInfo.GetDisplayID() == displayUpdate.GetDisplayID()) {
|
|
|
|
if (displayUpdate.GetIsConnected() && !prevInfo.GetIsConnected()) {
|
2017-02-14 19:21:09 +00:00
|
|
|
connectedDisplays.AppendElement(displayUpdate.GetDisplayID());
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
if (!displayUpdate.GetIsConnected() && prevInfo.GetIsConnected()) {
|
2017-02-14 19:21:09 +00:00
|
|
|
disconnectedDisplays.AppendElement(displayUpdate.GetDisplayID());
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
display->UpdateDisplayInfo(displayUpdate);
|
|
|
|
displays.AppendElement(display);
|
|
|
|
isNewDisplay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isNewDisplay) {
|
|
|
|
displays.AppendElement(new VRDisplayClient(displayUpdate));
|
2017-02-14 19:21:09 +00:00
|
|
|
connectedDisplays.AppendElement(displayUpdate.GetDisplayID());
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 21:23:13 +00:00
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
mDisplays = displays;
|
2015-09-17 21:23:13 +00:00
|
|
|
|
2017-02-14 19:21:09 +00:00
|
|
|
// We wish to fire the events only after mDisplays is updated
|
|
|
|
for (uint32_t displayID : disconnectedDisplays) {
|
|
|
|
FireDOMVRDisplayDisconnectEvent(displayID);
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
2017-02-14 19:21:09 +00:00
|
|
|
|
|
|
|
for (uint32_t displayID : connectedDisplays) {
|
|
|
|
FireDOMVRDisplayConnectEvent(displayID);
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 22:52:21 +00:00
|
|
|
mDisplaysInitialized = true;
|
|
|
|
}
|
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
mozilla::ipc::IPCResult
|
2016-07-04 22:52:21 +00:00
|
|
|
VRManagerChild::RecvUpdateDisplayInfo(nsTArray<VRDisplayInfo>&& aDisplayUpdates)
|
|
|
|
{
|
|
|
|
UpdateDisplayInfo(aDisplayUpdates);
|
2016-11-24 19:50:43 +00:00
|
|
|
for (auto& windowId : mNavigatorCallbacks) {
|
2016-07-04 22:52:21 +00:00
|
|
|
/** We must call NotifyVRDisplaysUpdated for every
|
2016-11-24 19:50:43 +00:00
|
|
|
* window's Navigator in mNavigatorCallbacks to ensure that
|
2016-07-04 22:52:21 +00:00
|
|
|
* the promise returned by Navigator.GetVRDevices
|
|
|
|
* can resolve. This must happen even if no changes
|
|
|
|
* to VRDisplays have been detected here.
|
|
|
|
*/
|
2017-11-06 18:09:35 +00:00
|
|
|
nsGlobalWindowInner* window =
|
|
|
|
nsGlobalWindowInner::GetInnerWindowWithId(windowId);
|
2016-11-24 19:50:43 +00:00
|
|
|
if (!window) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-04-14 02:40:03 +00:00
|
|
|
dom::Navigator* nav = window->Navigator();
|
|
|
|
if (!nav) {
|
2016-11-24 19:50:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-07-04 22:52:21 +00:00
|
|
|
nav->NotifyVRDisplaysUpdated();
|
|
|
|
}
|
|
|
|
mNavigatorCallbacks.Clear();
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-02-24 23:54:50 +00:00
|
|
|
VRManagerChild::GetVRDisplays(nsTArray<RefPtr<VRDisplayClient>>& aDisplays)
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
2016-02-24 23:54:50 +00:00
|
|
|
aDisplays = mDisplays;
|
2015-09-17 21:23:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-11-24 19:50:43 +00:00
|
|
|
VRManagerChild::RefreshVRDisplaysWithCallback(uint64_t aWindowId)
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
2016-02-24 23:54:50 +00:00
|
|
|
bool success = SendRefreshDisplays();
|
2015-09-17 21:23:13 +00:00
|
|
|
if (success) {
|
2016-11-24 19:50:43 +00:00
|
|
|
mNavigatorCallbacks.AppendElement(aWindowId);
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2017-03-01 15:58:31 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
PVRLayerChild*
|
2017-03-23 06:19:11 +00:00
|
|
|
VRManagerChild::CreateVRLayer(uint32_t aDisplayID,
|
2017-05-08 23:01:36 +00:00
|
|
|
nsIEventTarget* aTarget,
|
|
|
|
uint32_t aGroup)
|
2017-03-23 06:19:11 +00:00
|
|
|
{
|
2017-08-28 23:20:59 +00:00
|
|
|
PVRLayerChild* vrLayerChild = AllocPVRLayerChild(aDisplayID, aGroup);
|
2017-03-23 06:19:11 +00:00
|
|
|
// Do the DOM labeling.
|
|
|
|
if (aTarget) {
|
|
|
|
SetEventTargetForActor(vrLayerChild, aTarget);
|
|
|
|
MOZ_ASSERT(vrLayerChild->GetActorEventTarget());
|
|
|
|
}
|
2017-08-28 23:20:59 +00:00
|
|
|
return SendPVRLayerConstructor(vrLayerChild, aDisplayID, aGroup);
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// XXX TODO - VRManagerChild::FrameRequest is the same as nsIDocument::FrameRequest, should we consolodate these?
|
|
|
|
struct VRManagerChild::FrameRequest
|
|
|
|
{
|
|
|
|
FrameRequest(mozilla::dom::FrameRequestCallback& aCallback,
|
|
|
|
int32_t aHandle) :
|
|
|
|
mCallback(&aCallback),
|
|
|
|
mHandle(aHandle)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Conversion operator so that we can append these to a
|
|
|
|
// FrameRequestCallbackList
|
|
|
|
operator const RefPtr<mozilla::dom::FrameRequestCallback>& () const {
|
|
|
|
return mCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comparator operators to allow RemoveElementSorted with an
|
|
|
|
// integer argument on arrays of FrameRequest
|
|
|
|
bool operator==(int32_t aHandle) const {
|
|
|
|
return mHandle == aHandle;
|
|
|
|
}
|
|
|
|
bool operator<(int32_t aHandle) const {
|
|
|
|
return mHandle < aHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<mozilla::dom::FrameRequestCallback> mCallback;
|
|
|
|
int32_t mHandle;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
VRManagerChild::ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback,
|
|
|
|
int32_t *aHandle)
|
|
|
|
{
|
|
|
|
if (mFrameRequestCallbackCounter == INT32_MAX) {
|
|
|
|
// Can't increment without overflowing; bail out
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
int32_t newHandle = ++mFrameRequestCallbackCounter;
|
|
|
|
|
|
|
|
DebugOnly<FrameRequest*> request =
|
|
|
|
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
|
|
|
|
NS_ASSERTION(request, "This is supposed to be infallible!");
|
|
|
|
|
|
|
|
*aHandle = newHandle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::CancelFrameRequestCallback(int32_t aHandle)
|
|
|
|
{
|
|
|
|
// mFrameRequestCallbacks is stored sorted by handle
|
|
|
|
mFrameRequestCallbacks.RemoveElementSorted(aHandle);
|
|
|
|
}
|
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
mozilla::ipc::IPCResult
|
2016-10-04 08:30:04 +00:00
|
|
|
VRManagerChild::RecvGamepadUpdate(const GamepadChangeEvent& aGamepadEvent)
|
|
|
|
{
|
2016-10-11 02:45:25 +00:00
|
|
|
// VRManagerChild could be at other processes, but GamepadManager
|
2016-12-01 05:12:10 +00:00
|
|
|
// only exists at the content process or the same process
|
2016-10-11 02:45:25 +00:00
|
|
|
// in non-e10s mode.
|
2016-12-01 05:12:10 +00:00
|
|
|
MOZ_ASSERT(XRE_IsContentProcess() || IsSameProcess());
|
|
|
|
|
|
|
|
RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
|
|
|
|
if (gamepadManager) {
|
|
|
|
gamepadManager->Update(aGamepadEvent);
|
2016-10-04 08:30:04 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 03:26:00 +00:00
|
|
|
return IPC_OK();
|
2016-10-04 08:30:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:58:31 +00:00
|
|
|
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.");
|
|
|
|
}
|
|
|
|
|
2017-03-15 05:50:34 +00:00
|
|
|
// We only allow one VRMockDisplay in VR tests.
|
|
|
|
if (!mVRMockDisplay) {
|
|
|
|
mVRMockDisplay = new VRMockDisplay(aID, aDeviceID);
|
|
|
|
}
|
|
|
|
p->MaybeResolve(mVRMockDisplay);
|
2017-03-01 15:58:31 +00:00
|
|
|
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.");
|
|
|
|
}
|
|
|
|
|
2017-11-21 22:18:16 +00:00
|
|
|
if (aDeviceID == 0) {
|
|
|
|
// A value of 0 indicates that the controller could not
|
|
|
|
// be created. Most likely due to having no VR display
|
|
|
|
// to associate it with.
|
|
|
|
p->MaybeRejectWithUndefined();
|
|
|
|
} else {
|
|
|
|
p->MaybeResolve(new VRMockController(aID, aDeviceID));
|
|
|
|
}
|
2017-03-01 15:58:31 +00:00
|
|
|
mPromiseList.Remove(aPromiseID);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::RunFrameRequestCallbacks()
|
|
|
|
{
|
2017-10-03 22:11:18 +00:00
|
|
|
AUTO_PROFILER_TRACING("VR", "RunFrameRequestCallbacks");
|
2017-09-06 08:08:21 +00:00
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
TimeStamp nowTime = TimeStamp::Now();
|
|
|
|
mozilla::TimeDuration duration = nowTime - mStartTimeStamp;
|
|
|
|
DOMHighResTimeStamp timeStamp = duration.ToMilliseconds();
|
|
|
|
|
|
|
|
|
|
|
|
nsTArray<FrameRequest> callbacks;
|
|
|
|
callbacks.AppendElements(mFrameRequestCallbacks);
|
|
|
|
mFrameRequestCallbacks.Clear();
|
|
|
|
for (auto& callback : callbacks) {
|
|
|
|
callback.mCallback->Call(timeStamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 22:18:10 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayMountedEvent(uint32_t aDisplayID)
|
|
|
|
{
|
2017-06-12 19:34:10 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod<uint32_t>(
|
|
|
|
"gfx::VRManagerChild::FireDOMVRDisplayMountedEventInternal",
|
|
|
|
this,
|
2016-10-18 22:18:10 +00:00
|
|
|
&VRManagerChild::FireDOMVRDisplayMountedEventInternal,
|
|
|
|
aDisplayID));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayUnmountedEvent(uint32_t aDisplayID)
|
|
|
|
{
|
2017-06-12 19:34:10 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod<uint32_t>(
|
|
|
|
"gfx::VRManagerChild::FireDOMVRDisplayUnmountedEventInternal",
|
|
|
|
this,
|
2016-10-18 22:18:10 +00:00
|
|
|
&VRManagerChild::FireDOMVRDisplayUnmountedEventInternal,
|
|
|
|
aDisplayID));
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
void
|
2017-02-14 19:21:09 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayConnectEvent(uint32_t aDisplayID)
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2017-06-12 19:34:10 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod<uint32_t>(
|
|
|
|
"gfx::VRManagerChild::FireDOMVRDisplayConnectEventInternal",
|
|
|
|
this,
|
2017-02-14 19:21:09 +00:00
|
|
|
&VRManagerChild::FireDOMVRDisplayConnectEventInternal,
|
|
|
|
aDisplayID));
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-14 19:21:09 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayDisconnectEvent(uint32_t aDisplayID)
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2017-06-12 19:34:10 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod<uint32_t>(
|
|
|
|
"gfx::VRManagerChild::FireDOMVRDisplayDisconnectEventInternal",
|
|
|
|
this,
|
2017-02-14 19:21:09 +00:00
|
|
|
&VRManagerChild::FireDOMVRDisplayDisconnectEventInternal,
|
|
|
|
aDisplayID));
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-14 19:21:09 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayPresentChangeEvent(uint32_t aDisplayID)
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2017-06-12 19:34:10 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod<uint32_t>(
|
|
|
|
"gfx::VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal",
|
|
|
|
this,
|
2017-02-14 19:21:09 +00:00
|
|
|
&VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal,
|
|
|
|
aDisplayID));
|
2016-07-04 22:46:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 22:18:10 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayMountedEventInternal(uint32_t aDisplayID)
|
|
|
|
{
|
2017-02-14 19:21:09 +00:00
|
|
|
// Iterate over a copy of mListeners, as dispatched events may modify it.
|
|
|
|
nsTArray<RefPtr<dom::VREventObserver>> listeners;
|
|
|
|
listeners = mListeners;
|
|
|
|
for (auto& listener : listeners) {
|
2016-10-18 22:18:10 +00:00
|
|
|
listener->NotifyVRDisplayMounted(aDisplayID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayUnmountedEventInternal(uint32_t aDisplayID)
|
|
|
|
{
|
2017-02-14 19:21:09 +00:00
|
|
|
// Iterate over a copy of mListeners, as dispatched events may modify it.
|
|
|
|
nsTArray<RefPtr<dom::VREventObserver>> listeners;
|
|
|
|
listeners = mListeners;
|
|
|
|
for (auto& listener : listeners) {
|
2016-10-18 22:18:10 +00:00
|
|
|
listener->NotifyVRDisplayUnmounted(aDisplayID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 22:46:49 +00:00
|
|
|
void
|
2017-02-14 19:21:09 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayConnectEventInternal(uint32_t aDisplayID)
|
2016-07-04 22:46:49 +00:00
|
|
|
{
|
2017-02-14 19:21:09 +00:00
|
|
|
// Iterate over a copy of mListeners, as dispatched events may modify it.
|
|
|
|
nsTArray<RefPtr<dom::VREventObserver>> listeners;
|
|
|
|
listeners = mListeners;
|
|
|
|
for (auto& listener : listeners) {
|
|
|
|
listener->NotifyVRDisplayConnect(aDisplayID);
|
2016-07-04 22:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-14 19:21:09 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayDisconnectEventInternal(uint32_t aDisplayID)
|
2016-07-04 22:46:49 +00:00
|
|
|
{
|
2017-02-14 19:21:09 +00:00
|
|
|
// Iterate over a copy of mListeners, as dispatched events may modify it.
|
|
|
|
nsTArray<RefPtr<dom::VREventObserver>> listeners;
|
|
|
|
listeners = mListeners;
|
|
|
|
for (auto& listener : listeners) {
|
|
|
|
listener->NotifyVRDisplayDisconnect(aDisplayID);
|
2016-07-04 22:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-14 19:21:09 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal(uint32_t aDisplayID)
|
2016-07-04 22:46:49 +00:00
|
|
|
{
|
2017-02-14 19:21:09 +00:00
|
|
|
// Iterate over a copy of mListeners, as dispatched events may modify it.
|
|
|
|
nsTArray<RefPtr<dom::VREventObserver>> listeners;
|
|
|
|
listeners = mListeners;
|
|
|
|
for (auto& listener : listeners) {
|
|
|
|
listener->NotifyVRDisplayPresentChange(aDisplayID);
|
2016-07-04 22:46:49 +00:00
|
|
|
}
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
2016-07-04 22:46:49 +00:00
|
|
|
|
2018-01-04 22:27:03 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayConnectEventsForLoadInternal(uint32_t aDisplayID,
|
|
|
|
dom::VREventObserver* aObserver)
|
|
|
|
{
|
|
|
|
aObserver->NotifyVRDisplayConnect(aDisplayID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayConnectEventsForLoad(dom::VREventObserver* aObserver)
|
|
|
|
{
|
|
|
|
// We need to fire the VRDisplayConnect event when a page is loaded
|
|
|
|
// for each VR Display that has already been enumerated
|
|
|
|
nsTArray<RefPtr<VRDisplayClient>> displays;
|
|
|
|
displays = mDisplays;
|
|
|
|
for (auto& display : displays) {
|
|
|
|
const VRDisplayInfo& info = display->GetDisplayInfo();
|
|
|
|
if (info.GetIsConnected()) {
|
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod<uint32_t, RefPtr<dom::VREventObserver>>(
|
|
|
|
"gfx::VRManagerChild::FireDOMVRDisplayConnectEventsForLoadInternal",
|
|
|
|
this,
|
|
|
|
&VRManagerChild::FireDOMVRDisplayConnectEventsForLoadInternal,
|
|
|
|
info.GetDisplayID(),
|
|
|
|
aObserver));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 22:46:49 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::AddListener(dom::VREventObserver* aObserver)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aObserver);
|
|
|
|
|
|
|
|
if (mListeners.IndexOf(aObserver) != kNoIndex) {
|
|
|
|
return; // already exists
|
|
|
|
}
|
|
|
|
|
|
|
|
mListeners.AppendElement(aObserver);
|
|
|
|
if (mListeners.Length() == 1) {
|
|
|
|
Unused << SendSetHaveEventListener(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::RemoveListener(dom::VREventObserver* aObserver)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aObserver);
|
|
|
|
|
|
|
|
mListeners.RemoveElement(aObserver);
|
|
|
|
if (mListeners.IsEmpty()) {
|
|
|
|
Unused << SendSetHaveEventListener(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-04 08:31:27 +00:00
|
|
|
void
|
2016-11-01 16:10:42 +00:00
|
|
|
VRManagerChild::HandleFatalError(const char* aName, const char* aMsg) const
|
2016-10-04 08:31:27 +00:00
|
|
|
{
|
|
|
|
dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
|
|
|
|
}
|
|
|
|
|
2017-02-02 06:59:44 +00:00
|
|
|
void
|
|
|
|
VRManagerChild::AddPromise(const uint32_t& aID, dom::Promise* aPromise)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mGamepadPromiseList.Get(aID, nullptr));
|
|
|
|
mGamepadPromiseList.Put(aID, aPromise);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
VRManagerChild::RecvReplyGamepadVibrateHaptic(const uint32_t& aPromiseID)
|
|
|
|
{
|
2017-03-07 02:17:57 +00:00
|
|
|
// 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());
|
|
|
|
|
2017-02-02 06:59:44 +00:00
|
|
|
RefPtr<dom::Promise> p;
|
|
|
|
if (!mGamepadPromiseList.Get(aPromiseID, getter_AddRefs(p))) {
|
|
|
|
MOZ_CRASH("We should always have a promise.");
|
|
|
|
}
|
|
|
|
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
mGamepadPromiseList.Remove(aPromiseID);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-23 08:55:30 +00:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
VRManagerChild::RecvDispatchSubmitFrameResult(const uint32_t& aDisplayID,
|
|
|
|
const VRSubmitFrameResultInfo& aResult)
|
|
|
|
{
|
|
|
|
for (auto& display : mDisplays) {
|
|
|
|
if (display->GetDisplayInfo().GetDisplayID() == aDisplayID) {
|
|
|
|
display->UpdateSubmitFrameResult(aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|