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

Unified Diff: cc/vsync_time_source.cc

Issue 11854013: Use input events to improve vsync scheduling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't set last-input-for-vsync bit on pages with touch handlers. Created 7 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698