Bug 1148009; Add support for Cardboard (and other rotation-sensor based VR) in Firefox for Android; r=jrmuizel

This commit is contained in:
Vladimir Vukicevic 2015-04-01 16:02:20 -04:00
Родитель 32d8dbc20e
Коммит 24157e2002
11 изменённых файлов: 1318 добавлений и 810 удалений

Просмотреть файл

@ -214,9 +214,21 @@ public:
: HMDVRDevice(aParent, aHMD)
{
// XXX TODO use real names/IDs
mHWID.AppendPrintf("HMDInfo-0x%llx", aHMD);
mDeviceId.AssignLiteral("somedevid");
mDeviceName.AssignLiteral("HMD Device");
uint64_t hmdid = reinterpret_cast<uint64_t>(aHMD);
mHWID.Truncate();
mHWID.AppendPrintf("HMDInfo-0x%llx", hmdid);
mDeviceId.Truncate();
mDeviceId.AppendPrintf("HMDInfo-dev-0x%llx", hmdid);
if (aHMD->GetType() == VRHMDType::Oculus) {
mDeviceName.AssignLiteral("VR HMD Device (oculus)");
} else if (aHMD->GetType() == VRHMDType::Cardboard) {
mDeviceName.AssignLiteral("VR HMD Device (cardboard)");
} else {
mDeviceName.AssignLiteral("VR HMD Device (unknown)");
}
mValid = true;
}
@ -270,9 +282,21 @@ public:
, mTracking(false)
{
// XXX TODO use real names/IDs
mHWID.AppendPrintf("HMDInfo-0x%llx", aHMD);
mDeviceId.AssignLiteral("somedevid");
mDeviceName.AssignLiteral("HMD Position Device");
uint64_t hmdid = reinterpret_cast<uint64_t>(aHMD);
mHWID.Truncate();
mHWID.AppendPrintf("HMDInfo-0x%llx", hmdid);
mDeviceId.Truncate();
mDeviceId.AppendPrintf("HMDInfo-dev-0x%llx", hmdid);
if (aHMD->GetType() == VRHMDType::Oculus) {
mDeviceName.AssignLiteral("VR Position Device (oculus)");
} else if (aHMD->GetType() == VRHMDType::Cardboard) {
mDeviceName.AssignLiteral("VR Position Device (cardboard)");
} else {
mDeviceName.AssignLiteral("VR Position Device (unknown)");
}
mValid = true;
}

Просмотреть файл

