summaryrefslogtreecommitdiffstats
path: root/cc/scheduler/vsync_time_source.cc
blob: 206e2376675156e36cd20ee0d284a7dc40b5f7ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/scheduler/vsync_time_source.h"

#include "base/logging.h"

namespace cc {

scoped_refptr<VSyncTimeSource> VSyncTimeSource::Create(
    VSyncProvider* vsync_provider, NotificationDisableOption option) {
  return make_scoped_refptr(new VSyncTimeSource(vsync_provider, option));
}

VSyncTimeSource::VSyncTimeSource(
    VSyncProvider* vsync_provider, NotificationDisableOption option)
    : active_(false),
      notification_requested_(false),
      vsync_provider_(vsync_provider),
      client_(NULL),
      disable_option_(option) {}

VSyncTimeSource::~VSyncTimeSource() {}

void VSyncTimeSource::SetClient(TimeSourceClient* client) {
  client_ = client;
}

void VSyncTimeSource::SetActive(bool active) {
  if (active_ == active)
    return;
  active_ = active;
  if (active_ && !notification_requested_) {
    notification_requested_ = true;
    vsync_provider_->RequestVSyncNotification(this);
  }
  if (!active_ && disable_option_ == DISABLE_SYNCHRONOUSLY) {
    notification_requested_ = false;
    vsync_provider_->RequestVSyncNotification(NULL);
  }
}

bool VSyncTimeSource::Active() const {
  return active_;
}

base::TimeTicks VSyncTimeSource::LastTickTime() {
  return last_tick_time_;
}

base::TimeTicks VSyncTimeSource::NextTickTime() {
  return Active() ? last_tick_time_ + interval_ : base::TimeTicks();
}

void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks,
                                             base::TimeDelta interval) {
  interval_ = interval;
}

void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) {
  last_tick_time_ = frame_time;
  if (disable_option_ == DISABLE_SYNCHRONOUSLY) {
    DCHECK(active_);
  } else if (!active_) {
    if (notification_requested_) {
      notification_requested_ = false;
      vsync_provider_->RequestVSyncNotification(NULL);
    }
    return;
  }
  if (client_)
    client_->OnTimerTick();
}

}  // namespace cc