| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/android/vr_shell/ui_interface.h" | 16 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 17 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 17 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 18 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" | 18 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
| 19 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 19 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 20 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 20 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 21 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 21 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 22 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 22 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 23 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 23 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 24 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/render_widget_host.h" | 26 #include "content/public/browser/render_widget_host.h" |
| 27 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/referrer.h" | 29 #include "content/public/common/referrer.h" |
| 30 #include "device/vr/android/gvr/gvr_device.h" |
| 30 #include "device/vr/android/gvr/gvr_device_provider.h" | 31 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 31 #include "jni/VrShellImpl_jni.h" | 32 #include "jni/VrShellImpl_jni.h" |
| 32 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 33 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 33 #include "ui/android/view_android.h" | 34 #include "ui/android/view_android.h" |
| 34 #include "ui/android/window_android.h" | 35 #include "ui/android/window_android.h" |
| 35 #include "ui/base/page_transition_types.h" | 36 #include "ui/base/page_transition_types.h" |
| 36 #include "ui/display/display.h" | 37 #include "ui/display/display.h" |
| 37 #include "ui/display/screen.h" | 38 #include "ui/display/screen.h" |
| 38 #include "ui/gfx/transform.h" | 39 #include "ui/gfx/transform.h" |
| 39 #include "ui/gfx/transform_util.h" | 40 #include "ui/gfx/transform_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 : WebContentsObserver(ui_contents), | 69 : WebContentsObserver(ui_contents), |
| 69 main_contents_(main_contents), | 70 main_contents_(main_contents), |
| 70 content_compositor_( | 71 content_compositor_( |
| 71 base::MakeUnique<VrCompositor>(content_window, false)), | 72 base::MakeUnique<VrCompositor>(content_window, false)), |
| 72 ui_contents_(ui_contents), | 73 ui_contents_(ui_contents), |
| 73 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), | 74 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), |
| 74 delegate_provider_(delegate), | 75 delegate_provider_(delegate), |
| 75 metrics_helper_(base::MakeUnique<VrMetricsHelper>(main_contents_)), | 76 metrics_helper_(base::MakeUnique<VrMetricsHelper>(main_contents_)), |
| 76 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 77 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 77 reprojected_rendering_(reprojected_rendering), | 78 reprojected_rendering_(reprojected_rendering), |
| 79 gvr_api_(gvr_api), |
| 78 weak_ptr_factory_(this) { | 80 weak_ptr_factory_(this) { |
| 79 DCHECK(g_instance == nullptr); | 81 DCHECK(g_instance == nullptr); |
| 80 g_instance = this; | 82 g_instance = this; |
| 81 j_vr_shell_.Reset(env, obj); | 83 j_vr_shell_.Reset(env, obj); |
| 82 | 84 |
| 83 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); | 85 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); |
| 84 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); | 86 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); |
| 85 | 87 |
| 86 content_compositor_->SetLayer(main_contents_); | 88 content_compositor_->SetLayer(main_contents_); |
| 87 ui_compositor_->SetLayer(ui_contents_); | 89 ui_compositor_->SetLayer(ui_contents_); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 232 } |
| 231 } | 233 } |
| 232 | 234 |
| 233 void VrShell::OnLoadProgressChanged( | 235 void VrShell::OnLoadProgressChanged( |
| 234 JNIEnv* env, | 236 JNIEnv* env, |
| 235 const base::android::JavaParamRef<jobject>& obj, | 237 const base::android::JavaParamRef<jobject>& obj, |
| 236 double progress) { | 238 double progress) { |
| 237 html_interface_->SetLoadProgress(progress); | 239 html_interface_->SetLoadProgress(progress); |
| 238 } | 240 } |
| 239 | 241 |
| 240 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { | |
| 241 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR | |
| 242 // render surface size. | |
| 243 } | |
| 244 | |
| 245 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { | |
| 246 const gfx::Size& size = content_compositor_->GetWindowBounds(); | |
| 247 return {size.width(), size.height()}; | |
| 248 } | |
| 249 | |
| 250 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 242 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
| 251 // TODO(cjgrant): Align this state with the logic that drives the omnibox. | 243 // TODO(cjgrant): Align this state with the logic that drives the omnibox. |
| 252 html_interface_->SetWebVRSecureOrigin(secure_origin); | 244 html_interface_->SetWebVRSecureOrigin(secure_origin); |
| 253 } | 245 } |
| 254 | 246 |
| 255 void VrShell::SubmitWebVRFrame() {} | 247 void VrShell::SubmitWebVRFrame() {} |
| 256 | 248 |
| 257 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, | 249 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, |
| 258 const gvr::Rectf& left_bounds, | 250 const gvr::Rectf& left_bounds, |
| 259 const gvr::Rectf& right_bounds) { | 251 const gvr::Rectf& right_bounds) { |
| 260 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, | 252 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, |
| 261 gl_thread_->GetVrShellGl(), frame_index, | 253 gl_thread_->GetVrShellGl(), frame_index, |
| 262 left_bounds, right_bounds)); | 254 left_bounds, right_bounds)); |
| 263 } | 255 } |
| 264 | 256 |
| 265 // TODO(mthiesse): Do not expose GVR API outside of GL thread. | 257 bool VrShell::SupportsPresentation() { |
| 266 // It's not thread-safe. | 258 return true; |
| 267 gvr::GvrApi* VrShell::gvr_api() { | 259 } |
| 268 if (gl_thread_->GetVrShellGlUnsafe()) { | 260 |
| 269 return gl_thread_->GetVrShellGlUnsafe()->gvr_api(); | 261 void VrShell::ResetPose() { |
| 270 } | 262 gl_thread_->task_runner()->PostTask( |
| 271 CHECK(false); | 263 FROM_HERE, base::Bind(&VrShellGl::ResetPose, gl_thread_->GetVrShellGl())); |
| 272 return nullptr; | 264 } |
| 265 |
| 266 void VrShell::CreateVRDisplayInfo( |
| 267 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 268 uint32_t device_id) { |
| 269 PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo, |
| 270 gl_thread_->GetVrShellGl(), |
| 271 callback, device_id)); |
| 273 } | 272 } |
| 274 | 273 |
| 275 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { | 274 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { |
| 276 content_compositor_->SurfaceChanged(content_surface); | 275 content_compositor_->SurfaceChanged(content_surface); |
| 277 ui_compositor_->SurfaceChanged(ui_surface); | 276 ui_compositor_->SurfaceChanged(ui_surface); |
| 278 } | 277 } |
| 279 | 278 |
| 280 void VrShell::GvrDelegateReady() { | 279 void VrShell::GvrDelegateReady() { |
| 281 delegate_provider_->SetDelegate(this); | 280 delegate_provider_->SetDelegate(this, gvr_api_); |
| 282 } | 281 } |
| 283 | 282 |
| 284 void VrShell::AppButtonPressed() { | 283 void VrShell::AppButtonPressed() { |
| 285 #if defined(ENABLE_VR_SHELL) | 284 #if defined(ENABLE_VR_SHELL) |
| 286 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); | 285 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); |
| 287 | 286 |
| 288 // TODO(mthiesse): The page is no longer visible when in menu mode. We | 287 // TODO(mthiesse): The page is no longer visible when in menu mode. We |
| 289 // should unfocus or otherwise let it know it's hidden. | 288 // should unfocus or otherwise let it know it's hidden. |
| 290 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | 289 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 291 if (delegate_provider_->device_provider()) { | 290 if (delegate_provider_->device_provider()) { |
| 292 if (html_interface_->GetMenuMode()) { | 291 if (html_interface_->GetMenuMode()) { |
| 293 delegate_provider_->device_provider()->OnDisplayBlur(); | 292 delegate_provider_->device_provider()->Device()->OnBlur(); |
| 294 } else { | 293 } else { |
| 295 delegate_provider_->device_provider()->OnDisplayFocus(); | 294 delegate_provider_->device_provider()->Device()->OnFocus(); |
| 296 } | 295 } |
| 297 } | 296 } |
| 298 } | 297 } |
| 299 #endif | 298 #endif |
| 300 } | 299 } |
| 301 | 300 |
| 302 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, | 301 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, |
| 303 const JavaParamRef<jobject>& object, | 302 const JavaParamRef<jobject>& object, |
| 304 jint width, jint height, | 303 jint width, jint height, |
| 305 jfloat dpr) { | 304 jfloat dpr) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 472 |
| 474 pose->position.emplace(3); | 473 pose->position.emplace(3); |
| 475 pose->position.value()[0] = decomposed_transform.translate[0]; | 474 pose->position.value()[0] = decomposed_transform.translate[0]; |
| 476 pose->position.value()[1] = decomposed_transform.translate[1]; | 475 pose->position.value()[1] = decomposed_transform.translate[1]; |
| 477 pose->position.value()[2] = decomposed_transform.translate[2]; | 476 pose->position.value()[2] = decomposed_transform.translate[2]; |
| 478 } | 477 } |
| 479 | 478 |
| 480 return pose; | 479 return pose; |
| 481 } | 480 } |
| 482 | 481 |
| 482 device::mojom::VRDisplayInfoPtr VrShell::CreateVRDisplayInfo( |
| 483 gvr::GvrApi* gvr_api, gvr::Sizei compositor_size, uint32_t device_id) { |
| 484 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); |
| 485 |
| 486 device::mojom::VRDisplayInfoPtr device = device::mojom::VRDisplayInfo::New(); |
| 487 |
| 488 device->index = device_id; |
| 489 |
| 490 device->capabilities = device::mojom::VRDisplayCapabilities::New(); |
| 491 device->capabilities->hasOrientation = true; |
| 492 device->capabilities->hasPosition = false; |
| 493 device->capabilities->hasExternalDisplay = false; |
| 494 device->capabilities->canPresent = true; |
| 495 |
| 496 std::string vendor = gvr_api->GetViewerVendor(); |
| 497 std::string model = gvr_api->GetViewerModel(); |
| 498 device->displayName = vendor + " " + model; |
| 499 |
| 500 gvr::BufferViewportList gvr_buffer_viewports = |
| 501 gvr_api->CreateEmptyBufferViewportList(); |
| 502 gvr_buffer_viewports.SetToRecommendedBufferViewports(); |
| 503 |
| 504 device->leftEye = device::mojom::VREyeParameters::New(); |
| 505 device->rightEye = device::mojom::VREyeParameters::New(); |
| 506 for (auto eye : {GVR_LEFT_EYE, GVR_RIGHT_EYE}) { |
| 507 device::mojom::VREyeParametersPtr& eye_params = |
| 508 (eye == GVR_LEFT_EYE) ? device->leftEye : device->rightEye; |
| 509 eye_params->fieldOfView = device::mojom::VRFieldOfView::New(); |
| 510 eye_params->offset.resize(3); |
| 511 eye_params->renderWidth = compositor_size.width / 2; |
| 512 eye_params->renderHeight = compositor_size.height; |
| 513 |
| 514 gvr::BufferViewport eye_viewport = gvr_api->CreateBufferViewport(); |
| 515 gvr_buffer_viewports.GetBufferViewport(eye, &eye_viewport); |
| 516 gvr::Rectf eye_fov = eye_viewport.GetSourceFov(); |
| 517 eye_params->fieldOfView->upDegrees = eye_fov.top; |
| 518 eye_params->fieldOfView->downDegrees = eye_fov.bottom; |
| 519 eye_params->fieldOfView->leftDegrees = eye_fov.left; |
| 520 eye_params->fieldOfView->rightDegrees = eye_fov.right; |
| 521 |
| 522 gvr::Mat4f eye_mat = gvr_api->GetEyeFromHeadMatrix(eye); |
| 523 eye_params->offset[0] = -eye_mat.m[0][3]; |
| 524 eye_params->offset[1] = -eye_mat.m[1][3]; |
| 525 eye_params->offset[2] = -eye_mat.m[2][3]; |
| 526 } |
| 527 |
| 528 return device; |
| 529 } |
| 530 |
| 483 // ---------------------------------------------------------------------------- | 531 // ---------------------------------------------------------------------------- |
| 484 // Native JNI methods | 532 // Native JNI methods |
| 485 // ---------------------------------------------------------------------------- | 533 // ---------------------------------------------------------------------------- |
| 486 | 534 |
| 487 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, | 535 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, |
| 488 const JavaParamRef<jobject>& content_web_contents, | 536 const JavaParamRef<jobject>& content_web_contents, |
| 489 jlong content_window_android, | 537 jlong content_window_android, |
| 490 const JavaParamRef<jobject>& ui_web_contents, | 538 const JavaParamRef<jobject>& ui_web_contents, |
| 491 jlong ui_window_android, jboolean for_web_vr, | 539 jlong ui_window_android, jboolean for_web_vr, |
| 492 const base::android::JavaParamRef<jobject>& delegate, | 540 const base::android::JavaParamRef<jobject>& delegate, |
| 493 jlong gvr_api, jboolean reprojected_rendering) { | 541 jlong gvr_api, jboolean reprojected_rendering) { |
| 494 return reinterpret_cast<intptr_t>(new VrShell( | 542 return reinterpret_cast<intptr_t>(new VrShell( |
| 495 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 543 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 496 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 544 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 497 content::WebContents::FromJavaWebContents(ui_web_contents), | 545 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 498 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 546 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
| 499 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 547 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 500 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 548 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 501 } | 549 } |
| 502 | 550 |
| 503 } // namespace vr_shell | 551 } // namespace vr_shell |
| OLD | NEW |