| 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, | 110 void VrShell::SwapContents( |
| 110 const JavaParamRef<jobject>& obj, | 111 JNIEnv* env, |
| 111 const JavaParamRef<jobject>& web_contents) { | 112 const JavaParamRef<jobject>& obj, |
| 113 const JavaParamRef<jobject>& web_contents, |
| 114 const JavaParamRef<jobject>& touch_event_synthesizer) { |
| 112 content::WebContents* contents = | 115 content::WebContents* contents = |
| 113 content::WebContents::FromJavaWebContents(web_contents); | 116 content::WebContents::FromJavaWebContents(web_contents); |
| 114 if (contents == main_contents_) | 117 if (contents == main_contents_ && |
| 118 touch_event_synthesizer.obj() == j_motion_event_synthesizer_.obj()) |
| 115 return; | 119 return; |
| 116 | 120 |
| 117 SetIsInVR(main_contents_, false); | 121 SetIsInVR(main_contents_, false); |
| 118 | 122 j_motion_event_synthesizer_.Reset(env, touch_event_synthesizer); |
| 119 main_contents_ = contents; | 123 main_contents_ = contents; |
| 120 content_compositor_->SetLayer(main_contents_); | 124 content_compositor_->SetLayer(main_contents_); |
| 121 SetIsInVR(main_contents_, true); | 125 SetIsInVR(main_contents_, true); |
| 122 ContentFrameWasResized(false /* unused */); | 126 ContentFrameWasResized(false /* unused */); |
| 123 SetUiState(); | 127 SetUiState(); |
| 124 | 128 |
| 125 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())); |
| 126 content_input_manager_ = nullptr; | 133 content_input_manager_ = nullptr; |
| 127 vr_web_contents_observer_ = nullptr; | 134 vr_web_contents_observer_ = nullptr; |
| 128 metrics_helper_ = nullptr; | 135 metrics_helper_ = nullptr; |
| 129 return; | 136 return; |
| 130 } | 137 } |
| 131 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); | 138 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); |
| 132 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( | 139 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( |
| 133 main_contents_, html_interface_.get(), this); | 140 main_contents_, html_interface_.get(), this); |
| 134 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple | 141 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple |
| 135 // tabs. crbug.com/684661 | 142 // tabs. crbug.com/684661 |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 void VrShell::ProcessUIGesture(std::unique_ptr<blink::WebInputEvent> event) { | 567 void VrShell::ProcessUIGesture(std::unique_ptr<blink::WebInputEvent> event) { |
| 561 if (ui_input_manager_) { | 568 if (ui_input_manager_) { |
| 562 ui_input_manager_->ProcessUpdatedGesture(std::move(event)); | 569 ui_input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 563 } | 570 } |
| 564 } | 571 } |
| 565 | 572 |
| 566 void VrShell::ProcessContentGesture( | 573 void VrShell::ProcessContentGesture( |
| 567 std::unique_ptr<blink::WebInputEvent> event) { | 574 std::unique_ptr<blink::WebInputEvent> event) { |
| 568 if (content_input_manager_) { | 575 if (content_input_manager_) { |
| 569 content_input_manager_->ProcessUpdatedGesture(std::move(event)); | 576 content_input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 577 } else if (android_ui_gesture_target_) { |
| 578 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); |
| 570 } | 579 } |
| 571 } | 580 } |
| 572 | 581 |
| 573 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { | 582 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { |
| 574 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); | 583 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
| 575 | 584 |
| 576 pose->timestamp = base::Time::Now().ToJsTime(); | 585 pose->timestamp = base::Time::Now().ToJsTime(); |
| 577 pose->orientation.emplace(4); | 586 pose->orientation.emplace(4); |
| 578 | 587 |
| 579 gfx::Transform inv_transform( | 588 gfx::Transform inv_transform( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 jboolean reprojected_rendering) { | 676 jboolean reprojected_rendering) { |
| 668 return reinterpret_cast<intptr_t>(new VrShell( | 677 return reinterpret_cast<intptr_t>(new VrShell( |
| 669 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 678 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 670 content::WebContents::FromJavaWebContents(ui_web_contents), | 679 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 671 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 680 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
| 672 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 681 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 673 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 682 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 674 } | 683 } |
| 675 | 684 |
| 676 } // namespace vr_shell | 685 } // namespace vr_shell |
| OLD | NEW |