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_SCHEDULER_FRAME_RATE_CONTROLLER_H_
6 #define CC_SCHEDULER_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/base/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
{
33 DEFAULT_MAX_FRAMES_PENDING
= 2
36 explicit FrameRateController(scoped_refptr
<TimeSource
> timer
);
37 // Alternate form of FrameRateController with unthrottled frame-rate.
38 explicit FrameRateController(Thread
* thread
);
39 virtual ~FrameRateController();
41 void SetClient(FrameRateControllerClient
* client
) { client_
= client
; }
43 void SetActive(bool active
);
45 // Use the following methods to adjust target frame rate.
47 // Multiple frames can be in-progress, but for every DidBeginFrame, a
48 // DidFinishFrame should be posted.
50 // If the rendering pipeline crashes, call DidAbortAllPendingFrames.
52 void DidFinishFrame();
53 void DidAbortAllPendingFrames();
54 void SetMaxFramesPending(int max_frames_pending
); // 0 for unlimited.
55 int MaxFramesPending() const { return max_frames_pending_
; }
57 // This returns null for unthrottled frame-rate.
58 base::TimeTicks
NextTickTime();
60 // This returns now for unthrottled frame-rate.
61 base::TimeTicks
LastTickTime();
63 void SetTimebaseAndInterval(base::TimeTicks timebase
,
64 base::TimeDelta interval
);
65 void SetSwapBuffersCompleteSupported(bool supported
);
68 friend class FrameRateControllerTimeSourceAdapter
;
71 void PostManualTick();
74 FrameRateControllerClient
* client_
;
75 int num_frames_pending_
;
76 int max_frames_pending_
;
77 scoped_refptr
<TimeSource
> time_source_
;
78 scoped_ptr
<FrameRateControllerTimeSourceAdapter
> time_source_client_adapter_
;
80 bool swap_buffers_complete_supported_
;
82 // Members for unthrottled frame-rate.
83 bool is_time_source_throttling_
;
84 base::WeakPtrFactory
<FrameRateController
> weak_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(FrameRateController
);
92 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_