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/non_presenting_gvr_delegate.h" | 5 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" |
6 | 6 |
7 #include "chrome/browser/android/vr_shell/vr_shell.h" | 7 #include "chrome/browser/android/vr_shell/vr_shell.h" |
8 | 8 |
9 namespace vr_shell { | 9 namespace vr_shell { |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 device::mojom::VRVSyncProviderRequest | 49 device::mojom::VRVSyncProviderRequest |
50 NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { | 50 NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { |
51 StopVSyncLoop(); | 51 StopVSyncLoop(); |
52 if (binding_.is_bound()) | 52 if (binding_.is_bound()) |
53 return binding_.Unbind(); | 53 return binding_.Unbind(); |
54 return nullptr; | 54 return nullptr; |
55 } | 55 } |
56 | 56 |
57 void NonPresentingGvrDelegate::StopVSyncLoop() { | 57 void NonPresentingGvrDelegate::StopVSyncLoop() { |
58 vsync_task_.Cancel(); | 58 vsync_task_.Cancel(); |
59 if (!callback_.is_null()) | 59 if (!callback_.is_null()) { |
60 callback_.Run(nullptr, base::TimeDelta()); | 60 callback_.Run(nullptr, base::TimeDelta(), -1); |
dcheng
2017/01/27 09:41:33
One possibility (if you want) is base::ResetAndRet
mthiesse
2017/01/27 16:15:31
That works well, thanks!
| |
61 callback_.Reset(); | |
62 } | |
61 callback_.Reset(); | 63 callback_.Reset(); |
62 gvr_api_->PauseTracking(); | 64 gvr_api_->PauseTracking(); |
63 // If the loop is stopped, it's not considered to be paused. | 65 // If the loop is stopped, it's not considered to be paused. |
64 vsync_paused_ = false; | 66 vsync_paused_ = false; |
65 } | 67 } |
66 | 68 |
67 void NonPresentingGvrDelegate::StartVSyncLoop() { | 69 void NonPresentingGvrDelegate::StartVSyncLoop() { |
68 vsync_task_.Reset( | 70 vsync_task_.Reset( |
69 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); | 71 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); |
70 gvr_api_->RefreshViewerProfile(); | 72 gvr_api_->RefreshViewerProfile(); |
(...skipping 16 matching lines...) Expand all Loading... | |
87 target = now + vsync_interval_; | 89 target = now + vsync_interval_; |
88 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; | 90 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; |
89 target = vsync_timebase_ + intervals * vsync_interval_; | 91 target = vsync_timebase_ + intervals * vsync_interval_; |
90 if (!vsync_task_.IsCancelled()) { | 92 if (!vsync_task_.IsCancelled()) { |
91 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), | 93 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), |
92 target - now); | 94 target - now); |
93 } | 95 } |
94 | 96 |
95 base::TimeDelta time = intervals * vsync_interval_; | 97 base::TimeDelta time = intervals * vsync_interval_; |
96 if (!callback_.is_null()) { | 98 if (!callback_.is_null()) { |
97 callback_.Run(GetPose(), time); | 99 SendVSync(time, callback_); |
98 callback_.Reset(); | 100 callback_.Reset(); |
99 } else { | 101 } else { |
100 pending_vsync_ = true; | 102 pending_vsync_ = true; |
101 pending_time_ = time; | 103 pending_time_ = time; |
102 } | 104 } |
103 } | 105 } |
104 | 106 |
105 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) { | 107 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) { |
106 if (!pending_vsync_) { | 108 if (!pending_vsync_) { |
107 if (!callback_.is_null()) { | 109 if (!callback_.is_null()) { |
108 mojo::ReportBadMessage("Requested VSync before waiting for response to " | 110 mojo::ReportBadMessage("Requested VSync before waiting for response to " |
109 "previous request."); | 111 "previous request."); |
110 return; | 112 return; |
111 } | 113 } |
112 callback_ = callback; | 114 callback_ = callback; |
113 return; | 115 return; |
114 } | 116 } |
115 pending_vsync_ = false; | 117 pending_vsync_ = false; |
116 callback.Run(GetPose(), pending_time_); | 118 SendVSync(pending_time_, callback); |
117 } | 119 } |
118 | 120 |
119 void NonPresentingGvrDelegate::UpdateVSyncInterval(long timebase_nanos, | 121 void NonPresentingGvrDelegate::UpdateVSyncInterval(long timebase_nanos, |
120 double interval_seconds) { | 122 double interval_seconds) { |
121 vsync_timebase_ = base::TimeTicks(); | 123 vsync_timebase_ = base::TimeTicks(); |
122 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); | 124 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); |
123 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); | 125 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); |
124 StartVSyncLoop(); | 126 StartVSyncLoop(); |
125 } | 127 } |
126 | 128 |
127 device::mojom::VRPosePtr NonPresentingGvrDelegate::GetPose() { | 129 void NonPresentingGvrDelegate::SendVSync(base::TimeDelta time, |
130 const GetVSyncCallback& callback) { | |
128 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 131 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
129 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 132 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
130 | 133 |
131 gvr::Mat4f head_mat = | 134 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( |
132 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 135 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); |
133 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); | 136 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1); |
134 | |
135 uint32_t pose_index = pose_index_++; | |
136 | |
137 return VrShell::VRPosePtrFromGvrPose(head_mat, pose_index); | |
138 } | 137 } |
139 | 138 |
140 } // namespace vr_shell | 139 } // namespace vr_shell |
OLD | NEW |