@ -73,17 +73,19 @@ struct DeviceAttachmentsD3D11
//
// VR pieces
//
RefPtr<ID3D11InputLayout> mVRDistortionInputLayout;
RefPtr<ID3D11Buffer> mVRDistortionConstants;
typedef EnumeratedArray<VRHMDType, VRHMDType::NumHMDTypes, RefPtr<ID3D11InputLayout>>
VRDistortionInputLayoutArray;
typedef EnumeratedArray<VRHMDType, VRHMDType::NumHMDTypes, RefPtr<ID3D11VertexShader>>
VRVertexShaderArray;
typedef EnumeratedArray<VRHMDType, VRHMDType::NumHMDTypes, RefPtr<ID3D11PixelShader>>
VRPixelShaderArray;
VRDistortionInputLayoutArray mVRDistortionInputLayout;
VRVertexShaderArray mVRDistortionVS;
VRPixelShaderArray mVRDistortionPS;
RefPtr<ID3D11Buffer> mVRDistortionConstants;
// These will be created/filled in as needed during rendering whenever the configuration
// changes.
VRHMDConfiguration mVRConfiguration;
@ -334,7 +336,12 @@ CompositorD3D11::Initialize()
sizeof(vrlayout) / sizeof(D3D11_INPUT_ELEMENT_DESC),
OculusVRDistortionVS,
sizeof(OculusVRDistortionVS),
byRef(mAttachments->mVRDistortionInputLayout));
byRef(mAttachments->mVRDistortionInputLayout[VRHMDType::Oculus]));
// XXX shared for now, rename
mAttachments->mVRDistortionInputLayout[VRHMDType::Cardboard] =
mAttachments->mVRDistortionInputLayout[VRHMDType::Oculus];
cBufferDesc.ByteWidth = sizeof(gfx::VRDistortionConstants);
hr = mDevice->CreateBuffer(&cBufferDesc, nullptr, byRef(mAttachments->mVRDistortionConstants));
if (FAILED(hr)) {
@ -661,6 +668,7 @@ CompositorD3D11::DrawVRDistortion(const gfx::Rect& aRect,
gfx::IntSize size = vrEffect->mRenderTarget->GetSize(); // XXX source->GetSize()
VRHMDInfo* hmdInfo = vrEffect->mHMD;
VRHMDType hmdType = hmdInfo->GetType();
VRDistortionConstants shaderConstants;
// do we need to recreate the VR buffers, since the config has changed?
@ -709,20 +717,17 @@ CompositorD3D11::DrawVRDistortion(const gfx::Rect& aRect,
// Triangle lists and same layout for both eyes
mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
mContext->IASetInputLayout(mAttachments->mVRDistortionInputLayout);
// Shaders for this HMD
mContext->VSSetShader(mAttachments->mVRDistortionVS[mAttachments->mVRConfiguration.hmdType], nullptr, 0);
mContext->PSSetShader(mAttachments->mVRDistortionPS[mAttachments->mVRConfiguration.hmdType], nullptr, 0);
mContext->IASetInputLayout(mAttachments->mVRDistortionInputLayout[hmdType]);
mContext->VSSetShader(mAttachments->mVRDistortionVS[hmdType], nullptr, 0);
mContext->PSSetShader(mAttachments->mVRDistortionPS[hmdType], nullptr, 0);
// This is the source texture SRV for the pixel shader
// XXX, um should we cache this SRV?
// XXX, um should we cache this SRV on the source?
RefPtr<ID3D11ShaderResourceView> view;
mDevice->CreateShaderResourceView(source->GetD3D11Texture(), nullptr, byRef(view));
ID3D11ShaderResourceView* srView = view;
mContext->PSSetShaderResources(0, 1, &srView);
gfx::IntSize vpSizeInt = mCurrentRT->GetSize();
gfx::Size vpSize(vpSizeInt.width, vpSizeInt.height);
ID3D11Buffer* vbuffer;
@ -1343,6 +1348,11 @@ CompositorD3D11::CreateShaders()
return false;
}
// These are shared
// XXX rename Oculus shaders to something more generic
mAttachments->mVRDistortionVS[VRHMDType::Cardboard] = mAttachments->mVRDistortionVS[VRHMDType::Oculus];
mAttachments->mVRDistortionPS[VRHMDType::Cardboard] = mAttachments->mVRDistortionPS[VRHMDType::Oculus];
return true;
}

Просмотреть файл

@ -1,9 +1,8 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -104,10 +103,10 @@ ret
const BYTE LayerQuadVS[] =
{
68, 88, 66, 67, 67, 61,
27, 151, 57, 33, 48, 19,
55, 6, 95, 77, 254, 163,
118, 237, 1, 0, 0, 0,
68, 88, 66, 67, 200, 251,
64, 251, 166, 240, 101, 137,
191, 140, 75, 217, 9, 168,
61, 163, 1, 0, 0, 0,
180, 6, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
152, 1, 0, 0, 160, 3,
@ -262,7 +261,7 @@ const BYTE LayerQuadVS[] =
65, 84, 116, 0, 0, 0,
13, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 6, 0,
3, 0, 0, 0, 12, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
@ -272,7 +271,7 @@ const BYTE LayerQuadVS[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -363,10 +362,10 @@ const BYTE LayerQuadVS[] =
41, 32, 72, 76, 83, 76,
32, 83, 104, 97, 100, 101,
114, 32, 67, 111, 109, 112,
105, 108, 101, 114, 32, 57,
46, 51, 48, 46, 57, 50,
48, 48, 46, 50, 48, 53,
52, 54, 0, 171, 73, 83,
105, 108, 101, 114, 32, 54,
46, 51, 46, 57, 54, 48,
48, 46, 49, 54, 51, 56,
52, 0, 171, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
@ -393,10 +392,9 @@ const BYTE LayerQuadVS[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -460,10 +458,10 @@ ret
const BYTE SolidColorShader[] =
{
68, 88, 66, 67, 182, 98,
102, 100, 187, 218, 19, 40,
99, 74, 29, 228, 47, 107,
160, 122, 1, 0, 0, 0,
68, 88, 66, 67, 30, 148,
104, 202, 165, 39, 58, 182,
100, 205, 95, 195, 52, 137,
197, 241, 1, 0, 0, 0,
224, 3, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
132, 0, 0, 0, 204, 0,
@ -508,7 +506,7 @@ const BYTE SolidColorShader[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -599,9 +597,9 @@ const BYTE SolidColorShader[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
@ -629,10 +627,9 @@ const BYTE SolidColorShader[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -716,10 +713,10 @@ ret
const BYTE RGBShader[] =
{
68, 88, 66, 67, 195, 54,
227, 44, 79, 159, 121, 69,
60, 252, 145, 90, 151, 241,
175, 162, 1, 0, 0, 0,
68, 88, 66, 67, 239, 198,
87, 206, 69, 92, 245, 30,
125, 195, 239, 77, 37, 241,
175, 187, 1, 0, 0, 0,
232, 4, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
204, 0, 0, 0, 136, 1,
@ -795,7 +792,7 @@ const BYTE RGBShader[] =
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -899,9 +896,9 @@ const BYTE RGBShader[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
@ -929,10 +926,9 @@ const BYTE RGBShader[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -1014,10 +1010,10 @@ ret
const BYTE RGBAShader[] =
{
68, 88, 66, 67, 124, 18,
8, 218, 34, 168, 20, 218,
144, 232, 183, 104, 152, 211,
5, 26, 1, 0, 0, 0,
68, 88, 66, 67, 230, 59,
90, 23, 60, 77, 18, 113,
14, 129, 183, 152, 233, 55,
111, 42, 1, 0, 0, 0,
196, 4, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
192, 0, 0, 0, 100, 1,
@ -1087,7 +1083,7 @@ const BYTE RGBAShader[] =
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -1191,9 +1187,9 @@ const BYTE RGBAShader[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
@ -1221,10 +1217,9 @@ const BYTE RGBAShader[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -1324,10 +1319,10 @@ ret
const BYTE ComponentAlphaShader[] =
{
68, 88, 66, 67, 152, 37,
117, 77, 87, 153, 20, 62,
92, 142, 77, 134, 246, 203,
174, 59, 1, 0, 0, 0,
68, 88, 66, 67, 186, 162,
72, 42, 69, 36, 160, 68,
108, 121, 216, 238, 108, 37,
6, 145, 1, 0, 0, 0,
68, 6, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
64, 1, 0, 0, 160, 2,
@ -1450,7 +1445,7 @@ const BYTE ComponentAlphaShader[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -1561,9 +1556,9 @@ const BYTE ComponentAlphaShader[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 80, 0,
0, 0, 2, 0, 0, 0,
8, 0, 0, 0, 56, 0,
@ -1595,10 +1590,9 @@ const BYTE ComponentAlphaShader[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -1714,10 +1708,10 @@ ret
const BYTE YCbCrShader[] =
{
68, 88, 66, 67, 26, 187,
43, 127, 28, 135, 212, 40,
57, 230, 160, 198, 151, 242,
106, 110, 1, 0, 0, 0,
68, 88, 66, 67, 181, 118,
100, 53, 248, 120, 136, 92,
59, 190, 18, 201, 139, 224,
32, 141, 1, 0, 0, 0,
212, 7, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
220, 1, 0, 0, 44, 4,
@ -1896,7 +1890,7 @@ const BYTE YCbCrShader[] =
0, 0, 15, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
6, 0, 0, 0, 0, 0,
10, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -1906,7 +1900,7 @@ const BYTE YCbCrShader[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -2022,9 +2016,9 @@ const BYTE YCbCrShader[] =
76, 32, 83, 104, 97, 100,
101, 114, 32, 67, 111, 109,
112, 105, 108, 101, 114, 32,
57, 46, 51, 48, 46, 57,
50, 48, 48, 46, 50, 48,
53, 52, 54, 0, 73, 83,
54, 46, 51, 46, 57, 54,
48, 48, 46, 49, 54, 51,
56, 52, 0, 171, 73, 83,
71, 78, 80, 0, 0, 0,
2, 0, 0, 0, 8, 0,
0, 0, 56, 0, 0, 0,
@ -2051,10 +2045,9 @@ const BYTE YCbCrShader[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -2165,10 +2158,10 @@ ret
const BYTE LayerQuadMaskVS[] =
{
68, 88, 66, 67, 229, 18,
238, 182, 176, 120, 118, 84,
74, 135, 103, 188, 146, 51,
229, 207, 1, 0, 0, 0,
68, 88, 66, 67, 223, 251,
10, 17, 13, 90, 47, 25,
119, 198, 20, 157, 124, 193,
251, 234, 1, 0, 0, 0,
120, 7, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
224, 1, 0, 0, 76, 4,
@ -2352,7 +2345,7 @@ const BYTE LayerQuadMaskVS[] =
116, 0, 0, 0, 16, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 4, 0,
0, 0, 8, 0, 0, 0,
0, 0, 14, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -2362,7 +2355,7 @@ const BYTE LayerQuadMaskVS[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -2453,10 +2446,10 @@ const BYTE LayerQuadMaskVS[] =
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 51,
48, 46, 57, 50, 48, 48,
46, 50, 48, 53, 52, 54,
0, 171, 73, 83, 71, 78,
101, 114, 32, 54, 46, 51,
46, 57, 54, 48, 48, 46,
49, 54, 51, 56, 52, 0,
171, 171, 73, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
@ -2487,10 +2480,9 @@ const BYTE LayerQuadMaskVS[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -2605,10 +2597,10 @@ ret
const BYTE LayerQuadMask3DVS[] =
{
68, 88, 66, 67, 81, 198,
45, 88, 207, 133, 27, 66,
4, 235, 107, 238, 69, 93,
43, 232, 1, 0, 0, 0,
68, 88, 66, 67, 151, 141,
11, 11, 111, 244, 17, 242,
119, 116, 248, 53, 235, 192,
38, 193, 1, 0, 0, 0,
204, 7, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
24, 2, 0, 0, 160, 4,
@ -2806,7 +2798,7 @@ const BYTE LayerQuadMask3DVS[] =
116, 0, 0, 0, 17, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 4, 0,
0, 0, 9, 0, 0, 0,
0, 0, 15, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -2816,7 +2808,7 @@ const BYTE LayerQuadMask3DVS[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -2907,10 +2899,10 @@ const BYTE LayerQuadMask3DVS[] =
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 51,
48, 46, 57, 50, 48, 48,
46, 50, 48, 53, 52, 54,
0, 171, 73, 83, 71, 78,
101, 114, 32, 54, 46, 51,
46, 57, 54, 48, 48, 46,
49, 54, 51, 56, 52, 0,
171, 171, 73, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
@ -2941,10 +2933,9 @@ const BYTE LayerQuadMask3DVS[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -3028,10 +3019,10 @@ ret
const BYTE SolidColorShaderMask[] =
{
68, 88, 66, 67, 110, 173,
179, 170, 121, 56, 16, 38,
131, 202, 191, 200, 149, 158,
191, 136, 1, 0, 0, 0,
68, 88, 66, 67, 236, 109,
19, 151, 23, 187, 157, 205,
112, 188, 91, 187, 108, 106,
138, 14, 1, 0, 0, 0,
232, 4, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
204, 0, 0, 0, 112, 1,
@ -3103,7 +3094,7 @@ const BYTE SolidColorShaderMask[] =
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -3207,9 +3198,9 @@ const BYTE SolidColorShaderMask[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 104, 0,
0, 0, 3, 0, 0, 0,
8, 0, 0, 0, 80, 0,
@ -3241,10 +3232,9 @@ const BYTE SolidColorShaderMask[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -3339,10 +3329,10 @@ ret
const BYTE RGBShaderMask[] =
{
68, 88, 66, 67, 90, 156,
108, 215, 2, 184, 95, 225,
139, 102, 23, 57, 234, 197,
48, 52, 1, 0, 0, 0,
68, 88, 66, 67, 30, 30,
87, 58, 114, 156, 251, 151,
29, 94, 34, 100, 228, 250,
37, 251, 1, 0, 0, 0,
192, 5, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
8, 1, 0, 0, 32, 2,
@ -3443,7 +3433,7 @@ const BYTE RGBShaderMask[] =
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -3554,9 +3544,9 @@ const BYTE RGBShaderMask[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 104, 0,
0, 0, 3, 0, 0, 0,
8, 0, 0, 0, 80, 0,
@ -3588,10 +3578,9 @@ const BYTE RGBShaderMask[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -3684,10 +3673,10 @@ ret
const BYTE RGBAShaderMask[] =
{
68, 88, 66, 67, 106, 15,
51, 47, 230, 18, 55, 40,
97, 21, 143, 67, 32, 99,
176, 32, 1, 0, 0, 0,
68, 88, 66, 67, 188, 13,
191, 168, 231, 201, 42, 209,
88, 243, 29, 35, 226, 31,
145, 20, 1, 0, 0, 0,
156, 5, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
252, 0, 0, 0, 252, 1,
@ -3782,7 +3771,7 @@ const BYTE RGBAShaderMask[] =
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -3893,9 +3882,9 @@ const BYTE RGBAShaderMask[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 104, 0,
0, 0, 3, 0, 0, 0,
8, 0, 0, 0, 80, 0,
@ -3927,10 +3916,9 @@ const BYTE RGBAShaderMask[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -4028,10 +4016,10 @@ ret
const BYTE RGBAShaderMask3D[] =
{
68, 88, 66, 67, 176, 186,
72, 64, 199, 228, 205, 219,
97, 152, 199, 132, 157, 124,
226, 212, 1, 0, 0, 0,
68, 88, 66, 67, 113, 141,
78, 23, 128, 223, 235, 10,
0, 97, 49, 111, 47, 53,
229, 55, 1, 0, 0, 0,
24, 6, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
24, 1, 0, 0, 64, 2,
@ -4138,7 +4126,7 @@ const BYTE RGBAShaderMask3D[] =
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -4258,9 +4246,9 @@ const BYTE RGBAShaderMask3D[] =
76, 32, 83, 104, 97, 100,
101, 114, 32, 67, 111, 109,
112, 105, 108, 101, 114, 32,
57, 46, 51, 48, 46, 57,
50, 48, 48, 46, 50, 48,
53, 52, 54, 0, 73, 83,
54, 46, 51, 46, 57, 54,
48, 48, 46, 49, 54, 51,
56, 52, 0, 171, 73, 83,
71, 78, 104, 0, 0, 0,
3, 0, 0, 0, 8, 0,
0, 0, 80, 0, 0, 0,
@ -4291,10 +4279,9 @@ const BYTE RGBAShaderMask3D[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -4421,10 +4408,10 @@ ret
const BYTE YCbCrShaderMask[] =
{
68, 88, 66, 67, 115, 10,
33, 43, 108, 217, 72, 92,
140, 65, 97, 68, 194, 221,
95, 25, 1, 0, 0, 0,
68, 88, 66, 67, 103, 162,
223, 236, 236, 142, 143, 151,
73, 154, 187, 112, 81, 114,
229, 251, 1, 0, 0, 0,
168, 8, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
24, 2, 0, 0, 196, 4,
@ -4628,7 +4615,7 @@ const BYTE YCbCrShaderMask[] =
116, 0, 0, 0, 17, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 7, 0, 0, 0,
0, 0, 11, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -4638,7 +4625,7 @@ const BYTE YCbCrShaderMask[] =
4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -4760,9 +4747,9 @@ const BYTE YCbCrShaderMask[] =
76, 83, 76, 32, 83, 104,
97, 100, 101, 114, 32, 67,
111, 109, 112, 105, 108, 101,
114, 32, 57, 46, 51, 48,
46, 57, 50, 48, 48, 46,
50, 48, 53, 52, 54, 0,
114, 32, 54, 46, 51, 46,
57, 54, 48, 48, 46, 49,
54, 51, 56, 52, 0, 171,
73, 83, 71, 78, 104, 0,
0, 0, 3, 0, 0, 0,
8, 0, 0, 0, 80, 0,
@ -4794,10 +4781,9 @@ const BYTE YCbCrShaderMask[] =
};
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
///
// Buffer Definitions:
//
// cbuffer $Globals
@ -4908,10 +4894,10 @@ ret
const BYTE ComponentAlphaShaderMask[] =
{
68, 88, 66, 67, 66, 175,
106, 103, 136, 76, 200, 80,
95, 179, 74, 140, 138, 144,
12, 21, 1, 0, 0, 0,
68, 88, 66, 67, 245, 71,
211, 223, 156, 101, 223, 204,
145, 138, 53, 12, 16, 220,
106, 83, 1, 0, 0, 0,
20, 7, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
124, 1, 0, 0, 52, 3,
@ -5058,7 +5044,7 @@ const BYTE ComponentAlphaShaderMask[] =
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
@ -5176,9 +5162,9 @@ const BYTE ComponentAlphaShaderMask[] =
76, 32, 83, 104, 97, 100,
101, 114, 32, 67, 111, 109,
112, 105, 108, 101, 114, 32,
57, 46, 51, 48, 46, 57,
50, 48, 48, 46, 50, 48,
53, 52, 54, 0, 73, 83,
54, 46, 51, 46, 57, 54,
48, 48, 46, 49, 54, 51,
56, 52, 0, 171, 73, 83,
71, 78, 104, 0, 0, 0,
3, 0, 0, 0, 8, 0,
0, 0, 80, 0, 0, 0,

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -37,13 +37,16 @@ SamplerState Linear
AddressV = Clamp;
};
/*
* Oculus basic distortion, with chroma aberration correction
*/
VS_VR_OUTPUT OculusVRDistortionVS(const VS_VR_INPUT aVertex)
{
VS_VR_OUTPUT res;
float2 tc0 = VREyeToSource.xy * aVertex.vTexCoord0 + VREyeToSource.zw;
float2 tc1 = VREyeToSource.xy * aVertex.vTexCoord1 + VREyeToSource.zw;
float2 tc2 = VREyeToSource.xy * aVertex.vTexCoord2 + VREyeToSource.zw;
float2 tc0 = aVertex.vTexCoord0 * VREyeToSource.zw + VREyeToSource.xy;
float2 tc1 = aVertex.vTexCoord1 * VREyeToSource.zw + VREyeToSource.xy;
float2 tc2 = aVertex.vTexCoord2 * VREyeToSource.zw + VREyeToSource.xy;
//res.vPosition.xy = aVertex.vPosition.xy;
res.vPosition.xy = aVertex.vPosition.xy * VRDestinationScaleAndOffset.zw + VRDestinationScaleAndOffset.xy;

Просмотреть файл

@ -13,6 +13,7 @@
#include "gfxPrefs.h"
#include "gfxVR.h"
#include "gfxVROculus.h"
#include "gfxVRCardboard.h"
#include "nsServiceManagerUtils.h"
#include "nsIScreenManager.h"
@ -85,6 +86,10 @@ VRHMDManager::ManagerInit()
mgr = new VRHMDManagerOculus();
if (mgr->PlatformInit())
sManagers->AppendElement(mgr);
mgr = new VRHMDManagerCardboard();
if (mgr->PlatformInit())
sManagers->AppendElement(mgr);
}
/* static */ void

Просмотреть файл

@ -19,6 +19,7 @@ namespace gfx {
enum class VRHMDType : uint16_t {
Oculus,
Cardboard,
NumHMDTypes
};
@ -217,6 +218,7 @@ public:
protected:
VRHMDManager() { }
virtual ~VRHMDManager() { }
};
} // namespace gfx

382
gfx/vr/gfxVRCardboard.cpp Normal file
Просмотреть файл

@ -0,0 +1,382 @@
/* -*- 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/dom/ScreenOrientation.h"
#include "mozilla/Preferences.h"
#include "mozilla/Hal.h"
#include "gfxVRCardboard.h"
#include "nsServiceManagerUtils.h"
#include "nsIScreenManager.h"
#ifdef ANDROID
#include <android/log.h>
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoVR" , ## args)
#else
#define LOG(...) do { } while(0)
#endif
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
// 1/sqrt(2) (aka sqrt(2)/2)
#ifndef M_SQRT1_2
# define M_SQRT1_2 0.70710678118654752440
#endif
using namespace mozilla::dom;
using namespace mozilla::gfx;
using namespace mozilla::gfx::impl;
namespace {
// some utility functions
// This remaps axes in the given matrix to a new configuration based on the
// screen orientation. Similar to what Android SensorManager.remapCoordinateSystem
// does, except only for a fixed number of transforms that we need.
Matrix4x4
RemapMatrixForOrientation(ScreenOrientation screenConfig, const Matrix4x4& aMatrix)
{
Matrix4x4 out;
const float *in = &aMatrix._11;
float *o = &out._11;
if (screenConfig == eScreenOrientation_LandscapePrimary) {
// remap X,Y -> Y,-X
o[0] = -in[1]; o[1] = in[0]; o[2] = in[2];
o[4] = -in[5]; o[5] = in[4]; o[6] = in[6];
o[8] = -in[9]; o[9] = in[8]; o[10] = in[10];
} else if (screenConfig == eScreenOrientation_LandscapeSecondary) {
// remap X,Y -> -Y,X
o[0] = in[1]; o[1] = -in[0]; o[2] = in[2];
o[4] = in[5]; o[5] = -in[4]; o[6] = in[6];
o[8] = in[9]; o[9] = -in[8]; o[10] = in[10];
} else if (screenConfig == eScreenOrientation_PortraitPrimary ||
screenConfig == eScreenOrientation_PortraitSecondary)
{
// remap X,Y -> X,-Z
o[0] = in[0]; o[1] = in[2]; o[2] = -in[1];
o[4] = in[4]; o[5] = in[6]; o[6] = -in[5];
o[8] = in[8]; o[9] = in[10]; o[10] = -in[9];
} else {
MOZ_ASSERT(0, "gfxVRCardboard::RemapMatrixForOrientation invalid screenConfig");
}
return out;
}
}
HMDInfoCardboard::HMDInfoCardboard()
: VRHMDInfo(VRHMDType::Cardboard)
, mStartCount(0)
, mOrient(eScreenOrientation_PortraitPrimary)
{
MOZ_ASSERT(sizeof(HMDInfoCardboard::DistortionVertex) == sizeof(VRDistortionVertex),
"HMDInfoCardboard::DistortionVertex must match the size of VRDistortionVertex");
mSupportedSensorBits = State_Orientation;
mRecommendedEyeFOV[Eye_Left] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
mRecommendedEyeFOV[Eye_Right] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
mMaximumEyeFOV[Eye_Left] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
mMaximumEyeFOV[Eye_Right] = VRFieldOfView(45.0, 45.0, 45.0, 45.0);
SetFOV(mRecommendedEyeFOV[Eye_Left], mRecommendedEyeFOV[Eye_Right], 0.01, 10000.0);
}
bool
HMDInfoCardboard::StartSensorTracking()
{
LOG("HMDInfoCardboard::StartSensorTracking %d\n", mStartCount);
if (mStartCount == 0) {
// it's never been started before; initialize observers and
// initial state.
mozilla::hal::ScreenConfiguration sconfig;
mozilla::hal::GetCurrentScreenConfiguration(&sconfig);
this->Notify(sconfig);
mozilla::hal::RegisterSensorObserver(mozilla::hal::SENSOR_GAME_ROTATION_VECTOR, this);
mozilla::hal::RegisterScreenConfigurationObserver(this);
mLastSensorState.Clear();
}
mStartCount++;
return true;
}
void
HMDInfoCardboard::Notify(const mozilla::hal::ScreenConfiguration& config)
{
mOrient = config.orientation();
if (mOrient == eScreenOrientation_LandscapePrimary) {
mScreenTransform = Quaternion(0.f, 0.f, M_SQRT1_2, M_SQRT1_2);
} else if (mOrient == eScreenOrientation_LandscapeSecondary) {
mScreenTransform = Quaternion(0.f, 0.f, -M_SQRT1_2, M_SQRT1_2);
} else if (mOrient == eScreenOrientation_PortraitPrimary) {
mScreenTransform = Quaternion();
} else if (mOrient == eScreenOrientation_PortraitSecondary) {
mScreenTransform = Quaternion(0.f, 0.f, 1.f, 0.f);
}
}
void
HMDInfoCardboard::Notify(const mozilla::hal::SensorData& data)
{
if (data.sensor() != mozilla::hal::SENSOR_GAME_ROTATION_VECTOR)
return;
const nsTArray<float>& sensorValues = data.values();
// This is super chatty
//LOG("HMDInfoCardboard::Notify %f %f %f %f\n", sensorValues[0], sensorValues[1], sensorValues[2], sensorValues[3]);
mSavedLastSensor.Set(sensorValues[0], sensorValues[1], sensorValues[2], sensorValues[3]);
mSavedLastSensorTime = data.timestamp();
mNeedsSensorCompute = true;
}
void
HMDInfoCardboard::ComputeStateFromLastSensor()
{
if (!mNeedsSensorCompute)
return;
// apply the zero orientation
Quaternion q = mSensorZeroInverse * mSavedLastSensor;
// make a matrix from the quat
Matrix4x4 qm;
qm.SetRotationFromQuaternion(q);
// remap the coordinate space, based on the orientation
Matrix4x4 qmRemapped = RemapMatrixForOrientation(mOrient, qm);
// turn it back into a quat
q.SetFromRotationMatrix(qmRemapped);
// apply adjustment based on what's been done to the screen and the original zero
// position of the base coordinate space
q = mScreenTransform * q;
VRHMDSensorState& state = mLastSensorState;
state.flags |= State_Orientation;
state.orientation[0] = q.x;
state.orientation[1] = q.y;
state.orientation[2] = q.z;
state.orientation[3] = q.w;
state.timestamp = mSavedLastSensorTime / 1000000.0;
mNeedsSensorCompute = false;
}
VRHMDSensorState
HMDInfoCardboard::GetSensorState(double timeOffset)
{
ComputeStateFromLastSensor();
return mLastSensorState;
}
void
HMDInfoCardboard::StopSensorTracking()
{
LOG("HMDInfoCardboard::StopSensorTracking, count %d\n", mStartCount);
if (--mStartCount == 0) {
mozilla::hal::UnregisterScreenConfigurationObserver(this);
mozilla::hal::UnregisterSensorObserver(mozilla::hal::SENSOR_GAME_ROTATION_VECTOR, this);
}
}
void
HMDInfoCardboard::ZeroSensor()
{
mSensorZeroInverse = mSavedLastSensor;
mSensorZeroInverse.Invert();
}
static Matrix4x4
ConstructProjectionMatrix(const VRFieldOfView& fov, bool rightHanded, double zNear, double zFar)
{
float upTan = tan(fov.upDegrees * M_PI / 180.0);
float downTan = tan(fov.downDegrees * M_PI / 180.0);
float leftTan = tan(fov.leftDegrees * M_PI / 180.0);
float rightTan = tan(fov.rightDegrees * M_PI / 180.0);
float handednessScale = rightHanded ? -1.0 : 1.0;
float pxscale = 2.0f / (leftTan + rightTan);
float pxoffset = (leftTan - rightTan) * pxscale * 0.5;
float pyscale = 2.0f / (upTan + downTan);
float pyoffset = (upTan - downTan) * pyscale * 0.5;
Matrix4x4 mobj;
float *m = &mobj._11;
m[0*4+0] = pxscale;
m[0*4+2] = pxoffset * handednessScale;
m[1*4+1] = pyscale;
m[1*4+2] = -pyoffset * handednessScale;
m[2*4+2] = zFar / (zNear - zFar) * -handednessScale;
m[2*4+3] = (zFar * zNear) / (zNear - zFar);
m[3*4+2] = handednessScale;
return mobj;
}
bool
HMDInfoCardboard::SetFOV(const VRFieldOfView& aFOVLeft,
const VRFieldOfView& aFOVRight,
double zNear, double zFar)
{
const float standardIPD = 0.064f;
for (uint32_t eye = 0; eye < NumEyes; eye++) {
mEyeFOV[eye] = eye == Eye_Left ? aFOVLeft : aFOVRight;
mEyeTranslation[eye] = Point3D(standardIPD * (eye == Eye_Left ? -1.0 : 1.0), 0.0, 0.0);
mEyeProjectionMatrix[eye] = ConstructProjectionMatrix(mEyeFOV[eye], true, zNear, zFar);
mDistortionMesh[eye].mVertices.SetLength(4);
mDistortionMesh[eye].mIndices.SetLength(6);
HMDInfoCardboard::DistortionVertex *destv = reinterpret_cast<HMDInfoCardboard::DistortionVertex*>(mDistortionMesh[eye].mVertices.Elements());
float xoffs = eye == Eye_Left ? 0.0f : 1.0f;
float txoffs = eye == Eye_Left ? 0.0f : 0.5f;
destv[0].pos[0] = -1.0 + xoffs;
destv[0].pos[1] = -1.0;
destv[0].texR[0] = destv[0].texG[0] = destv[0].texB[0] = 0.0 + txoffs;
destv[0].texR[1] = destv[0].texG[1] = destv[0].texB[1] = 1.0;
destv[0].padding[0] = 1.0; // vignette factor
destv[1].pos[0] = 0.0 + xoffs;
destv[1].pos[1] = -1.0;
destv[1].texR[0] = destv[1].texG[0] = destv[1].texB[0] = 0.5 + txoffs;
destv[1].texR[1] = destv[1].texG[1] = destv[1].texB[1] = 1.0;
destv[1].padding[0] = 1.0; // vignette factor
destv[2].pos[0] = 0.0 + xoffs;
destv[2].pos[1] = 1.0;
destv[2].texR[0] = destv[2].texG[0] = destv[2].texB[0] = 0.5 + txoffs;
destv[2].texR[1] = destv[2].texG[1] = destv[2].texB[1] = 0.0;
destv[2].padding[0] = 1.0; // vignette factor
destv[3].pos[0] = -1.0 + xoffs;
destv[3].pos[1] = 1.0;
destv[3].texR[0] = destv[3].texG[0] = destv[3].texB[0] = 0.0 + txoffs;
destv[3].texR[1] = destv[3].texG[1] = destv[3].texB[1] = 0.0;
destv[3].padding[0] = 1.0; // vignette factor
uint16_t *iv = mDistortionMesh[eye].mIndices.Elements();
iv[0] = 0; iv[1] = 1; iv[2] = 2;
iv[3] = 2; iv[4] = 3; iv[5] = 0;
}
// XXX find out the default screen size and use that
mEyeResolution.width = 1920 / 2;
mEyeResolution.height = 1080;
mConfiguration.hmdType = mType;
mConfiguration.value = 0;
mConfiguration.fov[0] = aFOVLeft;
mConfiguration.fov[1] = aFOVRight;
return true;
}
void
HMDInfoCardboard::FillDistortionConstants(uint32_t whichEye,
const IntSize& textureSize, const IntRect& eyeViewport,
const Size& destViewport, const Rect& destRect,
VRDistortionConstants& values)
{
// these modify the texture coordinates; texcoord * zw + xy
values.eyeToSourceScaleAndOffset[0] = 0.0;
values.eyeToSourceScaleAndOffset[1] = 0.0;
values.eyeToSourceScaleAndOffset[2] = 1.0;
values.eyeToSourceScaleAndOffset[3] = 1.0;
// Our mesh positions are in the [-1..1] clip space; we give appropriate offset
// and scaling for the right viewport. (In the 0..2 space for sanity)
// this is the destRect in clip space
float x0 = destRect.x / destViewport.width * 2.0 - 1.0;
float x1 = (destRect.x + destRect.width) / destViewport.width * 2.0 - 1.0;
float y0 = destRect.y / destViewport.height * 2.0 - 1.0;
float y1 = (destRect.y + destRect.height) / destViewport.height * 2.0 - 1.0;
// offset
values.destinationScaleAndOffset[0] = (x0+x1) / 2.0;
values.destinationScaleAndOffset[1] = (y0+y1) / 2.0;
// scale
values.destinationScaleAndOffset[2] = destRect.width / destViewport.width;
values.destinationScaleAndOffset[3] = destRect.height / destViewport.height;
}
void
HMDInfoCardboard::Destroy()
{
}
bool
VRHMDManagerCardboard::PlatformInit()
{
return true;
}
bool
VRHMDManagerCardboard::Init()
{
if (mCardboardInitialized)
return true;
nsRefPtr<HMDInfoCardboard> hmd = new HMDInfoCardboard();
mCardboardHMDs.AppendElement(hmd);
mCardboardInitialized = true;
return true;
}
void
VRHMDManagerCardboard::Destroy()
{
if (!mCardboardInitialized)
return;
for (size_t i = 0; i < mCardboardHMDs.Length(); ++i) {
mCardboardHMDs[i]->Destroy();
}
mCardboardHMDs.Clear();
mCardboardInitialized = false;
}
void
VRHMDManagerCardboard::GetHMDs(nsTArray<nsRefPtr<VRHMDInfo>>& aHMDResult)
{
Init();
for (size_t i = 0; i < mCardboardHMDs.Length(); ++i) {
aHMDResult.AppendElement(mCardboardHMDs[i]);
}
}

97
gfx/vr/gfxVRCardboard.h Normal file
Просмотреть файл

@ -0,0 +1,97 @@
/* -*- 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/. */
#ifndef GFX_VR_CARDBOARD_H
#define GFX_VR_CARDBOARD_H
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Quaternion.h"
#include "mozilla/EnumeratedArray.h"
#include "mozilla/HalSensor.h"
#include "mozilla/HalScreenConfiguration.h"
#include "gfxVR.h"
namespace mozilla {
namespace gfx {
namespace impl {
class HMDInfoCardboard :
public VRHMDInfo,
public hal::ISensorObserver,
public hal::ScreenConfigurationObserver
{
public:
explicit HMDInfoCardboard();
bool SetFOV(const VRFieldOfView& aFOVLeft, const VRFieldOfView& aFOVRight,
double zNear, double zFar) override;
bool StartSensorTracking() override;
VRHMDSensorState GetSensorState(double timeOffset) override;
void StopSensorTracking() override;
void ZeroSensor() override;
void FillDistortionConstants(uint32_t whichEye,
const IntSize& textureSize, const IntRect& eyeViewport,
const Size& destViewport, const Rect& destRect,
VRDistortionConstants& values) override;
void Destroy();
// ISensorObserver interface
void Notify(const hal::SensorData& SensorData) override;
// ScreenConfigurationObserver interface
void Notify(const hal::ScreenConfiguration& ScreenConfiguration) override;
protected:
// must match the size of VRDistortionVertex
struct DistortionVertex {
float pos[2];
float texR[2];
float texG[2];
float texB[2];
float padding[4];
};
virtual ~HMDInfoCardboard() {
Destroy();
}
void ComputeStateFromLastSensor();
uint32_t mStartCount;
VRHMDSensorState mLastSensorState;
uint32_t mOrient;
Quaternion mScreenTransform;
Quaternion mSensorZeroInverse;
Quaternion mSavedLastSensor;
double mSavedLastSensorTime;
bool mNeedsSensorCompute; // if we need to compute the state from mSavedLastSensor
};
} // namespace impl
class VRHMDManagerCardboard : public VRHMDManager
{
public:
VRHMDManagerCardboard()
: mCardboardInitialized(false)
{ }
virtual bool PlatformInit() override;
virtual bool Init() override;
virtual void Destroy() override;
virtual void GetHMDs(nsTArray<nsRefPtr<VRHMDInfo> >& aHMDResult) override;
protected:
nsTArray<nsRefPtr<impl::HMDInfoCardboard>> mCardboardHMDs;
bool mCardboardInitialized;
};
} // namespace gfx
} // namespace mozilla
#endif /* GFX_VR_CARDBOARD_H */

Просмотреть файл

@ -331,10 +331,10 @@ HMDInfoOculus::FillDistortionConstants(uint32_t whichEye,
ovrHmd_GetRenderScaleAndOffset(mFOVPort[whichEye], texSize, eyePort, scaleOut);
values.eyeToSourceScaleAndOffset[0] = scaleOut[0].x;
values.eyeToSourceScaleAndOffset[1] = scaleOut[0].y;
values.eyeToSourceScaleAndOffset[2] = scaleOut[1].x;
values.eyeToSourceScaleAndOffset[3] = scaleOut[1].y;
values.eyeToSourceScaleAndOffset[0] = scaleOut[1].x;
values.eyeToSourceScaleAndOffset[1] = scaleOut[1].y;
values.eyeToSourceScaleAndOffset[2] = scaleOut[0].x;
values.eyeToSourceScaleAndOffset[3] = scaleOut[0].y;
// These values are in clip space [-1..1] range, but we're providing
// scaling in the 0..2 space for sanity.

Просмотреть файл

@ -14,6 +14,7 @@ LOCAL_INCLUDES += [
UNIFIED_SOURCES += [
'gfxVR.cpp',
'gfxVRCardboard.cpp',
'gfxVROculus.cpp',
]