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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 // object_from_reference_matrix, we're not updating position_external. | 648 // object_from_reference_matrix, we're not updating position_external. |
644 // TODO: Not sure what object_from_reference_matrix is. The new api removed | 649 // TODO: Not sure what object_from_reference_matrix is. The new api removed |
645 // it. For now, removing it seems working fine. | 650 // it. For now, removing it seems working fine. |
646 gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 651 gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
647 } | 652 } |
648 | 653 |
649 frame.BindBuffer(kFramePrimaryBuffer); | 654 frame.BindBuffer(kFramePrimaryBuffer); |
650 | 655 |
651 // Update the render position of all UI elements (including desktop). | 656 // Update the render position of all UI elements (including desktop). |
652 const float screen_tilt = kDesktopScreenTiltDefault * M_PI / 180.0f; | 657 const float screen_tilt = kDesktopScreenTiltDefault * M_PI / 180.0f; |
653 scene_->UpdateTransforms(screen_tilt, UiScene::TimeInMicroseconds()); | 658 scene_->UpdateTransforms(screen_tilt, TimeInMicroseconds()); |
654 | 659 |
655 UpdateController(GetForwardVector(head_pose)); | 660 UpdateController(GetForwardVector(head_pose)); |
656 | 661 |
657 if (vr_shell_->GetUiInterface()->GetMode() == UiInterface::Mode::WEB_VR) { | 662 if (vr_shell_->GetUiInterface()->GetMode() == UiInterface::Mode::WEB_VR) { |
658 DrawWebVr(); | 663 DrawWebVr(); |
659 | 664 |
660 // When using async reprojection, we need to know which pose was used in | 665 // When using async reprojection, we need to know which pose was used in |
661 // the WebVR app for drawing this frame. Due to unknown amounts of | 666 // the WebVR app for drawing this frame. Due to unknown amounts of |
662 // buffering in the compositor and SurfaceTexture, we read the pose number | 667 // buffering in the compositor and SurfaceTexture, we read the pose number |
663 // from a corner pixel. There's no point in doing this for legacy | 668 // from a corner pixel. There's no point in doing this for legacy |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 } | 1008 } |
1004 | 1009 |
1005 task_runner_->PostDelayedTask(FROM_HERE, draw_task_.callback(), target - now); | 1010 task_runner_->PostDelayedTask(FROM_HERE, draw_task_.callback(), target - now); |
1006 } | 1011 } |
1007 | 1012 |
1008 void VrShellGl::ForceExitVR() { | 1013 void VrShellGl::ForceExitVR() { |
1009 main_thread_task_runner_->PostTask( | 1014 main_thread_task_runner_->PostTask( |
1010 FROM_HERE, base::Bind(&VrShell::ForceExitVR, weak_vr_shell_)); | 1015 FROM_HERE, base::Bind(&VrShell::ForceExitVR, weak_vr_shell_)); |
1011 } | 1016 } |
1012 | 1017 |
| 1018 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { |
| 1019 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); |
| 1020 } |
| 1021 |
1013 } // namespace vr_shell | 1022 } // namespace vr_shell |
OLD | NEW |