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

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

Issue 2494733002: Reland of mojo VR interface simpified. (Closed)
Patch Set: Fix Werror 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
« no previous file with comments | « device/vr/android/gvr/gvr_device.h ('k') | device/vr/android/gvr/gvr_device_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 197
192 // Should never call RecenterTracking when using with Daydream viewers. On 198 // Should never call RecenterTracking when using with Daydream viewers. On
193 // those devices recentering should only be done via the controller. 199 // those devices recentering should only be done via the controller.
194 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 200 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
195 gvr_api->RecenterTracking(); 201 gvr_api->RecenterTracking();
196 } 202 }
197 203
198 bool GvrDevice::RequestPresent(bool secure_origin) { 204 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) {
205 if (!IsAccessAllowed(service))
206 return false;
207
208 // One service could present on several devices at the same time
209 // and different service could present on different devices the same time
210 if (presenting_service_ == nullptr)
211 presenting_service_ = service;
212
199 secure_origin_ = secure_origin; 213 secure_origin_ = secure_origin;
200 if (delegate_) 214 if (delegate_)
201 delegate_->SetWebVRSecureOrigin(secure_origin_); 215 delegate_->SetWebVRSecureOrigin(secure_origin_);
216
202 return gvr_provider_->RequestPresent(); 217 return gvr_provider_->RequestPresent();
203 } 218 }
204 219
205 void GvrDevice::ExitPresent() { 220 void GvrDevice::ExitPresent(VRServiceImpl* service) {
221 if (IsPresentingService(service))
222 presenting_service_ = nullptr;
223
206 gvr_provider_->ExitPresent(); 224 gvr_provider_->ExitPresent();
225 OnExitPresent(service);
207 } 226 }
208 227
209 void GvrDevice::SubmitFrame(VRPosePtr pose) { 228 void GvrDevice::SubmitFrame(VRServiceImpl* service, mojom::VRPosePtr pose) {
210 if (delegate_) 229 if (!IsPresentingService(service) || !delegate_)
211 delegate_->SubmitWebVRFrame(); 230 return;
231 delegate_->SubmitWebVRFrame();
212 } 232 }
213 233
214 void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds, 234 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service,
215 VRLayerBoundsPtr rightBounds) { 235 mojom::VRLayerBoundsPtr leftBounds,
216 if (!delegate_) 236 mojom::VRLayerBoundsPtr rightBounds) {
237 if (!IsAccessAllowed(service) || !delegate_)
217 return; 238 return;
218 239
219 delegate_->UpdateWebVRTextureBounds(0, // Left eye 240 delegate_->UpdateWebVRTextureBounds(0, // Left eye
220 leftBounds->left, leftBounds->top, 241 leftBounds->left, leftBounds->top,
221 leftBounds->width, leftBounds->height); 242 leftBounds->width, leftBounds->height);
222 delegate_->UpdateWebVRTextureBounds(1, // Right eye 243 delegate_->UpdateWebVRTextureBounds(1, // Right eye
223 rightBounds->left, rightBounds->top, 244 rightBounds->left, rightBounds->top,
224 rightBounds->width, rightBounds->height); 245 rightBounds->width, rightBounds->height);
225 } 246 }
226 247
227 void GvrDevice::SetDelegate(GvrDelegate* delegate) { 248 void GvrDevice::SetDelegate(GvrDelegate* delegate) {
228 delegate_ = delegate; 249 delegate_ = delegate;
229 250
230 // Notify the clients that this device has changed 251 // Notify the clients that this device has changed
231 if (delegate_) { 252 if (delegate_) {
232 delegate_->SetWebVRSecureOrigin(secure_origin_); 253 delegate_->SetWebVRSecureOrigin(secure_origin_);
233 VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice()); 254 OnDisplayChanged();
234 } 255 }
235 } 256 }
236 257
237 gvr::GvrApi* GvrDevice::GetGvrApi() { 258 gvr::GvrApi* GvrDevice::GetGvrApi() {
238 if (!delegate_) 259 if (!delegate_)
239 return nullptr; 260 return nullptr;
240 261
241 return delegate_->gvr_api(); 262 return delegate_->gvr_api();
242 } 263 }
243 264
244 } // namespace device 265 } // namespace device
OLDNEW
« no previous file with comments | « device/vr/android/gvr/gvr_device.h ('k') | device/vr/android/gvr/gvr_device_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698