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"
10 #include <wtf/PassRefPtr.h>
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
{
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;
43 CCDelayBasedTimeSource(double interval
, CCThread
*);
44 double nextTickTarget(double now
);
45 void postNextTickTask(double now
);
54 Parameters(double interval
, double tickTarget
)
55 : interval(interval
), tickTarget(tickTarget
)
61 CCTimeSourceClient
* m_client
;
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
;
78 #endif // CCDelayBasedTimeSource_h