2015-09-17 21:23:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
|
|
|
/* 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"
|
2016-02-24 23:54:50 +00:00
|
|
|
#include "VRDisplayClient.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
|
|
|
|
#include "mozilla/layers/TextureClient.h"
|
2016-07-04 22:46:49 +00:00
|
|
|
#include "nsContentUtils.h"
|
2016-02-24 23:54:50 +00:00
|
|
|
|
|
|
|
using layers::TextureClient;
|
2015-09-17 21:23:13 +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()
|
2016-02-24 23:54:50 +00:00
|
|
|
: TextureForwarder()
|
|
|
|
, mInputFrameID(-1)
|
|
|
|
, mMessageLoop(MessageLoop::current())
|
|
|
|
, mFrameRequestCallbackCounter(0)
|
|
|
|
, mBackend(layers::LayersBackend::LAYERS_NONE)
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(VRManagerChild);
|
|
|
|
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());
|
|
|
|
MOZ_COUNT_DTOR(VRManagerChild);
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
/*static*/ void
|
|
|
|
VRManagerChild::IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier)
|
|
|
|
{
|
|
|
|
if (sVRManagerChildSingleton) {
|
|
|
|
sVRManagerChildSingleton->mBackend = aIdentifier.mParentBackend;
|
|
|
|
sVRManagerChildSingleton->mSyncObject = SyncObject::CreateSyncObject(aIdentifier.mSyncHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-21 07:14:59 +00:00
|
|
|
if (!aEndpoint.Bind(child, nullptr)) {
|
2015-09-17 21:23:13 +00:00
|
|
|
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
|
2016-07-21 07:14:59 +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
|
|
|
}
|
|
|
|
|
|
|
|
/*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(),
|
|
|
|
mozilla::layers::CompositorThreadHolder::Loop(),
|
|
|
|
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();
|
|
|
|
if (!aEndpoint.Bind(sVRManagerChildSingleton, nullptr)) {
|
|
|
|
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2016-02-24 23:54:50 +00:00
|
|
|
mTexturesWaitingRecycled.Clear();
|
2015-09-17 21:23:13 +00:00
|
|
|
|
|
|
|
// 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(
|
2015-09-17 21:23:13 +00:00
|
|
|
NewRunnableFunction(DeferredDestroy, selfRef));
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
layers::PTextureChild*
|
|
|
|
VRManagerChild::AllocPTextureChild(const SurfaceDescriptor&,
|
|
|
|
const LayersBackend&,
|
|
|
|
const TextureFlags&,
|
|
|
|
const uint64_t&)
|
|
|
|
{
|
|
|
|
return TextureClient::CreateIPDLActor();
|
|
|
|
}
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
bool
|
2016-02-24 23:54:50 +00:00
|
|
|
VRManagerChild::DeallocPTextureChild(PTextureChild* actor)
|
2015-09-17 21:23:13 +00:00
|
|
|
{
|
2016-02-24 23:54:50 +00:00
|
|
|
return TextureClient::DestroyIPDLActor(actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRLayerChild*
|
|
|
|
VRManagerChild::AllocPVRLayerChild(const uint32_t& aDisplayID,
|
|
|
|
const float& aLeftEyeX,
|
|
|
|
const float& aLeftEyeY,
|
|
|
|
const float& aLeftEyeWidth,
|
|
|
|
const float& aLeftEyeHeight,
|
|
|
|
const float& aRightEyeX,
|
|
|
|
const float& aRightEyeY,
|
|
|
|
const float& aRightEyeWidth,
|
|
|
|
const float& aRightEyeHeight)
|
|
|
|
{
|
|
|
|
RefPtr<VRLayerChild> layer = new VRLayerChild(aDisplayID, this);
|
|
|
|
return layer.forget().take();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::DeallocPVRLayerChild(PVRLayerChild* actor)
|
|
|
|
{
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::RecvUpdateDisplayInfo(nsTArray<VRDisplayInfo>&& aDisplayUpdates)
|
|
|
|
{
|
|
|
|
bool bDisplayConnected = false;
|
|
|
|
bool bDisplayDisconnected = false;
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
bDisplayDisconnected = true;
|
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;
|
|
|
|
for (VRDisplayInfo& displayUpdate: aDisplayUpdates) {
|
|
|
|
bool isNewDisplay = true;
|
|
|
|
for (auto& display: mDisplays) {
|
|
|
|
const VRDisplayInfo& prevInfo = display->GetDisplayInfo();
|
|
|
|
if (prevInfo.GetDisplayID() == displayUpdate.GetDisplayID()) {
|
|
|
|
if (displayUpdate.GetIsConnected() && !prevInfo.GetIsConnected()) {
|
|
|
|
bDisplayConnected = true;
|
|
|
|
}
|
|
|
|
if (!displayUpdate.GetIsConnected() && prevInfo.GetIsConnected()) {
|
|
|
|
bDisplayDisconnected = true;
|
|
|
|
}
|
|
|
|
display->UpdateDisplayInfo(displayUpdate);
|
|
|
|
displays.AppendElement(display);
|
|
|
|
isNewDisplay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isNewDisplay) {
|
|
|
|
displays.AppendElement(new VRDisplayClient(displayUpdate));
|
|
|
|
bDisplayConnected = true;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
for (auto& nav: mNavigatorCallbacks) {
|
2016-02-24 23:54:50 +00:00
|
|
|
// We must call NotifyVRDisplaysUpdated for every
|
|
|
|
// Navigator in mNavigatorCallbacks to ensure that
|
|
|
|
// the promise returned by Navigator.GetVRDevices
|
|
|
|
// can resolve. This must happen even if no changes
|
|
|
|
// to VRDisplays have been detected here.
|
2016-04-13 00:39:28 +00:00
|
|
|
nav->NotifyVRDisplaysUpdated();
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
mNavigatorCallbacks.Clear();
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
if (bDisplayConnected) {
|
2016-07-04 22:46:49 +00:00
|
|
|
FireDOMVRDisplayConnectEvent();
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
if (bDisplayDisconnected) {
|
2016-07-04 22:46:49 +00:00
|
|
|
FireDOMVRDisplayDisconnectEvent();
|
2015-09-17 21:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-13 00:39:28 +00:00
|
|
|
VRManagerChild::RefreshVRDisplaysWithCallback(dom::Navigator* aNavigator)
|
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) {
|
|
|
|
mNavigatorCallbacks.AppendElement(aNavigator);
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:50:10 +00:00
|
|
|
int
|
|
|
|
VRManagerChild::GetInputFrameID()
|
|
|
|
{
|
|
|
|
return mInputFrameID;
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:54:50 +00:00
|
|
|
bool
|
|
|
|
VRManagerChild::RecvParentAsyncMessages(InfallibleTArray<AsyncParentMessageData>&& aMessages)
|
|
|
|
{
|
|
|
|
for (InfallibleTArray<AsyncParentMessageData>::index_type i = 0; i < aMessages.Length(); ++i) {
|
|
|
|
const AsyncParentMessageData& message = aMessages[i];
|
|
|
|
|
|
|
|
switch (message.type()) {
|
|
|
|
case AsyncParentMessageData::TOpDeliverFence: {
|
|
|
|
const OpDeliverFence& op = message.get_OpDeliverFence();
|
|
|
|
FenceHandle fence = op.fence();
|
|
|
|
DeliverFence(op.TextureId(), fence);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AsyncParentMessageData::TOpNotifyNotUsed: {
|
|
|
|
const OpNotifyNotUsed& op = message.get_OpNotifyNotUsed();
|
|
|
|
NotifyNotUsed(op.TextureId(), op.fwdTransactionId());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ERROR("unknown AsyncParentMessageData type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PTextureChild*
|
|
|
|
VRManagerChild::CreateTexture(const SurfaceDescriptor& aSharedData,
|
|
|
|
LayersBackend aLayersBackend,
|
|
|
|
TextureFlags aFlags,
|
|
|
|
uint64_t aSerial)
|
|
|
|
{
|
|
|
|
return SendPTextureConstructor(aSharedData, aLayersBackend, aFlags, aSerial);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::DeliverFence(uint64_t aTextureId, FenceHandle& aReleaseFenceHandle)
|
|
|
|
{
|
|
|
|
RefPtr<TextureClient> client = mTexturesWaitingRecycled.Get(aTextureId);
|
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
client->SetReleaseFenceHandle(aReleaseFenceHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::CancelWaitForRecycle(uint64_t aTextureId)
|
|
|
|
{
|
|
|
|
RefPtr<TextureClient> client = mTexturesWaitingRecycled.Get(aTextureId);
|
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTexturesWaitingRecycled.Remove(aTextureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::NotifyNotUsed(uint64_t aTextureId, uint64_t aFwdTransactionId)
|
|
|
|
{
|
|
|
|
RefPtr<TextureClient> client = mTexturesWaitingRecycled.Get(aTextureId);
|
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTexturesWaitingRecycled.Remove(aTextureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::AllocShmem(size_t aSize,
|
|
|
|
ipc::SharedMemory::SharedMemoryType aType,
|
|
|
|
ipc::Shmem* aShmem)
|
|
|
|
{
|
|
|
|
return PVRManagerChild::AllocShmem(aSize, aType, aShmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::AllocUnsafeShmem(size_t aSize,
|
|
|
|
ipc::SharedMemory::SharedMemoryType aType,
|
|
|
|
ipc::Shmem* aShmem)
|
|
|
|
{
|
|
|
|
return PVRManagerChild::AllocUnsafeShmem(aSize, aType, aShmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::DeallocShmem(ipc::Shmem& aShmem)
|
|
|
|
{
|
|
|
|
PVRManagerChild::DeallocShmem(aShmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRLayerChild*
|
|
|
|
VRManagerChild::CreateVRLayer(uint32_t aDisplayID, const Rect& aLeftEyeRect, const Rect& aRightEyeRect)
|
|
|
|
{
|
|
|
|
return SendPVRLayerConstructor(aDisplayID,
|
|
|
|
aLeftEyeRect.x, aLeftEyeRect.y, aLeftEyeRect.width, aLeftEyeRect.height,
|
|
|
|
aRightEyeRect.x, aRightEyeRect.y, aRightEyeRect.width, aRightEyeRect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::RecvNotifyVSync()
|
|
|
|
{
|
|
|
|
for (auto& display : mDisplays) {
|
|
|
|
display->NotifyVsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerChild::RecvNotifyVRVSync(const uint32_t& aDisplayID)
|
|
|
|
{
|
|
|
|
for (auto& display : mDisplays) {
|
|
|
|
if (display->GetDisplayInfo().GetDisplayID() == aDisplayID) {
|
|
|
|
display->NotifyVRVsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::RunFrameRequestCallbacks()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-04 22:46:49 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayConnectEvent()
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2016-07-04 22:46:49 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod(this,
|
|
|
|
&VRManagerChild::FireDOMVRDisplayConnectEventInternal));
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-04 22:46:49 +00:00
|
|
|
VRManagerChild::FireDOMVRDisplayDisconnectEvent()
|
2016-02-24 23:54:50 +00:00
|
|
|
{
|
2016-07-04 22:46:49 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod(this,
|
|
|
|
&VRManagerChild::FireDOMVRDisplayDisconnectEventInternal));
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayPresentChangeEvent()
|
|
|
|
{
|
2016-07-04 22:46:49 +00:00
|
|
|
nsContentUtils::AddScriptRunner(NewRunnableMethod(this,
|
|
|
|
&VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayConnectEventInternal()
|
|
|
|
{
|
|
|
|
for (auto& listener : mListeners) {
|
|
|
|
listener->NotifyVRDisplayConnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayDisconnectEventInternal()
|
|
|
|
{
|
|
|
|
for (auto& listener : mListeners) {
|
|
|
|
listener->NotifyVRDisplayDisconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerChild::FireDOMVRDisplayPresentChangeEventInternal()
|
|
|
|
{
|
|
|
|
for (auto& listener : mListeners) {
|
|
|
|
listener->NotifyVRDisplayPresentChange();
|
|
|
|
}
|
2016-02-24 23:54:50 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 21:23:13 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|