Chromium Code Reviews| Index: cc/vsync_time_source.cc |
| diff --git a/cc/vsync_time_source.cc b/cc/vsync_time_source.cc |
| index 8b2426bbda08ab2733be446ec42f8f30b2cafd1c..e8e654dafe31b0f1f25f8a4aca5ccedec8ddb629 100644 |
| --- a/cc/vsync_time_source.cc |
| +++ b/cc/vsync_time_source.cc |
| @@ -15,7 +15,8 @@ VSyncTimeSource::VSyncTimeSource(VSyncProvider* vsync_provider) |
| : vsync_provider_(vsync_provider) |
| , client_(0) |
| , active_(false) |
| - , notification_requested_(false) {} |
| + , notification_requested_(false) |
| + , did_synthesize_last_vsync_(false) {} |
| VSyncTimeSource::~VSyncTimeSource() {} |
| @@ -54,7 +55,18 @@ void VSyncTimeSource::setTimebaseAndInterval(base::TimeTicks, |
| } |
| void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { |
| + // We can use input events to synthesize vsync events, but we must be careful |
|
jamesr
2013/01/16 04:13:26
this logic seems really fishy to me. I think you
Sami
2013/01/16 10:49:15
I suppose you're right. Doing this in the browser
|
| + // to avoid ticking multiple times during a single frame. To do that we keep |
| + // track of when the last synthesized vsync happened and ignore any real vsync |
| + // notifications during the first half of the same frame. |
| + double intervals_since_last_tick = |
| + (frame_time - last_tick_time_).InSecondsF() / interval_.InSecondsF(); |
| last_tick_time_ = frame_time; |
| + if (did_synthesize_last_vsync_) { |
| + did_synthesize_last_vsync_ = false; |
| + if (intervals_since_last_tick < .5) |
| + return; |
|
jamesr
2013/01/16 04:13:26
we should trace this early-out
|
| + } |
| if (!active_) { |
| if (notification_requested_) { |
| notification_requested_ = false; |
| @@ -66,4 +78,24 @@ void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { |
| client_->onTimerTick(); |
| } |
| +base::TimeTicks VSyncTimeSource::Now() const |
| +{ |
| + return base::TimeTicks::Now(); |
| +} |
| + |
| +void VSyncTimeSource::DidReceiveLastInputEventForVSync() { |
| + if (!active_ || interval_ == base::TimeDelta()) |
| + return; |
| + |
| + // Since input events currently aren't timestamped, we need to estimate the |
| + // current frame time. |
| + double intervals_since_last_tick = |
| + (Now() - last_tick_time_).InSecondsF() / interval_.InSecondsF(); |
| + last_tick_time_ += interval_ * std::max(1., floor(intervals_since_last_tick)); |
| + did_synthesize_last_vsync_ = true; |
| + |
| + if (client_) |
| + client_->onTimerTick(); |
| +} |
| + |
| } // namespace cc |