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

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

Issue 2879973002: Expose Gamepad API instance for Cardboard button (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
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_shell.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 delegate_provider_->device_provider()->Device()->OnBlur(); 239 delegate_provider_->device_provider()->Device()->OnBlur();
240 else 240 else
241 delegate_provider_->device_provider()->Device()->OnFocus(); 241 delegate_provider_->device_provider()->Device()->OnFocus();
242 } 242 }
243 243
244 void VrShell::NavigateBack() { 244 void VrShell::NavigateBack() {
245 JNIEnv* env = base::android::AttachCurrentThread(); 245 JNIEnv* env = base::android::AttachCurrentThread();
246 Java_VrShellImpl_navigateBack(env, j_vr_shell_.obj()); 246 Java_VrShellImpl_navigateBack(env, j_vr_shell_.obj());
247 } 247 }
248 248
249 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { 249 void VrShell::OnTriggerEvent(JNIEnv* env,
250 const JavaParamRef<jobject>& obj,
251 bool touched) {
250 gl_thread_->task_runner()->PostTask( 252 gl_thread_->task_runner()->PostTask(
251 FROM_HERE, 253 FROM_HERE, base::Bind(&VrShellGl::OnTriggerEvent,
252 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); 254 gl_thread_->GetVrShellGl(), touched));
253 } 255 }
254 256
255 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 257 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
256 gl_thread_->task_runner()->PostTask( 258 gl_thread_->task_runner()->PostTask(
257 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); 259 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
258 260
259 // exit vr session 261 // exit vr session
260 if (metrics_helper_) 262 if (metrics_helper_)
261 metrics_helper_->SetVRActive(false); 263 metrics_helper_->SetVRActive(false);
262 SetIsInVR(web_contents_, false); 264 SetIsInVR(web_contents_, false);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 588 }
587 } 589 }
588 590
589 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) { 591 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) {
590 if (!gamepad_source_active_) { 592 if (!gamepad_source_active_) {
591 if (!delegate_provider_->device_provider()) 593 if (!delegate_provider_->device_provider())
592 return; 594 return;
593 595
594 unsigned int device_id = 596 unsigned int device_id =
595 delegate_provider_->device_provider()->Device()->id(); 597 delegate_provider_->device_provider()->Device()->id();
598
599 // Two gamepad factories: one for screen only, and one for controller.
596 device::GamepadDataFetcherManager::GetInstance()->AddFactory( 600 device::GamepadDataFetcherManager::GetInstance()->AddFactory(
597 new device::GvrGamepadDataFetcher::Factory(this, device_id)); 601 new device::GvrGamepadDataFetcher::Factory(this, device_id, true));
602
603 device::GamepadDataFetcherManager::GetInstance()->AddFactory(
mthiesse 2017/05/16 00:44:37 sidenote, gamepad API is scary :P Add twice, remov
604 new device::GvrGamepadDataFetcher::Factory(this, device_id, false));
598 gamepad_source_active_ = true; 605 gamepad_source_active_ = true;
599 } 606 }
600 if (gamepad_data_fetcher_) { 607 for (auto* fetcher : gamepad_data_fetchers_) {
601 gamepad_data_fetcher_->SetGamepadData(pad); 608 fetcher->SetGamepadData(pad);
602 } 609 }
603 } 610 }
604 611
605 void VrShell::RegisterGamepadDataFetcher( 612 void VrShell::RegisterGamepadDataFetcher(
606 device::GvrGamepadDataFetcher* fetcher) { 613 device::GvrGamepadDataFetcher* fetcher) {
607 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; 614 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")";
608 gamepad_data_fetcher_ = fetcher; 615 gamepad_data_fetchers_.push_back(fetcher);
609 } 616 }
610 617
611 // ---------------------------------------------------------------------------- 618 // ----------------------------------------------------------------------------
612 // Native JNI methods 619 // Native JNI methods
613 // ---------------------------------------------------------------------------- 620 // ----------------------------------------------------------------------------
614 621
615 jlong Init(JNIEnv* env, 622 jlong Init(JNIEnv* env,
616 const JavaParamRef<jobject>& obj, 623 const JavaParamRef<jobject>& obj,
617 const JavaParamRef<jobject>& delegate, 624 const JavaParamRef<jobject>& delegate,
618 jlong window_android, 625 jlong window_android,
619 jboolean for_web_vr, 626 jboolean for_web_vr,
620 jboolean in_cct, 627 jboolean in_cct,
621 jlong gvr_api, 628 jlong gvr_api,
622 jboolean reprojected_rendering) { 629 jboolean reprojected_rendering) {
623 return reinterpret_cast<intptr_t>(new VrShell( 630 return reinterpret_cast<intptr_t>(new VrShell(
624 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 631 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
625 for_web_vr, in_cct, 632 for_web_vr, in_cct,
626 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 633 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
627 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 634 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
628 } 635 }
629 636
630 } // namespace vr_shell 637 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698