| 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 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 28 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 31 #include "content/public/browser/render_widget_host.h" | 31 #include "content/public/browser/render_widget_host.h" |
| 32 #include "content/public/browser/render_widget_host_view.h" | 32 #include "content/public/browser/render_widget_host_view.h" |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/common/content_features.h" | 34 #include "content/public/common/content_features.h" |
| 35 #include "content/public/common/referrer.h" | 35 #include "content/public/common/referrer.h" |
| 36 #include "device/vr/android/gvr/gvr_device.h" | 36 #include "device/vr/android/gvr/gvr_device.h" |
| 37 #include "device/vr/android/gvr/gvr_device_provider.h" | 37 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 38 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| 38 #include "gpu/command_buffer/common/mailbox.h" | 39 #include "gpu/command_buffer/common/mailbox.h" |
| 39 #include "jni/VrShellImpl_jni.h" | 40 #include "jni/VrShellImpl_jni.h" |
| 40 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 41 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 41 #include "ui/android/view_android.h" | 42 #include "ui/android/view_android.h" |
| 42 #include "ui/android/window_android.h" | 43 #include "ui/android/window_android.h" |
| 43 #include "ui/base/page_transition_types.h" | 44 #include "ui/base/page_transition_types.h" |
| 44 #include "ui/display/display.h" | 45 #include "ui/display/display.h" |
| 45 #include "ui/display/screen.h" | 46 #include "ui/display/screen.h" |
| 46 #include "ui/gfx/transform.h" | 47 #include "ui/gfx/transform.h" |
| 47 #include "ui/gfx/transform_util.h" | 48 #include "ui/gfx/transform_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 content_window_(content_window), | 85 content_window_(content_window), |
| 85 content_compositor_( | 86 content_compositor_( |
| 86 base::MakeUnique<VrCompositor>(content_window_, false)), | 87 base::MakeUnique<VrCompositor>(content_window_, false)), |
| 87 ui_contents_(ui_contents), | 88 ui_contents_(ui_contents), |
| 88 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), | 89 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), |
| 89 delegate_provider_(delegate), | 90 delegate_provider_(delegate), |
| 90 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 91 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 91 reprojected_rendering_(reprojected_rendering), | 92 reprojected_rendering_(reprojected_rendering), |
| 92 gvr_api_(gvr_api), | 93 gvr_api_(gvr_api), |
| 93 weak_ptr_factory_(this) { | 94 weak_ptr_factory_(this) { |
| 95 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 94 DCHECK(g_instance == nullptr); | 96 DCHECK(g_instance == nullptr); |
| 95 g_instance = this; | 97 g_instance = this; |
| 96 j_vr_shell_.Reset(env, obj); | 98 j_vr_shell_.Reset(env, obj); |
| 97 | 99 |
| 98 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); | 100 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); |
| 99 ui_compositor_->SetLayer(ui_contents_); | 101 ui_compositor_->SetLayer(ui_contents_); |
| 100 | 102 |
| 101 gl_thread_ = base::MakeUnique<VrGLThread>(weak_ptr_factory_.GetWeakPtr(), | 103 gl_thread_ = base::MakeUnique<VrGLThread>(weak_ptr_factory_.GetWeakPtr(), |
| 102 main_thread_task_runner_, gvr_api, | 104 main_thread_task_runner_, gvr_api, |
| 103 for_web_vr, reprojected_rendering_); | 105 for_web_vr, reprojected_rendering_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 ui_contents_->GetController().LoadURL( | 172 ui_contents_->GetController().LoadURL( |
| 171 url, content::Referrer(), | 173 url, content::Referrer(), |
| 172 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); | 174 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); |
| 173 } | 175 } |
| 174 | 176 |
| 175 bool RegisterVrShell(JNIEnv* env) { | 177 bool RegisterVrShell(JNIEnv* env) { |
| 176 return RegisterNativesImpl(env); | 178 return RegisterNativesImpl(env); |
| 177 } | 179 } |
| 178 | 180 |
| 179 VrShell::~VrShell() { | 181 VrShell::~VrShell() { |
| 182 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 183 if (gamepad_source_active_) { |
| 184 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| 185 device::GAMEPAD_SOURCE_GVR); |
| 186 } |
| 187 |
| 180 delegate_provider_->RemoveDelegate(); | 188 delegate_provider_->RemoveDelegate(); |
| 181 { | 189 { |
| 182 // The GvrLayout is, and must always be, used only on the UI thread, and the | 190 // The GvrLayout is, and must always be, used only on the UI thread, and the |
| 183 // GvrApi used for rendering should only be used from the GL thread as it's | 191 // GvrApi used for rendering should only be used from the GL thread as it's |
| 184 // not thread safe. However, the GvrLayout owns the GvrApi instance, and | 192 // not thread safe. However, the GvrLayout owns the GvrApi instance, and |
| 185 // when it gets shut down it deletes the GvrApi instance with it. Therefore, | 193 // when it gets shut down it deletes the GvrApi instance with it. Therefore, |
| 186 // we need to block shutting down the GvrLayout on stopping our GL thread | 194 // we need to block shutting down the GvrLayout on stopping our GL thread |
| 187 // from using the GvrApi instance. | 195 // from using the GvrApi instance. |
| 188 // base::Thread::Stop, which is called when destroying the thread, asserts | 196 // base::Thread::Stop, which is called when destroying the thread, asserts |
| 189 // that IO is allowed to prevent jank, but there shouldn't be any concerns | 197 // that IO is allowed to prevent jank, but there shouldn't be any concerns |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 625 |
| 618 void VrShell::ProcessContentGesture( | 626 void VrShell::ProcessContentGesture( |
| 619 std::unique_ptr<blink::WebInputEvent> event) { | 627 std::unique_ptr<blink::WebInputEvent> event) { |
| 620 if (content_input_manager_) { | 628 if (content_input_manager_) { |
| 621 content_input_manager_->ProcessUpdatedGesture(std::move(event)); | 629 content_input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 622 } else if (android_ui_gesture_target_) { | 630 } else if (android_ui_gesture_target_) { |
| 623 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); | 631 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); |
| 624 } | 632 } |
| 625 } | 633 } |
| 626 | 634 |
| 635 void VrShell::UpdateGamepadData(device::GvrGamepadData pad) { |
| 636 if (!gamepad_source_active_) { |
| 637 if (!delegate_provider_->device_provider()) |
| 638 return; |
| 639 |
| 640 unsigned int device_id = |
| 641 delegate_provider_->device_provider()->Device()->id(); |
| 642 device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
| 643 new device::GvrGamepadDataFetcher::Factory(this, device_id)); |
| 644 gamepad_source_active_ = true; |
| 645 } |
| 646 if (gamepad_data_fetcher_) { |
| 647 gamepad_data_fetcher_->SetGamepadData(pad); |
| 648 } |
| 649 } |
| 650 |
| 651 void VrShell::RegisterGamepadDataFetcher( |
| 652 device::GvrGamepadDataFetcher* fetcher) { |
| 653 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; |
| 654 gamepad_data_fetcher_ = fetcher; |
| 655 } |
| 656 |
| 627 /* static */ | 657 /* static */ |
| 628 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { | 658 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { |
| 629 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); | 659 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
| 630 | 660 |
| 631 pose->orientation.emplace(4); | 661 pose->orientation.emplace(4); |
| 632 | 662 |
| 633 gfx::Transform inv_transform( | 663 gfx::Transform inv_transform( |
| 634 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], | 664 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], |
| 635 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], | 665 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], |
| 636 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], | 666 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 jboolean reprojected_rendering) { | 779 jboolean reprojected_rendering) { |
| 750 return reinterpret_cast<intptr_t>(new VrShell( | 780 return reinterpret_cast<intptr_t>(new VrShell( |
| 751 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 781 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 752 content::WebContents::FromJavaWebContents(ui_web_contents), | 782 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 753 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 783 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
| 754 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 784 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 755 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 785 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 756 } | 786 } |
| 757 | 787 |
| 758 } // namespace vr_shell | 788 } // namespace vr_shell |
| OLD | NEW |