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

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

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

Powered by Google App Engine
This is Rietveld 408576698