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

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

Issue 2488273002: Revert of mojo VR interface simplified (Closed)
Patch Set: 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 mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() { 32 VRDisplayPtr GvrDevice::GetVRDevice() {
33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); 33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice");
34 34
35 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New(); 35 VRDisplayPtr device = VRDisplay::New();
36 36
37 device->index = id(); 37 device->index = id();
38 38
39 device->capabilities = mojom::VRDisplayCapabilities::New(); 39 device->capabilities = 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 = mojom::VREyeParameters::New(); 45 device->leftEye = VREyeParameters::New();
46 device->rightEye = mojom::VREyeParameters::New(); 46 device->rightEye = VREyeParameters::New();
47 mojom::VREyeParametersPtr& left_eye = device->leftEye; 47 VREyeParametersPtr& left_eye = device->leftEye;
48 mojom::VREyeParametersPtr& right_eye = device->rightEye; 48 VREyeParametersPtr& right_eye = device->rightEye;
49 49
50 left_eye->fieldOfView = mojom::VRFieldOfView::New(); 50 left_eye->fieldOfView = VRFieldOfView::New();
51 right_eye->fieldOfView = mojom::VRFieldOfView::New(); 51 right_eye->fieldOfView = 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 mojom::VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) { 130 VRPosePtr GvrDevice::GetPose() {
131 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); 131 TRACE_EVENT0("input", "GvrDevice::GetSensorState");
132 132
133 if (!IsAccessAllowed(service)) 133 VRPosePtr pose = VRPose::New();
134 return nullptr;
135
136 mojom::VRPosePtr pose = mojom::VRPose::New();
137 134
138 pose->timestamp = base::Time::Now().ToJsTime(); 135 pose->timestamp = base::Time::Now().ToJsTime();
139 136
140 // Increment pose frame counter always, even if it's a faked pose. 137 // Increment pose frame counter always, even if it's a faked pose.
141 pose->poseIndex = ++pose_index_; 138 pose->poseIndex = ++pose_index_;
142 139
143 pose->orientation = mojo::Array<float>::New(4); 140 pose->orientation = mojo::Array<float>::New(4);
144 141
145 gvr::GvrApi* gvr_api = GetGvrApi(); 142 gvr::GvrApi* gvr_api = GetGvrApi();
146 if (!gvr_api) { 143 if (!gvr_api) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 pose->position[2] = decomposed_transform.translate[2]; 179 pose->position[2] = decomposed_transform.translate[2];
183 } 180 }
184 181
185 // Save the underlying GVR pose for use by rendering. It can't use a 182 // Save the underlying GVR pose for use by rendering. It can't use a
186 // VRPosePtr since that's a different data type. 183 // VRPosePtr since that's a different data type.
187 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); 184 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_);
188 185
189 return pose; 186 return pose;
190 } 187 }
191 188
192 void GvrDevice::ResetPose(VRServiceImpl* service) { 189 void GvrDevice::ResetPose() {
193 if (!IsAccessAllowed(service))
194 return;
195
196 gvr::GvrApi* gvr_api = GetGvrApi(); 190 gvr::GvrApi* gvr_api = GetGvrApi();
197 191
198 // Should never call RecenterTracking when using with Daydream viewers. On 192 // Should never call RecenterTracking when using with Daydream viewers. On
199 // those devices recentering should only be done via the controller. 193 // those devices recentering should only be done via the controller.
200 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 194 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
201 gvr_api->RecenterTracking(); 195 gvr_api->RecenterTracking();
202 } 196 }
203 197
204 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) { 198 bool GvrDevice::RequestPresent(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
213 secure_origin_ = secure_origin; 199 secure_origin_ = secure_origin;
214 if (delegate_) 200 if (delegate_)
215 delegate_->SetWebVRSecureOrigin(secure_origin_); 201 delegate_->SetWebVRSecureOrigin(secure_origin_);
216
217 return gvr_provider_->RequestPresent(); 202 return gvr_provider_->RequestPresent();
218 } 203 }
219 204
220 void GvrDevice::ExitPresent(VRServiceImpl* service) { 205 void GvrDevice::ExitPresent() {
221 if (IsPresentingService(service))
222 presenting_service_ = nullptr;
223
224 gvr_provider_->ExitPresent(); 206 gvr_provider_->ExitPresent();
225 OnExitPresent(service);
226 } 207 }
227 208
228 void GvrDevice::SubmitFrame(VRServiceImpl* service, mojom::VRPosePtr pose) { 209 void GvrDevice::SubmitFrame(VRPosePtr pose) {
229 if (!IsPresentingService(service) || !delegate_) 210 if (delegate_)
230 return; 211 delegate_->SubmitWebVRFrame();
231 delegate_->SubmitWebVRFrame();
232 } 212 }
233 213
234 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service, 214 void GvrDevice::UpdateLayerBounds(VRLayerBoundsPtr leftBounds,
235 mojom::VRLayerBoundsPtr leftBounds, 215 VRLayerBoundsPtr rightBounds) {
236 mojom::VRLayerBoundsPtr rightBounds) { 216 if (!delegate_)
237 if (!IsAccessAllowed(service) || !delegate_)
238 return; 217 return;
239 218
240 delegate_->UpdateWebVRTextureBounds(0, // Left eye 219 delegate_->UpdateWebVRTextureBounds(0, // Left eye
241 leftBounds->left, leftBounds->top, 220 leftBounds->left, leftBounds->top,
242 leftBounds->width, leftBounds->height); 221 leftBounds->width, leftBounds->height);
243 delegate_->UpdateWebVRTextureBounds(1, // Right eye 222 delegate_->UpdateWebVRTextureBounds(1, // Right eye
244 rightBounds->left, rightBounds->top, 223 rightBounds->left, rightBounds->top,
245 rightBounds->width, rightBounds->height); 224 rightBounds->width, rightBounds->height);
246 } 225 }
247 226
248 void GvrDevice::SetDelegate(GvrDelegate* delegate) { 227 void GvrDevice::SetDelegate(GvrDelegate* delegate) {
249 delegate_ = delegate; 228 delegate_ = delegate;
250 229
251 // Notify the clients that this device has changed 230 // Notify the clients that this device has changed
252 if (delegate_) { 231 if (delegate_) {
253 delegate_->SetWebVRSecureOrigin(secure_origin_); 232 delegate_->SetWebVRSecureOrigin(secure_origin_);
254 OnDisplayChanged(); 233 VRDeviceManager::GetInstance()->OnDeviceChanged(GetVRDevice());
255 } 234 }
256 } 235 }
257 236
258 gvr::GvrApi* GvrDevice::GetGvrApi() { 237 gvr::GvrApi* GvrDevice::GetGvrApi() {
259 if (!delegate_) 238 if (!delegate_)
260 return nullptr; 239 return nullptr;
261 240
262 return delegate_->gvr_api(); 241 return delegate_->gvr_api();
263 } 242 }
264 243
265 } // namespace device 244 } // 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