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

Unified Diff: chrome/browser/android/vr_shell/vr_controller.cc

Issue 2762003002: Refactor GVR controller gamepad API integration (Closed)
Patch Set: Rebase, no changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.h ('k') | chrome/browser/android/vr_shell/vr_shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/vr_controller.cc
diff --git a/chrome/browser/android/vr_shell/vr_controller.cc b/chrome/browser/android/vr_shell/vr_controller.cc
index 387db15085eddf5ab875652daf1b57db79e3815e..0bcf10f6816befb5afa37c22ab11aa202c74688d 100644
--- a/chrome/browser/android/vr_shell/vr_controller.cc
+++ b/chrome/browser/android/vr_shell/vr_controller.cc
@@ -82,11 +82,14 @@ class Vector {
} // namespace
VrController::VrController(gvr_context* vr_context) {
+ DVLOG(1) << __FUNCTION__ << "=" << this;
Initialize(vr_context);
Reset();
}
-VrController::~VrController() {}
+VrController::~VrController() {
+ DVLOG(1) << __FUNCTION__ << "=" << this;
+}
void VrController::OnResume() {
if (controller_api_)
@@ -98,6 +101,22 @@ void VrController::OnPause() {
controller_api_->Pause();
}
+device::GvrGamepadData VrController::GetGamepadData() {
+ device::GvrGamepadData pad;
+
+ pad.timestamp = controller_state_->GetLastOrientationTimestamp();
+ pad.touch_pos = controller_state_->GetTouchPos();
+ pad.orientation = controller_state_->GetOrientation();
+ pad.accel = controller_state_->GetAccel();
+ pad.gyro = controller_state_->GetGyro();
+ pad.is_touching = controller_state_->IsTouching();
+ pad.controller_button_pressed =
+ controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK);
+ pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED;
+
+ return pad;
+}
+
bool VrController::IsTouching() {
return controller_state_->IsTouching();
}
@@ -181,11 +200,30 @@ void VrController::Initialize(gvr_context* gvr_context) {
CHECK(gvr_context != nullptr) << "invalid gvr_context";
controller_api_.reset(new gvr::ControllerApi);
controller_state_.reset(new gvr::ControllerState);
+
int32_t options = gvr::ControllerApi::DefaultOptions();
- // Enable non-default options, if you need them:
- // options |= GVR_CONTROLLER_ENABLE_GYRO;
+ // Enable non-default options - WebVR needs gyro, and since VrShell
+ // implements GvrGamepadDataProvider we need this always.
+ options |= GVR_CONTROLLER_ENABLE_GYRO;
+
CHECK(controller_api_->Init(options, gvr_context));
+
+ std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context);
+ // TODO(bajones): Monitor changes to the controller handedness.
+ handedness_ = gvr->GetUserPrefs().GetControllerHandedness();
+
+ // Work around an obscure link error in component build.
+ // third_party/gvr-android-sdk/libgvr_shim_static_arm.a needs
+ // __aeabi_f2lz (float to int64_t static cast implementation) for
+ // ION's logging.cc::ThrottledLogger. Somehow this is no longer
+ // being provided, so convince the compiler to emit it here so that
+ // it's resolvable when linking libchrome.so.
+ // TODO(bshe,crbug.com/704305): look into a more elegant fix?
+ volatile float fixme_float = 1.3f;
+ volatile int64_t fixme_int64 = static_cast<int64_t>(fixme_float);
+ (void)fixme_int64;
+
controller_api_->Resume();
}
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.h ('k') | chrome/browser/android/vr_shell/vr_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698