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

Side by Side Diff: device/vr/android/gvr/gvr_device.cc

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: update binding process and update some unittest Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "device/vr/android/gvr/gvr_device.h" 5 #include "device/vr/android/gvr/gvr_device.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 16 matching lines...) Expand all
27 GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate) 27 GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate)
28 : VRDevice(provider), delegate_(delegate), gvr_provider_(provider) {} 28 : VRDevice(provider), delegate_(delegate), gvr_provider_(provider) {}
29 29
30 GvrDevice::~GvrDevice() {} 30 GvrDevice::~GvrDevice() {}
31 31
32 VRDisplayPtr GvrDevice::GetVRDevice() { 32 VRDisplayPtr GvrDevice::GetVRDevice() {
33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); 33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice");
34 34
35 VRDisplayPtr device = VRDisplay::New(); 35 VRDisplayPtr device = VRDisplay::New();
36 36
37 device->index = id();
38
39 device->capabilities = VRDisplayCapabilities::New(); 37 device->capabilities = VRDisplayCapabilities::New();
40 device->capabilities->hasOrientation = true; 38 device->capabilities->hasOrientation = true;
41 device->capabilities->hasPosition = false; 39 device->capabilities->hasPosition = false;
42 device->capabilities->hasExternalDisplay = false; 40 device->capabilities->hasExternalDisplay = false;
43 device->capabilities->canPresent = true; 41 device->capabilities->canPresent = true;
44 42
45 device->leftEye = VREyeParameters::New(); 43 device->leftEye = VREyeParameters::New();
46 device->rightEye = VREyeParameters::New(); 44 device->rightEye = VREyeParameters::New();
47 VREyeParametersPtr& left_eye = device->leftEye; 45 VREyeParametersPtr& left_eye = device->leftEye;
48 VREyeParametersPtr& right_eye = device->rightEye; 46 VREyeParametersPtr& right_eye = device->rightEye;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 left_eye->offset[2] = -left_eye_mat.m[2][3]; 118 left_eye->offset[2] = -left_eye_mat.m[2][3];
121 119
122 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); 120 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE);
123 right_eye->offset[0] = -right_eye_mat.m[0][3]; 121 right_eye->offset[0] = -right_eye_mat.m[0][3];
124 right_eye->offset[1] = -right_eye_mat.m[1][3]; 122 right_eye->offset[1] = -right_eye_mat.m[1][3];
125 right_eye->offset[2] = -right_eye_mat.m[2][3]; 123 right_eye->offset[2] = -right_eye_mat.m[2][3];
126 124
127 return device; 125 return device;
128 } 126 }
129 127
130 VRPosePtr GvrDevice::GetPose() { 128 VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) {
131 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); 129 TRACE_EVENT0("input", "GvrDevice::GetSensorState");
132 130
131 if (CheckAccessAllowed(service))
132 return nullptr;
133
133 VRPosePtr pose = VRPose::New(); 134 VRPosePtr pose = VRPose::New();
134 135
135 pose->timestamp = base::Time::Now().ToJsTime(); 136 pose->timestamp = base::Time::Now().ToJsTime();
136 137
137 // Increment pose frame counter always, even if it's a faked pose. 138 // Increment pose frame counter always, even if it's a faked pose.
138 pose->poseIndex = ++pose_index_; 139 pose->poseIndex = ++pose_index_;
139 140
140 pose->orientation = mojo::Array<float>::New(4); 141 pose->orientation = mojo::Array<float>::New(4);
141 142
142 gvr::GvrApi* gvr_api = GetGvrApi(); 143 gvr::GvrApi* gvr_api = GetGvrApi();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 pose->position[2] = decomposed_transform.translate[2]; 180 pose->position[2] = decomposed_transform.translate[2];
180 } 181 }
181 182
182 // Save the underlying GVR pose for use by rendering. It can't use a 183 // Save the underlying GVR pose for use by rendering. It can't use a
183 // VRPosePtr since that's a different data type. 184 // VRPosePtr since that's a different data type.
184 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); 185 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_);
185 186
186 return pose; 187 return pose;
187 } 188 }
188 189
189 void GvrDevice::ResetPose() { 190 void GvrDevice::ResetPose(VRServiceImpl* service) {
191 if (CheckAccessAllowed(service))
192 return;
193
190 gvr::GvrApi* gvr_api = GetGvrApi(); 194 gvr::GvrApi* gvr_api = GetGvrApi();
191 if (gvr_api) 195 if (gvr_api)
192 gvr_api->ResetTracking(); 196 gvr_api->ResetTracking();
193 } 197 }
194 198
195 bool GvrDevice::RequestPresent(bool secure_origin) { 199 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) {
200 if (presenting_service_ != nullptr)
201 if (presenting_service_ != service)
202 return false;
203
204 // One service could present on several devices at the same time
205 // and different service could present on different devices the same time
206 if (presenting_service_ == nullptr)
207 presenting_service_ = service;
208
196 secure_origin_ = secure_origin; 209 secure_origin_ = secure_origin;
197 if (delegate_) 210 if (delegate_)
198 delegate_->SetWebVRSecureOrigin(secure_origin_); 211 delegate_->SetWebVRSecureOrigin(secure_origin_);
199 return gvr_provider_->RequestPresent(); 212
213 if (!gvr_provider_->RequestPresent()) {
214 return false;
215 }
216 return true;
200 } 217 }
201 218
202 void GvrDevice::ExitPresent() { 219 void GvrDevice::ExitPresent(VRServiceImpl* service) {
220 if (IsPresentingService(service))
221 presenting_service_ = nullptr;
222
203 gvr_provider_->ExitPresent(); 223 gvr_provider_->ExitPresent();
224 OnExitPresent(service);
204 } 225 }
205 226
206 void GvrDevice::SubmitFrame(VRPosePtr pose) { 227 void GvrDevice::SubmitFrame(VRServiceImpl* service, VRPosePtr pose) {
207 if (delegate_) 228 if (IsPresentingService(service)) {
208 delegate_->SubmitWebVRFrame(); 229 if (delegate_)
230 delegate_->SubmitWebVRFrame();
231 }
209 } 232 }
210 233
211 void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds, 234 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service,
235 VRLayerBoundsPtr leftBounds,
212 VRLayerBoundsPtr rightBounds) { 236 VRLayerBoundsPtr rightBounds) {
213 if (!delegate_) 237 if (CheckAccessAllowed(service)) {
214 return; 238 if (!delegate_)
239 return;
215 240
216 delegate_->UpdateWebVRTextureBounds(0, // Left eye 241 delegate_->UpdateWebVRTextureBounds(0, // Left eye
217 leftBounds->left, leftBounds->top, 242 leftBounds->left, leftBounds->top,
218 leftBounds->width, leftBounds->height); 243 leftBounds->width, leftBounds->height);
219 delegate_->UpdateWebVRTextureBounds(1, // Right eye 244 delegate_->UpdateWebVRTextureBounds(1, // Right eye
220 rightBounds->left, rightBounds->top, 245 rightBounds->left, rightBounds->top,
221 rightBounds->width, rightBounds->height); 246 rightBounds->width,
247 rightBounds->height);
248 }
222 } 249 }
223 250
224 void GvrDevice::SetDelegate(GvrDelegate* delegate) { 251 void GvrDevice::SetDelegate(GvrDelegate* delegate) {
225 delegate_ = delegate; 252 delegate_ = delegate;
226 253
227 // Notify the clients that this device has changed 254 // Notify the clients that this device has changed
228 if (delegate_) { 255 if (delegate_) {
229 delegate_->SetWebVRSecureOrigin(secure_origin_); 256 delegate_->SetWebVRSecureOrigin(secure_origin_);
230 VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice()); 257 this->OnDisplayChanged();
231 } 258 }
232 } 259 }
233 260
234 gvr::GvrApi* GvrDevice::GetGvrApi() { 261 gvr::GvrApi* GvrDevice::GetGvrApi() {
235 if (!delegate_) 262 if (!delegate_)
236 return nullptr; 263 return nullptr;
237 264
238 return delegate_->gvr_api(); 265 return delegate_->gvr_api();
239 } 266 }
240 267
268 void GvrDevice::OnDisplayChanged() {
269 VRDisplayPtr vr_device_info = GetVRDevice();
270 if (vr_device_info.is_null())
271 return;
272
273 for (const auto& client : display_clients_)
274 client.second->OnDisplayChanged(vr_device_info.Clone());
275 }
276
277 void GvrDevice::OnExitPresent(VRServiceImpl* service) {
278 DisplayClientMap::iterator it = display_clients_.find(service);
279 if (it != display_clients_.end())
280 it->second->OnExitPresent();
281 }
282
283 void GvrDevice::OnDisplayConnected() {
284 VRDisplayPtr vr_device_info = GetVRDevice();
285 if (vr_device_info.is_null())
286 return;
287
288 for (const auto& client : display_clients_)
289 client.second->OnDisplayConnected(vr_device_info.Clone());
290 }
291
292 void GvrDevice::OnDisplayDisconnected() {
293 for (const auto& client : display_clients_)
294 client.second->OnDisplayDisconnected();
295 }
296
241 } // namespace device 297 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698