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"
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
)
18 , notification_requested_(false) {}
20 VSyncTimeSource::~VSyncTimeSource() {}
22 void VSyncTimeSource::setClient(TimeSourceClient
* client
) {
26 void VSyncTimeSource::setActive(bool active
) {
27 if (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
33 if (active_
&& !notification_requested_
) {
34 notification_requested_
= true;
35 vsync_provider_
->RequestVSyncNotification(this);
39 bool VSyncTimeSource::active() const {
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
) {
56 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time
) {
57 last_tick_time_
= frame_time
;
59 if (notification_requested_
) {
60 notification_requested_
= false;
61 vsync_provider_
->RequestVSyncNotification(NULL
);
66 client_
->onTimerTick();