forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVRDeviceProxy.cpp
153 lines (128 loc) · 4.49 KB
/
VRDeviceProxy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* -*- 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"
#include "mozilla/unused.h"
#include "nsServiceManagerUtils.h"
#include "nsIScreenManager.h"
#ifdef XP_WIN
#include "../layers/d3d11/CompositorD3D11.h"
#endif
#include "VRDeviceProxy.h"
#include "VRManagerChild.h"
using namespace mozilla;
using namespace mozilla::gfx;
VRDeviceProxy::VRDeviceProxy(const VRDeviceUpdate& aDeviceUpdate)
: mDeviceInfo(aDeviceUpdate.mDeviceInfo)
, mSensorState(aDeviceUpdate.mSensorState)
{
MOZ_COUNT_CTOR(VRDeviceProxy);
if (mDeviceInfo.mScreenRect.width && mDeviceInfo.mScreenRect.height) {
if (mDeviceInfo.mIsFakeScreen) {
mScreen = MakeFakeScreen(mDeviceInfo.mScreenRect);
} else {
nsCOMPtr<nsIScreenManager> screenmgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
if (screenmgr) {
screenmgr->ScreenForRect(mDeviceInfo.mScreenRect.x, mDeviceInfo.mScreenRect.y,
mDeviceInfo.mScreenRect.width, mDeviceInfo.mScreenRect.height,
getter_AddRefs(mScreen));
}
}
#ifdef DEBUG
printf_stderr("VR DEVICE SCREEN: %d %d %d %d\n",
mDeviceInfo.mScreenRect.x, mDeviceInfo.mScreenRect.y,
mDeviceInfo.mScreenRect.width, mDeviceInfo.mScreenRect.height);
#endif
}
}
VRDeviceProxy::~VRDeviceProxy() {
MOZ_COUNT_DTOR(VRDeviceProxy);
}
void
VRDeviceProxy::UpdateDeviceInfo(const VRDeviceUpdate& aDeviceUpdate)
{
mDeviceInfo = aDeviceUpdate.mDeviceInfo;
mSensorState = aDeviceUpdate.mSensorState;
}
bool
VRDeviceProxy::SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
double zNear, double zFar)
{
VRManagerChild *vm = VRManagerChild::Get();
vm->SendSetFOV(mDeviceInfo.mDeviceID, aFOVLeft, aFOVRight, zNear, zFar);
return true;
}
void
VRDeviceProxy::ZeroSensor()
{
VRManagerChild *vm = VRManagerChild::Get();
vm->SendResetSensor(mDeviceInfo.mDeviceID);
}
VRHMDSensorState
VRDeviceProxy::GetSensorState(double timeOffset)
{
VRManagerChild *vm = VRManagerChild::Get();
Unused << vm->SendKeepSensorTracking(mDeviceInfo.mDeviceID);
return mSensorState;
}
void
VRDeviceProxy::UpdateSensorState(const VRHMDSensorState& aSensorState)
{
mSensorState = aSensorState;
}
// Dummy nsIScreen implementation, for when we just need to specify a size
class FakeScreen : public nsIScreen
{
public:
explicit FakeScreen(const IntRect& aScreenRect)
: mScreenRect(aScreenRect)
{ }
NS_DECL_ISUPPORTS
NS_IMETHOD GetRect(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
*l = mScreenRect.x;
*t = mScreenRect.y;
*w = mScreenRect.width;
*h = mScreenRect.height;
return NS_OK;
}
NS_IMETHOD GetAvailRect(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
return GetRect(l, t, w, h);
}
NS_IMETHOD GetRectDisplayPix(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
return GetRect(l, t, w, h);
}
NS_IMETHOD GetAvailRectDisplayPix(int32_t *l, int32_t *t, int32_t *w, int32_t *h) override {
return GetAvailRect(l, t, w, h);
}
NS_IMETHOD GetId(uint32_t* aId) override { *aId = (uint32_t)-1; return NS_OK; }
NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override { *aPixelDepth = 24; return NS_OK; }
NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override { *aColorDepth = 24; return NS_OK; }
NS_IMETHOD LockMinimumBrightness(uint32_t aBrightness) override { return NS_ERROR_NOT_AVAILABLE; }
NS_IMETHOD UnlockMinimumBrightness(uint32_t aBrightness) override { return NS_ERROR_NOT_AVAILABLE; }
NS_IMETHOD GetRotation(uint32_t* aRotation) override {
*aRotation = nsIScreen::ROTATION_0_DEG;
return NS_OK;
}
NS_IMETHOD SetRotation(uint32_t aRotation) override { return NS_ERROR_NOT_AVAILABLE; }
NS_IMETHOD GetContentsScaleFactor(double* aContentsScaleFactor) override {
*aContentsScaleFactor = 1.0;
return NS_OK;
}
protected:
virtual ~FakeScreen() {}
IntRect mScreenRect;
};
NS_IMPL_ISUPPORTS(FakeScreen, nsIScreen)
/* static */ already_AddRefed<nsIScreen>
VRDeviceProxy::MakeFakeScreen(const IntRect& aScreenRect)
{
nsCOMPtr<nsIScreen> screen = new FakeScreen(aScreenRect);
return screen.forget();
}