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

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

Issue 2879973002: Expose Gamepad API instance for Cardboard button (Closed)
Patch Set: 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 return; 217 return;
218 218
219 // TODO(mthiesse): The page is no longer visible when in menu mode. We 219 // TODO(mthiesse): The page is no longer visible when in menu mode. We
220 // should unfocus or otherwise let it know it's hidden. 220 // should unfocus or otherwise let it know it's hidden.
221 if (paused) 221 if (paused)
222 delegate_provider_->device_provider()->Device()->OnBlur(); 222 delegate_provider_->device_provider()->Device()->OnBlur();
223 else 223 else
224 delegate_provider_->device_provider()->Device()->OnFocus(); 224 delegate_provider_->device_provider()->Device()->OnFocus();
225 } 225 }
226 226
227 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { 227 void VrShell::OnTriggerEvent(JNIEnv* env,
228 const JavaParamRef<jobject>& obj,
229 bool touched) {
228 gl_thread_->task_runner()->PostTask( 230 gl_thread_->task_runner()->PostTask(
229 FROM_HERE, 231 FROM_HERE, base::Bind(&VrShellGl::OnTriggerEvent,
230 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); 232 gl_thread_->GetVrShellGl(), touched));
231 } 233 }
232 234
233 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 235 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
234 gl_thread_->task_runner()->PostTask( 236 gl_thread_->task_runner()->PostTask(
235 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); 237 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
236 238
237 // exit vr session 239 // exit vr session
238 if (metrics_helper_) 240 if (metrics_helper_)
239 metrics_helper_->SetVRActive(false); 241 metrics_helper_->SetVRActive(false);
240 SetIsInVR(web_contents_, false); 242 SetIsInVR(web_contents_, false);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 528 }
527 } 529 }
528 530
529 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) { 531 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) {
530 if (!gamepad_source_active_) { 532 if (!gamepad_source_active_) {
531 if (!delegate_provider_->device_provider()) 533 if (!delegate_provider_->device_provider())
532 return; 534 return;
533 535
534 unsigned int device_id = 536 unsigned int device_id =
535 delegate_provider_->device_provider()->Device()->id(); 537 delegate_provider_->device_provider()->Device()->id();
538
539 // Two gamepad factories: one for screen only, and one for controller.
536 device::GamepadDataFetcherManager::GetInstance()->AddFactory( 540 device::GamepadDataFetcherManager::GetInstance()->AddFactory(
537 new device::GvrGamepadDataFetcher::Factory(this, device_id)); 541 new device::GvrGamepadDataFetcher::Factory(this, device_id, true));
542
543 device::GamepadDataFetcherManager::GetInstance()->AddFactory(
544 new device::GvrGamepadDataFetcher::Factory(this, device_id, false));
538 gamepad_source_active_ = true; 545 gamepad_source_active_ = true;
539 } 546 }
540 if (gamepad_data_fetcher_) { 547 for (auto* fetcher : gamepad_data_fetchers_) {
541 gamepad_data_fetcher_->SetGamepadData(pad); 548 fetcher->SetGamepadData(pad);
542 } 549 }
543 } 550 }
544 551
545 void VrShell::RegisterGamepadDataFetcher( 552 void VrShell::RegisterGamepadDataFetcher(
546 device::GvrGamepadDataFetcher* fetcher) { 553 device::GvrGamepadDataFetcher* fetcher) {
547 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; 554 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")";
548 gamepad_data_fetcher_ = fetcher; 555 gamepad_data_fetchers_.push_back(fetcher);
549 } 556 }
550 557
551 // ---------------------------------------------------------------------------- 558 // ----------------------------------------------------------------------------
552 // Native JNI methods 559 // Native JNI methods
553 // ---------------------------------------------------------------------------- 560 // ----------------------------------------------------------------------------
554 561
555 jlong Init(JNIEnv* env, 562 jlong Init(JNIEnv* env,
556 const JavaParamRef<jobject>& obj, 563 const JavaParamRef<jobject>& obj,
557 const JavaParamRef<jobject>& delegate, 564 const JavaParamRef<jobject>& delegate,
558 jlong window_android, 565 jlong window_android,
559 jboolean for_web_vr, 566 jboolean for_web_vr,
560 jboolean in_cct, 567 jboolean in_cct,
561 jlong gvr_api, 568 jlong gvr_api,
562 jboolean reprojected_rendering) { 569 jboolean reprojected_rendering) {
563 return reinterpret_cast<intptr_t>(new VrShell( 570 return reinterpret_cast<intptr_t>(new VrShell(
564 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 571 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
565 for_web_vr, in_cct, 572 for_web_vr, in_cct,
566 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 573 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
567 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 574 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
568 } 575 }
569 576
570 } // namespace vr_shell 577 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698