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

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: Created 3 years, 9 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/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::Error::ERROR_TRY_AGAIN);
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 28 matching lines...) Expand all
103 pending_vsync_ = true; 105 pending_vsync_ = true;
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("Requested VSync before waiting for response to " 113 mojo::ReportBadMessage("Requested VSync before waiting for response to "
112 "previous request."); 114 "previous request.");
115 callback.Run(nullptr, base::TimeDelta(), -1,
116 device::mojom::VRVSyncProvider::Error::ERROR_BAD_REQUEST);
113 return; 117 return;
114 } 118 }
115 callback_ = callback; 119 callback_ = callback;
116 return; 120 return;
117 } 121 }
118 pending_vsync_ = false; 122 pending_vsync_ = false;
119 SendVSync(pending_time_, callback); 123 SendVSync(pending_time_, callback);
120 } 124 }
121 125
122 void NonPresentingGvrDelegate::UpdateVSyncInterval(int64_t timebase_nanos, 126 void NonPresentingGvrDelegate::UpdateVSyncInterval(int64_t timebase_nanos,
123 double interval_seconds) { 127 double interval_seconds) {
124 vsync_timebase_ = base::TimeTicks(); 128 vsync_timebase_ = base::TimeTicks();
125 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); 129 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
126 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 130 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
127 StartVSyncLoop(); 131 StartVSyncLoop();
128 } 132 }
129 133
130 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, 134 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time,
131 const GetVSyncCallback& callback) { 135 const GetVSyncCallback& callback) {
132 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 136 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
133 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 137 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
134 138
135 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( 139 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel(
136 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); 140 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f);
137 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1); 141 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1,
142 device::mojom::VRVSyncProvider::Error::ERROR_NONE);
138 } 143 }
139 144
140 bool NonPresentingGvrDelegate::SupportsPresentation() { 145 bool NonPresentingGvrDelegate::SupportsPresentation() {
141 return false; 146 return false;
142 } 147 }
143 148
144 void NonPresentingGvrDelegate::ResetPose() { 149 void NonPresentingGvrDelegate::ResetPose() {
145 // Should never call RecenterTracking when using with Daydream viewers. On 150 // Should never call RecenterTracking when using with Daydream viewers. On
146 // those devices recentering should only be done via the controller. 151 // those devices recentering should only be done via the controller.
147 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 152 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
148 gvr_api_->RecenterTracking(); 153 gvr_api_->RecenterTracking();
149 } 154 }
150 155
151 void NonPresentingGvrDelegate::CreateVRDisplayInfo( 156 void NonPresentingGvrDelegate::CreateVRDisplayInfo(
152 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 157 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
153 uint32_t device_id) { 158 uint32_t device_id) {
154 callback.Run(VrShell::CreateVRDisplayInfo( 159 callback.Run(VrShell::CreateVRDisplayInfo(
155 gvr_api_.get(), device::kInvalidRenderTargetSize, device_id)); 160 gvr_api_.get(), device::kInvalidRenderTargetSize, device_id));
156 } 161 }
157 162
158 } // 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') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698