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

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

Issue 2493063004: Fix exiting WebVR via Android UI not fully exiting fullscreen. (Closed)
Patch Set: Rebase pt. 2 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 left_eye->offset[2] = -left_eye_mat.m[2][3]; 122 left_eye->offset[2] = -left_eye_mat.m[2][3];
123 123
124 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); 124 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE);
125 right_eye->offset[0] = -right_eye_mat.m[0][3]; 125 right_eye->offset[0] = -right_eye_mat.m[0][3];
126 right_eye->offset[1] = -right_eye_mat.m[1][3]; 126 right_eye->offset[1] = -right_eye_mat.m[1][3];
127 right_eye->offset[2] = -right_eye_mat.m[2][3]; 127 right_eye->offset[2] = -right_eye_mat.m[2][3];
128 128
129 return device; 129 return device;
130 } 130 }
131 131
132 mojom::VRPosePtr GvrDevice::GetPose(VRServiceImpl* service) { 132 mojom::VRPosePtr GvrDevice::GetPose() {
133 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); 133 TRACE_EVENT0("input", "GvrDevice::GetSensorState");
134 134
135 if (!IsAccessAllowed(service))
136 return nullptr;
137
138 mojom::VRPosePtr pose = mojom::VRPose::New(); 135 mojom::VRPosePtr pose = mojom::VRPose::New();
139 136
140 pose->timestamp = base::Time::Now().ToJsTime(); 137 pose->timestamp = base::Time::Now().ToJsTime();
141 138
142 // Increment pose frame counter always, even if it's a faked pose. 139 // Increment pose frame counter always, even if it's a faked pose.
143 pose->poseIndex = ++pose_index_; 140 pose->poseIndex = ++pose_index_;
144 141
145 pose->orientation.emplace(4); 142 pose->orientation.emplace(4);
146 143
147 gvr::GvrApi* gvr_api = GetGvrApi(); 144 gvr::GvrApi* gvr_api = GetGvrApi();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 pose->position.value()[2] = decomposed_transform.translate[2]; 184 pose->position.value()[2] = decomposed_transform.translate[2];
188 } 185 }
189 186
190 // Save the underlying GVR pose for use by rendering. It can't use a 187 // Save the underlying GVR pose for use by rendering. It can't use a
191 // VRPosePtr since that's a different data type. 188 // VRPosePtr since that's a different data type.
192 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); 189 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_);
193 190
194 return pose; 191 return pose;
195 } 192 }
196 193
197 void GvrDevice::ResetPose(VRServiceImpl* service) { 194 void GvrDevice::ResetPose() {
198 if (!IsAccessAllowed(service))
199 return;
200
201 gvr::GvrApi* gvr_api = GetGvrApi(); 195 gvr::GvrApi* gvr_api = GetGvrApi();
202 196
203 // Should never call RecenterTracking when using with Daydream viewers. On 197 // Should never call RecenterTracking when using with Daydream viewers. On
204 // those devices recentering should only be done via the controller. 198 // those devices recentering should only be done via the controller.
205 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 199 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
206 gvr_api->RecenterTracking(); 200 gvr_api->RecenterTracking();
207 } 201 }
208 202
209 bool GvrDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) { 203 bool GvrDevice::RequestPresent(bool secure_origin) {
210 if (!IsAccessAllowed(service))
211 return false;
212
213 // One service could present on several devices at the same time
214 // and different service could present on different devices the same time
215 if (presenting_service_ == nullptr)
216 presenting_service_ = service;
217
218 secure_origin_ = secure_origin; 204 secure_origin_ = secure_origin;
219 if (delegate_) 205 if (delegate_)
220 delegate_->SetWebVRSecureOrigin(secure_origin_); 206 delegate_->SetWebVRSecureOrigin(secure_origin_);
221 207
222 return gvr_provider_->RequestPresent(); 208 return gvr_provider_->RequestPresent();
223 } 209 }
224 210
225 void GvrDevice::ExitPresent(VRServiceImpl* service) { 211 void GvrDevice::ExitPresent() {
226 if (IsPresentingService(service))
227 presenting_service_ = nullptr;
228
229 gvr_provider_->ExitPresent(); 212 gvr_provider_->ExitPresent();
230 OnExitPresent(service); 213 OnExitPresent();
231 } 214 }
232 215
233 void GvrDevice::SubmitFrame(VRServiceImpl* service, mojom::VRPosePtr pose) { 216 void GvrDevice::SubmitFrame(mojom::VRPosePtr pose) {
234 if (!IsPresentingService(service) || !delegate_) 217 if (delegate_)
235 return; 218 delegate_->SubmitWebVRFrame();
236 delegate_->SubmitWebVRFrame();
237 } 219 }
238 220
239 void GvrDevice::UpdateLayerBounds(VRServiceImpl* service, 221 void GvrDevice::UpdateLayerBounds(mojom::VRLayerBoundsPtr leftBounds,
240 mojom::VRLayerBoundsPtr leftBounds,
241 mojom::VRLayerBoundsPtr rightBounds) { 222 mojom::VRLayerBoundsPtr rightBounds) {
242 if (!IsAccessAllowed(service) || !delegate_) 223 if (!delegate_)
243 return; 224 return;
244 225
245 delegate_->UpdateWebVRTextureBounds(0, // Left eye 226 delegate_->UpdateWebVRTextureBounds(0, // Left eye
246 leftBounds->left, leftBounds->top, 227 leftBounds->left, leftBounds->top,
247 leftBounds->width, leftBounds->height); 228 leftBounds->width, leftBounds->height);
248 delegate_->UpdateWebVRTextureBounds(1, // Right eye 229 delegate_->UpdateWebVRTextureBounds(1, // Right eye
249 rightBounds->left, rightBounds->top, 230 rightBounds->left, rightBounds->top,
250 rightBounds->width, rightBounds->height); 231 rightBounds->width, rightBounds->height);
251 } 232 }
252 233
253 void GvrDevice::SetDelegate(const base::WeakPtr<GvrDelegate>& delegate) { 234 void GvrDevice::SetDelegate(const base::WeakPtr<GvrDelegate>& delegate) {
254 delegate_ = delegate; 235 delegate_ = delegate;
255 236
256 // Notify the clients that this device has changed 237 // Notify the clients that this device has changed
257 if (delegate_) { 238 if (delegate_) {
258 delegate_->SetWebVRSecureOrigin(secure_origin_); 239 delegate_->SetWebVRSecureOrigin(secure_origin_);
259 OnDisplayChanged(); 240 OnDisplayChanged();
260 } 241 }
261 } 242 }
262 243
263 gvr::GvrApi* GvrDevice::GetGvrApi() { 244 gvr::GvrApi* GvrDevice::GetGvrApi() {
264 if (!delegate_) 245 if (!delegate_)
265 return nullptr; 246 return nullptr;
266 247
267 return delegate_->gvr_api(); 248 return delegate_->gvr_api();
268 } 249 }
269 250
270 } // namespace device 251 } // 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