Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2176)

Unified Diff: Source/modules/vr/HMDVRDevice.cpp

Issue 848053002: Adding WebVR interface to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed feedback from philipj@opera.com, rebased Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/vr/HMDVRDevice.cpp
diff --git a/Source/modules/vr/HMDVRDevice.cpp b/Source/modules/vr/HMDVRDevice.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8b4c153d63287600c50ccb7fff47d0a2cb617863
--- /dev/null
+++ b/Source/modules/vr/HMDVRDevice.cpp
@@ -0,0 +1,152 @@
+// 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/HMDVRDevice.h"
+
+#include "modules/vr/VRFieldOfView.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebSize.h"
+
+namespace blink {
+
+namespace {
+
+void setDomPoint(DOMPoint* point, const blink::WebVRVector3& vec)
+{
+ point->setX(vec.x);
+ point->setY(vec.y);
+ point->setZ(vec.z);
+ point->setW(0.0);
+}
+
+}
sof 2015/02/24 12:35:28 // namespace
+
+HMDVRDevice::HMDVRDevice(VRHardwareUnit* hardwareUnit)
+ : VRDevice(hardwareUnit)
+{
+ m_recommendedFOVLeft = new VRFieldOfView();
+ m_recommendedFOVRight = new VRFieldOfView();
+ m_maximumFOVLeft = new VRFieldOfView();
+ m_maximumFOVRight = new VRFieldOfView();
+ m_eyeTranslationLeft = DOMPoint::create(0, 0, 0, 0);
+ m_eyeTranslationRight = DOMPoint::create(0, 0, 0, 0);
+}
+
+HMDVRDevice::VREye HMDVRDevice::StringToVREye(const String& whichEye)
+{
+ if (whichEye == "left")
+ return VREyeLeft;
+ if (whichEye == "right")
+ return VREyeRight;
+ return VREyeNone;
+}
+
+void HMDVRDevice::updateFromWebVRDevice(const WebVRDevice& device)
+{
+ VRDevice::updateFromWebVRDevice(device);
+ const blink::WebVRHMDInfo &hmdInfo = device.hmdInfo;
+
+ m_recommendedFOVLeft->setFromWebVRFieldOfView(hmdInfo.recommendedFOVLeft);
+ m_recommendedFOVRight->setFromWebVRFieldOfView(hmdInfo.recommendedFOVRight);
+ m_maximumFOVLeft->setFromWebVRFieldOfView(hmdInfo.maximumFOVLeft);
+ m_maximumFOVRight->setFromWebVRFieldOfView(hmdInfo.maximumFOVRight);
+ setDomPoint(m_eyeTranslationLeft, hmdInfo.eyeTranslationLeft);
+ setDomPoint(m_eyeTranslationRight, hmdInfo.eyeTranslationRight);
+ hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft);
+ hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight);
+}
+
+DOMPoint* HMDVRDevice::getEyeTranslation(const String& whichEye)
+{
+ switch (StringToVREye(whichEye)) {
+ case VREyeLeft:
+ return m_eyeTranslationLeft;
+ case VREyeRight:
+ return m_eyeTranslationRight;
+ default:
+ return DOMPoint::create(0, 0, 0, 0);
+ }
+}
+
+VRFieldOfView* HMDVRDevice::getCurrentEyeFieldOfView(const String& whichEye)
+{
+ return hardwareUnit()->getCurrentEyeFieldOfView(StringToVREye(whichEye));
+}
+
+VRFieldOfView* HMDVRDevice::getRecommendedEyeFieldOfView(const String& whichEye)
+{
+ switch (StringToVREye(whichEye)) {
+ case VREyeLeft:
+ return new VRFieldOfView(*m_recommendedFOVLeft);
+ case VREyeRight:
+ return new VRFieldOfView(*m_recommendedFOVRight);
+ default:
+ return new VRFieldOfView();
+ }
+}
+
+VRFieldOfView* HMDVRDevice::getMaximumEyeFieldOfView(const String& whichEye)
+{
+ switch (StringToVREye(whichEye)) {
+ case VREyeLeft:
+ return new VRFieldOfView(*m_maximumFOVLeft);
+ case VREyeRight:
+ return new VRFieldOfView(*m_maximumFOVRight);
+ default:
+ return new VRFieldOfView();
+ }
+}
+
+DOMRect* HMDVRDevice::getRecommendedEyeRenderRect(const String& whichEye)
+{
+ // TODO(bajones): This doesn't change unless you reset the FOV. Cache it.
sof 2015/02/24 12:35:28 nit: FIXMEs in Blink.
+ blink::WebSize size;
+ blink::Platform::current()->getVRRenderTargetSize(index(),
+ hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeLeft),
+ hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeRight),
+ &size);
+
+ // TODO(bajones): We can actually fetch individual eye rects from the Oculus SDK.
+ // Plumb that through and expose it here.
+ switch (StringToVREye(whichEye)) {
+ case VREyeLeft:
+ return DOMRect::create(0, 0, size.width / 2.0f, size.height);
+ case VREyeRight:
+ return DOMRect::create(size.width / 2.0f, 0, size.width / 2.0f, size.height);
+ default:
+ return DOMRect::create(0, 0, 0, 0);
+ }
+}
+
+void HMDVRDevice::setFieldOfView(VRFieldOfView* leftFov, VRFieldOfView* rightFov)
+{
+ // TODO(bajones): Clamp to maxFOV
+
+ if (leftFov) {
+ hardwareUnit()->setFieldOfView(0, leftFov);
+ } else {
+ hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft);
+ }
+
+ if (rightFov) {
+ hardwareUnit()->setFieldOfView(1, rightFov);
+ } else {
+ hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight);
+ }
+}
+
+void HMDVRDevice::trace(Visitor* visitor)
+{
+ VRDevice::trace(visitor);
sof 2015/02/24 12:35:28 nit: preference is to trace the subclasses last.
+
+ visitor->trace(m_recommendedFOVLeft);
+ visitor->trace(m_recommendedFOVRight);
+ visitor->trace(m_maximumFOVLeft);
+ visitor->trace(m_maximumFOVRight);
+ visitor->trace(m_eyeTranslationLeft);
+ visitor->trace(m_eyeTranslationRight);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698