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 19 matching lines...) Expand all Loading... |
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 "jni/VrShellImpl_jni.h" | 38 #include "jni/VrShellImpl_jni.h" |
39 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 39 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
40 #include "ui/android/view_android.h" | 40 #include "ui/android/view_root.h" |
41 #include "ui/android/window_android.h" | |
42 #include "ui/base/page_transition_types.h" | 41 #include "ui/base/page_transition_types.h" |
43 #include "ui/display/display.h" | 42 #include "ui/display/display.h" |
44 #include "ui/display/screen.h" | 43 #include "ui/display/screen.h" |
45 #include "ui/gfx/transform.h" | 44 #include "ui/gfx/transform.h" |
46 #include "ui/gfx/transform_util.h" | 45 #include "ui/gfx/transform_util.h" |
47 | 46 |
48 using base::android::JavaParamRef; | 47 using base::android::JavaParamRef; |
49 using base::android::JavaRef; | 48 using base::android::JavaRef; |
50 | 49 |
51 namespace vr_shell { | 50 namespace vr_shell { |
52 | 51 |
53 namespace { | 52 namespace { |
54 vr_shell::VrShell* g_instance; | 53 vr_shell::VrShell* g_instance; |
55 | 54 |
56 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; | 55 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; |
57 | 56 |
58 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { | 57 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { |
59 if (contents && contents->GetRenderWidgetHostView()) | 58 if (contents && contents->GetRenderWidgetHostView()) |
60 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); | 59 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); |
61 } | 60 } |
62 | 61 |
63 } // namespace | 62 } // namespace |
64 | 63 |
65 VrShell::VrShell(JNIEnv* env, | 64 VrShell::VrShell(JNIEnv* env, |
66 jobject obj, | 65 jobject obj, |
67 ui::WindowAndroid* content_window, | 66 ui::ViewRoot* content_view_root, |
68 content::WebContents* ui_contents, | 67 content::WebContents* ui_contents, |
69 ui::WindowAndroid* ui_window, | 68 ui::ViewRoot* ui_view_root, |
70 bool for_web_vr, | 69 bool for_web_vr, |
71 VrShellDelegate* delegate, | 70 VrShellDelegate* delegate, |
72 gvr_context* gvr_api, | 71 gvr_context* gvr_api, |
73 bool reprojected_rendering) | 72 bool reprojected_rendering) |
74 : WebContentsObserver(ui_contents), | 73 : WebContentsObserver(ui_contents), |
75 vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)), | 74 vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)), |
76 content_window_(content_window), | 75 content_view_root_(content_view_root), |
77 content_compositor_( | 76 content_compositor_( |
78 base::MakeUnique<VrCompositor>(content_window_, false)), | 77 base::MakeUnique<VrCompositor>(content_view_root, false)), |
79 ui_contents_(ui_contents), | 78 ui_contents_(ui_contents), |
80 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), | 79 ui_compositor_(base::MakeUnique<VrCompositor>(ui_view_root, true)), |
81 delegate_provider_(delegate), | 80 delegate_provider_(delegate), |
82 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 81 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
83 reprojected_rendering_(reprojected_rendering), | 82 reprojected_rendering_(reprojected_rendering), |
84 gvr_api_(gvr_api), | 83 gvr_api_(gvr_api), |
85 weak_ptr_factory_(this) { | 84 weak_ptr_factory_(this) { |
86 DCHECK(g_instance == nullptr); | 85 DCHECK(g_instance == nullptr); |
87 g_instance = this; | 86 g_instance = this; |
88 j_vr_shell_.Reset(env, obj); | 87 j_vr_shell_.Reset(env, obj); |
89 | 88 |
90 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); | 89 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 void VrShell::MainFrameWasResized(bool width_changed) { | 474 void VrShell::MainFrameWasResized(bool width_changed) { |
476 display::Display display = display::Screen::GetScreen() | 475 display::Display display = display::Screen::GetScreen() |
477 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); | 476 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); |
478 PostToGlThreadWhenReady( | 477 PostToGlThreadWhenReady( |
479 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(), | 478 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(), |
480 display.size().width(), display.size().height())); | 479 display.size().width(), display.size().height())); |
481 } | 480 } |
482 | 481 |
483 void VrShell::ContentFrameWasResized(bool width_changed) { | 482 void VrShell::ContentFrameWasResized(bool width_changed) { |
484 display::Display display = | 483 display::Display display = |
485 display::Screen::GetScreen()->GetDisplayNearestWindow(content_window_); | 484 display::Screen::GetScreen()->GetDisplayNearestWindowAndroid( |
| 485 content_view_root_->GetWindowAndroid()); |
486 PostToGlThreadWhenReady( | 486 PostToGlThreadWhenReady( |
487 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(), | 487 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(), |
488 display.size().width(), display.size().height())); | 488 display.size().width(), display.size().height())); |
489 } | 489 } |
490 | 490 |
491 void VrShell::WebContentsDestroyed() { | 491 void VrShell::WebContentsDestroyed() { |
492 ui_input_manager_.reset(); | 492 ui_input_manager_.reset(); |
493 ui_contents_ = nullptr; | 493 ui_contents_ = nullptr; |
494 // TODO(mthiesse): Handle web contents being destroyed. | 494 // TODO(mthiesse): Handle web contents being destroyed. |
495 ForceExitVr(); | 495 ForceExitVr(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 return device; | 636 return device; |
637 } | 637 } |
638 | 638 |
639 // ---------------------------------------------------------------------------- | 639 // ---------------------------------------------------------------------------- |
640 // Native JNI methods | 640 // Native JNI methods |
641 // ---------------------------------------------------------------------------- | 641 // ---------------------------------------------------------------------------- |
642 | 642 |
643 jlong Init(JNIEnv* env, | 643 jlong Init(JNIEnv* env, |
644 const JavaParamRef<jobject>& obj, | 644 const JavaParamRef<jobject>& obj, |
645 const JavaParamRef<jobject>& ui_web_contents, | 645 const JavaParamRef<jobject>& ui_web_contents, |
646 jlong content_window_android, | 646 jlong content_view_root, |
647 jlong ui_window_android, | 647 jlong ui_view_root, |
648 jboolean for_web_vr, | 648 jboolean for_web_vr, |
649 const base::android::JavaParamRef<jobject>& delegate, | 649 const base::android::JavaParamRef<jobject>& delegate, |
650 jlong gvr_api, | 650 jlong gvr_api, |
651 jboolean reprojected_rendering) { | 651 jboolean reprojected_rendering) { |
652 return reinterpret_cast<intptr_t>(new VrShell( | 652 return reinterpret_cast<intptr_t>(new VrShell( |
653 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 653 env, obj, reinterpret_cast<ui::ViewRoot*>(content_view_root), |
654 content::WebContents::FromJavaWebContents(ui_web_contents), | 654 content::WebContents::FromJavaWebContents(ui_web_contents), |
655 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 655 reinterpret_cast<ui::ViewRoot*>(ui_view_root), for_web_vr, |
656 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 656 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
657 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 657 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
658 } | 658 } |
659 | 659 |
660 } // namespace vr_shell | 660 } // namespace vr_shell |
OLD | NEW |