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 BeginFrame(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 DidSwapBuffers, a
48 // DidFinishFrame should be posted.
50 // If the rendering pipeline crashes, call DidAbortAllPendingFrames.
51 void DidSwapBuffers();
52 void DidSwapBuffersComplete();
53 void DidAbortAllPendingFrames();
54 void SetMaxFramesPending(int max_frames_pending
); // 0 for unlimited.
55 int MaxFramesPending() const { return max_frames_pending_
; }
56 int NumFramesPendingForTesting() const { return num_frames_pending_
; }
58 // This returns null for unthrottled frame-rate.
59 base::TimeTicks
NextTickTime();
61 // This returns now for unthrottled frame-rate.
62 base::TimeTicks
LastTickTime();
64 void SetTimebaseAndInterval(base::TimeTicks timebase
,
65 base::TimeDelta interval
);
66 void SetSwapBuffersCompleteSupported(bool supported
);
69 friend class FrameRateControllerTimeSourceAdapter
;
72 void PostManualTick();
75 FrameRateControllerClient
* client_
;
76 int num_frames_pending_
;
77 int max_frames_pending_
;
78 scoped_refptr
<TimeSource
> time_source_
;
79 scoped_ptr
<FrameRateControllerTimeSourceAdapter
> time_source_client_adapter_
;
81 bool swap_buffers_complete_supported_
;
83 // Members for unthrottled frame-rate.
84 bool is_time_source_throttling_
;
85 base::WeakPtrFactory
<FrameRateController
> weak_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(FrameRateController
);
93 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_