Chromium Code Reviews| Index: chrome/browser/android/vr_shell/non_presenting_gvr_delegate.cc |
| diff --git a/chrome/browser/android/vr_shell/non_presenting_gvr_delegate.cc b/chrome/browser/android/vr_shell/non_presenting_gvr_delegate.cc |
| index c25da54458e04fc8f1922be5bb5c9247182402dd..d36c416c2499ea89348782713941b120dfe5efff 100644 |
| --- a/chrome/browser/android/vr_shell/non_presenting_gvr_delegate.cc |
| +++ b/chrome/browser/android/vr_shell/non_presenting_gvr_delegate.cc |
| @@ -20,7 +20,8 @@ NonPresentingGvrDelegate::NonPresentingGvrDelegate(gvr_context* context) |
| : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| binding_(this), |
| weak_ptr_factory_(this) { |
| - gvr_api_ = gvr::GvrApi::WrapNonOwned(context); |
| + if (context) |
|
dcheng
2017/03/08 07:23:39
Just for my understanding: why can context be null
klausw
2017/03/08 08:11:09
mthiesse@, can you clarify? You had suggested this
mthiesse
2017/03/08 13:44:48
Yeah, this is to prevent crashes in strange error
klausw
2017/03/08 16:56:26
Added this as a comment. That is rather devious.
|
| + gvr_api_ = gvr::GvrApi::WrapNonOwned(context); |
| } |
| NonPresentingGvrDelegate::~NonPresentingGvrDelegate() { |
| @@ -40,7 +41,8 @@ void NonPresentingGvrDelegate::OnVRVsyncProviderRequest( |
| void NonPresentingGvrDelegate::Pause() { |
| vsync_task_.Cancel(); |
| vsync_paused_ = true; |
| - gvr_api_->PauseTracking(); |
| + if (gvr_api_) |
| + gvr_api_->PauseTracking(); |
| } |
| void NonPresentingGvrDelegate::Resume() { |
| @@ -60,12 +62,14 @@ NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { |
| void NonPresentingGvrDelegate::StopVSyncLoop() { |
| vsync_task_.Cancel(); |
| + binding_.Close(); |
| if (!callback_.is_null()) { |
| base::ResetAndReturn(&callback_) |
| .Run(nullptr, base::TimeDelta(), -1, |
| - device::mojom::VRVSyncProvider::Status::RETRY); |
| + device::mojom::VRVSyncProvider::Status::CLOSING); |
| } |
| - gvr_api_->PauseTracking(); |
| + if (gvr_api_) |
| + gvr_api_->PauseTracking(); |
| // If the loop is stopped, it's not considered to be paused. |
| vsync_paused_ = false; |
| } |
| @@ -73,8 +77,10 @@ void NonPresentingGvrDelegate::StopVSyncLoop() { |
| void NonPresentingGvrDelegate::StartVSyncLoop() { |
| vsync_task_.Reset( |
| base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); |
| - gvr_api_->RefreshViewerProfile(); |
| - gvr_api_->ResumeTracking(); |
| + if (gvr_api_) { |
| + gvr_api_->RefreshViewerProfile(); |
| + gvr_api_->ResumeTracking(); |
| + } |
| OnVSync(); |
| } |
| @@ -136,6 +142,12 @@ void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, |
| gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
| target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
| + if (!gvr_api_) { |
| + callback.Run(device::mojom::VRPosePtr(nullptr), time, -1, |
| + device::mojom::VRVSyncProvider::Status::SUCCESS); |
| + return; |
| + } |
| + |
| gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( |
| gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); |
| callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1, |
| @@ -156,6 +168,11 @@ void NonPresentingGvrDelegate::ResetPose() { |
| void NonPresentingGvrDelegate::CreateVRDisplayInfo( |
| const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| uint32_t device_id) { |
| + if (!gvr_api_) { |
| + callback.Run(device::mojom::VRDisplayInfoPtr(nullptr)); |
| + return; |
| + } |
| + |
| callback.Run(VrShell::CreateVRDisplayInfo( |
| gvr_api_.get(), device::kInvalidRenderTargetSize, device_id)); |
| } |