add a use_alsa gyp setting
[chromium-blink-merge.git] / cc / vsync_time_source.cc
blob8b2426bbda08ab2733be446ec42f8f30b2cafd1c
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/vsync_time_source.h"
7 namespace cc {
9 scoped_refptr<VSyncTimeSource> VSyncTimeSource::create(
10 VSyncProvider* vsync_provider) {
11 return make_scoped_refptr(new VSyncTimeSource(vsync_provider));
14 VSyncTimeSource::VSyncTimeSource(VSyncProvider* vsync_provider)
15 : vsync_provider_(vsync_provider)
16 , client_(0)
17 , active_(false)
18 , notification_requested_(false) {}
20 VSyncTimeSource::~VSyncTimeSource() {}
22 void VSyncTimeSource::setClient(TimeSourceClient* client) {
23 client_ = client;
26 void VSyncTimeSource::setActive(bool active) {
27 if (active_ == active)
28 return;
29 active_ = active;
30 // The notification will be lazily disabled in the callback to ensure
31 // we get notified of the frame immediately following a quick on-off-on
32 // transition.
33 if (active_ && !notification_requested_) {
34 notification_requested_ = true;
35 vsync_provider_->RequestVSyncNotification(this);
39 bool VSyncTimeSource::active() const {
40 return active_;
43 base::TimeTicks VSyncTimeSource::lastTickTime() {
44 return last_tick_time_;
47 base::TimeTicks VSyncTimeSource::nextTickTime() {
48 return active() ? last_tick_time_ + interval_ : base::TimeTicks();
51 void VSyncTimeSource::setTimebaseAndInterval(base::TimeTicks,
52 base::TimeDelta interval) {
53 interval_ = interval;
56 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) {
57 last_tick_time_ = frame_time;
58 if (!active_) {
59 if (notification_requested_) {
60 notification_requested_ = false;
61 vsync_provider_->RequestVSyncNotification(NULL);
63 return;
65 if (client_)
66 client_->onTimerTick();
69 } // namespace cc