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 "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" | 5 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "chrome/browser/android/vr_shell/vr_shell.h" | 8 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 9 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" |
9 | 10 |
10 namespace vr_shell { | 11 namespace vr_shell { |
11 | 12 |
12 namespace { | 13 namespace { |
13 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; | 14 static constexpr long kPredictionTimeWithoutVsyncNanos = 50000000; |
14 } // namespace | 15 } // namespace |
15 | 16 |
16 NonPresentingGvrDelegate::NonPresentingGvrDelegate(long context) | 17 NonPresentingGvrDelegate::NonPresentingGvrDelegate(gvr_context* context) |
17 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 18 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
18 binding_(this), | 19 binding_(this), |
19 weak_ptr_factory_(this) { | 20 weak_ptr_factory_(this) { |
20 gvr_api_ = gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context)); | 21 gvr_api_ = gvr::GvrApi::WrapNonOwned(context); |
21 } | 22 } |
22 | 23 |
23 NonPresentingGvrDelegate::~NonPresentingGvrDelegate() { | 24 NonPresentingGvrDelegate::~NonPresentingGvrDelegate() { |
24 StopVSyncLoop(); | 25 StopVSyncLoop(); |
25 } | 26 } |
26 | 27 |
27 gvr::Sizei NonPresentingGvrDelegate::GetWebVRCompositorSurfaceSize() { | |
28 return device::kInvalidRenderTargetSize; | |
29 } | |
30 | |
31 gvr::GvrApi* NonPresentingGvrDelegate::gvr_api() { | |
32 return gvr_api_.get(); | |
33 } | |
34 | |
35 void NonPresentingGvrDelegate::OnVRVsyncProviderRequest( | 28 void NonPresentingGvrDelegate::OnVRVsyncProviderRequest( |
36 device::mojom::VRVSyncProviderRequest request) { | 29 device::mojom::VRVSyncProviderRequest request) { |
37 binding_.Close(); | 30 binding_.Close(); |
38 binding_.Bind(std::move(request)); | 31 binding_.Bind(std::move(request)); |
39 binding_.set_connection_error_handler( | 32 binding_.set_connection_error_handler( |
40 base::Bind(&NonPresentingGvrDelegate::StopVSyncLoop, | 33 base::Bind(&NonPresentingGvrDelegate::StopVSyncLoop, |
41 weak_ptr_factory_.GetWeakPtr())); | 34 weak_ptr_factory_.GetWeakPtr())); |
42 StartVSyncLoop(); | 35 StartVSyncLoop(); |
43 } | 36 } |
44 | 37 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, | 128 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, |
136 const GetVSyncCallback& callback) { | 129 const GetVSyncCallback& callback) { |
137 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 130 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
138 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 131 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
139 | 132 |
140 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( | 133 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( |
141 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); | 134 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); |
142 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1); | 135 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1); |
143 } | 136 } |
144 | 137 |
| 138 bool NonPresentingGvrDelegate::SupportsPresentation() { |
| 139 return false; |
| 140 } |
| 141 |
| 142 void NonPresentingGvrDelegate::ResetPose() { |
| 143 // Should never call RecenterTracking when using with Daydream viewers. On |
| 144 // those devices recentering should only be done via the controller. |
| 145 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 146 gvr_api_->RecenterTracking(); |
| 147 } |
| 148 |
| 149 void NonPresentingGvrDelegate::CreateVRDisplayInfo( |
| 150 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 151 uint32_t device_id) { |
| 152 callback.Run(VrShell::CreateVRDisplayInfo( |
| 153 gvr_api_.get(), device::kInvalidRenderTargetSize, device_id)); |
| 154 } |
| 155 |
145 } // namespace vr_shell | 156 } // namespace vr_shell |
OLD | NEW |