Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2801073002: [vr] Use base's time classes (Closed)
Patch Set: updated tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return mouse_event; 124 return mouse_event;
125 } 125 }
126 126
127 enum class ViewerType { 127 enum class ViewerType {
128 UNKNOWN_TYPE = 0, 128 UNKNOWN_TYPE = 0,
129 CARDBOARD = 1, 129 CARDBOARD = 1,
130 DAYDREAM = 2, 130 DAYDREAM = 2,
131 VIEWER_TYPE_MAX, 131 VIEWER_TYPE_MAX,
132 }; 132 };
133 133
134 int64_t TimeInMicroseconds() {
135 return std::chrono::duration_cast<std::chrono::microseconds>(
136 std::chrono::steady_clock::now().time_since_epoch())
137 .count();
138 }
139
140 void RunVRDisplayInfoCallback( 134 void RunVRDisplayInfoCallback(
141 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 135 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
142 device::mojom::VRDisplayInfoPtr info) { 136 device::mojom::VRDisplayInfoPtr info) {
143 callback.Run(std::move(info)); 137 callback.Run(std::move(info));
144 } 138 }
145 139
146 } // namespace 140 } // namespace
147 141
148 VrShellGl::VrShellGl( 142 VrShellGl::VrShellGl(
149 const base::WeakPtr<VrShell>& weak_vr_shell, 143 const base::WeakPtr<VrShell>& weak_vr_shell,
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 ? &VrShell::ProcessContentGesture 709 ? &VrShell::ProcessContentGesture
716 : &VrShell::ProcessUIGesture; 710 : &VrShell::ProcessUIGesture;
717 main_thread_task_runner_->PostTask( 711 main_thread_task_runner_->PostTask(
718 FROM_HERE, 712 FROM_HERE,
719 base::Bind(target, weak_vr_shell_, base::Passed(std::move(event)))); 713 base::Bind(target, weak_vr_shell_, base::Passed(std::move(event))));
720 } 714 }
721 715
722 void VrShellGl::DrawFrame(int16_t frame_index) { 716 void VrShellGl::DrawFrame(int16_t frame_index) {
723 TRACE_EVENT1("gpu", "VrShellGl::DrawFrame", "frame", frame_index); 717 TRACE_EVENT1("gpu", "VrShellGl::DrawFrame", "frame", frame_index);
724 718
719 base::TimeTicks current_time = base::TimeTicks::Now();
720
725 // Reset the viewport list to just the pair of viewports for the 721 // Reset the viewport list to just the pair of viewports for the
726 // primary buffer each frame. Head-locked viewports get added by 722 // primary buffer each frame. Head-locked viewports get added by
727 // DrawVrShell if needed. 723 // DrawVrShell if needed.
728 buffer_viewport_list_->SetToRecommendedBufferViewports(); 724 buffer_viewport_list_->SetToRecommendedBufferViewports();
729 725
730 // If needed, resize the primary buffer for use with WebVR. Resizing 726 // If needed, resize the primary buffer for use with WebVR. Resizing
731 // needs to happen before acquiring a frame. 727 // needs to happen before acquiring a frame.
732 if (ShouldDrawWebVr()) { 728 if (ShouldDrawWebVr()) {
733 // Process all pending_bounds_ changes targeted for before this 729 // Process all pending_bounds_ changes targeted for before this
734 // frame, being careful of wrapping frame indices. 730 // frame, being careful of wrapping frame indices.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) { 812 if (position.x == 0.0f && position.y == 0.0f && position.z == 0.0f) {
817 // This appears to be a 3DOF pose without a neck model. Add one. 813 // This appears to be a 3DOF pose without a neck model. Add one.
818 // The head pose has redundant data. Assume we're only using the 814 // The head pose has redundant data. Assume we're only using the
819 // object_from_reference_matrix, we're not updating position_external. 815 // object_from_reference_matrix, we're not updating position_external.
820 // TODO: Not sure what object_from_reference_matrix is. The new api removed 816 // TODO: Not sure what object_from_reference_matrix is. The new api removed
821 // it. For now, removing it seems working fine. 817 // it. For now, removing it seems working fine.
822 gvr_api_->ApplyNeckModel(head_pose, 1.0f); 818 gvr_api_->ApplyNeckModel(head_pose, 1.0f);
823 } 819 }
824 820
825 // Update the render position of all UI elements (including desktop). 821 // Update the render position of all UI elements (including desktop).
826 scene_->UpdateTransforms(TimeInMicroseconds()); 822 scene_->UpdateTransforms(current_time);
827 823
828 { 824 {
829 // TODO(crbug.com/704690): Acquire controller state in a way that's timely 825 // TODO(crbug.com/704690): Acquire controller state in a way that's timely
830 // for both the gamepad API and UI input handling. 826 // for both the gamepad API and UI input handling.
831 TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); 827 TRACE_EVENT0("gpu", "VrShellGl::UpdateController");
832 UpdateController(); 828 UpdateController();
833 HandleControllerInput(GetForwardVector(head_pose)); 829 HandleControllerInput(GetForwardVector(head_pose));
834 } 830 }
835 831
836 DrawWorldElements(head_pose); 832 DrawWorldElements(head_pose);
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this))); 1257 vsync_task_.Reset(base::Bind(&VrShellGl::OnVSync, base::Unretained(this)));
1262 OnVSync(); 1258 OnVSync();
1263 } 1259 }
1264 1260
1265 void VrShellGl::ForceExitVr() { 1261 void VrShellGl::ForceExitVr() {
1266 main_thread_task_runner_->PostTask( 1262 main_thread_task_runner_->PostTask(
1267 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); 1263 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_));
1268 } 1264 }
1269 1265
1270 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { 1266 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) {
1271 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); 1267 scene_->HandleCommands(std::move(commands), base::TimeTicks::Now());
1272 } 1268 }
1273 1269
1274 void VrShellGl::SendVSync(base::TimeDelta time, 1270 void VrShellGl::SendVSync(base::TimeDelta time,
1275 const GetVSyncCallback& callback) { 1271 const GetVSyncCallback& callback) {
1276 uint8_t frame_index = frame_index_++; 1272 uint8_t frame_index = frame_index_++;
1277 1273
1278 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); 1274 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index);
1279 1275
1280 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 1276 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
1281 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 1277 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
(...skipping 15 matching lines...) Expand all
1297 // appropriate recommended render resolution as the default size during 1293 // appropriate recommended render resolution as the default size during
1298 // InitializeGl. Revisit if the initialization order changes. 1294 // InitializeGl. Revisit if the initialization order changes.
1299 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( 1295 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo(
1300 gvr_api_.get(), webvr_surface_size_, device_id); 1296 gvr_api_.get(), webvr_surface_size_, device_id);
1301 main_thread_task_runner_->PostTask( 1297 main_thread_task_runner_->PostTask(
1302 FROM_HERE, 1298 FROM_HERE,
1303 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1299 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1304 } 1300 }
1305 1301
1306 } // namespace vr_shell 1302 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698