| 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_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_elements.h" | 10 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if (pixels[1] == kWebVrPosePixelMagicNumbers[0] && | 162 if (pixels[1] == kWebVrPosePixelMagicNumbers[0] && |
| 163 pixels[2] == kWebVrPosePixelMagicNumbers[1]) { | 163 pixels[2] == kWebVrPosePixelMagicNumbers[1]) { |
| 164 // Pose is good. | 164 // Pose is good. |
| 165 return pixels[0]; | 165 return pixels[0]; |
| 166 } | 166 } |
| 167 VLOG(1) << "WebVR: reject decoded pose index " << (int)pixels[0] << | 167 VLOG(1) << "WebVR: reject decoded pose index " << (int)pixels[0] << |
| 168 ", bad magic number " << (int)pixels[1] << ", " << (int)pixels[2]; | 168 ", bad magic number " << (int)pixels[1] << ", " << (int)pixels[2]; |
| 169 return -1; | 169 return -1; |
| 170 } | 170 } |
| 171 | 171 |
| 172 int64_t TimeInMicroseconds() { |
| 173 return std::chrono::duration_cast<std::chrono::microseconds>( |
| 174 std::chrono::steady_clock::now().time_since_epoch()).count(); |
| 175 } |
| 176 |
| 172 } // namespace | 177 } // namespace |
| 173 | 178 |
| 174 VrShellGl::VrShellGl( | 179 VrShellGl::VrShellGl( |
| 175 VrShell* vr_shell, | 180 VrShell* vr_shell, |
| 176 const base::WeakPtr<VrShell>& weak_vr_shell, | 181 const base::WeakPtr<VrShell>& weak_vr_shell, |
| 177 const base::WeakPtr<VrInputManager>& content_input_manager, | 182 const base::WeakPtr<VrInputManager>& content_input_manager, |
| 178 const base::WeakPtr<VrInputManager>& ui_input_manager, | 183 const base::WeakPtr<VrInputManager>& ui_input_manager, |
| 179 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 184 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 180 gvr_context* gvr_api) | 185 gvr_context* gvr_api) |
| 181 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 186 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 // object_from_reference_matrix, we're not updating position_external. | 628 // object_from_reference_matrix, we're not updating position_external. |
| 624 // TODO: Not sure what object_from_reference_matrix is. The new api removed | 629 // TODO: Not sure what object_from_reference_matrix is. The new api removed |
| 625 // it. For now, removing it seems working fine. | 630 // it. For now, removing it seems working fine. |
| 626 gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 631 gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
| 627 } | 632 } |
| 628 | 633 |
| 629 frame.BindBuffer(kFramePrimaryBuffer); | 634 frame.BindBuffer(kFramePrimaryBuffer); |
| 630 | 635 |
| 631 // Update the render position of all UI elements (including desktop). | 636 // Update the render position of all UI elements (including desktop). |
| 632 const float screen_tilt = kDesktopScreenTiltDefault * M_PI / 180.0f; | 637 const float screen_tilt = kDesktopScreenTiltDefault * M_PI / 180.0f; |
| 633 scene_->UpdateTransforms(screen_tilt, UiScene::TimeInMicroseconds()); | 638 scene_->UpdateTransforms(screen_tilt, TimeInMicroseconds()); |
| 634 | 639 |
| 635 UpdateController(GetForwardVector(head_pose)); | 640 UpdateController(GetForwardVector(head_pose)); |
| 636 | 641 |
| 637 if (vr_shell_->GetUiInterface()->GetMode() == UiInterface::Mode::WEB_VR) { | 642 if (vr_shell_->GetUiInterface()->GetMode() == UiInterface::Mode::WEB_VR) { |
| 638 DrawWebVr(); | 643 DrawWebVr(); |
| 639 | 644 |
| 640 // When using async reprojection, we need to know which pose was used in | 645 // When using async reprojection, we need to know which pose was used in |
| 641 // the WebVR app for drawing this frame. Due to unknown amounts of | 646 // the WebVR app for drawing this frame. Due to unknown amounts of |
| 642 // buffering in the compositor and SurfaceTexture, we read the pose number | 647 // buffering in the compositor and SurfaceTexture, we read the pose number |
| 643 // from a corner pixel. There's no point in doing this for legacy | 648 // from a corner pixel. There's no point in doing this for legacy |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 } | 981 } |
| 977 | 982 |
| 978 task_runner_->PostDelayedTask(FROM_HERE, draw_task_.callback(), target - now); | 983 task_runner_->PostDelayedTask(FROM_HERE, draw_task_.callback(), target - now); |
| 979 } | 984 } |
| 980 | 985 |
| 981 void VrShellGl::ForceExitVr() { | 986 void VrShellGl::ForceExitVr() { |
| 982 main_thread_task_runner_->PostTask( | 987 main_thread_task_runner_->PostTask( |
| 983 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); | 988 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); |
| 984 } | 989 } |
| 985 | 990 |
| 991 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { |
| 992 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); |
| 993 } |
| 994 |
| 986 } // namespace vr_shell | 995 } // namespace vr_shell |
| OLD | NEW |