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

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

Issue 2770353002: WebVR: add angular velocity estimate to pose (Closed)
Patch Set: Review feedback, move constants to vr_shell.h Created 3 years, 8 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"
11 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" 11 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h"
12 12
13 namespace vr_shell { 13 namespace vr_shell {
14 14
15 namespace {
16 static constexpr int64_t kPredictionTimeWithoutVsyncNanos = 50000000;
17 } // namespace
18
19 NonPresentingGvrDelegate::NonPresentingGvrDelegate(gvr_context* context) 15 NonPresentingGvrDelegate::NonPresentingGvrDelegate(gvr_context* context)
20 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 16 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
21 binding_(this), 17 binding_(this),
22 weak_ptr_factory_(this) { 18 weak_ptr_factory_(this) {
23 // Context may be null, see VrShellDelegate#createNonPresentingNativeContext 19 // Context may be null, see VrShellDelegate#createNonPresentingNativeContext
24 // for possible reasons a context could fail to be created. For example, 20 // for possible reasons a context could fail to be created. For example,
25 // the user might uninstall apps or clear data after VR support was detected. 21 // the user might uninstall apps or clear data after VR support was detected.
26 if (context) 22 if (context)
27 gvr_api_ = gvr::GvrApi::WrapNonOwned(context); 23 gvr_api_ = gvr::GvrApi::WrapNonOwned(context);
28 } 24 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 double interval_seconds) { 132 double interval_seconds) {
137 vsync_timebase_ = base::TimeTicks(); 133 vsync_timebase_ = base::TimeTicks();
138 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); 134 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
139 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 135 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
140 StartVSyncLoop(); 136 StartVSyncLoop();
141 } 137 }
142 138
143 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, 139 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time,
144 const GetVSyncCallback& callback) { 140 const GetVSyncCallback& callback) {
145 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 141 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
146 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 142 target_time.monotonic_system_time_nanos +=
143 VrShell::kPredictionTimeWithoutVsyncNanos;
147 144
148 if (!gvr_api_) { 145 if (!gvr_api_) {
149 callback.Run(device::mojom::VRPosePtr(nullptr), time, -1, 146 callback.Run(device::mojom::VRPosePtr(nullptr), time, -1,
150 device::mojom::VRVSyncProvider::Status::SUCCESS); 147 device::mojom::VRVSyncProvider::Status::SUCCESS);
151 return; 148 return;
152 } 149 }
153 150
154 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( 151 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel(
155 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); 152 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f);
156 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1, 153
157 device::mojom::VRVSyncProvider::Status::SUCCESS); 154 target_time.monotonic_system_time_nanos +=
155 VrShell::kAngularVelocityEpsilonNanos;
156 gvr::Mat4f head_mat_2 =
157 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time);
158
159 callback.Run(VrShell::VRPosePtrFromGvrPose(
160 head_mat, head_mat_2, VrShell::kAngularVelocityEpsilonNanos),
161 time, -1, device::mojom::VRVSyncProvider::Status::SUCCESS);
158 } 162 }
159 163
160 bool NonPresentingGvrDelegate::SupportsPresentation() { 164 bool NonPresentingGvrDelegate::SupportsPresentation() {
161 return false; 165 return false;
162 } 166 }
163 167
164 void NonPresentingGvrDelegate::ResetPose() { 168 void NonPresentingGvrDelegate::ResetPose() {
165 // Should never call RecenterTracking when using with Daydream viewers. On 169 // Should never call RecenterTracking when using with Daydream viewers. On
166 // those devices recentering should only be done via the controller. 170 // those devices recentering should only be done via the controller.
167 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) 171 if (gvr_api_ && gvr_api_->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD)
168 gvr_api_->RecenterTracking(); 172 gvr_api_->RecenterTracking();
169 } 173 }
170 174
171 void NonPresentingGvrDelegate::CreateVRDisplayInfo( 175 void NonPresentingGvrDelegate::CreateVRDisplayInfo(
172 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 176 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
173 uint32_t device_id) { 177 uint32_t device_id) {
174 if (!gvr_api_) { 178 if (!gvr_api_) {
175 callback.Run(device::mojom::VRDisplayInfoPtr(nullptr)); 179 callback.Run(device::mojom::VRDisplayInfoPtr(nullptr));
176 return; 180 return;
177 } 181 }
178 182
179 gvr::Sizei webvr_size = VrShell::GetRecommendedWebVrSize(gvr_api_.get()); 183 gvr::Sizei webvr_size = VrShell::GetRecommendedWebVrSize(gvr_api_.get());
180 DVLOG(1) << __FUNCTION__ << ": resize recommended to " << webvr_size.width 184 DVLOG(1) << __FUNCTION__ << ": resize recommended to " << webvr_size.width
181 << "x" << webvr_size.height; 185 << "x" << webvr_size.height;
182 callback.Run( 186 callback.Run(
183 VrShell::CreateVRDisplayInfo(gvr_api_.get(), webvr_size, device_id)); 187 VrShell::CreateVRDisplayInfo(gvr_api_.get(), webvr_size, device_id));
184 } 188 }
185 189
186 } // namespace vr_shell 190 } // namespace vr_shell
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_controller.cc » ('j') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698