Experimental push messaging api reference docs.
[chromium-blink-merge.git] / cc / CCDelayBasedTimeSource.h
blobd9c9c28dcb3042125f691d1b6b90d3b6a87695d2
1 // Copyright 2011 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 #ifndef CCDelayBasedTimeSource_h
6 #define CCDelayBasedTimeSource_h
8 #include "CCTimeSource.h"
9 #include "CCTimer.h"
10 #include <wtf/PassRefPtr.h>
12 namespace cc {
14 class CCThread;
16 // This timer implements a time source that achieves the specified interval
17 // in face of millisecond-precision delayed callbacks and random queueing delays.
18 class CCDelayBasedTimeSource : public CCTimeSource, CCTimerClient {
19 public:
20 static PassRefPtr<CCDelayBasedTimeSource> create(double intervalSeconds, CCThread*);
22 virtual ~CCDelayBasedTimeSource() { }
24 virtual void setClient(CCTimeSourceClient* client) OVERRIDE { m_client = client; }
26 // CCTimeSource implementation
27 virtual void setTimebaseAndInterval(double timebase, double intervalSeconds) OVERRIDE;
29 virtual void setActive(bool) OVERRIDE;
30 virtual bool active() const OVERRIDE { return m_state != STATE_INACTIVE; }
32 // Get the last and next tick times.
33 virtual double lastTickTime() OVERRIDE;
34 virtual double nextTickTimeIfActivated() OVERRIDE;
36 // CCTimerClient implementation.
37 virtual void onTimerFired() OVERRIDE;
39 // Virtual for testing.
40 virtual double monotonicTimeNow() const;
42 protected:
43 CCDelayBasedTimeSource(double interval, CCThread*);
44 double nextTickTarget(double now);
45 void postNextTickTask(double now);
47 enum State {
48 STATE_INACTIVE,
49 STATE_STARTING,
50 STATE_ACTIVE,
53 struct Parameters {
54 Parameters(double interval, double tickTarget)
55 : interval(interval), tickTarget(tickTarget)
56 { }
57 double interval;
58 double tickTarget;
61 CCTimeSourceClient* m_client;
62 bool m_hasTickTarget;
63 double m_lastTickTime;
65 // m_currentParameters should only be written by postNextTickTask.
66 // m_nextParameters will take effect on the next call to postNextTickTask.
67 // Maintaining a pending set of parameters allows nextTickTime() to always
68 // reflect the actual time we expect onTimerFired to be called.
69 Parameters m_currentParameters;
70 Parameters m_nextParameters;
72 State m_state;
73 CCThread* m_thread;
74 CCTimer m_timer;
78 #endif // CCDelayBasedTimeSource_h