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

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

Issue 2612333002: Allow VRDisplay to specify which frame the layer bounds should be updated at. (Closed)
Patch Set: Finish implementaion Created 3 years, 11 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
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/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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 StartVSyncLoop(); 46 StartVSyncLoop();
47 } 47 }
48 48
49 void NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() { 49 void NonPresentingGvrDelegate::OnSwitchToPresentingDelegate() {
50 StopVSyncLoop(); 50 StopVSyncLoop();
51 } 51 }
52 52
53 void NonPresentingGvrDelegate::StopVSyncLoop() { 53 void NonPresentingGvrDelegate::StopVSyncLoop() {
54 vsync_task_.Cancel(); 54 vsync_task_.Cancel();
55 if (!callback_.is_null()) 55 if (!callback_.is_null())
56 callback_.Run(nullptr, 0); 56 callback_.Run(nullptr, 0, -1);
57 callback_.Reset(); 57 callback_.Reset();
58 if (binding_.is_bound()) 58 if (binding_.is_bound())
59 binding_.Close(); 59 binding_.Close();
60 gvr_api_->PauseTracking(); 60 gvr_api_->PauseTracking();
61 paused_ = false; 61 paused_ = false;
62 } 62 }
63 63
64 void NonPresentingGvrDelegate::StartVSyncLoop() { 64 void NonPresentingGvrDelegate::StartVSyncLoop() {
65 vsync_task_.Reset( 65 vsync_task_.Reset(
66 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this))); 66 base::Bind(&NonPresentingGvrDelegate::OnVSync, base::Unretained(this)));
(...skipping 16 matching lines...) Expand all
83 target = now + vsync_interval_; 83 target = now + vsync_interval_;
84 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; 84 int64_t intervals = (target - vsync_timebase_) / vsync_interval_;
85 target = vsync_timebase_ + intervals * vsync_interval_; 85 target = vsync_timebase_ + intervals * vsync_interval_;
86 if (!vsync_task_.IsCancelled()) { 86 if (!vsync_task_.IsCancelled()) {
87 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), 87 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(),
88 target - now); 88 target - now);
89 } 89 }
90 90
91 double time = (intervals * vsync_interval_).InSecondsF(); 91 double time = (intervals * vsync_interval_).InSecondsF();
92 if (!callback_.is_null()) { 92 if (!callback_.is_null()) {
93 callback_.Run(GetPose(), time); 93 SendVSync(time, std::move(callback_));
94 callback_.Reset();
95 } else { 94 } else {
96 pending_vsync_ = true; 95 pending_vsync_ = true;
97 pending_time_ = time; 96 pending_time_ = time;
98 } 97 }
99 } 98 }
100 99
101 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) { 100 void NonPresentingGvrDelegate::GetVSync(const GetVSyncCallback& callback) {
102 if (!pending_vsync_) { 101 if (!pending_vsync_) {
103 callback_ = std::move(callback); 102 callback_ = std::move(callback);
104 return; 103 return;
105 } 104 }
106 pending_vsync_ = false; 105 pending_vsync_ = false;
107 callback.Run(GetPose(), pending_time_); 106 SendVSync(pending_time_, std::move(callback));
108 } 107 }
109 108
110 void NonPresentingGvrDelegate::UpdateVSyncInterval(long timebase_nanos, 109 void NonPresentingGvrDelegate::UpdateVSyncInterval(long timebase_nanos,
111 double interval_seconds) { 110 double interval_seconds) {
112 vsync_timebase_ = base::TimeTicks(); 111 vsync_timebase_ = base::TimeTicks();
113 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000); 112 vsync_timebase_ += base::TimeDelta::FromMicroseconds(timebase_nanos / 1000);
114 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds); 113 vsync_interval_ = base::TimeDelta::FromSecondsD(interval_seconds);
115 StartVSyncLoop(); 114 StartVSyncLoop();
116 } 115 }
117 116
118 device::mojom::VRPosePtr NonPresentingGvrDelegate::GetPose() { 117 void NonPresentingGvrDelegate::SendVSync(double time,
118 GetVSyncCallback callback) {
119 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 119 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
120 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; 120 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos;
121 121
122 gvr::Mat4f head_mat = 122 gvr::Mat4f head_mat = gvr_api_->ApplyNeckModel(
123 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); 123 gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f);
124 head_mat = gvr_api_->ApplyNeckModel(head_mat, 1.0f); 124 callback.Run(VrShell::VRPosePtrFromGvrPose(head_mat), time, -1);
125
126 uint32_t pose_index = pose_index_++;
127
128 return VrShell::VRPosePtrFromGvrPose(head_mat, pose_index);
129 } 125 }
130 126
131 } // namespace vr_shell 127 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698