| 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/vr_shell_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 weak_vr_shell_(weak_vr_shell), | 169 weak_vr_shell_(weak_vr_shell), |
| 170 delegate_provider_(delegate_provider), | 170 delegate_provider_(delegate_provider), |
| 171 main_thread_task_runner_(std::move(main_thread_task_runner)), | 171 main_thread_task_runner_(std::move(main_thread_task_runner)), |
| 172 weak_ptr_factory_(this) { | 172 weak_ptr_factory_(this) { |
| 173 GvrInit(gvr_api); | 173 GvrInit(gvr_api); |
| 174 } | 174 } |
| 175 | 175 |
| 176 VrShellGl::~VrShellGl() { | 176 VrShellGl::~VrShellGl() { |
| 177 vsync_task_.Cancel(); | 177 vsync_task_.Cancel(); |
| 178 if (!callback_.is_null()) { | 178 if (!callback_.is_null()) { |
| 179 base::ResetAndReturn(&callback_).Run(nullptr, base::TimeDelta(), -1); | 179 // When this VSync provider is going away we have to respond to pending |
| 180 // callbacks, so instead of providing a VSync, tell the requester to try |
| 181 // again. A VSyncProvider is guaranteed to exist, so the request in response |
| 182 // to this message will go through some other VSyncProvider. |
| 183 base::ResetAndReturn(&callback_) |
| 184 .Run(nullptr, base::TimeDelta(), -1, |
| 185 device::mojom::VRVSyncProvider::Status::RETRY); |
| 180 } | 186 } |
| 181 if (binding_.is_bound()) { | 187 if (binding_.is_bound()) { |
| 182 main_thread_task_runner_->PostTask( | 188 main_thread_task_runner_->PostTask( |
| 183 FROM_HERE, | 189 FROM_HERE, |
| 184 base::Bind(&VrShellDelegate::OnVRVsyncProviderRequest, | 190 base::Bind(&VrShellDelegate::OnVRVsyncProviderRequest, |
| 185 delegate_provider_, base::Passed(binding_.Unbind()))); | 191 delegate_provider_, base::Passed(binding_.Unbind()))); |
| 186 } | 192 } |
| 187 } | 193 } |
| 188 | 194 |
| 189 void VrShellGl::Initialize() { | 195 void VrShellGl::Initialize() { |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 | 1092 |
| 1087 void VrShellGl::OnRequest(device::mojom::VRVSyncProviderRequest request) { | 1093 void VrShellGl::OnRequest(device::mojom::VRVSyncProviderRequest request) { |
| 1088 binding_.Close(); | 1094 binding_.Close(); |
| 1089 binding_.Bind(std::move(request)); | 1095 binding_.Bind(std::move(request)); |
| 1090 } | 1096 } |
| 1091 | 1097 |
| 1092 void VrShellGl::GetVSync(const GetVSyncCallback& callback) { | 1098 void VrShellGl::GetVSync(const GetVSyncCallback& callback) { |
| 1093 if (!pending_vsync_) { | 1099 if (!pending_vsync_) { |
| 1094 if (!callback_.is_null()) { | 1100 if (!callback_.is_null()) { |
| 1095 mojo::ReportBadMessage( | 1101 mojo::ReportBadMessage( |
| 1096 "Requested VSync before waiting for response to " | 1102 "Requested VSync before waiting for response to previous request."); |
| 1097 "previous request."); | 1103 binding_.Close(); |
| 1098 return; | 1104 return; |
| 1099 } | 1105 } |
| 1100 callback_ = callback; | 1106 callback_ = callback; |
| 1101 return; | 1107 return; |
| 1102 } | 1108 } |
| 1103 pending_vsync_ = false; | 1109 pending_vsync_ = false; |
| 1104 SendVSync(pending_time_, callback); | 1110 SendVSync(pending_time_, callback); |
| 1105 } | 1111 } |
| 1106 | 1112 |
| 1107 void VrShellGl::UpdateVSyncInterval(int64_t timebase_nanos, | 1113 void VrShellGl::UpdateVSyncInterval(int64_t timebase_nanos, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1130 | 1136 |
| 1131 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 1137 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
| 1132 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 1138 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
| 1133 | 1139 |
| 1134 gvr::Mat4f head_mat = | 1140 gvr::Mat4f head_mat = |
| 1135 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 1141 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); |
| 1136 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); | 1142 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); |
| 1137 | 1143 |
| 1138 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; | 1144 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; |
| 1139 | 1145 |
| 1140 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index); | 1146 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, frame_index, |
| 1147 device::mojom::VRVSyncProvider::Status::SUCCESS); |
| 1141 } | 1148 } |
| 1142 | 1149 |
| 1143 void VrShellGl::ResetPose() { | 1150 void VrShellGl::ResetPose() { |
| 1144 // Should never call RecenterTracking when using with Daydream viewers. On | 1151 // Should never call RecenterTracking when using with Daydream viewers. On |
| 1145 // those devices recentering should only be done via the controller. | 1152 // those devices recentering should only be done via the controller. |
| 1146 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) | 1153 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 1147 gvr_api_->RecenterTracking(); | 1154 gvr_api_->RecenterTracking(); |
| 1148 } | 1155 } |
| 1149 | 1156 |
| 1150 void VrShellGl::CreateVRDisplayInfo( | 1157 void VrShellGl::CreateVRDisplayInfo( |
| 1151 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1158 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 1152 uint32_t device_id) { | 1159 uint32_t device_id) { |
| 1153 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1160 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1154 gvr_api_.get(), content_tex_physical_size_, device_id); | 1161 gvr_api_.get(), content_tex_physical_size_, device_id); |
| 1155 main_thread_task_runner_->PostTask( | 1162 main_thread_task_runner_->PostTask( |
| 1156 FROM_HERE, | 1163 FROM_HERE, |
| 1157 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1164 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1158 } | 1165 } |
| 1159 | 1166 |
| 1160 } // namespace vr_shell | 1167 } // namespace vr_shell |
| OLD | NEW |