| 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); | 
 |   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     html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); | 
|   354       // Temporary: Hit app button a second time to exit menu mode. |   358  | 
|   355       if (webvr_mode_) { |   359     // TODO(mthiesse): The page is no longer visible when in menu mode. We | 
|   356         html_interface_->SetMode(UiInterface::Mode::WEB_VR); |   360     // should unfocus or otherwise let it know it's hidden. | 
|   357         main_thread_task_runner_->PostTask( |   361     if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | 
|   358             FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayFocus, |   362       const auto&& task = html_interface_->GetMenuMode() ? | 
|   359                                   delegate_->GetDeviceProvider())); |   363           &device::GvrDeviceProvider::OnDisplayBlur : | 
|   360       } else { |   364           &device::GvrDeviceProvider::OnDisplayFocus; | 
|   361         html_interface_->SetMode(UiInterface::Mode::STANDARD); |   365       main_thread_task_runner_->PostTask( | 
|   362       } |   366           FROM_HERE, base::Bind(task, delegate_->GetDeviceProvider())); | 
|   363     } else { |  | 
|   364       if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |  | 
|   365         main_thread_task_runner_->PostTask( |  | 
|   366             FROM_HERE, base::Bind(&device::GvrDeviceProvider::OnDisplayBlur, |  | 
|   367                                   delegate_->GetDeviceProvider())); |  | 
|   368       } |  | 
|   369       html_interface_->SetMode(UiInterface::Mode::MENU); |  | 
|   370       // TODO(mthiesse): The page is no longer visible here. We should unfocus |  | 
|   371       // or otherwise let it know it's hidden. |  | 
|   372     } |   367     } | 
|   373   } |   368   } | 
|   374 #endif |   369 #endif | 
|   375   if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |   370   if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | 
|   376     // Process screen touch events for Cardboard button compatibility. |   371     // Process screen touch events for Cardboard button compatibility. | 
|   377     // Also send tap events for controller "touchpad click" events. |   372     // Also send tap events for controller "touchpad click" events. | 
|   378     if (touch_pending_ || controller_->IsButtonUp( |   373     if (touch_pending_ || controller_->IsButtonUp( | 
|   379             gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { |   374             gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { | 
|   380       touch_pending_ = false; |   375       touch_pending_ = false; | 
|   381       std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); |   376       std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); | 
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   896  |   891  | 
|   897 void VrShell::OnDomContentsLoaded() { |   892 void VrShell::OnDomContentsLoaded() { | 
|   898   html_interface_->SetURL(main_contents_->GetVisibleURL()); |   893   html_interface_->SetURL(main_contents_->GetVisibleURL()); | 
|   899   html_interface_->SetLoading(main_contents_->IsLoading()); |   894   html_interface_->SetLoading(main_contents_->IsLoading()); | 
|   900   html_interface_->OnDomContentsLoaded(); |   895   html_interface_->OnDomContentsLoaded(); | 
|   901 } |   896 } | 
|   902  |   897  | 
|   903 void VrShell::SetWebVrMode(JNIEnv* env, |   898 void VrShell::SetWebVrMode(JNIEnv* env, | 
|   904                            const base::android::JavaParamRef<jobject>& obj, |   899                            const base::android::JavaParamRef<jobject>& obj, | 
|   905                            bool enabled) { |   900                            bool enabled) { | 
|   906   webvr_mode_ = enabled; |   901   metrics_helper_->SetWebVREnabled(enabled); | 
|   907   metrics_helper_->SetWebVREnabled(webvr_mode_); |  | 
|   908   if (enabled) { |   902   if (enabled) { | 
|   909     html_interface_->SetMode(UiInterface::Mode::WEB_VR); |   903     html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 
|   910   } else { |   904   } else { | 
|   911     html_interface_->SetMode(UiInterface::Mode::STANDARD); |   905     html_interface_->SetMode(UiInterface::Mode::STANDARD); | 
|   912   } |   906   } | 
|   913 } |   907 } | 
|   914  |   908  | 
|   915 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |   909 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 
|   916   html_interface_->SetSecureOrigin(secure_origin); |   910   html_interface_->SetSecureOrigin(secure_origin); | 
|   917 } |   911 } | 
|   918  |   912  | 
|   919 void VrShell::SubmitWebVRFrame() { |   913 void VrShell::SubmitWebVRFrame() {} | 
|   920 } |  | 
|   921  |   914  | 
|   922 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, |   915 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 
|   923                                        const gvr::Rectf& right_bounds) { |   916                                        const gvr::Rectf& right_bounds) { | 
|   924   webvr_left_viewport_->SetSourceUv(left_bounds); |   917   webvr_left_viewport_->SetSourceUv(left_bounds); | 
|   925   webvr_right_viewport_->SetSourceUv(right_bounds); |   918   webvr_right_viewport_->SetSourceUv(right_bounds); | 
|   926 } |   919 } | 
|   927  |   920  | 
|   928 gvr::GvrApi* VrShell::gvr_api() { |   921 gvr::GvrApi* VrShell::gvr_api() { | 
|   929   return gvr_api_.get(); |   922   return gvr_api_.get(); | 
|   930 } |   923 } | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1011     case HISTORY_FORWARD: |  1004     case HISTORY_FORWARD: | 
|  1012       if (controller.CanGoForward()) |  1005       if (controller.CanGoForward()) | 
|  1013         controller.GoForward(); |  1006         controller.GoForward(); | 
|  1014       break; |  1007       break; | 
|  1015     case RELOAD: |  1008     case RELOAD: | 
|  1016       controller.Reload(false); |  1009       controller.Reload(false); | 
|  1017       break; |  1010       break; | 
|  1018 #if defined(ENABLE_VR_SHELL_UI_DEV) |  1011 #if defined(ENABLE_VR_SHELL_UI_DEV) | 
|  1019     case RELOAD_UI: |  1012     case RELOAD_UI: | 
|  1020       ui_contents_->GetController().Reload(false); |  1013       ui_contents_->GetController().Reload(false); | 
|  1021       html_interface_.reset(new UiInterface); |  1014       html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD)); | 
|  1022       html_interface_->SetMode(UiInterface::Mode::STANDARD); |  | 
|  1023       vr_web_contents_observer_->SetUiInterface(html_interface_.get()); |  1015       vr_web_contents_observer_->SetUiInterface(html_interface_.get()); | 
|  1024       break; |  1016       break; | 
|  1025 #endif |  1017 #endif | 
|  1026     case ZOOM_OUT:  // Not handled yet. |  1018     case ZOOM_OUT:  // Not handled yet. | 
|  1027     case ZOOM_IN:  // Not handled yet. |  1019     case ZOOM_IN:  // Not handled yet. | 
|  1028       break; |  1020       break; | 
|  1029     default: |  1021     default: | 
|  1030       NOTREACHED(); |  1022       NOTREACHED(); | 
|  1031   } |  1023   } | 
|  1032 } |  1024 } | 
|  1033  |  1025  | 
|  1034 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, |  1026 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, | 
|  1035                                     content::RenderViewHost* new_host) { |  1027                                     content::RenderViewHost* new_host) { | 
|  1036   new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); |  1028   new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); | 
|  1037 } |  1029 } | 
|  1038  |  1030  | 
|  1039 // ---------------------------------------------------------------------------- |  1031 // ---------------------------------------------------------------------------- | 
|  1040 // Native JNI methods |  1032 // Native JNI methods | 
|  1041 // ---------------------------------------------------------------------------- |  1033 // ---------------------------------------------------------------------------- | 
|  1042  |  1034  | 
|  1043 jlong Init(JNIEnv* env, |  1035 jlong Init(JNIEnv* env, | 
|  1044            const JavaParamRef<jobject>& obj, |  1036            const JavaParamRef<jobject>& obj, | 
|  1045            const JavaParamRef<jobject>& content_web_contents, |  1037            const JavaParamRef<jobject>& content_web_contents, | 
|  1046            jlong content_window_android, |  1038            jlong content_window_android, | 
|  1047            const JavaParamRef<jobject>& ui_web_contents, |  1039            const JavaParamRef<jobject>& ui_web_contents, | 
|  1048            jlong ui_window_android) { |  1040            jlong ui_window_android, | 
 |  1041            jboolean for_web_vr) { | 
|  1049   return reinterpret_cast<intptr_t>(new VrShell( |  1042   return reinterpret_cast<intptr_t>(new VrShell( | 
|  1050       env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |  1043       env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 
|  1051       reinterpret_cast<ui::WindowAndroid*>(content_window_android), |  1044       reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 
|  1052       content::WebContents::FromJavaWebContents(ui_web_contents), |  1045       content::WebContents::FromJavaWebContents(ui_web_contents), | 
|  1053       reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |  1046       reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 
 |  1047       for_web_vr)); | 
|  1054 } |  1048 } | 
|  1055  |  1049  | 
|  1056 }  // namespace vr_shell |  1050 }  // namespace vr_shell | 
| OLD | NEW |