Chromium Code Reviews| Index: chrome/browser/android/vr_shell/vr_shell.cc |
| diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc |
| index c32e477f7b76dcd5eecf5d42f5a2828e2f32c90f..263fe67f0f3dd19528ee914376f6d5a335011f33 100644 |
| --- a/chrome/browser/android/vr_shell/vr_shell.cc |
| +++ b/chrome/browser/android/vr_shell/vr_shell.cc |
| @@ -42,6 +42,7 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/content_features.h" |
| #include "content/public/common/referrer.h" |
| +#include "device/vr/android/gvr/cardboard_gamepad_data_fetcher.h" |
| #include "device/vr/android/gvr/gvr_device.h" |
| #include "device/vr/android/gvr/gvr_device_provider.h" |
| #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| @@ -125,7 +126,6 @@ VrShell::VrShell(JNIEnv* env, |
| options.priority = base::ThreadPriority::DISPLAY; |
| gl_thread_->StartWithOptions(options); |
| - |
| content::BrowserThread::PostTask( |
| content::BrowserThread::FILE, FROM_HERE, |
| base::Bind(LoadControllerModelTask, weak_ptr_factory_.GetWeakPtr(), |
| @@ -195,11 +195,16 @@ bool RegisterVrShell(JNIEnv* env) { |
| VrShell::~VrShell() { |
| DVLOG(1) << __FUNCTION__ << "=" << this; |
| poll_capturing_media_task_.Cancel(); |
| - if (gamepad_source_active_) { |
| + if (gvr_gamepad_source_active_) { |
| device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| device::GAMEPAD_SOURCE_GVR); |
| } |
| + if (cardboard_gamepad_source_active_) { |
| + device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| + device::GAMEPAD_SOURCE_CARDBOARD); |
| + } |
| + |
| delegate_provider_->RemoveDelegate(); |
| { |
| // The GvrLayout is, and must always be, used only on the UI thread, and the |
| @@ -246,10 +251,48 @@ void VrShell::NavigateBack() { |
| Java_VrShellImpl_navigateBack(env, j_vr_shell_.obj()); |
| } |
| -void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| - gl_thread_->task_runner()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); |
| +void VrShell::ToggleCardboardGamepad(bool enabled) { |
| + // enable/disable updating gamepad state |
| + if (cardboard_gamepad_source_active_ && !enabled) { |
| + device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| + device::GAMEPAD_SOURCE_CARDBOARD); |
| + cardboard_gamepad_data_fetcher_ = nullptr; |
| + cardboard_gamepad_source_active_ = false; |
| + } |
| + |
| + if (!cardboard_gamepad_source_active_ && enabled) { |
| + // enable the gamepad |
|
mthiesse
2017/05/18 18:31:35
DCHECK that the gvr fetcher isn't active at the sa
billorr
2017/05/22 20:11:09
We do want them both active. For Oculus or Vive y
|
| + if (!delegate_provider_->device_provider()) |
| + return; |
| + |
| + unsigned int device_id = |
| + delegate_provider_->device_provider()->Device()->id(); |
| + |
| + device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
| + new device::CardboardGamepadDataFetcher::Factory(this, device_id)); |
| + cardboard_gamepad_source_active_ = true; |
| + } |
| +} |
| + |
| +void VrShell::OnTriggerEvent(JNIEnv* env, |
| + const JavaParamRef<jobject>& obj, |
| + bool touched) { |
| + // Send screen taps over to VrShellGl to be turned into simulated clicks for |
| + // cardboard. |
| + if (touched) |
| + gl_thread_->task_runner()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); |
| + |
| + // If we are running cardboard, update gamepad state. |
| + if (cardboard_gamepad_source_active_) { |
| + device::CardboardGamepadData pad; |
| + pad.timestamp = cardboard_gamepad_timer_++; |
|
mthiesse
2017/05/18 18:31:35
Why are we using a counter for the timestamp? Why
billorr
2017/05/22 20:11:09
The timestamp is just a monotonically increasing v
|
| + pad.is_screen_touching = touched; |
| + if (cardboard_gamepad_data_fetcher_) { |
| + cardboard_gamepad_data_fetcher_->SetGamepadData(pad); |
| + } |
| + } |
| } |
| void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| @@ -587,25 +630,30 @@ void VrShell::ProcessContentGesture( |
| } |
| void VrShell::UpdateGamepadData(device::GvrGamepadData pad) { |
| - if (!gamepad_source_active_) { |
| + if (!gvr_gamepad_source_active_) { |
| if (!delegate_provider_->device_provider()) |
| return; |
| unsigned int device_id = |
| delegate_provider_->device_provider()->Device()->id(); |
| + |
| device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
| new device::GvrGamepadDataFetcher::Factory(this, device_id)); |
| - gamepad_source_active_ = true; |
| - } |
| - if (gamepad_data_fetcher_) { |
| - gamepad_data_fetcher_->SetGamepadData(pad); |
| + gvr_gamepad_source_active_ = true; |
| } |
| + gvr_gamepad_data_fetcher_->SetGamepadData(pad); |
| } |
| -void VrShell::RegisterGamepadDataFetcher( |
| +void VrShell::RegisterGvrGamepadDataFetcher( |
| device::GvrGamepadDataFetcher* fetcher) { |
| DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| - gamepad_data_fetcher_ = fetcher; |
| + gvr_gamepad_data_fetcher_ = fetcher; |
| +} |
| + |
| +void VrShell::RegisterCardboardGamepadDataFetcher( |
| + device::CardboardGamepadDataFetcher* fetcher) { |
| + DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| + cardboard_gamepad_data_fetcher_ = fetcher; |
| } |
| // ---------------------------------------------------------------------------- |