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

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRHardwareUnit.cpp

Issue 1918143007: Updated Blink WebVR interfaces to WebVR v1 spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webvr_mojo
Patch Set: Fixed layout test Created 4 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "modules/vr/VRHardwareUnit.h"
6
7 #include "modules/vr/HMDVRDevice.h"
8 #include "modules/vr/NavigatorVRDevice.h"
9 #include "modules/vr/PositionSensorVRDevice.h"
10 #include "modules/vr/VRController.h"
11 #include "modules/vr/VRDevice.h"
12 #include "public/platform/Platform.h"
13
14 namespace blink {
15
16 VRHardwareUnit::VRHardwareUnit(NavigatorVRDevice* navigatorVRDevice)
17 : m_nextDeviceId(1)
18 , m_frameIndex(0)
19 , m_navigatorVRDevice(navigatorVRDevice)
20 , m_canUpdatePositionState(true)
21 {
22 m_positionState = VRPositionState::create();
23 }
24
25 VRHardwareUnit::~VRHardwareUnit()
26 {
27 if (!m_canUpdatePositionState)
28 Platform::current()->currentThread()->removeTaskObserver(this);
29 }
30
31 void VRHardwareUnit::updateFromWebVRDevice(const WebVRDevice& device)
32 {
33 m_index = device.index;
34 m_hardwareUnitId = String::number(device.index);
35
36 if (device.flags & WebVRDeviceTypeHMD) {
37 if (!m_hmd)
38 m_hmd = new HMDVRDevice(this, m_nextDeviceId++);
39 m_hmd->updateFromWebVRDevice(device);
40 } else if (m_hmd) {
41 m_hmd.clear();
42 }
43
44 if (device.flags & WebVRDeviceTypePosition) {
45 if (!m_positionSensor)
46 m_positionSensor = new PositionSensorVRDevice(this, m_nextDeviceId++ );
47 m_positionSensor->updateFromWebVRDevice(device);
48 } else if (m_positionSensor) {
49 m_positionSensor.clear();
50 }
51 }
52
53 void VRHardwareUnit::addDevicesToVector(HeapVector<Member<VRDevice>>& vrDevices)
54 {
55 if (m_hmd)
56 vrDevices.append(m_hmd);
57
58 if (m_positionSensor)
59 vrDevices.append(m_positionSensor);
60 }
61
62 VRController* VRHardwareUnit::controller()
63 {
64 return m_navigatorVRDevice->controller();
65 }
66
67 VRPositionState* VRHardwareUnit::getSensorState()
68 {
69 if (m_canUpdatePositionState) {
70 m_positionState = getImmediateSensorState(true);
71 Platform::current()->currentThread()->addTaskObserver(this);
72 m_canUpdatePositionState = false;
73 }
74
75 return m_positionState;
76 }
77
78 VRPositionState* VRHardwareUnit::getImmediateSensorState(bool updateFrameIndex)
79 {
80 WebHMDSensorState state;
81 controller()->getSensorState(m_index, state);
82 if (updateFrameIndex)
83 m_frameIndex = state.frameIndex;
84
85 VRPositionState* immediatePositionState = VRPositionState::create();
86 immediatePositionState->setState(state);
87 return immediatePositionState;
88 }
89
90
91 void VRHardwareUnit::didProcessTask()
92 {
93 // State should be stable until control is returned to the user agent.
94 if (!m_canUpdatePositionState) {
95 Platform::current()->currentThread()->removeTaskObserver(this);
96 m_canUpdatePositionState = true;
97 }
98 }
99
100 DEFINE_TRACE(VRHardwareUnit)
101 {
102 visitor->trace(m_navigatorVRDevice);
103 visitor->trace(m_positionState);
104 visitor->trace(m_hmd);
105 visitor->trace(m_positionSensor);
106 }
107
108 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/vr/VRHardwareUnit.h ('k') | third_party/WebKit/Source/modules/vr/VRHardwareUnitCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698