OLD | NEW |
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/android/gvr/gvr_device_provider.h" |
14 #include "device/vr/vr_device_manager.h" | 14 #include "device/vr/vr_device_manager.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.h" |
16 #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" |
17 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
18 #include "ui/gfx/transform_util.h" | 18 #include "ui/gfx/transform_util.h" |
19 | 19 |
20 namespace device { | 20 namespace device { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; | 24 static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 GvrDevice::GvrDevice(GvrDeviceProvider* provider, | 28 GvrDevice::GvrDevice(GvrDeviceProvider* provider, GvrDelegate* delegate) |
29 const base::WeakPtr<GvrDelegate>& delegate) | |
30 : VRDevice(), delegate_(delegate), gvr_provider_(provider) {} | 29 : VRDevice(), delegate_(delegate), gvr_provider_(provider) {} |
31 | 30 |
32 GvrDevice::~GvrDevice() {} | 31 GvrDevice::~GvrDevice() {} |
33 | 32 |
34 mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() { | 33 mojom::VRDisplayInfoPtr GvrDevice::GetVRDevice() { |
35 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); | 34 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); |
36 | 35 |
37 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New(); | 36 mojom::VRDisplayInfoPtr device = mojom::VRDisplayInfo::New(); |
38 | 37 |
39 device->index = id(); | 38 device->index = id(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 left_eye->offset[0] = -0.0; | 83 left_eye->offset[0] = -0.0; |
85 left_eye->offset[1] = -0.0; | 84 left_eye->offset[1] = -0.0; |
86 left_eye->offset[2] = -0.03; | 85 left_eye->offset[2] = -0.03; |
87 | 86 |
88 right_eye->offset[0] = 0.0; | 87 right_eye->offset[0] = 0.0; |
89 right_eye->offset[1] = 0.0; | 88 right_eye->offset[1] = 0.0; |
90 right_eye->offset[2] = 0.03; | 89 right_eye->offset[2] = 0.03; |
91 | 90 |
92 // Tell the delegate not to draw yet, to avoid a race condition | 91 // Tell the delegate not to draw yet, to avoid a race condition |
93 // (and visible wobble) on entering VR. | 92 // (and visible wobble) on entering VR. |
94 delegate_->SetWebVRRenderSurfaceSize(kInvalidRenderTargetSize.width, | 93 if (delegate_) { |
95 kInvalidRenderTargetSize.height); | 94 delegate_->SetWebVRRenderSurfaceSize(kInvalidRenderTargetSize.width, |
| 95 kInvalidRenderTargetSize.height); |
| 96 } |
96 | 97 |
97 return device; | 98 return device; |
98 } | 99 } |
99 | 100 |
100 // In compositor mode, we have to use the current compositor window's | 101 // In compositor mode, we have to use the current compositor window's |
101 // surface size. Would be nice to change it, but that needs more browser | 102 // surface size. Would be nice to change it, but that needs more browser |
102 // internals to be modified. TODO(klausw,crbug.com/655722): remove this once | 103 // internals to be modified. TODO(klausw,crbug.com/655722): remove this once |
103 // we can pick our own surface size. | 104 // we can pick our own surface size. |
104 gvr::Sizei compositor_size = delegate_->GetWebVRCompositorSurfaceSize(); | 105 gvr::Sizei compositor_size = delegate_->GetWebVRCompositorSurfaceSize(); |
105 left_eye->renderWidth = compositor_size.width / 2; | 106 left_eye->renderWidth = compositor_size.width / 2; |
(...skipping 28 matching lines...) Expand all Loading... |
134 gvr::Mat4f left_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_LEFT_EYE); | 135 gvr::Mat4f left_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_LEFT_EYE); |
135 left_eye->offset[0] = -left_eye_mat.m[0][3]; | 136 left_eye->offset[0] = -left_eye_mat.m[0][3]; |
136 left_eye->offset[1] = -left_eye_mat.m[1][3]; | 137 left_eye->offset[1] = -left_eye_mat.m[1][3]; |
137 left_eye->offset[2] = -left_eye_mat.m[2][3]; | 138 left_eye->offset[2] = -left_eye_mat.m[2][3]; |
138 | 139 |
139 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); | 140 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); |
140 right_eye->offset[0] = -right_eye_mat.m[0][3]; | 141 right_eye->offset[0] = -right_eye_mat.m[0][3]; |
141 right_eye->offset[1] = -right_eye_mat.m[1][3]; | 142 right_eye->offset[1] = -right_eye_mat.m[1][3]; |
142 right_eye->offset[2] = -right_eye_mat.m[2][3]; | 143 right_eye->offset[2] = -right_eye_mat.m[2][3]; |
143 | 144 |
144 delegate_->SetWebVRRenderSurfaceSize(2 * left_eye->renderWidth, | 145 if (delegate_) { |
145 left_eye->renderHeight); | 146 delegate_->SetWebVRRenderSurfaceSize(2 * left_eye->renderWidth, |
| 147 left_eye->renderHeight); |
| 148 } |
146 | 149 |
147 return device; | 150 return device; |
148 } | 151 } |
149 | 152 |
150 mojom::VRPosePtr GvrDevice::GetPose() { | 153 mojom::VRPosePtr GvrDevice::GetPose() { |
151 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); | 154 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); |
152 | 155 |
153 mojom::VRPosePtr pose = mojom::VRPose::New(); | 156 mojom::VRPosePtr pose = mojom::VRPose::New(); |
154 | 157 |
155 pose->timestamp = base::Time::Now().ToJsTime(); | 158 pose->timestamp = base::Time::Now().ToJsTime(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 254 |
252 gvr::Rectf right_gvr_bounds; | 255 gvr::Rectf right_gvr_bounds; |
253 right_gvr_bounds.left = right_bounds->left; | 256 right_gvr_bounds.left = right_bounds->left; |
254 right_gvr_bounds.top = 1.0f - right_bounds->top; | 257 right_gvr_bounds.top = 1.0f - right_bounds->top; |
255 right_gvr_bounds.right = right_bounds->left + right_bounds->width; | 258 right_gvr_bounds.right = right_bounds->left + right_bounds->width; |
256 right_gvr_bounds.bottom = 1.0f - (right_bounds->top + right_bounds->height); | 259 right_gvr_bounds.bottom = 1.0f - (right_bounds->top + right_bounds->height); |
257 | 260 |
258 delegate_->UpdateWebVRTextureBounds(left_gvr_bounds, right_gvr_bounds); | 261 delegate_->UpdateWebVRTextureBounds(left_gvr_bounds, right_gvr_bounds); |
259 } | 262 } |
260 | 263 |
261 void GvrDevice::SetDelegate(const base::WeakPtr<GvrDelegate>& delegate) { | 264 void GvrDevice::SetDelegate(GvrDelegate* delegate) { |
262 delegate_ = delegate; | 265 delegate_ = delegate; |
263 | 266 |
264 // Notify the clients that this device has changed | 267 // Notify the clients that this device has changed |
265 if (delegate_) { | 268 if (delegate_) { |
266 delegate_->SetWebVRSecureOrigin(secure_origin_); | 269 delegate_->SetWebVRSecureOrigin(secure_origin_); |
267 OnChanged(); | 270 OnChanged(); |
268 } | 271 } |
269 } | 272 } |
270 | 273 |
271 gvr::GvrApi* GvrDevice::GetGvrApi() { | 274 gvr::GvrApi* GvrDevice::GetGvrApi() { |
272 if (!delegate_) | 275 if (!delegate_) |
273 return nullptr; | 276 return nullptr; |
274 | 277 |
275 return delegate_->gvr_api(); | 278 return delegate_->gvr_api(); |
276 } | 279 } |
277 | 280 |
278 } // namespace device | 281 } // namespace device |
OLD | NEW |