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

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

Issue 2471433002: Implement WebVR presentation pausing for VR Shell Menu Mode (Closed)
Patch Set: rebase 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"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "device/vr/android/gvr/gvr_delegate.h" 12 #include "device/vr/android/gvr/gvr_delegate.h"
13 #include "device/vr/android/gvr/gvr_device_provider.h"
13 #include "device/vr/vr_device_manager.h" 14 #include "device/vr/vr_device_manager.h"
14 #include "third_party/gvr-android-sdk/src/ndk/include/vr/gvr/capi/include/gvr.h" 15 #include "third_party/gvr-android-sdk/src/ndk/include/vr/gvr/capi/include/gvr.h"
15 #include "third_party/gvr-android-sdk/src/ndk/include/vr/gvr/capi/include/gvr_ty pes.h" 16 #include "third_party/gvr-android-sdk/src/ndk/include/vr/gvr/capi/include/gvr_ty pes.h"
16 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
17 #include "ui/gfx/transform_util.h" 18 #include "ui/gfx/transform_util.h"
18 19
19 namespace device { 20 namespace device {
20 21
21 namespace { 22 namespace {
22 23
23 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; 24 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000;
24 25
25 } // namespace 26 } // namespace
26 27
27 GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate) 28 GvrDevice::GvrDevice(GvrDeviceProvider* provider,
28 : VRDevice(provider), delegate_(delegate), gvr_provider_(provider) {} 29 const base::WeakPtr<GvrDelegate>& delegate)
30 : VRDevice(), delegate_(delegate), gvr_provider_(provider) {}
29 31
30 GvrDevice::~GvrDevice() {} 32 GvrDevice::~GvrDevice() {}
31 33
32 mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() { 34 mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() {
33 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); 35 TRACE_EVENT0("input", "GvrDevice::GetVRDevice");
34 36
35 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New(); 37 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New();
36 38
37 device->index = id(); 39 device->index = id();
38 40
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (!gvr_api) { 148 if (!gvr_api) {
147 // If we don't have a GvrApi instance return a static forward orientation. 149 // If we don't have a GvrApi instance return a static forward orientation.
148 pose->orientation[0] = 0.0; 150 pose->orientation[0] = 0.0;
149 pose->orientation[1] = 0.0; 151 pose->orientation[1] = 0.0;
150 pose->orientation[2] = 0.0; 152 pose->orientation[2] = 0.0;
151 pose->orientation[3] = 1.0; 153 pose->orientation[3] = 1.0;
152 154
153 return pose; 155 return pose;
154 } 156 }
155 157
158 if (!delegate_)
159 return nullptr;
160
156 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 161 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
157 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 162 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
158 163
159 gvr::Mat4f head_mat = 164 gvr::Mat4f head_mat =
160 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time); 165 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time);
161 head_mat = gvr_api->ApplyNeckModel(head_mat, 1.0f); 166 head_mat = gvr_api->ApplyNeckModel(head_mat, 1.0f);
162 167
163 gfx::Transform inv_transform( 168 gfx::Transform inv_transform(
164 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], 169 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3],
165 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], 170 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3],
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return; 243 return;
239 244
240 delegate_->UpdateWebVRTextureBounds(0, // Left eye 245 delegate_->UpdateWebVRTextureBounds(0, // Left eye
241 leftBounds->left, leftBounds->top, 246 leftBounds->left, leftBounds->top,
242 leftBounds->width, leftBounds->height); 247 leftBounds->width, leftBounds->height);
243 delegate_->UpdateWebVRTextureBounds(1, // Right eye 248 delegate_->UpdateWebVRTextureBounds(1, // Right eye
244 rightBounds->left, rightBounds->top, 249 rightBounds->left, rightBounds->top,
245 rightBounds->width, rightBounds->height); 250 rightBounds->width, rightBounds->height);
246 } 251 }
247 252
248 void GvrDevice::SetDelegate(GvrDelegate* delegate) { 253 void GvrDevice::SetDelegate(const base::WeakPtr<GvrDelegate>& delegate) {
249 delegate_ = delegate; 254 delegate_ = delegate;
250 255
251 // Notify the clients that this device has changed 256 // Notify the clients that this device has changed
252 if (delegate_) { 257 if (delegate_) {
253 delegate_->SetWebVRSecureOrigin(secure_origin_); 258 delegate_->SetWebVRSecureOrigin(secure_origin_);
254 OnDisplayChanged(); 259 OnDisplayChanged();
255 } 260 }
256 } 261 }
257 262
258 gvr::GvrApi* GvrDevice::GetGvrApi() { 263 gvr::GvrApi* GvrDevice::GetGvrApi() {
259 if (!delegate_) 264 if (!delegate_)
260 return nullptr; 265 return nullptr;
261 266
262 return delegate_->gvr_api(); 267 return delegate_->gvr_api();
263 } 268 }
264 269
265 } // namespace device 270 } // 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