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

Side by Side Diff: content/browser/vr/vr_device_manager.cc

Issue 1967633002: Updated VRService to match the latest Blink WebVR interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: And we're back to removing all the array size checks 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/vr/vr_device_manager.h" 5 #include "content/browser/vr/vr_device_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // non-nullptr and vica versa. 70 // non-nullptr and vica versa.
71 CHECK_NE(!!instance, !!g_vr_device_manager); 71 CHECK_NE(!!instance, !!g_vr_device_manager);
72 g_vr_device_manager = instance; 72 g_vr_device_manager = instance;
73 } 73 }
74 74
75 bool VRDeviceManager::HasInstance() { 75 bool VRDeviceManager::HasInstance() {
76 // For testing. Checks to see if a VRDeviceManager instance is active. 76 // For testing. Checks to see if a VRDeviceManager instance is active.
77 return !!g_vr_device_manager; 77 return !!g_vr_device_manager;
78 } 78 }
79 79
80 mojo::Array<blink::mojom::VRDeviceInfoPtr> VRDeviceManager::GetVRDevices() { 80 mojo::Array<blink::mojom::VRDisplayPtr> VRDeviceManager::GetVRDevices() {
81 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
82 82
83 InitializeProviders(); 83 InitializeProviders();
84 84
85 std::vector<VRDevice*> devices; 85 std::vector<VRDevice*> devices;
86 for (const auto& provider : providers_) 86 for (const auto& provider : providers_)
87 provider->GetDevices(&devices); 87 provider->GetDevices(&devices);
88 88
89 mojo::Array<blink::mojom::VRDeviceInfoPtr> out_devices; 89 mojo::Array<blink::mojom::VRDisplayPtr> out_devices;
90 for (const auto& device : devices) { 90 for (const auto& device : devices) {
91 if (device->id() == VR_DEVICE_LAST_ID) 91 if (device->id() == VR_DEVICE_LAST_ID)
92 continue; 92 continue;
93 93
94 if (devices_.find(device->id()) == devices_.end()) 94 if (devices_.find(device->id()) == devices_.end())
95 devices_[device->id()] = device; 95 devices_[device->id()] = device;
96 96
97 blink::mojom::VRDeviceInfoPtr vr_device_info = device->GetVRDevice(); 97 blink::mojom::VRDisplayPtr vr_device_info = device->GetVRDevice();
98 if (vr_device_info.is_null()) 98 if (vr_device_info.is_null())
99 continue; 99 continue;
100 100
101 vr_device_info->index = device->id(); 101 vr_device_info->index = device->id();
102 out_devices.push_back(std::move(vr_device_info)); 102 out_devices.push_back(std::move(vr_device_info));
103 } 103 }
104 104
105 return out_devices; 105 return out_devices;
106 } 106 }
107 107
108 VRDevice* VRDeviceManager::GetDevice(unsigned int index) { 108 VRDevice* VRDeviceManager::GetDevice(unsigned int index) {
109 DCHECK(thread_checker_.CalledOnValidThread()); 109 DCHECK(thread_checker_.CalledOnValidThread());
110 110
111 if (index == 0) {
112 return NULL;
113 }
114
111 DeviceMap::iterator iter = devices_.find(index); 115 DeviceMap::iterator iter = devices_.find(index);
112 if (iter == devices_.end()) { 116 if (iter == devices_.end()) {
113 return nullptr; 117 return nullptr;
114 } 118 }
115 return iter->second; 119 return iter->second;
116 } 120 }
117 121
118 void VRDeviceManager::InitializeProviders() { 122 void VRDeviceManager::InitializeProviders() {
119 if (vr_initialized_) { 123 if (vr_initialized_) {
120 return; 124 return;
121 } 125 }
122 126
123 for (const auto& provider : providers_) 127 for (const auto& provider : providers_)
124 provider->Initialize(); 128 provider->Initialize();
125 129
126 vr_initialized_ = true; 130 vr_initialized_ = true;
127 } 131 }
128 132
129 void VRDeviceManager::RegisterProvider( 133 void VRDeviceManager::RegisterProvider(
130 std::unique_ptr<VRDeviceProvider> provider) { 134 std::unique_ptr<VRDeviceProvider> provider) {
131 providers_.push_back(make_linked_ptr(provider.release())); 135 providers_.push_back(make_linked_ptr(provider.release()));
132 } 136 }
133 137
134 void VRDeviceManager::GetDevices(const GetDevicesCallback& callback) { 138 void VRDeviceManager::GetDisplays(const GetDisplaysCallback& callback) {
135 callback.Run(GetVRDevices()); 139 callback.Run(GetVRDevices());
136 } 140 }
137 141
138 void VRDeviceManager::GetSensorState(uint32_t index, 142 void VRDeviceManager::GetPose(uint32_t index,
139 const GetSensorStateCallback& callback) { 143 const GetPoseCallback& callback) {
140 VRDevice* device = GetDevice(index); 144 VRDevice* device = GetDevice(index);
141 if (device) { 145 if (device) {
142 callback.Run(device->GetSensorState()); 146 callback.Run(device->GetPose());
143 } else { 147 } else {
144 callback.Run(nullptr); 148 callback.Run(nullptr);
145 } 149 }
146 } 150 }
147 151
148 void VRDeviceManager::ResetSensor(uint32_t index) { 152 void VRDeviceManager::ResetPose(uint32_t index) {
149 VRDevice* device = GetDevice(index); 153 VRDevice* device = GetDevice(index);
150 if (device) 154 if (device)
151 device->ResetSensor(); 155 device->ResetPose();
152 } 156 }
153 157
154 } // namespace content 158 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/vr/vr_device_manager.h ('k') | content/browser/vr/vr_device_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698