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