2015-09-18 00:23:13 +03: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 "VRManagerParent.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "ipc/VRLayerParent.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "mozilla/gfx/PVRManagerParent.h"
|
|
|
|
#include "mozilla/ipc/ProtocolTypes.h"
|
|
|
|
#include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol
|
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp
|
2016-05-16 09:38:34 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "VRManager.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2016-02-25 02:54:50 +03:00
|
|
|
using namespace layers;
|
2015-09-18 00:23:13 +03:00
|
|
|
namespace gfx {
|
|
|
|
|
2016-07-21 10:14:59 +03:00
|
|
|
VRManagerParent::VRManagerParent(ProcessId aChildProcessId)
|
2016-02-25 02:54:50 +03:00
|
|
|
: HostIPCAllocator()
|
|
|
|
, mHaveEventListener(false)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(VRManagerParent);
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
SetOtherProcessId(aChildProcessId);
|
|
|
|
}
|
|
|
|
|
|
|
|
VRManagerParent::~VRManagerParent()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mVRManagerHolder);
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(VRManagerParent);
|
|
|
|
}
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
PTextureParent*
|
|
|
|
VRManagerParent::AllocPTextureParent(const SurfaceDescriptor& aSharedData,
|
|
|
|
const LayersBackend& aLayersBackend,
|
|
|
|
const TextureFlags& aFlags,
|
|
|
|
const uint64_t& aSerial)
|
|
|
|
{
|
|
|
|
return layers::TextureHost::CreateIPDLActor(this, aSharedData, aLayersBackend, aFlags, aSerial);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerParent::DeallocPTextureParent(PTextureParent* actor)
|
|
|
|
{
|
|
|
|
return layers::TextureHost::DestroyIPDLActor(actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRLayerParent*
|
|
|
|
VRManagerParent::AllocPVRLayerParent(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<VRLayerParent> layer;
|
|
|
|
layer = new VRLayerParent(aDisplayID,
|
|
|
|
Rect(aLeftEyeX, aLeftEyeY, aLeftEyeWidth, aLeftEyeHeight),
|
|
|
|
Rect(aRightEyeX, aRightEyeY, aRightEyeWidth, aRightEyeHeight));
|
|
|
|
VRManager* vm = VRManager::Get();
|
|
|
|
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
|
|
|
if (display) {
|
|
|
|
display->AddLayer(layer);
|
|
|
|
}
|
|
|
|
return layer.forget().take();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerParent::DeallocPVRLayerParent(PVRLayerParent* actor)
|
|
|
|
{
|
|
|
|
gfx::VRLayerParent* layer = static_cast<gfx::VRLayerParent*>(actor);
|
|
|
|
|
|
|
|
VRManager* vm = VRManager::Get();
|
|
|
|
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(layer->GetDisplayID());
|
|
|
|
if (display) {
|
|
|
|
display->RemoveLayer(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerParent::AllocShmem(size_t aSize,
|
|
|
|
ipc::SharedMemory::SharedMemoryType aType,
|
|
|
|
ipc::Shmem* aShmem)
|
|
|
|
{
|
|
|
|
return PVRManagerParent::AllocShmem(aSize, aType, aShmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerParent::AllocUnsafeShmem(size_t aSize,
|
|
|
|
ipc::SharedMemory::SharedMemoryType aType,
|
|
|
|
ipc::Shmem* aShmem)
|
|
|
|
{
|
|
|
|
return PVRManagerParent::AllocUnsafeShmem(aSize, aType, aShmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerParent::DeallocShmem(ipc::Shmem& aShmem)
|
|
|
|
{
|
|
|
|
PVRManagerParent::DeallocShmem(aShmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerParent::IsSameProcess() const
|
|
|
|
{
|
|
|
|
return OtherPid() == base::GetCurrentProcId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerParent::NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerParent::SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
|
|
|
|
base::ProcessId
|
|
|
|
VRManagerParent::GetChildProcessId()
|
|
|
|
{
|
|
|
|
return OtherPid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerParent::RegisterWithManager()
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
VRManager* vm = VRManager::Get();
|
|
|
|
vm->AddVRManagerParent(this);
|
|
|
|
mVRManagerHolder = vm;
|
|
|
|
}
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
void
|
|
|
|
VRManagerParent::UnregisterFromManager()
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
VRManager* vm = VRManager::Get();
|
|
|
|
vm->RemoveVRManagerParent(this);
|
|
|
|
mVRManagerHolder = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-21 10:14:59 +03:00
|
|
|
/* static */ bool
|
|
|
|
VRManagerParent::CreateForContent(Endpoint<PVRManagerParent>&& aEndpoint)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2016-07-21 10:14:59 +03:00
|
|
|
MessageLoop* loop = layers::CompositorThreadHolder::Loop();
|
|
|
|
|
|
|
|
RefPtr<VRManagerParent> vmp = new VRManagerParent(aEndpoint.OtherPid());
|
|
|
|
loop->PostTask(NewRunnableMethod<Endpoint<PVRManagerParent>&&>(
|
|
|
|
vmp, &VRManagerParent::Bind, Move(aEndpoint)));
|
|
|
|
|
|
|
|
return true;
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
2016-07-21 10:14:59 +03:00
|
|
|
void
|
|
|
|
VRManagerParent::Bind(Endpoint<PVRManagerParent>&& aEndpoint)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2016-09-02 23:13:50 +03:00
|
|
|
if (!aEndpoint.Bind(this)) {
|
2016-07-21 10:14:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mSelfRef = this;
|
|
|
|
|
|
|
|
RegisterWithManager();
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
VRManagerParent::RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager)
|
|
|
|
{
|
|
|
|
aVRManager->RegisterWithManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ VRManagerParent*
|
|
|
|
VRManagerParent::CreateSameProcess()
|
|
|
|
{
|
2016-05-16 09:39:30 +03:00
|
|
|
MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop();
|
2016-07-21 10:14:59 +03:00
|
|
|
RefPtr<VRManagerParent> vmp = new VRManagerParent(base::GetCurrentProcId());
|
2016-05-16 09:38:34 +03:00
|
|
|
vmp->mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
|
2015-09-18 00:23:13 +03:00
|
|
|
vmp->mSelfRef = vmp;
|
2016-04-28 03:06:05 +03:00
|
|
|
loop->PostTask(NewRunnableFunction(RegisterVRManagerInCompositorThread, vmp.get()));
|
2015-09-18 00:23:13 +03:00
|
|
|
return vmp.get();
|
|
|
|
}
|
|
|
|
|
2016-07-21 10:14:59 +03:00
|
|
|
bool
|
|
|
|
VRManagerParent::CreateForGPUProcess(Endpoint<PVRManagerParent>&& aEndpoint)
|
|
|
|
{
|
|
|
|
MessageLoop* loop = mozilla::layers::CompositorThreadHolder::Loop();
|
|
|
|
|
|
|
|
RefPtr<VRManagerParent> vmp = new VRManagerParent(aEndpoint.OtherPid());
|
|
|
|
vmp->mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
|
|
|
|
loop->PostTask(NewRunnableMethod<Endpoint<PVRManagerParent>&&>(
|
|
|
|
vmp, &VRManagerParent::Bind, Move(aEndpoint)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
void
|
|
|
|
VRManagerParent::DeferredDestroy()
|
|
|
|
{
|
|
|
|
mCompositorThreadHolder = nullptr;
|
|
|
|
mSelfRef = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
UnregisterFromManager();
|
2016-05-05 11:45:00 +03:00
|
|
|
MessageLoop::current()->PostTask(NewRunnableMethod(this, &VRManagerParent::DeferredDestroy));
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRManagerParent::OnChannelConnected(int32_t aPid)
|
|
|
|
{
|
2016-05-16 09:38:34 +03:00
|
|
|
mCompositorThreadHolder = layers::CompositorThreadHolder::GetSingleton();
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-02-25 02:54:50 +03:00
|
|
|
VRManagerParent::RecvRefreshDisplays()
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
2016-02-25 02:54:50 +03:00
|
|
|
// This is called to refresh the VR Displays for Navigator.GetVRDevices().
|
|
|
|
// We must pass "true" to VRManager::RefreshVRDisplays()
|
|
|
|
// to ensure that the promise returned by Navigator.GetVRDevices
|
|
|
|
// can resolve even if there are no changes to the VR Displays.
|
2015-09-18 00:23:13 +03:00
|
|
|
VRManager* vm = VRManager::Get();
|
2016-02-25 02:54:50 +03:00
|
|
|
vm->RefreshVRDisplays(true);
|
2015-09-18 00:23:13 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-05 01:52:21 +03:00
|
|
|
bool
|
|
|
|
VRManagerParent::RecvGetDisplays(nsTArray<VRDisplayInfo> *aDisplays)
|
|
|
|
{
|
|
|
|
VRManager* vm = VRManager::Get();
|
|
|
|
vm->GetVRDisplayInfo(*aDisplays);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
bool
|
2016-02-25 02:54:50 +03:00
|
|
|
VRManagerParent::RecvResetSensor(const uint32_t& aDisplayID)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
VRManager* vm = VRManager::Get();
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
|
|
|
if (display != nullptr) {
|
|
|
|
display->ZeroSensor();
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-02-25 02:54:50 +03:00
|
|
|
VRManagerParent::RecvGetSensorState(const uint32_t& aDisplayID, VRHMDSensorState* aState)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
VRManager* vm = VRManager::Get();
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
|
|
|
if (display != nullptr) {
|
|
|
|
*aState = display->GetSensorState();
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-02-25 02:54:50 +03:00
|
|
|
VRManagerParent::RecvGetImmediateSensorState(const uint32_t& aDisplayID, VRHMDSensorState* aState)
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
VRManager* vm = VRManager::Get();
|
2016-02-25 02:54:50 +03:00
|
|
|
RefPtr<gfx::VRDisplayHost> display = vm->GetDisplay(aDisplayID);
|
|
|
|
if (display != nullptr) {
|
|
|
|
*aState = display->GetImmediateSensorState();
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-25 02:54:50 +03:00
|
|
|
bool
|
|
|
|
VRManagerParent::HaveEventListener()
|
|
|
|
{
|
|
|
|
return mHaveEventListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRManagerParent::RecvSetHaveEventListener(const bool& aHaveEventListener)
|
|
|
|
{
|
|
|
|
mHaveEventListener = aHaveEventListener;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|