Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: chrome/browser/android/vr_shell/non_presenting_gvr_delegate.cc

Issue 2711173002: Prevent browser crash resulting from misbehaving WebVR renderer requesting multiple VSyncs. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "chrome/browser/android/vr_shell/vr_shell.h" 10 #include "chrome/browser/android/vr_shell/vr_shell.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { 54 NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() {
55 StopVSyncLoop(); 55 StopVSyncLoop();
56 if (binding_.is_bound()) 56 if (binding_.is_bound())
57 return binding_.Unbind(); 57 return binding_.Unbind();
58 return nullptr; 58 return nullptr;
59 } 59 }
60 60
61 void NonPresentingGvrDelegate::StopVSyncLoop() { 61 void NonPresentingGvrDelegate::StopVSyncLoop() {
62 vsync_task_.Cancel(); 62 vsync_task_.Cancel();
63 if (!callback_.is_null()) { 63 if (!callback_.is_null()) {
64 base::ResetAndReturn(&callback_).Run(nullptr, base::TimeDelta(), -1); 64 base::ResetAndReturn(&callback_)
65 .Run(nullptr, base::TimeDelta(), -1,
66 device::mojom::VRVSyncProvider::Status::RETRY);
65 } 67 }
66 gvr_api_->PauseTracking(); 68 gvr_api_->PauseTracking();
67 // If the loop is stopped, it's not considered to be paused. 69 // If the loop is stopped, it's not considered to be paused.
68 vsync_paused_ = false; 70 vsync_paused_ = false;
69 } 71 }
70 72
71 void NonPresentingGvrDelegate::StartVSyncLoop() { 73 void NonPresentingGvrDelegate::StartVSyncLoop() {
72 vsync_task_.Reset( 74 vsync_task_.Reset(
73 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); 75 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this)));
74 gvr_api_->RefreshViewerProfile(); 76 gvr_api_->RefreshViewerProfile();
(...skipping 29 matching lines...) Expand all
104 pending_time_ = time; 106 pending_time_ = time;
105 } 107 }
106 } 108 }
107 109
108 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) { 110 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) {
109 if (!pending_vsync_) { 111 if (!pending_vsync_) {
110 if (!callback_.is_null()) { 112 if (!callback_.is_null()) {
111 mojo::ReportBadMessage( 113 mojo::ReportBadMessage(
112 "Requested VSync before waiting for response to " 114 "Requested VSync before waiting for response to "
113 "previous request."); 115 "previous request.");
116 binding_.Close();
114 return; 117 return;
115 } 118 }
116 callback_ = callback; 119 callback_ = callback;
117 return; 120 return;
118 } 121 }
119 pending_vsync_ = false; 122 pending_vsync_ = false;
120 SendVSync(pending_time_, callback); 123 SendVSync(pending_time_, callback);
121 } 124 }
122 125
123 void NonPresentingGvrDelegate::UpdateVSyncInterval(int64_t timebase_nanos, 126 void NonPresentingGvrDelegate::UpdateVSyncInterval(int64_t timebase_nanos,
124 double interval_seconds) { 127 double interval_seconds) {
125 vsync_timebase_ = base::TimeTicks(); 128 vsync_timebase_ = base::TimeTicks();
126 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); 129 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
127 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 130 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
128 StartVSyncLoop(); 131 StartVSyncLoop();
129 } 132 }
130 133
131 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, 134 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time,
132 const GetVSyncCallback& callback) { 135 const GetVSyncCallback& callback) {
133 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 136 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
134 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 137 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
135 138
136 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( 139 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel(
137 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); 140 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f);
138 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1); 141 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1,
142 device::mojom::VRVSyncProvider::Status::SUCCESS);
139 } 143 }
140 144
141 bool NonPresentingGvrDelegate::SupportsPresentation() { 145 bool NonPresentingGvrDelegate::SupportsPresentation() {
142 return false; 146 return false;
143 } 147 }
144 148
145 void NonPresentingGvrDelegate::ResetPose() { 149 void NonPresentingGvrDelegate::ResetPose() {
146 // Should never call RecenterTracking when using with Daydream viewers. On 150 // Should never call RecenterTracking when using with Daydream viewers. On
147 // those devices recentering should only be done via the controller. 151 // those devices recentering should only be done via the controller.
148 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 152 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
149 gvr_api_->RecenterTracking(); 153 gvr_api_->RecenterTracking();
150 } 154 }
151 155
152 void NonPresentingGvrDelegate::CreateVRDisplayInfo( 156 void NonPresentingGvrDelegate::CreateVRDisplayInfo(
153 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 157 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
154 uint32_t device_id) { 158 uint32_t device_id) {
155 callback.Run(VrShell::CreateVRDisplayInfo( 159 callback.Run(VrShell::CreateVRDisplayInfo(
156 gvr_api_.get(), device::kInvalidRenderTargetSize, device_id)); 160 gvr_api_.get(), device::kInvalidRenderTargetSize, device_id));
157 } 161 }
158 162
159 } // namespace vr_shell 163 } // namespace vr_shell
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698