summaryrefslogtreecommitdiffstats
path: root/cc/scheduler/vsync_time_source.h
blob: 8d0659c6918af23577eea6faec460a2d266c2e08 (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
// 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.

#ifndef CC_SCHEDULER_VSYNC_TIME_SOURCE_H_
#define CC_SCHEDULER_VSYNC_TIME_SOURCE_H_

#include "cc/base/cc_export.h"
#include "cc/scheduler/time_source.h"

namespace cc {

class CC_EXPORT VSyncClient {
 public:
  virtual void DidVSync(base::TimeTicks frame_time) = 0;

 protected:
  virtual ~VSyncClient() {}
};

class VSyncProvider {
 public:
  // Request to be notified of future vsync events. The notifications will be
  // delivered until they are disabled by calling this function with a null
  // client.
  virtual void RequestVSyncNotification(VSyncClient* client) = 0;

 protected:
  virtual ~VSyncProvider() {}
};

// This timer implements a time source that is explicitly triggered by an
// external vsync signal.
class CC_EXPORT VSyncTimeSource : public TimeSource, public VSyncClient {
 public:
  static scoped_refptr<VSyncTimeSource> create(VSyncProvider* vsync_provider);

  // TimeSource implementation
  virtual void setClient(TimeSourceClient* client) OVERRIDE;
  virtual void setTimebaseAndInterval(base::TimeTicks timebase,
                                      base::TimeDelta interval) OVERRIDE;
  virtual void setActive(bool active) OVERRIDE;
  virtual bool active() const OVERRIDE;
  virtual base::TimeTicks lastTickTime() OVERRIDE;
  virtual base::TimeTicks nextTickTime() OVERRIDE;

  // VSyncClient implementation
  virtual void DidVSync(base::TimeTicks frame_time) OVERRIDE;

 protected:
  explicit VSyncTimeSource(VSyncProvider* vsync_provider);
  virtual ~VSyncTimeSource();

  base::TimeTicks last_tick_time_;
  base::TimeDelta interval_;
  bool active_;
  bool notification_requested_;

  VSyncProvider* vsync_provider_;
  TimeSourceClient* client_;

  DISALLOW_COPY_AND_ASSIGN(VSyncTimeSource);
};

}  // namespace cc

#endif  // CC_SCHEDULER_VSYNC_TIME_SOURCE_H_