Index: Source/modules/vr/VRHardwareUnit.cpp |
diff --git a/Source/modules/vr/VRHardwareUnit.cpp b/Source/modules/vr/VRHardwareUnit.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e5864d0c8ae38d4c14f40c0ae58cb2f554d2110b |
--- /dev/null |
+++ b/Source/modules/vr/VRHardwareUnit.cpp |
@@ -0,0 +1,114 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "modules/vr/VRHardwareUnit.h" |
+ |
+#include "modules/vr/HMDVRDevice.h" |
+#include "modules/vr/PositionSensorVRDevice.h" |
+#include "modules/vr/VRDevice.h" |
+#include "public/platform/Platform.h" |
+ |
+namespace blink { |
+ |
+VRHardwareUnit::VRHardwareUnit() |
+ : m_frameIndex(0) |
+{ |
+ m_positionState = VRPositionState::create(); |
+ m_currentFOVLeft = new VRFieldOfView(); |
+ m_currentFOVRight = new VRFieldOfView(); |
+} |
+ |
+VRHardwareUnit::~VRHardwareUnit() |
+{ |
+} |
+ |
+void VRHardwareUnit::updateFromWebVRDevice(const WebVRDevice& device) |
+{ |
+ m_index = device.index; |
+ m_hardwareUnitId = device.deviceId; |
+ |
+ if (device.flags & WebVRDeviceTypeHMD) { |
+ if (!m_hmd.get()) |
sof
2015/02/24 12:35:29
get() is redundant (here and for other Member<> bo
|
+ m_hmd = new HMDVRDevice(this); |
+ m_hmd->updateFromWebVRDevice(device); |
+ } else if (m_hmd.get()) { |
+ m_hmd.clear(); |
+ } |
+ |
+ if (device.flags & WebVRDeviceTypePosition) { |
+ if (!m_positionSensor.get()) |
+ m_positionSensor = new PositionSensorVRDevice(this); |
+ m_positionSensor->updateFromWebVRDevice(device); |
+ } else if (m_positionSensor.get()) { |
+ m_positionSensor.clear(); |
+ } |
+} |
+ |
+void VRHardwareUnit::addDevicesToVector(HeapVector<Member<VRDevice>>& vrDevices) |
Ken Russell (switch to Gerrit)
2015/02/23 19:39:32
Please make sure to get a review from someone who
|
+{ |
+ if (m_hmd.get()) |
+ vrDevices.append(m_hmd); |
+ |
+ if (m_positionSensor.get()) |
+ vrDevices.append(m_positionSensor); |
+} |
+ |
+VRPositionState* VRHardwareUnit::getPositionState(double timeOffset) |
+{ |
+ blink::WebHMDSensorState state; |
+ blink::Platform::current()->getHMDSensorState(m_index, timeOffset, state); |
+ |
+ m_positionState->setState(state); |
+ m_frameIndex = state.frameIndex; |
+ |
+ return m_positionState; |
+} |
+ |
+void VRHardwareUnit::setFieldOfView(unsigned eyeIndex, VRFieldOfView* fov) |
+{ |
+ switch (eyeIndex) { |
+ case 0: |
+ m_currentFOVLeft->setFromVRFieldOfView(*fov); |
+ break; |
+ case 1: |
+ m_currentFOVRight->setFromVRFieldOfView(*fov); |
+ break; |
+ } |
sof
2015/02/24 12:35:29
Appropriate to have a default: case here?
|
+} |
+ |
+VRFieldOfView* VRHardwareUnit::getCurrentEyeFieldOfView(unsigned eyeIndex) const |
+{ |
+ switch (eyeIndex) { |
+ case 0: |
+ return new VRFieldOfView(*m_currentFOVLeft); |
+ case 1: |
+ return new VRFieldOfView(*m_currentFOVRight); |
+ default: |
+ return 0; |
+ } |
+} |
+ |
+WebVRFieldOfView VRHardwareUnit::getFieldOfView(unsigned eyeIndex) const |
+{ |
+ VRFieldOfView* srcFov = eyeIndex == 0 ? m_currentFOVLeft : m_currentFOVRight; |
+ |
+ blink::WebVRFieldOfView fov; |
+ fov.upDegrees = srcFov->upDegrees(); |
+ fov.downDegrees = srcFov->downDegrees(); |
+ fov.leftDegrees = srcFov->leftDegrees(); |
+ fov.rightDegrees = srcFov->rightDegrees(); |
+ return fov; |
+} |
+ |
+void VRHardwareUnit::trace(Visitor* visitor) |
+{ |
+ visitor->trace(m_positionState); |
+ visitor->trace(m_currentFOVLeft); |
+ visitor->trace(m_currentFOVRight); |
+ visitor->trace(m_hmd); |
+ visitor->trace(m_positionSensor); |
+} |
+ |
+} // namespace blink |