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

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

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: Address haraken@ comments 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 11 matching lines...) Expand all
22 22
23 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; 23 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000;
24 24
25 } // namespace 25 } // namespace
26 26
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 mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() {
33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); 33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice");
34 34
35 VRDisplayPtr device = VRDisplay::New(); 35 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New();
36 36
37 device->index = id(); 37 device->index = id();
38 38
39 device->capabilities = VRDisplayCapabilities::New(); 39 device->capabilities = mojom::VRDisplayCapabilities::New();
40 device->capabilities->hasOrientation = true; 40 device->capabilities->hasOrientation = true;
41 device->capabilities->hasPosition = false; 41 device->capabilities->hasPosition = false;
42 device->capabilities->hasExternalDisplay = false; 42 device->capabilities->hasExternalDisplay = false;
43 device->capabilities->canPresent = true; 43 device->capabilities->canPresent = true;
44 44
45 device->leftEye = VREyeParameters::New(); 45 device->leftEye = mojom::VREyeParameters::New();
46 device->rightEye = VREyeParameters::New(); 46 device->rightEye = mojom::VREyeParameters::New();
47 VREyeParametersPtr& left_eye = device->leftEye; 47 mojom::VREyeParametersPtr& left_eye = device->leftEye;
48 VREyeParametersPtr& right_eye = device->rightEye; 48 mojom::VREyeParametersPtr& right_eye = device->rightEye;
49 49
50 left_eye->fieldOfView = VRFieldOfView::New(); 50 left_eye->fieldOfView = mojom::VRFieldOfView::New();
51 right_eye->fieldOfView = VRFieldOfView::New(); 51 right_eye->fieldOfView = mojom::VRFieldOfView::New();
52 52
53 left_eye->offset = mojo::Array<float>::New(3); 53 left_eye->offset = mojo::Array<float>::New(3);
54 right_eye->offset = mojo::Array<float>::New(3); 54 right_eye->offset = mojo::Array<float>::New(3);
55 55
56 // TODO(bajones): GVR has a bug that causes it to return bad render target 56 // TODO(bajones): GVR has a bug that causes it to return bad render target
57 // sizes when the phone is in portait mode. Send arbitrary, 57 // sizes when the phone is in portait mode. Send arbitrary,
58 // not-horrifically-wrong values instead. 58 // not-horrifically-wrong values instead.
59 // gvr::Sizei render_target_size = gvr_api->GetRecommendedRenderTargetSize(); 59 // gvr::Sizei render_target_size = gvr_api->GetRecommendedRenderTargetSize();
60 left_eye->renderWidth = 1024; // render_target_size.width / 2; 60 left_eye->renderWidth = 1024; // render_target_size.width / 2;
61 left_eye->renderHeight = 1024; // render_target_size.height; 61 left_eye->renderHeight = 1024; // render_target_size.height;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 left_eye->offset[2] = -left_eye_mat.m[2][3]; 120 left_eye->offset[2] = -left_eye_mat.m[2][3];
121 121
122 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); 122 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE);
123 right_eye->offset[0] = -right_eye_mat.m[0][3]; 123 right_eye->offset[0] = -right_eye_mat.m[0][3];
124 right_eye->offset[1] = -right_eye_mat.m[1][3]; 124 right_eye->offset[1] = -right_eye_mat.m[1][3];
125 right_eye->offset[2] = -right_eye_mat.m[2][3]; 125 right_eye->offset[2] = -right_eye_mat.m[2][3];
126 126
127 return device; 127 return device;
128 } 128 }
129 129
130 VRPosePtr GvrDevice::GetPose() { 130 mojom::VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) {
131 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); 131 TRACE_EVENT0("input", "GvrDevice::GetSensorState");
132 132
133 VRPosePtr pose = VRPose::New(); 133 if (!IsAccessAllowed(service))
134 return nullptr;
135
136 mojom::VRPosePtr pose = mojom::VRPose::New();
134 137
135 pose->timestamp = base::Time::Now().ToJsTime(); 138 pose->timestamp = base::Time::Now().ToJsTime();
136 139
137 // Increment pose frame counter always, even if it's a faked pose. 140 // Increment pose frame counter always, even if it's a faked pose.
138 pose->poseIndex = ++pose_index_; 141 pose->poseIndex = ++pose_index_;
139 142
140 pose->orientation = mojo::Array<float>::New(4); 143 pose->orientation = mojo::Array<float>::New(4);
141 144
142 gvr::GvrApi* gvr_api = GetGvrApi(); 145 gvr::GvrApi* gvr_api = GetGvrApi();
143 if (!gvr_api) { 146 if (!gvr_api) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 pose->position[2] = decomposed_transform.translate[2]; 182 pose->position[2] = decomposed_transform.translate[2];
180 } 183 }
181 184
182 // Save the underlying GVR pose for use by rendering. It can't use a 185 // Save the underlying GVR pose for use by rendering. It can't use a
183 // VRPosePtr since that's a different data type. 186 // VRPosePtr since that's a different data type.
184 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); 187 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_);
185 188
186 return pose; 189 return pose;
187 } 190 }
188 191
189 void GvrDevice::ResetPose() { 192 void GvrDevice::ResetPose(VRServiceImpl* service) {
193 if (!IsAccessAllowed(service))
194 return;
195
190 gvr::GvrApi* gvr_api = GetGvrApi(); 196 gvr::GvrApi* gvr_api = GetGvrApi();
191 if (gvr_api) 197 if (gvr_api)
192 gvr_api->ResetTracking(); 198 gvr_api->ResetTracking();
193 } 199 }
194 200
195 bool GvrDevice::RequestPresent(bool secure_origin) { 201 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) {
202 if (!IsAccessAllowed(service))
203 return false;
204
205 // One service could present on several devices at the same time
206 // and different service could present on different devices the same time
207 if (presenting_service_ == nullptr)
208 presenting_service_ = service;
209
196 secure_origin_ = secure_origin; 210 secure_origin_ = secure_origin;
197 if (delegate_) 211 if (delegate_)
198 delegate_->SetWebVRSecureOrigin(secure_origin_); 212 delegate_->SetWebVRSecureOrigin(secure_origin_);
213
199 return gvr_provider_->RequestPresent(); 214 return gvr_provider_->RequestPresent();
200 } 215 }
201 216
202 void GvrDevice::ExitPresent() { 217 void GvrDevice::ExitPresent(VRServiceImpl* service) {
218 if (IsPresentingService(service))
219 presenting_service_ = nullptr;
220
203 gvr_provider_->ExitPresent(); 221 gvr_provider_->ExitPresent();
222 OnExitPresent(service);
204 } 223 }
205 224
206 void GvrDevice::SubmitFrame(VRPosePtr pose) { 225 void GvrDevice::SubmitFrame(VRServiceImpl* service, mojom::VRPosePtr pose) {
207 if (delegate_) 226 if (IsPresentingService(service)) {
208 delegate_->SubmitWebVRFrame(); 227 if (delegate_)
228 delegate_->SubmitWebVRFrame();
229 }
209 } 230 }
210 231
211 void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds, 232 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service,
212 VRLayerBoundsPtr rightBounds) { 233 mojom::VRLayerBoundsPtr leftBounds,
213 if (!delegate_) 234 mojom::VRLayerBoundsPtr rightBounds) {
214 return; 235 if (!IsAccessAllowed(service)) {
dcheng 2016/11/04 05:12:20 Should this be an early return?
shaobo.yan 2016/11/05 08:11:38 Yes, and sorry for the fault.Updated to delete '!'
236 if (!delegate_)
237 return;
215 238
216 delegate_->UpdateWebVRTextureBounds(0, // Left eye 239 delegate_->UpdateWebVRTextureBounds(0, // Left eye
217 leftBounds->left, leftBounds->top, 240 leftBounds->left, leftBounds->top,
218 leftBounds->width, leftBounds->height); 241 leftBounds->width, leftBounds->height);
219 delegate_->UpdateWebVRTextureBounds(1, // Right eye 242 delegate_->UpdateWebVRTextureBounds(1, // Right eye
220 rightBounds->left, rightBounds->top, 243 rightBounds->left, rightBounds->top,
221 rightBounds->width, rightBounds->height); 244 rightBounds->width,
245 rightBounds->height);
246 }
222 } 247 }
223 248
224 void GvrDevice::SetDelegate(GvrDelegate* delegate) { 249 void GvrDevice::SetDelegate(GvrDelegate* delegate) {
225 delegate_ = delegate; 250 delegate_ = delegate;
226 251
227 // Notify the clients that this device has changed 252 // Notify the clients that this device has changed
228 if (delegate_) { 253 if (delegate_) {
229 delegate_->SetWebVRSecureOrigin(secure_origin_); 254 delegate_->SetWebVRSecureOrigin(secure_origin_);
230 VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice()); 255 OnDisplayChanged();
231 } 256 }
232 } 257 }
233 258
234 gvr::GvrApi* GvrDevice::GetGvrApi() { 259 gvr::GvrApi* GvrDevice::GetGvrApi() {
235 if (!delegate_) 260 if (!delegate_)
236 return nullptr; 261 return nullptr;
237 262
238 return delegate_->gvr_api(); 263 return delegate_->gvr_api();
239 } 264 }
240 265
241 } // namespace device 266 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698