| 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 "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/android/vr_shell/ui_interface.h" | 15 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 16 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 16 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 17 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 17 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 18 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 18 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 19 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 19 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 20 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 20 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 21 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 21 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 22 #include "content/public/browser/android/video_surface_manager.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/render_widget_host.h" | 25 #include "content/public/browser/render_widget_host.h" |
| 25 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/common/referrer.h" | 28 #include "content/public/common/referrer.h" |
| 28 #include "device/vr/android/gvr/gvr_device_provider.h" | 29 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 29 #include "jni/VrShellImpl_jni.h" | 30 #include "jni/VrShellImpl_jni.h" |
| 30 #include "ui/android/view_android.h" | 31 #include "ui/android/view_android.h" |
| 31 #include "ui/android/window_android.h" | 32 #include "ui/android/window_android.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 144 |
| 144 if (for_web_vr) | 145 if (for_web_vr) |
| 145 metrics_helper_->SetWebVREnabled(true); | 146 metrics_helper_->SetWebVREnabled(true); |
| 146 html_interface_.reset(new UiInterface( | 147 html_interface_.reset(new UiInterface( |
| 147 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, | 148 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, |
| 148 main_contents_->IsFullscreen())); | 149 main_contents_->IsFullscreen())); |
| 149 vr_web_contents_observer_.reset(new VrWebContentsObserver( | 150 vr_web_contents_observer_.reset(new VrWebContentsObserver( |
| 150 main_contents, html_interface_.get(), this)); | 151 main_contents, html_interface_.get(), this)); |
| 151 | 152 |
| 152 SetShowingOverscrollGlow(false); | 153 SetShowingOverscrollGlow(false); |
| 154 content::VideoSurfaceManager::GetInstance()-> |
| 155 SetOverrideVideoSurfaceProvider(this); |
| 153 } | 156 } |
| 154 | 157 |
| 155 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 158 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 159 content::VideoSurfaceManager::GetInstance()-> |
| 160 RemoveOverrideVideoSurfaceProvider(this); |
| 156 delete this; | 161 delete this; |
| 157 } | 162 } |
| 158 | 163 |
| 159 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 164 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 160 GURL url(kVrShellUIURL); | 165 GURL url(kVrShellUIURL); |
| 161 ui_contents_->GetController().LoadURL( | 166 ui_contents_->GetController().LoadURL( |
| 162 url, content::Referrer(), | 167 url, content::Referrer(), |
| 163 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); | 168 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); |
| 164 } | 169 } |
| 165 | 170 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 JNIEnv* env = base::android::AttachCurrentThread(); | 461 JNIEnv* env = base::android::AttachCurrentThread(); |
| 457 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 462 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
| 458 dpr); | 463 dpr); |
| 459 } | 464 } |
| 460 | 465 |
| 461 void VrShell::SetUiCssSize(float width, float height, float dpr) { | 466 void VrShell::SetUiCssSize(float width, float height, float dpr) { |
| 462 JNIEnv* env = base::android::AttachCurrentThread(); | 467 JNIEnv* env = base::android::AttachCurrentThread(); |
| 463 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); | 468 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); |
| 464 } | 469 } |
| 465 | 470 |
| 471 void VrShell::OnVideoSizeChanged(int width, int height) { |
| 472 // TODO(amp): Do something intelligent with the size. |
| 473 } |
| 474 |
| 475 void VrShell::CreateVideoSurface(content::VideoSurfaceProvider::Client* client, |
| 476 const gfx::Size& video_natural_size) { |
| 477 client_ = client; |
| 478 JNIEnv* env = base::android::AttachCurrentThread(); |
| 479 Java_VrShellImpl_createVideoSurface(env, j_vr_shell_.obj()); |
| 480 // TODO(amp): Use the natural size somehow. |
| 481 } |
| 482 |
| 483 void VrShell::SetVideoSurface(JNIEnv*, |
| 484 const JavaParamRef<jobject>&, |
| 485 const JavaParamRef<jobject>& surface) { |
| 486 client_->SetVideoSurface( |
| 487 gl::ScopedJavaSurface::AcquireExternalSurface(surface)); |
| 488 } |
| 489 |
| 466 // ---------------------------------------------------------------------------- | 490 // ---------------------------------------------------------------------------- |
| 467 // Native JNI methods | 491 // Native JNI methods |
| 468 // ---------------------------------------------------------------------------- | 492 // ---------------------------------------------------------------------------- |
| 469 | 493 |
| 470 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, | 494 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, |
| 471 const JavaParamRef<jobject>& content_web_contents, | 495 const JavaParamRef<jobject>& content_web_contents, |
| 472 jlong content_window_android, | 496 jlong content_window_android, |
| 473 const JavaParamRef<jobject>& ui_web_contents, | 497 const JavaParamRef<jobject>& ui_web_contents, |
| 474 jlong ui_window_android, jboolean for_web_vr, | 498 jlong ui_window_android, jboolean for_web_vr, |
| 475 const base::android::JavaParamRef<jobject>& delegate, | 499 const base::android::JavaParamRef<jobject>& delegate, |
| 476 jlong gvr_api, jboolean reprojected_rendering) { | 500 jlong gvr_api, jboolean reprojected_rendering) { |
| 477 return reinterpret_cast<intptr_t>(new VrShell( | 501 return reinterpret_cast<intptr_t>(new VrShell( |
| 478 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 502 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 479 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 503 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 480 content::WebContents::FromJavaWebContents(ui_web_contents), | 504 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 481 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 505 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
| 482 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 506 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), |
| 483 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 507 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 484 } | 508 } |
| 485 | 509 |
| 486 } // namespace vr_shell | 510 } // namespace vr_shell |
| OLD | NEW |