OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "modules/vr/NavigatorVRDevice.h" | |
7 | |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
9 #include "core/dom/Document.h" | |
10 #include "core/frame/LocalDOMWindow.h" | |
11 #include "core/frame/LocalFrame.h" | |
12 #include "core/frame/Navigator.h" | |
13 #include "core/page/Page.h" | |
14 #include "modules/vr/HMDVRDevice.h" | |
15 #include "modules/vr/PositionSensorVRDevice.h" | |
16 #include "modules/vr/VRHardwareUnit.h" | |
17 #include "modules/vr/VRPositionState.h" | |
18 #include "platform/RuntimeEnabledFeatures.h" | |
19 #include "public/platform/Platform.h" | |
20 | |
21 namespace blink { | |
22 | |
23 NavigatorVRDevice* NavigatorVRDevice::from(Document& document) | |
24 { | |
25 if (!document.frame() || !document.frame()->domWindow()) | |
26 return 0; | |
27 Navigator& navigator = *document.frame()->domWindow()->navigator(); | |
28 return &from(navigator); | |
29 } | |
30 | |
31 NavigatorVRDevice& NavigatorVRDevice::from(Navigator& navigator) | |
32 { | |
33 NavigatorVRDevice* supplement = static_cast<NavigatorVRDevice*>(WillBeHeapSu pplement<Navigator>::from(navigator, supplementName())); | |
34 if (!supplement) { | |
35 supplement = new NavigatorVRDevice(); | |
36 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); | |
37 } | |
38 return *supplement; | |
39 } | |
40 | |
41 ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState, Navigato r& navigator) | |
42 { | |
43 return NavigatorVRDevice::from(navigator).getVRDevices(scriptState); | |
44 } | |
45 | |
46 ScriptPromise NavigatorVRDevice::getVRDevices(ScriptState* scriptState) | |
47 { | |
48 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
49 ScriptPromise promise = resolver->promise(); | |
50 resolver->resolve(updateVRHardwareUnits()); | |
51 | |
52 return promise; | |
53 } | |
54 | |
55 HeapVector<Member<VRDevice>> NavigatorVRDevice::updateVRHardwareUnits() | |
sof
2015/02/24 12:35:29
Hmm, naming doesn't suggest that it returns a resu
| |
56 { | |
57 std::vector<blink::WebVRDevice> devices; | |
58 blink::Platform::current()->getVRDevices(&devices); | |
59 | |
60 VRDeviceVector vrDevices; | |
61 | |
62 std::vector<blink::WebVRDevice>::iterator deviceIterator; | |
63 for (deviceIterator = devices.begin(); deviceIterator != devices.end(); devi ceIterator++) { | |
64 const blink::WebVRDevice& device = *(deviceIterator); | |
65 | |
66 VRHardwareUnit* hardwareUnit = getHardwareUnitForIndex(device.index); | |
67 if (!hardwareUnit) { | |
68 hardwareUnit = new VRHardwareUnit(); | |
69 m_hardwareUnits.append(hardwareUnit); | |
70 } | |
71 | |
72 hardwareUnit->updateFromWebVRDevice(device); | |
73 hardwareUnit->addDevicesToVector(vrDevices); | |
74 } | |
75 | |
76 return vrDevices; | |
77 } | |
78 | |
79 VRHardwareUnit* NavigatorVRDevice::getHardwareUnitForIndex(unsigned index) | |
80 { | |
81 VRHardwareUnit* hardwareUnit; | |
82 HeapVector<Member<VRHardwareUnit>>::iterator iter; | |
83 for (iter = m_hardwareUnits.begin(); iter != m_hardwareUnits.end(); ++iter) { | |
sof
2015/02/24 12:35:29
Can we use a range-based for loop here?
| |
84 hardwareUnit = *iter; | |
85 if (hardwareUnit->index() == index) { | |
86 return hardwareUnit; | |
87 } | |
88 } | |
89 | |
90 return 0; | |
91 } | |
92 | |
93 void NavigatorVRDevice::trace(Visitor* visitor) | |
94 { | |
95 visitor->trace(m_hardwareUnits); | |
96 | |
97 WillBeHeapSupplement<Navigator>::trace(visitor); | |
98 } | |
99 | |
100 NavigatorVRDevice::NavigatorVRDevice() | |
101 { | |
102 } | |
103 | |
104 NavigatorVRDevice::~NavigatorVRDevice() | |
105 { | |
106 } | |
107 | |
108 const char* NavigatorVRDevice::supplementName() | |
109 { | |
110 return "NavigatorVRDevice"; | |
111 } | |
112 | |
113 } // namespace blink | |
OLD | NEW |