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 CC_FRAME_RATE_CONTROLLER_H_
6 #define CC_FRAME_RATE_CONTROLLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time.h"
12 #include "cc/cc_export.h"
19 class CC_EXPORT FrameRateControllerClient
{
21 // Throttled is true when we have a maximum number of frames pending.
22 virtual void vsyncTick(bool throttled
) = 0;
25 virtual ~FrameRateControllerClient() {}
28 class FrameRateControllerTimeSourceAdapter
;
30 class CC_EXPORT FrameRateController
{
32 explicit FrameRateController(scoped_refptr
<TimeSource
>);
33 // Alternate form of FrameRateController with unthrottled frame-rate.
34 explicit FrameRateController(Thread
*);
35 virtual ~FrameRateController();
37 void setClient(FrameRateControllerClient
* client
) { m_client
= client
; }
41 // Use the following methods to adjust target frame rate.
43 // Multiple frames can be in-progress, but for every didBeginFrame, a
44 // didFinishFrame should be posted.
46 // If the rendering pipeline crashes, call didAbortAllPendingFrames.
48 void didFinishFrame();
49 void didAbortAllPendingFrames();
50 void setMaxFramesPending(int); // 0 for unlimited.
52 // This returns null for unthrottled frame-rate.
53 base::TimeTicks
nextTickTime();
55 void setTimebaseAndInterval(base::TimeTicks timebase
, base::TimeDelta interval
);
56 void setSwapBuffersCompleteSupported(bool);
59 friend class FrameRateControllerTimeSourceAdapter
;
62 void postManualTick();
65 FrameRateControllerClient
* m_client
;
66 int m_numFramesPending
;
67 int m_maxFramesPending
;
68 scoped_refptr
<TimeSource
> m_timeSource
;
69 scoped_ptr
<FrameRateControllerTimeSourceAdapter
> m_timeSourceClientAdapter
;
71 bool m_swapBuffersCompleteSupported
;
73 // Members for unthrottled frame-rate.
74 bool m_isTimeSourceThrottling
;
75 base::WeakPtrFactory
<FrameRateController
> m_weakFactory
;
78 DISALLOW_COPY_AND_ASSIGN(FrameRateController
);
83 #endif // CC_FRAME_RATE_CONTROLLER_H_