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

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

Issue 2848283003: VR: Refresh controller handedness when resuming the controller. (Closed)
Patch Set: rebase Created 3 years, 7 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 | « chrome/browser/android/vr_shell/vr_controller.h ('k') | no next file » | 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/vr_controller.h" 5 #include "chrome/browser/android/vr_shell/vr_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 float DeltaTimeSeconds(int64_t last_timestamp_nanos) { 54 float DeltaTimeSeconds(int64_t last_timestamp_nanos) {
55 return (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos - 55 return (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos -
56 last_timestamp_nanos) / 56 last_timestamp_nanos) /
57 kNanoSecondsPerSecond; 57 kNanoSecondsPerSecond;
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 VrController::VrController(gvr_context* vr_context) { 62 VrController::VrController(gvr_context* gvr_context) {
63 DVLOG(1) << __FUNCTION__ << "=" << this; 63 DVLOG(1) << __FUNCTION__ << "=" << this;
64 Initialize(vr_context); 64 CHECK(gvr_context != nullptr) << "invalid gvr_context";
65 controller_api_ = base::MakeUnique<gvr::ControllerApi>();
66 controller_state_ = base::MakeUnique<gvr::ControllerState>();
67 gvr_api_ = gvr::GvrApi::WrapNonOwned(gvr_context);
68
69 int32_t options = gvr::ControllerApi::DefaultOptions();
70
71 // Enable non-default options - WebVR needs gyro and linear acceleration, and
72 // since VrShell implements GvrGamepadDataProvider we need this always.
73 options |= GVR_CONTROLLER_ENABLE_GYRO;
74 options |= GVR_CONTROLLER_ENABLE_ACCEL;
75
76 CHECK(controller_api_->Init(options, gvr_context));
77 controller_api_->Resume();
78
79 handedness_ = gvr_api_->GetUserPrefs().GetControllerHandedness();
65 elbow_model_ = base::MakeUnique<ElbowModel>(handedness_); 80 elbow_model_ = base::MakeUnique<ElbowModel>(handedness_);
81
66 Reset(); 82 Reset();
67 last_timestamp_nanos_ = 83 last_timestamp_nanos_ =
68 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; 84 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos;
69 } 85 }
70 86
71 VrController::~VrController() { 87 VrController::~VrController() {
72 DVLOG(1) << __FUNCTION__ << "=" << this; 88 DVLOG(1) << __FUNCTION__ << "=" << this;
73 } 89 }
74 90
75 void VrController::OnResume() { 91 void VrController::OnResume() {
76 if (controller_api_) 92 if (controller_api_) {
77 controller_api_->Resume(); 93 controller_api_->Resume();
94 handedness_ = gvr_api_->GetUserPrefs().GetControllerHandedness();
95 elbow_model_->SetHandedness(handedness_);
96 }
78 } 97 }
79 98
80 void VrController::OnPause() { 99 void VrController::OnPause() {
81 if (controller_api_) 100 if (controller_api_)
82 controller_api_->Pause(); 101 controller_api_->Pause();
83 } 102 }
84 103
85 device::GvrGamepadData VrController::GetGamepadData() { 104 device::GvrGamepadData VrController::GetGamepadData() {
86 device::GvrGamepadData pad; 105 device::GvrGamepadData pad;
87 106
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (extrapolated_touch_ == kMaxNumOfExtrapolations) { 237 if (extrapolated_touch_ == kMaxNumOfExtrapolations) {
219 overall_velocity_ = {0, 0}; 238 overall_velocity_ = {0, 0};
220 } 239 }
221 extrapolated_touch_ = 0; 240 extrapolated_touch_ = 0;
222 } 241 }
223 last_touch_timestamp_ = controller_state_->GetLastTouchTimestamp(); 242 last_touch_timestamp_ = controller_state_->GetLastTouchTimestamp();
224 last_timestamp_nanos_ = 243 last_timestamp_nanos_ =
225 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; 244 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos;
226 } 245 }
227 246
228 void VrController::Initialize(gvr_context* gvr_context) {
229 CHECK(gvr_context != nullptr) << "invalid gvr_context";
230 controller_api_.reset(new gvr::ControllerApi);
231 controller_state_.reset(new gvr::ControllerState);
232
233 int32_t options = gvr::ControllerApi::DefaultOptions();
234
235 // Enable non-default options - WebVR needs gyro and linear acceleration, and
236 // since VrShell implements GvrGamepadDataProvider we need this always.
237 options |= GVR_CONTROLLER_ENABLE_GYRO;
238 options |= GVR_CONTROLLER_ENABLE_ACCEL;
239
240 CHECK(controller_api_->Init(options, gvr_context));
241
242 std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context);
243 // TODO(bajones): Monitor changes to the controller handedness.
244 handedness_ = gvr->GetUserPrefs().GetControllerHandedness();
245
246 controller_api_->Resume();
247 }
248
249 std::vector<std::unique_ptr<WebGestureEvent>> VrController::DetectGestures() { 247 std::vector<std::unique_ptr<WebGestureEvent>> VrController::DetectGestures() {
250 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list; 248 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list;
251 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); 249 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent());
252 250
253 if (controller_state_->GetConnectionState() != gvr::kControllerConnected) { 251 if (controller_state_->GetConnectionState() != gvr::kControllerConnected) {
254 gesture_list.push_back(std::move(gesture)); 252 gesture_list.push_back(std::move(gesture));
255 return gesture_list; 253 return gesture_list;
256 } 254 }
257 255
258 touch_position_changed_ = UpdateCurrentTouchpoint(); 256 touch_position_changed_ = UpdateCurrentTouchpoint();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 439
442 const gfx::Vector2dF& velocity = ScaleVector2d(displacement, (1 / duration)); 440 const gfx::Vector2dF& velocity = ScaleVector2d(displacement, (1 / duration));
443 441
444 float weight = duration / (kRC + duration); 442 float weight = duration / (kRC + duration);
445 443
446 overall_velocity_ = ScaleVector2d(overall_velocity_, (1 - weight)) + 444 overall_velocity_ = ScaleVector2d(overall_velocity_, (1 - weight)) +
447 ScaleVector2d(velocity, weight); 445 ScaleVector2d(velocity, weight);
448 } 446 }
449 447
450 } // namespace vr_shell 448 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698