| OLD | NEW |
| 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 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 35 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 36 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 36 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/render_widget_host.h" | 40 #include "content/public/browser/render_widget_host.h" |
| 41 #include "content/public/browser/render_widget_host_view.h" | 41 #include "content/public/browser/render_widget_host_view.h" |
| 42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/content_features.h" | 43 #include "content/public/common/content_features.h" |
| 44 #include "content/public/common/referrer.h" | 44 #include "content/public/common/referrer.h" |
| 45 #include "device/vr/android/gvr/cardboard_gamepad_data_fetcher.h" |
| 45 #include "device/vr/android/gvr/gvr_device.h" | 46 #include "device/vr/android/gvr/gvr_device.h" |
| 46 #include "device/vr/android/gvr/gvr_device_provider.h" | 47 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 47 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" | 48 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| 48 #include "gpu/command_buffer/common/mailbox.h" | 49 #include "gpu/command_buffer/common/mailbox.h" |
| 49 #include "jni/VrShellImpl_jni.h" | 50 #include "jni/VrShellImpl_jni.h" |
| 50 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 51 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 51 #include "ui/android/view_android.h" | 52 #include "ui/android/view_android.h" |
| 52 #include "ui/android/window_android.h" | 53 #include "ui/android/window_android.h" |
| 53 #include "ui/base/page_transition_types.h" | 54 #include "ui/base/page_transition_types.h" |
| 54 #include "ui/display/display.h" | 55 #include "ui/display/display.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 bool RegisterVrShell(JNIEnv* env) { | 178 bool RegisterVrShell(JNIEnv* env) { |
| 178 return RegisterNativesImpl(env); | 179 return RegisterNativesImpl(env); |
| 179 } | 180 } |
| 180 | 181 |
| 181 VrShell::~VrShell() { | 182 VrShell::~VrShell() { |
| 182 DVLOG(1) << __FUNCTION__ << "=" << this; | 183 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 183 poll_capturing_media_task_.Cancel(); | 184 poll_capturing_media_task_.Cancel(); |
| 184 if (gamepad_source_active_) { | 185 if (gvr_gamepad_source_active_) { |
| 185 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( | 186 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| 186 device::GAMEPAD_SOURCE_GVR); | 187 device::GAMEPAD_SOURCE_GVR); |
| 187 } | 188 } |
| 188 | 189 |
| 190 if (cardboard_gamepad_source_active_) { |
| 191 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| 192 device::GAMEPAD_SOURCE_CARDBOARD); |
| 193 } |
| 194 |
| 189 delegate_provider_->RemoveDelegate(); | 195 delegate_provider_->RemoveDelegate(); |
| 190 { | 196 { |
| 191 // The GvrLayout is, and must always be, used only on the UI thread, and the | 197 // The GvrLayout is, and must always be, used only on the UI thread, and the |
| 192 // GvrApi used for rendering should only be used from the GL thread as it's | 198 // GvrApi used for rendering should only be used from the GL thread as it's |
| 193 // not thread safe. However, the GvrLayout owns the GvrApi instance, and | 199 // not thread safe. However, the GvrLayout owns the GvrApi instance, and |
| 194 // when it gets shut down it deletes the GvrApi instance with it. Therefore, | 200 // when it gets shut down it deletes the GvrApi instance with it. Therefore, |
| 195 // we need to block shutting down the GvrLayout on stopping our GL thread | 201 // we need to block shutting down the GvrLayout on stopping our GL thread |
| 196 // from using the GvrApi instance. | 202 // from using the GvrApi instance. |
| 197 // base::Thread::Stop, which is called when destroying the thread, asserts | 203 // base::Thread::Stop, which is called when destroying the thread, asserts |
| 198 // that IO is allowed to prevent jank, but there shouldn't be any concerns | 204 // that IO is allowed to prevent jank, but there shouldn't be any concerns |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 void VrShell::NavigateBack() { | 245 void VrShell::NavigateBack() { |
| 240 JNIEnv* env = base::android::AttachCurrentThread(); | 246 JNIEnv* env = base::android::AttachCurrentThread(); |
| 241 Java_VrShellImpl_navigateBack(env, j_vr_shell_.obj()); | 247 Java_VrShellImpl_navigateBack(env, j_vr_shell_.obj()); |
| 242 } | 248 } |
| 243 | 249 |
| 244 void VrShell::ExitCct() { | 250 void VrShell::ExitCct() { |
| 245 JNIEnv* env = base::android::AttachCurrentThread(); | 251 JNIEnv* env = base::android::AttachCurrentThread(); |
| 246 Java_VrShellImpl_exitCct(env, j_vr_shell_.obj()); | 252 Java_VrShellImpl_exitCct(env, j_vr_shell_.obj()); |
| 247 } | 253 } |
| 248 | 254 |
| 249 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 255 void VrShell::ToggleCardboardGamepad(bool enabled) { |
| 256 // enable/disable updating gamepad state |
| 257 if (cardboard_gamepad_source_active_ && !enabled) { |
| 258 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| 259 device::GAMEPAD_SOURCE_CARDBOARD); |
| 260 cardboard_gamepad_data_fetcher_ = nullptr; |
| 261 cardboard_gamepad_source_active_ = false; |
| 262 } |
| 263 |
| 264 if (!cardboard_gamepad_source_active_ && enabled) { |
| 265 // enable the gamepad |
| 266 if (!delegate_provider_->device_provider()) |
| 267 return; |
| 268 |
| 269 unsigned int device_id = |
| 270 delegate_provider_->device_provider()->Device()->id(); |
| 271 |
| 272 device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
| 273 new device::CardboardGamepadDataFetcher::Factory(this, device_id)); |
| 274 cardboard_gamepad_source_active_ = true; |
| 275 } |
| 276 } |
| 277 |
| 278 void VrShell::OnTriggerEvent(JNIEnv* env, |
| 279 const JavaParamRef<jobject>& obj, |
| 280 bool touched) { |
| 250 WaitForGlThread(); | 281 WaitForGlThread(); |
| 251 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::OnTriggerEvent, | 282 |
| 252 gl_thread_->GetVrShellGl())); | 283 // Send screen taps over to VrShellGl to be turned into simulated clicks for |
| 284 // cardboard. |
| 285 if (touched) |
| 286 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::OnTriggerEvent, |
| 287 gl_thread_->GetVrShellGl())); |
| 288 |
| 289 // If we are running cardboard, update gamepad state. |
| 290 if (cardboard_gamepad_source_active_) { |
| 291 device::CardboardGamepadData pad; |
| 292 pad.timestamp = cardboard_gamepad_timer_++; |
| 293 pad.is_screen_touching = touched; |
| 294 if (cardboard_gamepad_data_fetcher_) { |
| 295 cardboard_gamepad_data_fetcher_->SetGamepadData(pad); |
| 296 } |
| 297 } |
| 253 } | 298 } |
| 254 | 299 |
| 255 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 300 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 256 WaitForGlThread(); | 301 WaitForGlThread(); |
| 257 PostToGlThread(FROM_HERE, | 302 PostToGlThread(FROM_HERE, |
| 258 base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); | 303 base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); |
| 259 | 304 |
| 260 // exit vr session | 305 // exit vr session |
| 261 if (metrics_helper_) | 306 if (metrics_helper_) |
| 262 metrics_helper_->SetVRActive(false); | 307 metrics_helper_->SetVRActive(false); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 void VrShell::ProcessContentGesture( | 643 void VrShell::ProcessContentGesture( |
| 599 std::unique_ptr<blink::WebInputEvent> event) { | 644 std::unique_ptr<blink::WebInputEvent> event) { |
| 600 if (input_manager_) { | 645 if (input_manager_) { |
| 601 input_manager_->ProcessUpdatedGesture(std::move(event)); | 646 input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 602 } else if (android_ui_gesture_target_) { | 647 } else if (android_ui_gesture_target_) { |
| 603 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); | 648 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); |
| 604 } | 649 } |
| 605 } | 650 } |
| 606 | 651 |
| 607 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) { | 652 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) { |
| 608 if (!gamepad_source_active_) { | 653 if (!gvr_gamepad_source_active_) { |
| 609 if (!delegate_provider_->device_provider()) | 654 if (!delegate_provider_->device_provider()) |
| 610 return; | 655 return; |
| 611 | 656 |
| 612 unsigned int device_id = | 657 unsigned int device_id = |
| 613 delegate_provider_->device_provider()->Device()->id(); | 658 delegate_provider_->device_provider()->Device()->id(); |
| 659 |
| 614 device::GamepadDataFetcherManager::GetInstance()->AddFactory( | 660 device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
| 615 new device::GvrGamepadDataFetcher::Factory(this, device_id)); | 661 new device::GvrGamepadDataFetcher::Factory(this, device_id)); |
| 616 gamepad_source_active_ = true; | 662 gvr_gamepad_source_active_ = true; |
| 617 } | 663 } |
| 618 if (gamepad_data_fetcher_) { | 664 if (gvr_gamepad_data_fetcher_) { |
| 619 gamepad_data_fetcher_->SetGamepadData(pad); | 665 gvr_gamepad_data_fetcher_->SetGamepadData(pad); |
| 620 } | 666 } |
| 621 } | 667 } |
| 622 | 668 |
| 623 void VrShell::RegisterGamepadDataFetcher( | 669 void VrShell::RegisterGvrGamepadDataFetcher( |
| 624 device::GvrGamepadDataFetcher* fetcher) { | 670 device::GvrGamepadDataFetcher* fetcher) { |
| 625 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; | 671 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| 626 gamepad_data_fetcher_ = fetcher; | 672 gvr_gamepad_data_fetcher_ = fetcher; |
| 673 } |
| 674 |
| 675 void VrShell::RegisterCardboardGamepadDataFetcher( |
| 676 device::CardboardGamepadDataFetcher* fetcher) { |
| 677 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| 678 cardboard_gamepad_data_fetcher_ = fetcher; |
| 627 } | 679 } |
| 628 | 680 |
| 629 bool VrShell::HasDaydreamSupport(JNIEnv* env) { | 681 bool VrShell::HasDaydreamSupport(JNIEnv* env) { |
| 630 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj()); | 682 return Java_VrShellImpl_hasDaydreamSupport(env, j_vr_shell_.obj()); |
| 631 } | 683 } |
| 632 | 684 |
| 633 // ---------------------------------------------------------------------------- | 685 // ---------------------------------------------------------------------------- |
| 634 // Native JNI methods | 686 // Native JNI methods |
| 635 // ---------------------------------------------------------------------------- | 687 // ---------------------------------------------------------------------------- |
| 636 | 688 |
| 637 jlong Init(JNIEnv* env, | 689 jlong Init(JNIEnv* env, |
| 638 const JavaParamRef<jobject>& obj, | 690 const JavaParamRef<jobject>& obj, |
| 639 const JavaParamRef<jobject>& delegate, | 691 const JavaParamRef<jobject>& delegate, |
| 640 jlong window_android, | 692 jlong window_android, |
| 641 jboolean for_web_vr, | 693 jboolean for_web_vr, |
| 642 jboolean in_cct, | 694 jboolean in_cct, |
| 643 jlong gvr_api, | 695 jlong gvr_api, |
| 644 jboolean reprojected_rendering) { | 696 jboolean reprojected_rendering) { |
| 645 return reinterpret_cast<intptr_t>(new VrShell( | 697 return reinterpret_cast<intptr_t>(new VrShell( |
| 646 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 698 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 647 for_web_vr, in_cct, | 699 for_web_vr, in_cct, |
| 648 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 700 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 649 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 701 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 650 } | 702 } |
| 651 | 703 |
| 652 } // namespace vr_shell | 704 } // namespace vr_shell |
| OLD | NEW |