| 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> |
| 11 | 11 |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/android/tab_android.h" | 20 #include "chrome/browser/android/tab_android.h" |
| 21 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" |
| 21 #include "chrome/browser/android/vr_shell/ui_interface.h" | 22 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 22 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 23 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 23 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" | 24 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
| 24 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 25 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 25 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 26 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 26 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 27 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 27 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 28 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 28 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 29 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 gl_thread_->StartWithOptions(options); | 100 gl_thread_->StartWithOptions(options); |
| 100 | 101 |
| 101 html_interface_ = base::MakeUnique<UiInterface>( | 102 html_interface_ = base::MakeUnique<UiInterface>( |
| 102 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD); | 103 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 106 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 106 delete this; | 107 delete this; |
| 107 } | 108 } |
| 108 | 109 |
| 109 void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj, | 110 void VrShell::SwapContents( |
| 110 const JavaParamRef<jobject>& web_contents) { | 111 JNIEnv* env, |
| 112 const JavaParamRef<jobject>& obj, |
| 113 const JavaParamRef<jobject>& web_contents, |
| 114 const JavaParamRef<jobject>& touch_event_synthesizer) { |
| 111 content::WebContents* contents = | 115 content::WebContents* contents = |
| 112 content::WebContents::FromJavaWebContents(web_contents); | 116 content::WebContents::FromJavaWebContents(web_contents); |
| 113 if (contents == main_contents_) | 117 if (contents == main_contents_ && |
| 118 touch_event_synthesizer.obj() == j_motion_event_synthesizer_.obj()) |
| 114 return; | 119 return; |
| 115 | 120 |
| 116 SetIsInVR(main_contents_, false); | 121 SetIsInVR(main_contents_, false); |
| 117 | 122 j_motion_event_synthesizer_.Reset(env, touch_event_synthesizer); |
| 118 main_contents_ = contents; | 123 main_contents_ = contents; |
| 119 content_compositor_->SetLayer(main_contents_); | 124 content_compositor_->SetLayer(main_contents_); |
| 120 SetIsInVR(main_contents_, true); | 125 SetIsInVR(main_contents_, true); |
| 121 ContentFrameWasResized(false /* unused */); | 126 ContentFrameWasResized(false /* unused */); |
| 122 SetUiState(); | 127 SetUiState(); |
| 123 | 128 |
| 124 if (!main_contents_) { | 129 if (!main_contents_) { |
| 130 android_ui_gesture_target_ = base::MakeUnique<AndroidUiGestureTarget>( |
| 131 j_motion_event_synthesizer_.obj(), |
| 132 Java_VrShellImpl_getNativePageScrollRatio(env, j_vr_shell_.obj())); |
| 125 content_input_manager_ = nullptr; | 133 content_input_manager_ = nullptr; |
| 126 vr_web_contents_observer_ = nullptr; | 134 vr_web_contents_observer_ = nullptr; |
| 127 metrics_helper_ = nullptr; | 135 metrics_helper_ = nullptr; |
| 128 return; | 136 return; |
| 129 } | 137 } |
| 130 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); | 138 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); |
| 131 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( | 139 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( |
| 132 main_contents_, html_interface_.get(), this); | 140 main_contents_, html_interface_.get(), this); |
| 133 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple | 141 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple |
| 134 // tabs. crbug.com/684661 | 142 // tabs. crbug.com/684661 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 if (ui_input_manager_) { | 553 if (ui_input_manager_) { |
| 546 ui_input_manager_->ProcessUpdatedGesture(std::move(event)); | 554 ui_input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 547 } | 555 } |
| 548 | 556 |
| 549 } | 557 } |
| 550 | 558 |
| 551 void VrShell::ProcessContentGesture( | 559 void VrShell::ProcessContentGesture( |
| 552 std::unique_ptr<blink::WebInputEvent> event) { | 560 std::unique_ptr<blink::WebInputEvent> event) { |
| 553 if (content_input_manager_) { | 561 if (content_input_manager_) { |
| 554 content_input_manager_->ProcessUpdatedGesture(std::move(event)); | 562 content_input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 563 } else if (android_ui_gesture_target_) { |
| 564 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); |
| 555 } | 565 } |
| 556 } | 566 } |
| 557 | 567 |
| 558 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { | 568 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { |
| 559 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); | 569 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
| 560 | 570 |
| 561 pose->timestamp = base::Time::Now().ToJsTime(); | 571 pose->timestamp = base::Time::Now().ToJsTime(); |
| 562 pose->orientation.emplace(4); | 572 pose->orientation.emplace(4); |
| 563 | 573 |
| 564 gfx::Transform inv_transform( | 574 gfx::Transform inv_transform( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 jboolean reprojected_rendering) { | 660 jboolean reprojected_rendering) { |
| 651 return reinterpret_cast<intptr_t>(new VrShell( | 661 return reinterpret_cast<intptr_t>(new VrShell( |
| 652 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 662 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 653 content::WebContents::FromJavaWebContents(ui_web_contents), | 663 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 654 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 664 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
| 655 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 665 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 656 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 666 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 657 } | 667 } |
| 658 | 668 |
| 659 } // namespace vr_shell | 669 } // namespace vr_shell |
| OLD | NEW |