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

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: Move angular velocity calculation to helper function 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
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_controller.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 "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" 10 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h"
11 11
12 namespace vr_shell { 12 namespace vr_shell {
13 13
14 namespace {
15 static constexpr int64_t kPredictionTimeWithoutVsyncNanos = 50000000;
16 } // namespace
17
18 NonPresentingGvrDelegate::NonPresentingGvrDelegate(gvr_context* context) 14 NonPresentingGvrDelegate::NonPresentingGvrDelegate(gvr_context* context)
19 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 15 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
20 binding_(this), 16 binding_(this),
21 weak_ptr_factory_(this) { 17 weak_ptr_factory_(this) {
22 // Context may be null, see VrShellDelegate#createNonPresentingNativeContext 18 // Context may be null, see VrShellDelegate#createNonPresentingNativeContext
23 // for possible reasons a context could fail to be created. For example, 19 // for possible reasons a context could fail to be created. For example,
24 // the user might uninstall apps or clear data after VR support was detected. 20 // the user might uninstall apps or clear data after VR support was detected.
25 if (context) 21 if (context)
26 gvr_api_ = gvr::GvrApi::WrapNonOwned(context); 22 gvr_api_ = gvr::GvrApi::WrapNonOwned(context);
27 } 23 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void NonPresentingGvrDelegate::UpdateVSyncInterval(int64_t timebase_nanos, 130 void NonPresentingGvrDelegate::UpdateVSyncInterval(int64_t timebase_nanos,
135 double interval_seconds) { 131 double interval_seconds) {
136 vsync_timebase_ = base::TimeTicks(); 132 vsync_timebase_ = base::TimeTicks();
137 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); 133 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
138 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 134 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
139 StartVSyncLoop(); 135 StartVSyncLoop();
140 } 136 }
141 137
142 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, 138 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time,
143 const GetVSyncCallback& callback) { 139 const GetVSyncCallback& callback) {
144 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
145 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
146
147 if (!gvr_api_) { 140 if (!gvr_api_) {
148 callback.Run(device::mojom::VRPosePtr(nullptr), time, -1, 141 callback.Run(device::mojom::VRPosePtr(nullptr), time, -1,
149 device::mojom::VRVSyncProvider::Status::SUCCESS); 142 device::mojom::VRVSyncProvider::Status::SUCCESS);
150 return; 143 return;
151 } 144 }
152 145
153 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( 146 callback.Run(GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), nullptr),
154 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); 147 time, -1, device::mojom::VRVSyncProvider::Status::SUCCESS);
155 callback.Run(GvrDelegate::VRPosePtrFromGvrPose(head_mat), time, -1,
156 device::mojom::VRVSyncProvider::Status::SUCCESS);
157 } 148 }
158 149
159 void NonPresentingGvrDelegate::CreateVRDisplayInfo( 150 void NonPresentingGvrDelegate::CreateVRDisplayInfo(
160 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 151 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
161 uint32_t device_id) { 152 uint32_t device_id) {
162 if (!gvr_api_) { 153 if (!gvr_api_) {
163 callback.Run(device::mojom::VRDisplayInfoPtr(nullptr)); 154 callback.Run(device::mojom::VRDisplayInfoPtr(nullptr));
164 return; 155 return;
165 } 156 }
166 157
167 gvr::Sizei webvr_size = GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get()); 158 gvr::Sizei webvr_size = GvrDelegate::GetRecommendedWebVrSize(gvr_api_.get());
168 DVLOG(1) << __FUNCTION__ << ": resize recommended to " << webvr_size.width 159 DVLOG(1) << __FUNCTION__ << ": resize recommended to " << webvr_size.width
169 << "x" << webvr_size.height; 160 << "x" << webvr_size.height;
170 callback.Run( 161 callback.Run(
171 GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), webvr_size, device_id)); 162 GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), webvr_size, device_id));
172 } 163 }
173 164
174 } // namespace vr_shell 165 } // namespace vr_shell
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698