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 <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/android/vr_shell/ui_interface.h" | 15 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 16 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 16 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
| 17 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" | 17 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
| 18 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 18 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 19 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 19 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 20 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 20 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 21 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 21 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 22 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 22 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 23 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/render_widget_host.h" | 25 #include "content/public/browser/render_widget_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/referrer.h" | 28 #include "content/public/common/referrer.h" |
| 29 #include "device/vr/android/gvr/gvr_device.h" | |
| 29 #include "device/vr/android/gvr/gvr_device_provider.h" | 30 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 30 #include "jni/VrShellImpl_jni.h" | 31 #include "jni/VrShellImpl_jni.h" |
| 31 #include "ui/android/view_android.h" | 32 #include "ui/android/view_android.h" |
| 32 #include "ui/android/window_android.h" | 33 #include "ui/android/window_android.h" |
| 33 #include "ui/base/page_transition_types.h" | 34 #include "ui/base/page_transition_types.h" |
| 34 #include "ui/display/display.h" | 35 #include "ui/display/display.h" |
| 35 #include "ui/display/screen.h" | 36 #include "ui/display/screen.h" |
| 36 #include "ui/gfx/transform.h" | 37 #include "ui/gfx/transform.h" |
| 37 #include "ui/gfx/transform_util.h" | 38 #include "ui/gfx/transform_util.h" |
| 38 | 39 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 60 bool reprojected_rendering) | 61 bool reprojected_rendering) |
| 61 : WebContentsObserver(ui_contents), | 62 : WebContentsObserver(ui_contents), |
| 62 main_contents_(main_contents), | 63 main_contents_(main_contents), |
| 63 content_compositor_(new VrCompositor(content_window, false)), | 64 content_compositor_(new VrCompositor(content_window, false)), |
| 64 ui_contents_(ui_contents), | 65 ui_contents_(ui_contents), |
| 65 ui_compositor_(new VrCompositor(ui_window, true)), | 66 ui_compositor_(new VrCompositor(ui_window, true)), |
| 66 delegate_provider_(delegate), | 67 delegate_provider_(delegate), |
| 67 metrics_helper_(new VrMetricsHelper(main_contents_)), | 68 metrics_helper_(new VrMetricsHelper(main_contents_)), |
| 68 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 69 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 69 reprojected_rendering_(reprojected_rendering), | 70 reprojected_rendering_(reprojected_rendering), |
| 71 gvr_api_(gvr_api), | |
| 70 weak_ptr_factory_(this) { | 72 weak_ptr_factory_(this) { |
| 71 DCHECK(g_instance == nullptr); | 73 DCHECK(g_instance == nullptr); |
| 72 g_instance = this; | 74 g_instance = this; |
| 73 j_vr_shell_.Reset(env, obj); | 75 j_vr_shell_.Reset(env, obj); |
| 74 | 76 |
| 75 content_input_manager_.reset(new VrInputManager(main_contents_)); | 77 content_input_manager_.reset(new VrInputManager(main_contents_)); |
| 76 ui_input_manager_.reset(new VrInputManager(ui_contents_)); | 78 ui_input_manager_.reset(new VrInputManager(ui_contents_)); |
| 77 | 79 |
| 78 content_compositor_->SetLayer(main_contents_); | 80 content_compositor_->SetLayer(main_contents_); |
| 79 ui_compositor_->SetLayer(ui_contents_); | 81 ui_compositor_->SetLayer(ui_contents_); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 210 } |
| 209 } | 211 } |
| 210 | 212 |
| 211 void VrShell::OnLoadProgressChanged( | 213 void VrShell::OnLoadProgressChanged( |
| 212 JNIEnv* env, | 214 JNIEnv* env, |
| 213 const base::android::JavaParamRef<jobject>& obj, | 215 const base::android::JavaParamRef<jobject>& obj, |
| 214 double progress) { | 216 double progress) { |
| 215 html_interface_->SetLoadProgress(progress); | 217 html_interface_->SetLoadProgress(progress); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { | |
| 219 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR | |
| 220 // render surface size. | |
| 221 } | |
| 222 | |
| 223 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { | |
| 224 const gfx::Size& size = content_compositor_->GetWindowBounds(); | |
| 225 return {size.width(), size.height()}; | |
| 226 } | |
| 227 | |
| 228 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 220 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
| 229 // TODO(cjgrant): Align this state with the logic that drives the omnibox. | 221 // TODO(cjgrant): Align this state with the logic that drives the omnibox. |
| 230 html_interface_->SetWebVRSecureOrigin(secure_origin); | 222 html_interface_->SetWebVRSecureOrigin(secure_origin); |
| 231 } | 223 } |
| 232 | 224 |
| 233 void VrShell::SubmitWebVRFrame() {} | 225 void VrShell::SubmitWebVRFrame() {} |
| 234 | 226 |
| 235 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, | 227 void VrShell::UpdateWebVRTextureBounds(int16_t frame_index, |
| 236 const gvr::Rectf& left_bounds, | 228 const gvr::Rectf& left_bounds, |
| 237 const gvr::Rectf& right_bounds) { | 229 const gvr::Rectf& right_bounds) { |
| 238 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, | 230 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, |
| 239 gl_thread_->GetVrShellGl(), frame_index, | 231 gl_thread_->GetVrShellGl(), frame_index, |
| 240 left_bounds, right_bounds)); | 232 left_bounds, right_bounds)); |
| 241 } | 233 } |
| 242 | 234 |
| 243 // TODO(mthiesse): Do not expose GVR API outside of GL thread. | 235 bool VrShell::SupportsPresentation() { |
| 244 // It's not thread-safe. | 236 return true; |
| 245 gvr::GvrApi* VrShell::gvr_api() { | 237 } |
| 246 if (gl_thread_->GetVrShellGlUnsafe()) { | 238 |
| 247 return gl_thread_->GetVrShellGlUnsafe()->gvr_api(); | 239 void VrShell::ResetPose() { |
| 248 } | 240 gl_thread_->task_runner()->PostTask( |
| 249 CHECK(false); | 241 FROM_HERE, base::Bind(&VrShellGl::ResetPose, gl_thread_->GetVrShellGl())); |
| 250 return nullptr; | 242 } |
| 243 | |
| 244 void VrShell::CreateVRDisplayInfo( | |
| 245 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | |
| 246 uint32_t device_id) { | |
| 247 PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo, | |
| 248 gl_thread_->GetVrShellGl(), | |
| 249 callback, device_id)); | |
| 251 } | 250 } |
| 252 | 251 |
| 253 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { | 252 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { |
| 254 content_compositor_->SurfaceChanged(content_surface); | 253 content_compositor_->SurfaceChanged(content_surface); |
| 255 ui_compositor_->SurfaceChanged(ui_surface); | 254 ui_compositor_->SurfaceChanged(ui_surface); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void VrShell::GvrDelegateReady() { | 257 void VrShell::GvrDelegateReady() { |
| 259 delegate_provider_->SetDelegate(this); | 258 delegate_provider_->SetDelegate(this, gvr_api_); |
| 260 } | 259 } |
| 261 | 260 |
| 262 void VrShell::AppButtonPressed() { | 261 void VrShell::AppButtonPressed() { |
| 263 #if defined(ENABLE_VR_SHELL) | 262 #if defined(ENABLE_VR_SHELL) |
| 264 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); | 263 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); |
| 265 | 264 |
| 266 // TODO(mthiesse): The page is no longer visible when in menu mode. We | 265 // TODO(mthiesse): The page is no longer visible when in menu mode. We |
| 267 // should unfocus or otherwise let it know it's hidden. | 266 // should unfocus or otherwise let it know it's hidden. |
| 268 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { | 267 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 269 if (delegate_provider_->device_provider()) { | 268 if (delegate_provider_->device_provider()) { |
| 270 if (html_interface_->GetMenuMode()) { | 269 if (html_interface_->GetMenuMode()) { |
| 271 delegate_provider_->device_provider()->OnDisplayBlur(); | 270 delegate_provider_->device_provider()->Device()->OnBlur(); |
| 272 } else { | 271 } else { |
| 273 delegate_provider_->device_provider()->OnDisplayFocus(); | 272 delegate_provider_->device_provider()->Device()->OnFocus(); |
| 274 } | 273 } |
| 275 } | 274 } |
| 276 } | 275 } |
| 277 #endif | 276 #endif |
| 278 } | 277 } |
| 279 | 278 |
| 280 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, | 279 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, |
| 281 const JavaParamRef<jobject>& object, | 280 const JavaParamRef<jobject>& object, |
| 282 jint width, jint height, | 281 jint width, jint height, |
| 283 jfloat dpr) { | 282 jfloat dpr) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 | 434 |
| 436 pose->position.emplace(3); | 435 pose->position.emplace(3); |
| 437 pose->position.value()[0] = decomposed_transform.translate[0]; | 436 pose->position.value()[0] = decomposed_transform.translate[0]; |
| 438 pose->position.value()[1] = decomposed_transform.translate[1]; | 437 pose->position.value()[1] = decomposed_transform.translate[1]; |
| 439 pose->position.value()[2] = decomposed_transform.translate[2]; | 438 pose->position.value()[2] = decomposed_transform.translate[2]; |
| 440 } | 439 } |
| 441 | 440 |
| 442 return pose; | 441 return pose; |
| 443 } | 442 } |
| 444 | 443 |
| 444 device::mojom::VRDisplayInfoPtr VrShell::CreateVRDisplayInfo( | |
| 445 gvr::GvrApi* gvr_api, gvr::Sizei compositor_size, uint32_t device_id) { | |
| 446 TRACE_EVENT0("input", "GvrDevice::GetVRDevice"); | |
| 447 | |
| 448 device::mojom::VRDisplayInfoPtr device = device::mojom::VRDisplayInfo::New(); | |
| 449 | |
| 450 device->index = device_id; | |
| 451 | |
| 452 device->capabilities = device::mojom::VRDisplayCapabilities::New(); | |
| 453 device->capabilities->hasOrientation = true; | |
| 454 device->capabilities->hasPosition = false; | |
| 455 device->capabilities->hasExternalDisplay = false; | |
| 456 device->capabilities->canPresent = true; | |
| 457 | |
| 458 device->leftEye = device::mojom::VREyeParameters::New(); | |
| 459 device->rightEye = device::mojom::VREyeParameters::New(); | |
| 460 device::mojom::VREyeParametersPtr& left_eye = device->leftEye; | |
| 461 device::mojom::VREyeParametersPtr& right_eye = device->rightEye; | |
| 462 | |
| 463 left_eye->fieldOfView = device::mojom::VRFieldOfView::New(); | |
| 464 right_eye->fieldOfView = device::mojom::VRFieldOfView::New(); | |
| 465 | |
| 466 left_eye->offset.resize(3); | |
| 467 right_eye->offset.resize(3); | |
| 468 left_eye->renderWidth = compositor_size.width / 2; | |
| 469 left_eye->renderHeight = compositor_size.height; | |
| 470 right_eye->renderWidth = left_eye->renderWidth; | |
| 471 right_eye->renderHeight = left_eye->renderHeight; | |
| 472 | |
| 473 std::string vendor = gvr_api->GetViewerVendor(); | |
| 474 std::string model = gvr_api->GetViewerModel(); | |
| 475 device->displayName = vendor + " " + model; | |
| 476 | |
| 477 gvr::BufferViewportList gvr_buffer_viewports = | |
| 478 gvr_api->CreateEmptyBufferViewportList(); | |
| 479 gvr_buffer_viewports.SetToRecommendedBufferViewports(); | |
| 480 | |
| 481 gvr::BufferViewport eye_viewport = gvr_api->CreateBufferViewport(); | |
|
cjgrant
2017/01/25 21:45:31
Looking at the near-duplicate blocks for left and
mthiesse
2017/01/30 19:47:26
Good eye ;)
| |
| 482 gvr_buffer_viewports.GetBufferViewport(GVR_LEFT_EYE, &eye_viewport); | |
| 483 gvr::Rectf eye_fov = eye_viewport.GetSourceFov(); | |
| 484 left_eye->fieldOfView->upDegrees = eye_fov.top; | |
| 485 left_eye->fieldOfView->downDegrees = eye_fov.bottom; | |
| 486 left_eye->fieldOfView->leftDegrees = eye_fov.left; | |
| 487 left_eye->fieldOfView->rightDegrees = eye_fov.right; | |
| 488 | |
| 489 eye_viewport = gvr_api->CreateBufferViewport(); | |
| 490 gvr_buffer_viewports.GetBufferViewport(GVR_RIGHT_EYE, &eye_viewport); | |
| 491 eye_fov = eye_viewport.GetSourceFov(); | |
| 492 right_eye->fieldOfView->upDegrees = eye_fov.top; | |
| 493 right_eye->fieldOfView->downDegrees = eye_fov.bottom; | |
| 494 right_eye->fieldOfView->leftDegrees = eye_fov.left; | |
| 495 right_eye->fieldOfView->rightDegrees = eye_fov.right; | |
| 496 | |
| 497 gvr::Mat4f left_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_LEFT_EYE); | |
| 498 left_eye->offset[0] = -left_eye_mat.m[0][3]; | |
| 499 left_eye->offset[1] = -left_eye_mat.m[1][3]; | |
| 500 left_eye->offset[2] = -left_eye_mat.m[2][3]; | |
| 501 | |
| 502 gvr::Mat4f right_eye_mat = gvr_api->GetEyeFromHeadMatrix(GVR_RIGHT_EYE); | |
| 503 right_eye->offset[0] = -right_eye_mat.m[0][3]; | |
| 504 right_eye->offset[1] = -right_eye_mat.m[1][3]; | |
| 505 right_eye->offset[2] = -right_eye_mat.m[2][3]; | |
| 506 | |
| 507 return device; | |
| 508 } | |
| 509 | |
| 445 // ---------------------------------------------------------------------------- | 510 // ---------------------------------------------------------------------------- |
| 446 // Native JNI methods | 511 // Native JNI methods |
| 447 // ---------------------------------------------------------------------------- | 512 // ---------------------------------------------------------------------------- |
| 448 | 513 |
| 449 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, | 514 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, |
| 450 const JavaParamRef<jobject>& content_web_contents, | 515 const JavaParamRef<jobject>& content_web_contents, |
| 451 jlong content_window_android, | 516 jlong content_window_android, |
| 452 const JavaParamRef<jobject>& ui_web_contents, | 517 const JavaParamRef<jobject>& ui_web_contents, |
| 453 jlong ui_window_android, jboolean for_web_vr, | 518 jlong ui_window_android, jboolean for_web_vr, |
| 454 const base::android::JavaParamRef<jobject>& delegate, | 519 const base::android::JavaParamRef<jobject>& delegate, |
| 455 jlong gvr_api, jboolean reprojected_rendering) { | 520 jlong gvr_api, jboolean reprojected_rendering) { |
| 456 return reinterpret_cast<intptr_t>(new VrShell( | 521 return reinterpret_cast<intptr_t>(new VrShell( |
| 457 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 522 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 458 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 523 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 459 content::WebContents::FromJavaWebContents(ui_web_contents), | 524 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 460 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 525 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
| 461 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 526 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 462 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 527 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 463 } | 528 } |
| 464 | 529 |
| 465 } // namespace vr_shell | 530 } // namespace vr_shell |
| OLD | NEW |