| 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 // TODO: Not sure what object_from_reference_matrix is. The new api removed | 439 // TODO: Not sure what object_from_reference_matrix is. The new api removed |
| 440 // it. For now, removing it seems working fine. | 440 // it. For now, removing it seems working fine. |
| 441 gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 441 gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
| 442 } | 442 } |
| 443 | 443 |
| 444 // Bind the primary framebuffer. | 444 // Bind the primary framebuffer. |
| 445 frame.BindBuffer(kFramePrimaryBuffer); | 445 frame.BindBuffer(kFramePrimaryBuffer); |
| 446 | 446 |
| 447 if (webvr_mode_) { | 447 if (webvr_mode_) { |
| 448 DrawWebVr(); | 448 DrawWebVr(); |
| 449 |
| 450 // When using async reprojection, we need to know which pose was used in |
| 451 // the WebVR app for drawing this frame. Due to unknown amounts of |
| 452 // buffering in the compositor and SurfaceTexture, we read the pose number |
| 453 // from a corner pixel. There's no point in doing this for legacy |
| 454 // distortion rendering since that doesn't need a pose, and reading back |
| 455 // pixels is an expensive operation. TODO(klausw): stop doing this once we |
| 456 // have working no-compositor rendering for WebVR. |
| 457 if (gvr_api_->GetAsyncReprojectionEnabled()) { |
| 458 uint32_t webvr_pose_frame = GetPixelEncodedPoseIndex(); |
| 459 head_pose = webvr_head_pose_[webvr_pose_frame % kPoseRingBufferSize]; |
| 460 } |
| 461 |
| 449 // Wait for the DOM contents to be loaded before rendering to avoid drawing | 462 // Wait for the DOM contents to be loaded before rendering to avoid drawing |
| 450 // white rectangles with no content. | 463 // white rectangles with no content. |
| 451 if (!webvr_secure_origin_ && IsUiTextureReady()) { | 464 if (!webvr_secure_origin_ && IsUiTextureReady()) { |
| 452 size_t last_viewport = buffer_viewport_list_->GetSize(); | 465 size_t last_viewport = buffer_viewport_list_->GetSize(); |
| 453 buffer_viewport_list_->SetBufferViewport(last_viewport++, | 466 buffer_viewport_list_->SetBufferViewport(last_viewport++, |
| 454 *headlocked_left_viewport_); | 467 *headlocked_left_viewport_); |
| 455 buffer_viewport_list_->SetBufferViewport(last_viewport++, | 468 buffer_viewport_list_->SetBufferViewport(last_viewport++, |
| 456 *headlocked_right_viewport_); | 469 *headlocked_right_viewport_); |
| 457 | 470 |
| 458 // Bind the headlocked framebuffer. | 471 // Bind the headlocked framebuffer. |
| 459 frame.BindBuffer(kFrameHeadlockedBuffer); | 472 frame.BindBuffer(kFrameHeadlockedBuffer); |
| 460 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); | 473 DrawWebVrOverlay(target_time.monotonic_system_time_nanos); |
| 461 } | 474 } |
| 462 | |
| 463 // When using async reprojection, we need to know which pose was used in | |
| 464 // the WebVR app for drawing this frame. Due to unknown amounts of | |
| 465 // buffering in the compositor and SurfaceTexture, we read the pose number | |
| 466 // from a corner pixel. There's no point in doing this for legacy | |
| 467 // distortion rendering since that doesn't need a pose, and reading back | |
| 468 // pixels is an expensive operation. TODO(klausw): stop doing this once we | |
| 469 // have working no-compositor rendering for WebVR. | |
| 470 if (gvr_api_->GetAsyncReprojectionEnabled()) { | |
| 471 uint32_t webvr_pose_frame = GetPixelEncodedPoseIndex(); | |
| 472 head_pose = webvr_head_pose_[webvr_pose_frame % kPoseRingBufferSize]; | |
| 473 } | |
| 474 } else { | 475 } else { |
| 475 DrawVrShell(head_pose); | 476 DrawVrShell(head_pose); |
| 476 } | 477 } |
| 477 | 478 |
| 478 frame.Unbind(); | 479 frame.Unbind(); |
| 479 frame.Submit(*buffer_viewport_list_, head_pose); | 480 frame.Submit(*buffer_viewport_list_, head_pose); |
| 480 } | 481 } |
| 481 | 482 |
| 482 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { | 483 void VrShell::DrawVrShell(const gvr::Mat4f& head_pose) { |
| 483 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; | 484 float screen_tilt = desktop_screen_tilt_ * M_PI / 180.0f; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 const JavaParamRef<jobject>& ui_web_contents, | 917 const JavaParamRef<jobject>& ui_web_contents, |
| 917 jlong ui_window_android) { | 918 jlong ui_window_android) { |
| 918 return reinterpret_cast<intptr_t>(new VrShell( | 919 return reinterpret_cast<intptr_t>(new VrShell( |
| 919 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 920 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
| 920 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 921 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 921 content::WebContents::FromJavaWebContents(ui_web_contents), | 922 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 922 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 923 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
| 923 } | 924 } |
| 924 | 925 |
| 925 } // namespace vr_shell | 926 } // namespace vr_shell |
| OLD | NEW |