| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "device/vr/android/gvr/gvr_device_provider.h" | 49 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 50 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" | 50 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
| 51 #include "gpu/command_buffer/common/mailbox.h" | 51 #include "gpu/command_buffer/common/mailbox.h" |
| 52 #include "jni/VrShellImpl_jni.h" | 52 #include "jni/VrShellImpl_jni.h" |
| 53 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 53 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 54 #include "ui/android/view_android.h" | 54 #include "ui/android/view_android.h" |
| 55 #include "ui/android/window_android.h" | 55 #include "ui/android/window_android.h" |
| 56 #include "ui/base/page_transition_types.h" | 56 #include "ui/base/page_transition_types.h" |
| 57 #include "ui/display/display.h" | 57 #include "ui/display/display.h" |
| 58 #include "ui/display/screen.h" | 58 #include "ui/display/screen.h" |
| 59 #include "ui/gfx/android/java_bitmap.h" |
| 59 #include "ui/gfx/codec/png_codec.h" | 60 #include "ui/gfx/codec/png_codec.h" |
| 60 #include "ui/gfx/geometry/size.h" | 61 #include "ui/gfx/geometry/size.h" |
| 61 #include "ui/gfx/native_widget_types.h" | 62 #include "ui/gfx/native_widget_types.h" |
| 62 #include "url/gurl.h" | 63 #include "url/gurl.h" |
| 63 | 64 |
| 64 using base::android::JavaParamRef; | 65 using base::android::JavaParamRef; |
| 65 using base::android::JavaRef; | 66 using base::android::JavaRef; |
| 66 | 67 |
| 67 namespace vr_shell { | 68 namespace vr_shell { |
| 68 | 69 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 87 vr_tab_helper->SetIsInVr(is_in_vr); | 88 vr_tab_helper->SetIsInVr(is_in_vr); |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 | 91 |
| 91 } // namespace | 92 } // namespace |
| 92 | 93 |
| 93 VrShell::VrShell(JNIEnv* env, | 94 VrShell::VrShell(JNIEnv* env, |
| 94 jobject obj, | 95 jobject obj, |
| 95 ui::WindowAndroid* window, | 96 ui::WindowAndroid* window, |
| 96 bool for_web_vr, | 97 bool for_web_vr, |
| 97 bool web_vr_autopresented, | 98 bool web_vr_autopresentation_expected, |
| 98 bool in_cct, | 99 bool in_cct, |
| 99 VrShellDelegate* delegate, | 100 VrShellDelegate* delegate, |
| 100 gvr_context* gvr_api, | 101 gvr_context* gvr_api, |
| 101 bool reprojected_rendering) | 102 bool reprojected_rendering) |
| 102 : vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)), | 103 : vr_shell_enabled_(base::FeatureList::IsEnabled(features::kVrShell)), |
| 103 window_(window), | 104 window_(window), |
| 104 compositor_(base::MakeUnique<VrCompositor>(window_)), | 105 compositor_(base::MakeUnique<VrCompositor>(window_)), |
| 105 delegate_provider_(delegate), | 106 delegate_provider_(delegate), |
| 106 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 107 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 107 reprojected_rendering_(reprojected_rendering), | 108 reprojected_rendering_(reprojected_rendering), |
| 108 weak_ptr_factory_(this) { | 109 weak_ptr_factory_(this) { |
| 109 DVLOG(1) << __FUNCTION__ << "=" << this; | 110 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 110 DCHECK(g_instance == nullptr); | 111 DCHECK(g_instance == nullptr); |
| 111 g_instance = this; | 112 g_instance = this; |
| 112 j_vr_shell_.Reset(env, obj); | 113 j_vr_shell_.Reset(env, obj); |
| 113 | 114 |
| 114 gl_thread_ = base::MakeUnique<VrGLThread>( | 115 gl_thread_ = base::MakeUnique<VrGLThread>( |
| 115 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, | 116 weak_ptr_factory_.GetWeakPtr(), main_thread_task_runner_, gvr_api, |
| 116 for_web_vr, web_vr_autopresented, in_cct, reprojected_rendering_, | 117 for_web_vr, web_vr_autopresentation_expected, in_cct, |
| 117 HasDaydreamSupport(env)); | 118 reprojected_rendering_, HasDaydreamSupport(env)); |
| 118 ui_ = gl_thread_.get(); | 119 ui_ = gl_thread_.get(); |
| 119 | 120 |
| 120 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); | 121 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); |
| 121 options.priority = base::ThreadPriority::DISPLAY; | 122 options.priority = base::ThreadPriority::DISPLAY; |
| 122 gl_thread_->StartWithOptions(options); | 123 gl_thread_->StartWithOptions(options); |
| 123 } | 124 } |
| 124 | 125 |
| 126 void VrShell::SetSplashScreenIcon(JNIEnv* env, |
| 127 const JavaParamRef<jobject>& obj, |
| 128 const JavaParamRef<jobject>& bitmap) { |
| 129 ui_->SetSplashScreenIcon( |
| 130 gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(bitmap))); |
| 131 } |
| 132 |
| 125 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 133 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 126 delete this; | 134 delete this; |
| 127 } | 135 } |
| 128 | 136 |
| 129 void VrShell::SwapContents( | 137 void VrShell::SwapContents( |
| 130 JNIEnv* env, | 138 JNIEnv* env, |
| 131 const JavaParamRef<jobject>& obj, | 139 const JavaParamRef<jobject>& obj, |
| 132 const JavaParamRef<jobject>& web_contents, | 140 const JavaParamRef<jobject>& web_contents, |
| 133 const JavaParamRef<jobject>& touch_event_synthesizer) { | 141 const JavaParamRef<jobject>& touch_event_synthesizer) { |
| 134 content::WebContents* contents = | 142 content::WebContents* contents = |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); | 338 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); |
| 331 WaitForGlThread(); | 339 WaitForGlThread(); |
| 332 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::InitializeGl, | 340 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::InitializeGl, |
| 333 gl_thread_->GetVrShellGl(), | 341 gl_thread_->GetVrShellGl(), |
| 334 base::Unretained(window))); | 342 base::Unretained(window))); |
| 335 } | 343 } |
| 336 | 344 |
| 337 void VrShell::SetWebVrMode(JNIEnv* env, | 345 void VrShell::SetWebVrMode(JNIEnv* env, |
| 338 const JavaParamRef<jobject>& obj, | 346 const JavaParamRef<jobject>& obj, |
| 339 bool enabled, | 347 bool enabled, |
| 340 bool auto_presented, | |
| 341 bool show_toast) { | 348 bool show_toast) { |
| 342 webvr_mode_ = enabled; | 349 webvr_mode_ = enabled; |
| 343 if (metrics_helper_) | 350 if (metrics_helper_) |
| 344 metrics_helper_->SetWebVREnabled(enabled); | 351 metrics_helper_->SetWebVREnabled(enabled); |
| 345 WaitForGlThread(); | 352 WaitForGlThread(); |
| 346 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::SetWebVrMode, | 353 PostToGlThread(FROM_HERE, base::Bind(&VrShellGl::SetWebVrMode, |
| 347 gl_thread_->GetVrShellGl(), enabled)); | 354 gl_thread_->GetVrShellGl(), enabled)); |
| 348 ui_->SetWebVrMode(enabled, auto_presented, show_toast); | 355 ui_->SetWebVrMode(enabled, show_toast); |
| 349 } | 356 } |
| 350 | 357 |
| 351 void VrShell::OnFullscreenChanged(bool enabled) { | 358 void VrShell::OnFullscreenChanged(bool enabled) { |
| 352 JNIEnv* env = base::android::AttachCurrentThread(); | 359 JNIEnv* env = base::android::AttachCurrentThread(); |
| 353 Java_VrShellImpl_onFullscreenChanged(env, j_vr_shell_.obj(), enabled); | 360 Java_VrShellImpl_onFullscreenChanged(env, j_vr_shell_.obj(), enabled); |
| 354 ui_->SetFullscreen(enabled); | 361 ui_->SetFullscreen(enabled); |
| 355 } | 362 } |
| 356 | 363 |
| 357 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 364 bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 358 return webvr_mode_; | 365 return webvr_mode_; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 | 708 |
| 702 // ---------------------------------------------------------------------------- | 709 // ---------------------------------------------------------------------------- |
| 703 // Native JNI methods | 710 // Native JNI methods |
| 704 // ---------------------------------------------------------------------------- | 711 // ---------------------------------------------------------------------------- |
| 705 | 712 |
| 706 jlong Init(JNIEnv* env, | 713 jlong Init(JNIEnv* env, |
| 707 const JavaParamRef<jobject>& obj, | 714 const JavaParamRef<jobject>& obj, |
| 708 const JavaParamRef<jobject>& delegate, | 715 const JavaParamRef<jobject>& delegate, |
| 709 jlong window_android, | 716 jlong window_android, |
| 710 jboolean for_web_vr, | 717 jboolean for_web_vr, |
| 711 jboolean web_vr_autopresented, | 718 jboolean web_vr_autopresentation_expected, |
| 712 jboolean in_cct, | 719 jboolean in_cct, |
| 713 jlong gvr_api, | 720 jlong gvr_api, |
| 714 jboolean reprojected_rendering) { | 721 jboolean reprojected_rendering) { |
| 715 return reinterpret_cast<intptr_t>(new VrShell( | 722 return reinterpret_cast<intptr_t>(new VrShell( |
| 716 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 723 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 717 for_web_vr, web_vr_autopresented, in_cct, | 724 for_web_vr, web_vr_autopresentation_expected, in_cct, |
| 718 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 725 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 719 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 726 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 720 } | 727 } |
| 721 | 728 |
| 722 } // namespace vr_shell | 729 } // namespace vr_shell |
| OLD | NEW |