Chromium Code Reviews| 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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "chrome/browser/android/vr_shell/ui_elements.h" | 8 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_interface.h" | 9 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_scene.h" | 10 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 144 |
| 145 } // namespace | 145 } // namespace |
| 146 | 146 |
| 147 namespace vr_shell { | 147 namespace vr_shell { |
| 148 | 148 |
| 149 VrShell::VrShell(JNIEnv* env, | 149 VrShell::VrShell(JNIEnv* env, |
| 150 jobject obj, | 150 jobject obj, |
| 151 content::WebContents* main_contents, | 151 content::WebContents* main_contents, |
| 152 ui::WindowAndroid* content_window, | 152 ui::WindowAndroid* content_window, |
| 153 content::WebContents* ui_contents, | 153 content::WebContents* ui_contents, |
| 154 ui::WindowAndroid* ui_window) | 154 ui::WindowAndroid* ui_window, |
| 155 bool for_web_vr) | |
| 155 : WebContentsObserver(ui_contents), | 156 : WebContentsObserver(ui_contents), |
| 156 main_contents_(main_contents), | 157 main_contents_(main_contents), |
| 157 ui_contents_(ui_contents), | 158 ui_contents_(ui_contents), |
| 158 metrics_helper_(new VrMetricsHelper(main_contents)), | 159 metrics_helper_(new VrMetricsHelper(main_contents)), |
| 159 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 160 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 160 weak_ptr_factory_(this) { | 161 weak_ptr_factory_(this) { |
| 161 DCHECK(g_instance == nullptr); | 162 DCHECK(g_instance == nullptr); |
| 162 g_instance = this; | 163 g_instance = this; |
| 163 j_vr_shell_.Reset(env, obj); | 164 j_vr_shell_.Reset(env, obj); |
| 164 scene_.reset(new UiScene); | 165 scene_.reset(new UiScene); |
| 165 html_interface_.reset(new UiInterface); | 166 |
| 167 if (for_web_vr) | |
| 168 metrics_helper_->SetWebVREnabled(true); | |
|
amp
2016/11/28 23:09:49
Doesn't this need to be set to false in the non-we
mthiesse
2016/11/28 23:30:12
I would think not, because we're not setting WebVR
billorr
2016/11/29 00:05:31
It defaults to false, so we should only need this
mthiesse
2016/11/29 03:53:15
Ah, I didn't know that was how it worked. I'm goin
| |
| 169 html_interface_.reset(new UiInterface( | |
| 170 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD)); | |
| 166 content_compositor_.reset(new VrCompositor(content_window, false)); | 171 content_compositor_.reset(new VrCompositor(content_window, false)); |
| 167 ui_compositor_.reset(new VrCompositor(ui_window, true)); | 172 ui_compositor_.reset(new VrCompositor(ui_window, true)); |
| 168 vr_web_contents_observer_.reset( | 173 vr_web_contents_observer_.reset( |
| 169 new VrWebContentsObserver(main_contents, html_interface_.get())); | 174 new VrWebContentsObserver(main_contents, html_interface_.get())); |
| 170 | 175 |
| 171 LoadUIContent(); | 176 LoadUIContent(); |
| 172 | 177 |
| 173 gvr::Mat4f identity; | 178 gvr::Mat4f identity; |
| 174 SetIdentityM(identity); | 179 SetIdentityM(identity); |
| 175 webvr_head_pose_.resize(kPoseRingBufferSize, identity); | 180 webvr_head_pose_.resize(kPoseRingBufferSize, identity); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 DAYDREAM = 2, | 228 DAYDREAM = 2, |
| 224 VIEWER_TYPE_MAX, | 229 VIEWER_TYPE_MAX, |
| 225 }; | 230 }; |
| 226 | 231 |
| 227 void VrShell::GvrInit(JNIEnv* env, | 232 void VrShell::GvrInit(JNIEnv* env, |
| 228 const JavaParamRef<jobject>& obj, | 233 const JavaParamRef<jobject>& obj, |
| 229 jlong native_gvr_api) { | 234 jlong native_gvr_api) { |
| 230 base::AutoLock lock(gvr_init_lock_); | 235 base::AutoLock lock(gvr_init_lock_); |
| 231 | 236 |
| 232 // set the initial webvr state | 237 // set the initial webvr state |
| 233 metrics_helper_->SetWebVREnabled(webvr_mode_); | |
| 234 metrics_helper_->SetVRActive(true); | 238 metrics_helper_->SetVRActive(true); |
| 235 | 239 |
| 236 gvr_api_ = | 240 gvr_api_ = |
| 237 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); | 241 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(native_gvr_api)); |
| 238 // TODO(klausw,crbug.com/655722): should report OnGvrDelegateReady here once | 242 // TODO(klausw,crbug.com/655722): should report OnGvrDelegateReady here once |
| 239 // we switch to using a WebVR render surface. We currently need to wait for | 243 // we switch to using a WebVR render surface. We currently need to wait for |
| 240 // the compositor window's size to be known first. See also | 244 // the compositor window's size to be known first. See also |
| 241 // ContentSurfaceChanged. | 245 // ContentSurfaceChanged. |
| 242 controller_.reset( | 246 controller_.reset( |
| 243 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); | 247 new VrController(reinterpret_cast<gvr_context*>(native_gvr_api))); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); | 346 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); |
| 343 } | 347 } |
| 344 | 348 |
| 345 void VrShell::UpdateController(const gvr::Vec3f& forward_vector) { | 349 void VrShell::UpdateController(const gvr::Vec3f& forward_vector) { |
| 346 controller_->UpdateState(); | 350 controller_->UpdateState(); |
| 347 | 351 |
| 348 #if defined(ENABLE_VR_SHELL) | 352 #if defined(ENABLE_VR_SHELL) |
| 349 // Note that button up/down state is transient, so IsButtonUp only returns | 353 // Note that button up/down state is transient, so IsButtonUp only returns |
| 350 // true for a single frame (and we're guaranteed not to miss it). | 354 // true for a single frame (and we're guaranteed not to miss it). |
| 351 if (controller_->IsButtonUp( | 355 if (controller_->IsButtonUp( |
| 352 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) { | 356 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) { |
| 353 if (html_interface_->GetMode() == UiInterface::Mode::MENU) { | 357 // TODO(mthiesse): The page is no longer visible when in menu mode. We |
| 354 // Temporary: Hit app button a second time to exit menu mode. | 358 // should unfocus or otherwise let it know it's hidden. |
| 355 if (webvr_mode_) { | 359 switch (html_interface_->GetMode()) { |
|
cjgrant
2016/11/28 22:21:09
This block looks odd to me for a few reasons:
- We
amp
2016/11/28 23:09:49
+1 to trying to model this differently. The TODO
mthiesse
2016/11/28 23:28:34
Well okay Mr. "I care about long term health", I g
cjgrant
2016/11/29 02:26:35
LOL!
| |
| 360 case UiInterface::Mode::WEB_VR_MENU: | |
| 356 html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 361 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
| 357 main_thread_task_runner_->PostTask( | 362 main_thread_task_runner_->PostTask( |
| 358 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayFocus, | 363 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayFocus, |
| 359 delegate_->GetDeviceProvider())); | 364 delegate_->GetDeviceProvider())); |
| 360 } else { | 365 break; |
| 366 case UiInterface::Mode::STANDARD_MENU: | |
| 361 html_interface_->SetMode(UiInterface::Mode::STANDARD); | 367 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
| 362 } | 368 break; |
| 363 } else { | 369 case UiInterface::Mode::WEB_VR: |
| 364 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | |
| 365 main_thread_task_runner_->PostTask( | 370 main_thread_task_runner_->PostTask( |
| 366 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayBlur, | 371 FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayBlur, |
| 367 delegate_->GetDeviceProvider())); | 372 delegate_->GetDeviceProvider())); |
| 368 } | 373 html_interface_->SetMode(UiInterface::Mode::WEB_VR_MENU); |
| 369 html_interface_->SetMode(UiInterface::Mode::MENU); | 374 break; |
| 370 // TODO(mthiesse): The page is no longer visible here. We should unfocus | 375 case UiInterface::Mode::CINEMA: |
| 371 // or otherwise let it know it's hidden. | 376 // TODO(amp): Handle returning to CINEMA mode when returning from the |
| 377 // menu. For now fall through to STANDARD mode behavior. | |
| 378 case UiInterface::Mode::STANDARD: | |
| 379 html_interface_->SetMode(UiInterface::Mode::STANDARD_MENU); | |
| 380 break; | |
| 372 } | 381 } |
| 373 } | 382 } |
| 374 #endif | 383 #endif |
| 375 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | 384 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 376 // Process screen touch events for Cardboard button compatibility. | 385 // Process screen touch events for Cardboard button compatibility. |
| 377 // Also send tap events for controller "touchpad click" events. | 386 // Also send tap events for controller "touchpad click" events. |
| 378 if (touch_pending_ || controller_->IsButtonUp( | 387 if (touch_pending_ || controller_->IsButtonUp( |
| 379 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { | 388 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { |
| 380 touch_pending_ = false; | 389 touch_pending_ = false; |
| 381 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); | 390 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 | 905 |
| 897 void VrShell::OnDomContentsLoaded() { | 906 void VrShell::OnDomContentsLoaded() { |
| 898 html_interface_->SetURL(main_contents_->GetVisibleURL()); | 907 html_interface_->SetURL(main_contents_->GetVisibleURL()); |
| 899 html_interface_->SetLoading(main_contents_->IsLoading()); | 908 html_interface_->SetLoading(main_contents_->IsLoading()); |
| 900 html_interface_->OnDomContentsLoaded(); | 909 html_interface_->OnDomContentsLoaded(); |
| 901 } | 910 } |
| 902 | 911 |
| 903 void VrShell::SetWebVrMode(JNIEnv* env, | 912 void VrShell::SetWebVrMode(JNIEnv* env, |
| 904 const base::android::JavaParamRef<jobject>& obj, | 913 const base::android::JavaParamRef<jobject>& obj, |
| 905 bool enabled) { | 914 bool enabled) { |
| 906 webvr_mode_ = enabled; | 915 metrics_helper_->SetWebVREnabled(enabled); |
| 907 metrics_helper_->SetWebVREnabled(webvr_mode_); | |
| 908 if (enabled) { | 916 if (enabled) { |
| 909 html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 917 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
| 910 } else { | 918 } else { |
| 911 html_interface_->SetMode(UiInterface::Mode::STANDARD); | 919 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
| 912 } | 920 } |
| 913 } | 921 } |
| 914 | 922 |
| 915 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 923 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
| 916 html_interface_->SetSecureOrigin(secure_origin); | 924 html_interface_->SetSecureOrigin(secure_origin); |
| 917 } | 925 } |
| 918 | 926 |
| 919 void VrShell::SubmitWebVRFrame() { | 927 void VrShell::SubmitWebVRFrame() {} |
| 920 } | |
| 921 | 928 |
| 922 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 929 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, |
| 923 const gvr::Rectf& right_bounds) { | 930 const gvr::Rectf& right_bounds) { |
| 924 webvr_left_viewport_->SetSourceUv(left_bounds); | 931 webvr_left_viewport_->SetSourceUv(left_bounds); |
| 925 webvr_right_viewport_->SetSourceUv(right_bounds); | 932 webvr_right_viewport_->SetSourceUv(right_bounds); |
| 926 } | 933 } |
| 927 | 934 |
| 928 gvr::GvrApi* VrShell::gvr_api() { | 935 gvr::GvrApi* VrShell::gvr_api() { |
| 929 return gvr_api_.get(); | 936 return gvr_api_.get(); |
| 930 } | 937 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 case HISTORY_FORWARD: | 1018 case HISTORY_FORWARD: |
| 1012 if (controller.CanGoForward()) | 1019 if (controller.CanGoForward()) |
| 1013 controller.GoForward(); | 1020 controller.GoForward(); |
| 1014 break; | 1021 break; |
| 1015 case RELOAD: | 1022 case RELOAD: |
| 1016 controller.Reload(false); | 1023 controller.Reload(false); |
| 1017 break; | 1024 break; |
| 1018 #if defined(ENABLE_VR_SHELL_UI_DEV) | 1025 #if defined(ENABLE_VR_SHELL_UI_DEV) |
| 1019 case RELOAD_UI: | 1026 case RELOAD_UI: |
| 1020 ui_contents_->GetController().Reload(false); | 1027 ui_contents_->GetController().Reload(false); |
| 1021 html_interface_.reset(new UiInterface); | 1028 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD)); |
| 1022 html_interface_->SetMode(UiInterface::Mode::STANDARD); | |
| 1023 vr_web_contents_observer_->SetUiInterface(html_interface_.get()); | 1029 vr_web_contents_observer_->SetUiInterface(html_interface_.get()); |
| 1024 break; | 1030 break; |
| 1025 #endif | 1031 #endif |
| 1026 case ZOOM_OUT: // Not handled yet. | 1032 case ZOOM_OUT: // Not handled yet. |
| 1027 case ZOOM_IN: // Not handled yet. | 1033 case ZOOM_IN: // Not handled yet. |
| 1028 break; | 1034 break; |
| 1029 default: | 1035 default: |
| 1030 NOTREACHED(); | 1036 NOTREACHED(); |
| 1031 } | 1037 } |
| 1032 } | 1038 } |
| 1033 | 1039 |
| 1034 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, | 1040 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, |
| 1035 content::RenderViewHost* new_host) { | 1041 content::RenderViewHost* new_host) { |
| 1036 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); | 1042 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 1037 } | 1043 } |
| 1038 | 1044 |
| 1039 // ---------------------------------------------------------------------------- | 1045 // ---------------------------------------------------------------------------- |
| 1040 // Native JNI methods | 1046 // Native JNI methods |
| 1041 // ---------------------------------------------------------------------------- | 1047 // ---------------------------------------------------------------------------- |
| 1042 | 1048 |
| 1043 jlong Init(JNIEnv* env, | 1049 jlong Init(JNIEnv* env, |
| 1044 const JavaParamRef<jobject>& obj, | 1050 const JavaParamRef<jobject>& obj, |
| 1045 const JavaParamRef<jobject>& content_web_contents, | 1051 const JavaParamRef<jobject>& content_web_contents, |
| 1046 jlong content_window_android, | 1052 jlong content_window_android, |
| 1047 const JavaParamRef<jobject>& ui_web_contents, | 1053 const JavaParamRef<jobject>& ui_web_contents, |
| 1048 jlong ui_window_android) { | 1054 jlong ui_window_android, |
| 1055 jboolean for_web_vr) { | |
| 1049 return reinterpret_cast<intptr_t>(new VrShell( | 1056 return reinterpret_cast<intptr_t>(new VrShell( |
| 1050 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 1057 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 1051 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 1058 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 1052 content::WebContents::FromJavaWebContents(ui_web_contents), | 1059 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 1053 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 1060 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
| 1061 for_web_vr)); | |
| 1054 } | 1062 } |
| 1055 | 1063 |
| 1056 } // namespace vr_shell | 1064 } // namespace vr_shell |
| OLD | NEW |