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 <chrono> | 7 #include <chrono> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 // The GVR viewport list has two entries (left eye and right eye) for each | 76 // The GVR viewport list has two entries (left eye and right eye) for each |
77 // GVR buffer. | 77 // GVR buffer. |
78 static constexpr int kViewportListPrimaryOffset = 0; | 78 static constexpr int kViewportListPrimaryOffset = 0; |
79 static constexpr int kViewportListHeadlockedOffset = 2; | 79 static constexpr int kViewportListHeadlockedOffset = 2; |
80 | 80 |
81 // Buffer size large enough to handle the current backlog of poses which is | 81 // Buffer size large enough to handle the current backlog of poses which is |
82 // 2-3 frames. | 82 // 2-3 frames. |
83 static constexpr unsigned kPoseRingBufferSize = 8; | 83 static constexpr unsigned kPoseRingBufferSize = 8; |
84 | 84 |
85 // Number of frames to use for sliding averages for pose timings, | |
86 // as used for estimating prediction times. | |
87 static constexpr unsigned kWebVRSlidingAverageSize = 5; | |
88 | |
85 // Criteria for considering holding the app button in combination with | 89 // Criteria for considering holding the app button in combination with |
86 // controller movement as a gesture. | 90 // controller movement as a gesture. |
87 static constexpr float kMinAppButtonGestureAngleRad = 0.25; | 91 static constexpr float kMinAppButtonGestureAngleRad = 0.25; |
88 | 92 |
89 static constexpr gfx::PointF kInvalidTargetPoint = | 93 static constexpr gfx::PointF kInvalidTargetPoint = |
90 gfx::PointF(std::numeric_limits<float>::max(), | 94 gfx::PointF(std::numeric_limits<float>::max(), |
91 std::numeric_limits<float>::max()); | 95 std::numeric_limits<float>::max()); |
92 | 96 |
93 // Generate a quaternion representing the rotation from the negative Z axis | 97 // Generate a quaternion representing the rotation from the negative Z axis |
94 // (0, 0, -1) to a specified vector. This is an optimized version of a more | 98 // (0, 0, -1) to a specified vector. This is an optimized version of a more |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 : web_vr_mode_(initially_web_vr), | 223 : web_vr_mode_(initially_web_vr), |
220 surfaceless_rendering_(reprojected_rendering), | 224 surfaceless_rendering_(reprojected_rendering), |
221 daydream_support_(daydream_support), | 225 daydream_support_(daydream_support), |
222 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 226 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
223 binding_(this), | 227 binding_(this), |
224 browser_(browser), | 228 browser_(browser), |
225 scene_(scene), | 229 scene_(scene), |
226 #if DCHECK_IS_ON() | 230 #if DCHECK_IS_ON() |
227 fps_meter_(new FPSMeter()), | 231 fps_meter_(new FPSMeter()), |
228 #endif | 232 #endif |
233 webvr_js_time_(new SlidingAverage(kWebVRSlidingAverageSize)), | |
234 webvr_render_time_(new SlidingAverage(kWebVRSlidingAverageSize)), | |
229 weak_ptr_factory_(this) { | 235 weak_ptr_factory_(this) { |
230 GvrInit(gvr_api); | 236 GvrInit(gvr_api); |
231 } | 237 } |
232 | 238 |
233 VrShellGl::~VrShellGl() { | 239 VrShellGl::~VrShellGl() { |
234 vsync_task_.Cancel(); | 240 vsync_task_.Cancel(); |
235 // TODO(mthiesse): Can we omit the Close() here? Concern is that if | 241 // TODO(mthiesse): Can we omit the Close() here? Concern is that if |
236 // both ends of the connection ever live in the same process for | 242 // both ends of the connection ever live in the same process for |
237 // some reason, we could receive another VSync request in response | 243 // some reason, we could receive another VSync request in response |
238 // to the closing message in the destructor but fail to respond to | 244 // to the closing message in the destructor but fail to respond to |
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 void VrShellGl::ForceExitVr() { | 1523 void VrShellGl::ForceExitVr() { |
1518 browser_->ForceExitVr(); | 1524 browser_->ForceExitVr(); |
1519 } | 1525 } |
1520 | 1526 |
1521 void VrShellGl::SendVSync(base::TimeDelta time, | 1527 void VrShellGl::SendVSync(base::TimeDelta time, |
1522 const GetVSyncCallback& callback) { | 1528 const GetVSyncCallback& callback) { |
1523 uint8_t frame_index = frame_index_++; | 1529 uint8_t frame_index = frame_index_++; |
1524 | 1530 |
1525 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); | 1531 TRACE_EVENT1("input", "VrShellGl::SendVSync", "frame", frame_index); |
1526 | 1532 |
1533 int64_t frame_time_micros = vsync_interval_.InMicroseconds(); | |
cjgrant
2017/05/24 13:37:30
How do you feel about dropping this block into VrS
klausw
2017/05/24 16:32:23
Done, I've also added TRACE_COUNTER output so that
| |
1534 // If we aim to submit at vsync, that frame will start scanning out | |
1535 // one vsync later. Add a half frame to split the difference between | |
1536 // left and right eye. | |
1537 int64_t overhead_micros = frame_time_micros * 3 / 2; | |
1538 int64_t expected_frame_time = | |
1539 webvr_js_time_->GetAverageOrDefault(frame_time_micros) + | |
1540 webvr_render_time_->GetAverageOrDefault(frame_time_micros); | |
1541 int64_t prediction_nanos = (expected_frame_time + overhead_micros) * 1000; | |
1542 | |
1527 vr::Mat4f head_mat; | 1543 vr::Mat4f head_mat; |
1528 device::mojom::VRPosePtr pose = | 1544 device::mojom::VRPosePtr pose = |
1529 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat); | 1545 device::GvrDelegate::GetVRPosePtrWithNeckModel(gvr_api_.get(), &head_mat, |
1546 prediction_nanos); | |
1530 | 1547 |
1531 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; | 1548 webvr_head_pose_[frame_index % kPoseRingBufferSize] = head_mat; |
1532 | 1549 |
1533 callback.Run(std::move(pose), time, frame_index, | 1550 callback.Run(std::move(pose), time, frame_index, |
1534 device::mojom::VRVSyncProvider::Status::SUCCESS); | 1551 device::mojom::VRVSyncProvider::Status::SUCCESS); |
1535 } | 1552 } |
1536 | 1553 |
1537 void VrShellGl::CreateVRDisplayInfo( | 1554 void VrShellGl::CreateVRDisplayInfo( |
1538 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, | 1555 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
1539 uint32_t device_id) { | 1556 uint32_t device_id) { |
1540 // This assumes that the initial webvr_surface_size_ was set to the | 1557 // This assumes that the initial webvr_surface_size_ was set to the |
1541 // appropriate recommended render resolution as the default size during | 1558 // appropriate recommended render resolution as the default size during |
1542 // InitializeGl. Revisit if the initialization order changes. | 1559 // InitializeGl. Revisit if the initialization order changes. |
1543 device::mojom::VRDisplayInfoPtr info = | 1560 device::mojom::VRDisplayInfoPtr info = |
1544 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1561 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
1545 webvr_surface_size_, device_id); | 1562 webvr_surface_size_, device_id); |
1546 browser_->RunVRDisplayInfoCallback(callback, &info); | 1563 browser_->RunVRDisplayInfoCallback(callback, &info); |
1547 } | 1564 } |
1548 | 1565 |
1549 } // namespace vr_shell | 1566 } // namespace vr_shell |
OLD | NEW |