| 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 "chrome/browser/android/vr_shell/ui_scene.h" | 7 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 8 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 8 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 9 #include "chrome/browser/android/vr_shell/vr_controller.h" | 9 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 10 #include "chrome/browser/android/vr_shell/vr_gesture.h" |
| 10 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 11 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 11 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 12 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 12 #include "chrome/browser/android/vr_shell/vr_math.h" | 13 #include "chrome/browser/android/vr_shell/vr_math.h" |
| 13 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 14 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 14 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 15 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 15 #include "content/public/browser/android/content_view_core.h" | 16 #include "content/public/browser/android/content_view_core.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
| 18 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/referrer.h" | 21 #include "content/public/common/referrer.h" |
| 21 #include "content/public/common/screen_info.h" | 22 #include "content/public/common/screen_info.h" |
| 22 #include "jni/VrShell_jni.h" | 23 #include "jni/VrShell_jni.h" |
| 24 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 23 #include "ui/android/view_android.h" | 25 #include "ui/android/view_android.h" |
| 24 #include "ui/android/window_android.h" | 26 #include "ui/android/window_android.h" |
| 25 #include "ui/base/page_transition_types.h" | 27 #include "ui/base/page_transition_types.h" |
| 26 #include "ui/gl/gl_bindings.h" | 28 #include "ui/gl/gl_bindings.h" |
| 27 #include "ui/gl/init/gl_factory.h" | 29 #include "ui/gl/init/gl_factory.h" |
| 28 | 30 |
| 29 using base::android::JavaParamRef; | 31 using base::android::JavaParamRef; |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 // Constant taken from treasure_hunt demo. | 34 // Constant taken from treasure_hunt demo. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 ui_compositor_.reset(new VrCompositor(ui_window, true)); | 148 ui_compositor_.reset(new VrCompositor(ui_window, true)); |
| 147 | 149 |
| 148 float screen_width = kScreenWidthRatio * desktop_height_; | 150 float screen_width = kScreenWidthRatio * desktop_height_; |
| 149 float screen_height = kScreenHeightRatio * desktop_height_; | 151 float screen_height = kScreenHeightRatio * desktop_height_; |
| 150 std::unique_ptr<ContentRectangle> rect(new ContentRectangle()); | 152 std::unique_ptr<ContentRectangle> rect(new ContentRectangle()); |
| 151 rect->id = kBrowserUiElementId; | 153 rect->id = kBrowserUiElementId; |
| 152 rect->size = {screen_width, screen_height, 1.0f}; | 154 rect->size = {screen_width, screen_height, 1.0f}; |
| 153 rect->translation = kDesktopPositionDefault; | 155 rect->translation = kDesktopPositionDefault; |
| 154 scene_.AddUiElement(rect); | 156 scene_.AddUiElement(rect); |
| 155 | 157 |
| 156 desktop_plane_ = scene_.GetUiElementById(kBrowserUiElementId); | |
| 157 | |
| 158 LoadUIContent(); | 158 LoadUIContent(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void VrShell::UpdateCompositorLayers(JNIEnv* env, | 161 void VrShell::UpdateCompositorLayers(JNIEnv* env, |
| 162 const JavaParamRef<jobject>& obj) { | 162 const JavaParamRef<jobject>& obj) { |
| 163 content_compositor_->SetLayer(content_cvc_); | 163 content_compositor_->SetLayer(content_cvc_); |
| 164 ui_compositor_->SetLayer(ui_cvc_); | 164 ui_compositor_->SetLayer(ui_cvc_); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 167 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 168 delete this; | 168 delete this; |
| 169 } | 169 } |
| 170 | 170 |
| 171 void VrShell::LoadUIContent() { | 171 void VrShell::LoadUIContent() { |
| 172 GURL url(kVrShellUIURL); | 172 GURL url(kVrShellUIURL); |
| 173 ui_cvc_->GetWebContents()->GetController().LoadURL( | 173 ui_cvc_->GetWebContents()->GetController().LoadURL( |
| 174 url, content::Referrer(), | 174 url, content::Referrer(), |
| 175 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); | 175 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool RegisterVrShell(JNIEnv* env) { | 178 bool RegisterVrShell(JNIEnv* env) { |
| 179 return RegisterNativesImpl(env); | 179 return RegisterNativesImpl(env); |
| 180 } | 180 } |
| 181 | 181 |
| 182 VrShell::~VrShell() { | 182 VrShell::~VrShell() { |
| 183 DCHECK(g_instance == this); |
| 183 g_instance = nullptr; | 184 g_instance = nullptr; |
| 184 gl::init::ClearGLBindings(); | 185 gl::init::ClearGLBindings(); |
| 185 } | 186 } |
| 186 | 187 |
| 187 void VrShell::SetDelegate(JNIEnv* env, | 188 void VrShell::SetDelegate(JNIEnv* env, |
| 188 const base::android::JavaParamRef<jobject>& obj, | 189 const base::android::JavaParamRef<jobject>& obj, |
| 189 const base::android::JavaParamRef<jobject>& delegate) { | 190 const base::android::JavaParamRef<jobject>& delegate) { |
| 190 delegate_ = VrShellDelegate::getNativeDelegate(env, delegate); | 191 delegate_ = VrShellDelegate::getNativeDelegate(env, delegate); |
| 191 } | 192 } |
| 192 | 193 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 controller_quat_ = GetRotationFromZAxis(forward_vector); | 246 controller_quat_ = GetRotationFromZAxis(forward_vector); |
| 246 } else { | 247 } else { |
| 247 controller_quat_ = controller_->Orientation(); | 248 controller_quat_ = controller_->Orientation(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 gvr::Mat4f mat = QuatToMatrix(controller_quat_); | 251 gvr::Mat4f mat = QuatToMatrix(controller_quat_); |
| 251 gvr::Vec3f forward = MatrixVectorMul(mat, kNeutralPose); | 252 gvr::Vec3f forward = MatrixVectorMul(mat, kNeutralPose); |
| 252 gvr::Vec3f origin = kHandPosition; | 253 gvr::Vec3f origin = kHandPosition; |
| 253 | 254 |
| 254 target_element_ = nullptr; | 255 target_element_ = nullptr; |
| 255 float distance = scene_.GetUiElementById(kBrowserUiElementId) | 256 |
| 256 ->GetRayDistance(origin, forward); | 257 ContentRectangle* content_plane = |
| 258 scene_.GetUiElementById(kBrowserUiElementId); |
| 259 |
| 260 float distance = content_plane->GetRayDistance(origin, forward); |
| 257 | 261 |
| 258 // If we place the reticle based on elements intersecting the controller beam, | 262 // If we place the reticle based on elements intersecting the controller beam, |
| 259 // we can end up with the reticle hiding behind elements, or jumping laterally | 263 // we can end up with the reticle hiding behind elements, or jumping laterally |
| 260 // in the field of view. This is physically correct, but hard to use. For | 264 // in the field of view. This is physically correct, but hard to use. For |
| 261 // usability, do the following instead: | 265 // usability, do the following instead: |
| 262 // | 266 // |
| 263 // - Project the controller laser onto an outer surface, which is the | 267 // - Project the controller laser onto an outer surface, which is the |
| 264 // closer of the desktop plane, or a distance-limiting sphere. | 268 // closer of the desktop plane, or a distance-limiting sphere. |
| 265 // - Create a vector between the eyes and the outer surface point. | 269 // - Create a vector between the eyes and the outer surface point. |
| 266 // - If any UI elements intersect this vector, choose the closest to the eyes, | 270 // - If any UI elements intersect this vector, choose the closest to the eyes, |
| 267 // and place the reticle at the intersection point. | 271 // and place the reticle at the intersection point. |
| 268 | 272 |
| 269 // Find distance to a corner of the content quad, and limit the cursor | 273 // Find distance to a corner of the content quad, and limit the cursor |
| 270 // distance to a multiple of that distance. This lets us keep the reticle on | 274 // distance to a multiple of that distance. This lets us keep the reticle on |
| 271 // the content plane near the content window, and on the surface of a sphere | 275 // the content plane near the content window, and on the surface of a sphere |
| 272 // in other directions. Note that this approach uses distance from controller, | 276 // in other directions. Note that this approach uses distance from controller, |
| 273 // rather than eye, for simplicity. This will make the sphere slightly | 277 // rather than eye, for simplicity. This will make the sphere slightly |
| 274 // off-center. | 278 // off-center. |
| 275 gvr::Vec3f corner = {0.5f, 0.5f, 0.0f}; | 279 gvr::Vec3f corner = {0.5f, 0.5f, 0.0f}; |
| 276 corner = MatrixVectorMul(desktop_plane_->transform.to_world, corner); | 280 corner = MatrixVectorMul(content_plane->transform.to_world, corner); |
| 277 float max_distance = Distance(origin, corner) * kReticleDistanceMultiplier; | 281 float max_distance = Distance(origin, corner) * kReticleDistanceMultiplier; |
| 278 if (distance > max_distance || distance <= 0.0f) { | 282 if (distance > max_distance || distance <= 0.0f) { |
| 279 distance = max_distance; | 283 distance = max_distance; |
| 280 } | 284 } |
| 281 target_point_ = GetRayPoint(origin, forward, distance); | 285 target_point_ = GetRayPoint(origin, forward, distance); |
| 282 gvr::Vec3f eye_to_target = target_point_; | 286 gvr::Vec3f eye_to_target = target_point_; |
| 283 NormalizeVector(eye_to_target); | 287 NormalizeVector(eye_to_target); |
| 284 | 288 |
| 285 // Determine which UI element (if any) intersects the line between the eyes | 289 // Determine which UI element (if any) intersects the line between the eyes |
| 286 // and the controller target position. | 290 // and the controller target position. |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 content::WebContents::FromJavaWebContents(content_web_contents)); | 796 content::WebContents::FromJavaWebContents(content_web_contents)); |
| 793 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( | 797 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( |
| 794 content::WebContents::FromJavaWebContents(ui_web_contents)); | 798 content::WebContents::FromJavaWebContents(ui_web_contents)); |
| 795 return reinterpret_cast<intptr_t>(new VrShell( | 799 return reinterpret_cast<intptr_t>(new VrShell( |
| 796 env, obj, c_core, | 800 env, obj, c_core, |
| 797 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, | 801 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, |
| 798 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 802 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
| 799 } | 803 } |
| 800 | 804 |
| 801 } // namespace vr_shell | 805 } // namespace vr_shell |
| OLD | NEW |