2016-02-25 02:54:50 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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 <math.h>
|
|
|
|
|
|
|
|
#include "prlink.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "prenv.h"
|
|
|
|
#include "gfxPrefs.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-02-25 02:54:50 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIScreenManager.h"
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "../layers/d3d11/CompositorD3D11.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "VRDisplayClient.h"
|
|
|
|
#include "VRDisplayPresentation.h"
|
|
|
|
#include "VRManagerChild.h"
|
|
|
|
#include "VRLayerChild.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
VRDisplayClient::VRDisplayClient(const VRDisplayInfo& aDisplayInfo)
|
|
|
|
: mDisplayInfo(aDisplayInfo)
|
2016-10-19 01:18:10 +03:00
|
|
|
, bLastEventWasMounted(false)
|
2016-02-25 02:54:50 +03:00
|
|
|
, bLastEventWasPresenting(false)
|
|
|
|
, mPresentationCount(0)
|
2017-05-09 02:01:36 +03:00
|
|
|
, mLastEventFrameId(0)
|
2016-02-25 02:54:50 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(VRDisplayClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
VRDisplayClient::~VRDisplayClient() {
|
|
|
|
MOZ_COUNT_DTOR(VRDisplayClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRDisplayClient::UpdateDisplayInfo(const VRDisplayInfo& aDisplayInfo)
|
|
|
|
{
|
|
|
|
mDisplayInfo = aDisplayInfo;
|
2017-05-09 02:01:36 +03:00
|
|
|
FireEvents();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<VRDisplayPresentation>
|
2017-05-09 02:01:36 +03:00
|
|
|
VRDisplayClient::BeginPresentation(const nsTArray<mozilla::dom::VRLayer>& aLayers,
|
|
|
|
uint32_t aGroup)
|
2016-02-25 02:54:50 +03:00
|
|
|
{
|
|
|
|
++mPresentationCount;
|
2017-05-09 02:01:36 +03:00
|
|
|
RefPtr<VRDisplayPresentation> presentation = new VRDisplayPresentation(this, aLayers, aGroup);
|
2016-02-25 02:54:50 +03:00
|
|
|
return presentation.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRDisplayClient::PresentationDestroyed()
|
|
|
|
{
|
|
|
|
--mPresentationCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRDisplayClient::ZeroSensor()
|
|
|
|
{
|
|
|
|
VRManagerChild *vm = VRManagerChild::Get();
|
|
|
|
vm->SendResetSensor(mDisplayInfo.mDisplayID);
|
|
|
|
}
|
|
|
|
|
2017-05-09 02:01:36 +03:00
|
|
|
void
|
|
|
|
VRDisplayClient::SetGroupMask(uint32_t aGroupMask)
|
2016-02-25 02:54:50 +03:00
|
|
|
{
|
|
|
|
VRManagerChild *vm = VRManagerChild::Get();
|
2017-05-09 02:01:36 +03:00
|
|
|
vm->SendSetGroupMask(mDisplayInfo.mDisplayID, aGroupMask);
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-09 02:01:36 +03:00
|
|
|
VRDisplayClient::FireEvents()
|
2016-02-25 02:54:50 +03:00
|
|
|
{
|
|
|
|
VRManagerChild *vm = VRManagerChild::Get();
|
2017-05-09 02:01:36 +03:00
|
|
|
// Only fire these events for non-chrome VR sessions
|
|
|
|
bool isPresenting = (mDisplayInfo.mPresentingGroups & kVRGroupContent) != 0;
|
2016-02-25 02:54:50 +03:00
|
|
|
|
|
|
|
// Check if we need to trigger onVRDisplayPresentChange event
|
|
|
|
if (bLastEventWasPresenting != isPresenting) {
|
|
|
|
bLastEventWasPresenting = isPresenting;
|
2017-02-14 22:21:09 +03:00
|
|
|
vm->FireDOMVRDisplayPresentChangeEvent(mDisplayInfo.mDisplayID);
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
2016-10-19 01:18:10 +03:00
|
|
|
|
|
|
|
// Check if we need to trigger onvrdisplayactivate event
|
|
|
|
if (!bLastEventWasMounted && mDisplayInfo.mIsMounted) {
|
|
|
|
bLastEventWasMounted = true;
|
2017-04-04 21:28:56 +03:00
|
|
|
if (gfxPrefs::VRAutoActivateEnabled()) {
|
|
|
|
vm->FireDOMVRDisplayMountedEvent(mDisplayInfo.mDisplayID);
|
|
|
|
}
|
2016-10-19 01:18:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we need to trigger onvrdisplaydeactivate event
|
|
|
|
if (bLastEventWasMounted && !mDisplayInfo.mIsMounted) {
|
|
|
|
bLastEventWasMounted = false;
|
2017-04-04 21:28:56 +03:00
|
|
|
if (gfxPrefs::VRAutoActivateEnabled()) {
|
|
|
|
vm->FireDOMVRDisplayUnmountedEvent(mDisplayInfo.mDisplayID);
|
|
|
|
}
|
2016-10-19 01:18:10 +03:00
|
|
|
}
|
2017-05-09 02:01:36 +03:00
|
|
|
|
|
|
|
// Check if we need to trigger VRDisplay.requestAnimationFrame
|
|
|
|
if (mLastEventFrameId != mDisplayInfo.mFrameId) {
|
|
|
|
mLastEventFrameId = mDisplayInfo.mFrameId;
|
|
|
|
vm->RunFrameRequestCallbacks();
|
|
|
|
}
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
2017-05-09 02:01:36 +03:00
|
|
|
VRHMDSensorState
|
|
|
|
VRDisplayClient::GetSensorState()
|
2016-02-25 02:54:50 +03:00
|
|
|
{
|
2017-05-09 02:01:36 +03:00
|
|
|
return mDisplayInfo.GetSensorState();
|
2016-02-25 02:54:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VRDisplayClient::GetIsConnected() const
|
|
|
|
{
|
|
|
|
return mDisplayInfo.GetIsConnected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRDisplayClient::NotifyDisconnected()
|
|
|
|
{
|
|
|
|
mDisplayInfo.mIsConnected = false;
|
|
|
|
}
|
2017-05-23 11:55:30 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
VRDisplayClient::UpdateSubmitFrameResult(const VRSubmitFrameResultInfo& aResult)
|
|
|
|
{
|
|
|
|
mSubmitFrameResult = aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VRDisplayClient::GetSubmitFrameResult(VRSubmitFrameResultInfo& aResult)
|
|
|
|
{
|
|
|
|
aResult = mSubmitFrameResult;
|
|
|
|
}
|