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

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

Issue 848053002: Adding WebVR interface to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed compiler warning treated as an error on Windows Created 5 years, 9 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/NavigatorVRDevice.cpp
diff --git a/Source/modules/vr/NavigatorVRDevice.cpp b/Source/modules/vr/NavigatorVRDevice.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1e98a4604485a68e966c7d2c6fae00e29e61b47f
--- /dev/null
+++ b/Source/modules/vr/NavigatorVRDevice.cpp
@@ -0,0 +1,110 @@
+// Copyright 2015 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/NavigatorVRDevice.h"
+
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "core/dom/Document.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "core/frame/LocalFrame.h"
+#include "core/frame/Navigator.h"
+#include "core/page/Page.h"
+#include "modules/vr/HMDVRDevice.h"
+#include "modules/vr/PositionSensorVRDevice.h"
+#include "modules/vr/VRHardwareUnit.h"
+#include "modules/vr/VRPositionState.h"
+#include "platform/RuntimeEnabledFeatures.h"
+#include "public/platform/Platform.h"
+
+namespace blink {
+
+NavigatorVRDevice* NavigatorVRDevice::from(Document& document)
+{
+ if (!document.frame() || !document.frame()->domWindow())
+ return 0;
+ Navigator& navigator = *document.frame()->domWindow()->navigator();
+ return &from(navigator);
+}
+
+NavigatorVRDevice& NavigatorVRDevice::from(Navigator& navigator)
+{
+ NavigatorVRDevice* supplement = static_cast<NavigatorVRDevice*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
+ if (!supplement) {
+ supplement = new NavigatorVRDevice();
+ provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
+ }
+ return *supplement;
+}
+
+ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState, Navigator& navigator)
+{
+ return NavigatorVRDevice::from(navigator).getVRDevices(scriptState);
+}
+
+ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState)
+{
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ resolver->resolve(getUpdatedVRHardwareUnits());
+
+ return promise;
+}
+
+HeapVector<Member<VRDevice>> NavigatorVRDevice::getUpdatedVRHardwareUnits()
+{
+ WebVector<blink::WebVRDevice> devices;
+ blink::Platform::current()->getVRDevices(&devices);
+
+ VRDeviceVector vrDevices;
+ for (size_t i = 0; i < devices.size(); ++i) {
+ const blink::WebVRDevice& device = devices[i];
+
+ VRHardwareUnit* hardwareUnit = getHardwareUnitForIndex(device.index);
+ if (!hardwareUnit) {
+ hardwareUnit = new VRHardwareUnit();
+ m_hardwareUnits.append(hardwareUnit);
+ }
+
+ hardwareUnit->updateFromWebVRDevice(device);
+ hardwareUnit->addDevicesToVector(vrDevices);
+ }
+
+ return vrDevices;
+}
+
+VRHardwareUnit* NavigatorVRDevice::getHardwareUnitForIndex(unsigned index)
+{
+ VRHardwareUnit* hardwareUnit;
+ for (size_t i = 0; i < m_hardwareUnits.size(); ++i) {
+ hardwareUnit = m_hardwareUnits[i];
+ if (hardwareUnit->index() == index) {
+ return hardwareUnit;
+ }
+ }
+
+ return 0;
+}
+
+void NavigatorVRDevice::trace(Visitor* visitor)
+{
+ visitor->trace(m_hardwareUnits);
+
+ WillBeHeapSupplement<Navigator>::trace(visitor);
+}
+
+NavigatorVRDevice::NavigatorVRDevice()
+{
+}
+
+NavigatorVRDevice::~NavigatorVRDevice()
+{
+}
+
+const char* NavigatorVRDevice::supplementName()
+{
+ return "NavigatorVRDevice";
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698