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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { | 53 NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { |
54 StopVSyncLoop(); | 54 StopVSyncLoop(); |
55 if (binding_.is_bound()) | 55 if (binding_.is_bound()) |
56 return binding_.Unbind(); | 56 return binding_.Unbind(); |
57 return nullptr; | 57 return nullptr; |
58 } | 58 } |
59 | 59 |
60 void NonPresentingGvrDelegate::StopVSyncLoop() { | 60 void NonPresentingGvrDelegate::StopVSyncLoop() { |
61 vsync_task_.Cancel(); | 61 vsync_task_.Cancel(); |
62 if (!callback_.is_null()) | 62 if (!callback_.is_null()) |
63 callback_.Run(nullptr, base::TimeDelta()); | 63 callback_.Run(nullptr, base::TimeDelta(), -1); |
64 callback_.Reset(); | 64 callback_.Reset(); |
65 gvr_api_->PauseTracking(); | 65 gvr_api_->PauseTracking(); |
66 paused_ = false; | 66 paused_ = false; |
67 } | 67 } |
68 | 68 |
69 void NonPresentingGvrDelegate::StartVSyncLoop() { | 69 void NonPresentingGvrDelegate::StartVSyncLoop() { |
70 vsync_task_.Reset( | 70 vsync_task_.Reset( |
71 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); | 71 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); |
72 gvr_api_->RefreshViewerProfile(); | 72 gvr_api_->RefreshViewerProfile(); |
73 gvr_api_->ResumeTracking(); | 73 gvr_api_->ResumeTracking(); |
(...skipping 15 matching lines...) Expand all Loading... | |
89 target = now + vsync_interval_; | 89 target = now + vsync_interval_; |
90 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; | 90 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; |
91 target = vsync_timebase_ + intervals * vsync_interval_; | 91 target = vsync_timebase_ + intervals * vsync_interval_; |
92 if (!vsync_task_.IsCancelled()) { | 92 if (!vsync_task_.IsCancelled()) { |
93 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), | 93 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), |
94 target - now); | 94 target - now); |
95 } | 95 } |
96 | 96 |
97 base::TimeDelta time = intervals * vsync_interval_; | 97 base::TimeDelta time = intervals * vsync_interval_; |
98 if (!callback_.is_null()) { | 98 if (!callback_.is_null()) { |
99 callback_.Run(GetPose(), time); | 99 SendVSync(time, std::move(callback_)); |
100 callback_.Reset(); | |
101 } else { | 100 } else { |
102 pending_vsync_ = true; | 101 pending_vsync_ = true; |
103 pending_time_ = time; | 102 pending_time_ = time; |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) { | 106 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) { |
108 if (!pending_vsync_) { | 107 if (!pending_vsync_) { |
109 if (!callback_.is_null()) { | 108 if (!callback_.is_null()) { |
110 mojo::ReportBadMessage("Requested VSync before waiting for response to " | 109 mojo::ReportBadMessage("Requested VSync before waiting for response to " |
111 "previous request."); | 110 "previous request."); |
112 return; | 111 return; |
113 } | 112 } |
114 callback_ = std::move(callback); | 113 callback_ = std::move(callback); |
115 return; | 114 return; |
116 } | 115 } |
117 pending_vsync_ = false; | 116 pending_vsync_ = false; |
118 callback.Run(GetPose(), pending_time_); | 117 SendVSync(pending_time_, std::move(callback)); |
dcheng
2017/01/18 23:58:07
Nit: std::move() here is a no-op
mthiesse
2017/01/19 01:19:08
Done.
| |
119 } | 118 } |
120 | 119 |
121 void NonPresentingGvrDelegate::UpdateVSyncInterval(long timebase_nanos, | 120 void NonPresentingGvrDelegate::UpdateVSyncInterval(long timebase_nanos, |
122 double interval_seconds) { | 121 double interval_seconds) { |
123 vsync_timebase_ = base::TimeTicks(); | 122 vsync_timebase_ = base::TimeTicks(); |
124 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); | 123 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); |
125 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); | 124 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); |
126 StartVSyncLoop(); | 125 StartVSyncLoop(); |
127 } | 126 } |
128 | 127 |
129 device::mojom::VRPosePtr NonPresentingGvrDelegate::GetPose() { | 128 void NonPresentingGvrDelegate::SendVSync(const base::TimeDelta& time, |
129 GetVSyncCallback callback) { | |
130 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 130 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
131 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 131 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; |
132 | 132 |
133 gvr::Mat4f head_mat = | 133 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel( |
134 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); | 134 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); |
135 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); | 135 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1); |
136 | |
137 uint32_t pose_index = pose_index_++; | |
138 | |
139 return VrShell::VRPosePtrFromGvrPose(head_mat, pose_index); | |
140 } | 136 } |
141 | 137 |
142 } // namespace vr_shell | 138 } // namespace vr_shell |
OLD | NEW |