| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 ui_contents_->GetController().LoadURL( | 171 ui_contents_->GetController().LoadURL( |
| 171 url, content::Referrer(), | 172 url, content::Referrer(), |
| 172 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); | 173 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); |
| 173 } | 174 } |
| 174 | 175 |
| 175 bool RegisterVrShell(JNIEnv* env) { | 176 bool RegisterVrShell(JNIEnv* env) { |
| 176 return RegisterNativesImpl(env); | 177 return RegisterNativesImpl(env); |
| 177 } | 178 } |
| 178 | 179 |
| 179 VrShell::~VrShell() { | 180 VrShell::~VrShell() { |
| 181 if (gamepad_source_active_) { |
| 182 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| 183 device::GAMEPAD_SOURCE_GVR); |
| 184 } |
| 185 |
| 180 delegate_provider_->RemoveDelegate(); | 186 delegate_provider_->RemoveDelegate(); |
| 181 { | 187 { |
| 182 // The GvrLayout is, and must always be, used only on the UI thread, and the | 188 // 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 | 189 // 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 | 190 // 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, | 191 // 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 | 192 // we need to block shutting down the GvrLayout on stopping our GL thread |
| 187 // from using the GvrApi instance. | 193 // from using the GvrApi instance. |
| 188 // base::Thread::Stop, which is called when destroying the thread, asserts | 194 // 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 | 195 // 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 | 623 |
| 618 void VrShell::ProcessContentGesture( | 624 void VrShell::ProcessContentGesture( |
| 619 std::unique_ptr<blink::WebInputEvent> event) { | 625 std::unique_ptr<blink::WebInputEvent> event) { |
| 620 if (content_input_manager_) { | 626 if (content_input_manager_) { |
| 621 content_input_manager_->ProcessUpdatedGesture(std::move(event)); | 627 content_input_manager_->ProcessUpdatedGesture(std::move(event)); |
| 622 } else if (android_ui_gesture_target_) { | 628 } else if (android_ui_gesture_target_) { |
| 623 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); | 629 android_ui_gesture_target_->DispatchWebInputEvent(std::move(event)); |
| 624 } | 630 } |
| 625 } | 631 } |
| 626 | 632 |
| 633 void VrShell::GamepadDataUpdate(device::GvrGamepadData pad) { |
| 634 if (!gamepad_source_active_) { |
| 635 if (!delegate_provider_->device_provider()) |
| 636 return; |
| 637 |
| 638 unsigned int device_id = |
| 639 delegate_provider_->device_provider()->Device()->id(); |
| 640 device::GamepadDataFetcherManager::GetInstance()->AddFactory( |
| 641 new device::GvrGamepadDataFetcher::Factory(this, device_id)); |
| 642 gamepad_source_active_ = true; |
| 643 } |
| 644 gamepad_data_ = pad; |
| 645 } |
| 646 |
| 647 device::GvrGamepadData VrShell::GamepadDataGet() { |
| 648 return gamepad_data_; |
| 649 } |
| 650 |
| 627 /* static */ | 651 /* static */ |
| 628 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { | 652 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { |
| 629 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); | 653 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
| 630 | 654 |
| 631 pose->orientation.emplace(4); | 655 pose->orientation.emplace(4); |
| 632 | 656 |
| 633 gfx::Transform inv_transform( | 657 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], | 658 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], | 659 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], | 660 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) { | 773 jboolean reprojected_rendering) { |
| 750 return reinterpret_cast<intptr_t>(new VrShell( | 774 return reinterpret_cast<intptr_t>(new VrShell( |
| 751 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 775 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 752 content::WebContents::FromJavaWebContents(ui_web_contents), | 776 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 753 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 777 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
| 754 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 778 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 755 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 779 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 756 } | 780 } |
| 757 | 781 |
| 758 } // namespace vr_shell | 782 } // namespace vr_shell |
| OLD | NEW |