OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ | 5 #ifndef CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ |
6 #define CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ | 6 #define CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 class Thread; | 16 class Thread; |
17 class TimeSource; | 17 class TimeSource; |
18 | 18 |
19 class CC_EXPORT FrameRateControllerClient { | 19 class CC_EXPORT FrameRateControllerClient { |
20 public: | 20 public: |
21 // Throttled is true when we have a maximum number of frames pending. | 21 // Throttled is true when we have a maximum number of frames pending. |
22 virtual void vsyncTick(bool throttled) = 0; | 22 virtual void VSyncTick(bool throttled) = 0; |
23 | 23 |
24 protected: | 24 protected: |
25 virtual ~FrameRateControllerClient() {} | 25 virtual ~FrameRateControllerClient() {} |
26 }; | 26 }; |
27 | 27 |
28 class FrameRateControllerTimeSourceAdapter; | 28 class FrameRateControllerTimeSourceAdapter; |
29 | 29 |
30 class CC_EXPORT FrameRateController { | 30 class CC_EXPORT FrameRateController { |
31 public: | 31 public: |
32 enum { | 32 enum { |
33 kDefaultMaxFramesPending = 2 | 33 DEFAULT_MAX_FRAMES_PENDING = 2 |
34 }; | 34 }; |
35 | 35 |
36 explicit FrameRateController(scoped_refptr<TimeSource>); | 36 explicit FrameRateController(scoped_refptr<TimeSource> timer); |
37 // Alternate form of FrameRateController with unthrottled frame-rate. | 37 // Alternate form of FrameRateController with unthrottled frame-rate. |
38 explicit FrameRateController(Thread*); | 38 explicit FrameRateController(Thread* thread); |
39 virtual ~FrameRateController(); | 39 virtual ~FrameRateController(); |
40 | 40 |
41 void setClient(FrameRateControllerClient* client) { m_client = client; } | 41 void SetClient(FrameRateControllerClient* client) { client_ = client; } |
42 | 42 |
43 void setActive(bool); | 43 void SetActive(bool active); |
44 | 44 |
45 // Use the following methods to adjust target frame rate. | 45 // Use the following methods to adjust target frame rate. |
46 // | 46 // |
47 // Multiple frames can be in-progress, but for every didBeginFrame, a | 47 // Multiple frames can be in-progress, but for every DidBeginFrame, a |
48 // didFinishFrame should be posted. | 48 // DidFinishFrame should be posted. |
49 // | 49 // |
50 // If the rendering pipeline crashes, call didAbortAllPendingFrames. | 50 // If the rendering pipeline crashes, call DidAbortAllPendingFrames. |
51 void didBeginFrame(); | 51 void DidBeginFrame(); |
52 void didFinishFrame(); | 52 void DidFinishFrame(); |
53 void didAbortAllPendingFrames(); | 53 void DidAbortAllPendingFrames(); |
54 void setMaxFramesPending(int); // 0 for unlimited. | 54 void SetMaxFramesPending(int max_frames_pending); // 0 for unlimited. |
55 int maxFramesPending() const { return m_maxFramesPending; } | 55 int MaxFramesPending() const { return max_frames_pending_; } |
56 | 56 |
57 // This returns null for unthrottled frame-rate. | 57 // This returns null for unthrottled frame-rate. |
58 base::TimeTicks nextTickTime(); | 58 base::TimeTicks NextTickTime(); |
59 | 59 |
60 // This returns now for unthrottled frame-rate. | 60 // This returns now for unthrottled frame-rate. |
61 base::TimeTicks lastTickTime(); | 61 base::TimeTicks LastTickTime(); |
62 | 62 |
63 void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interv
al); | 63 void SetTimebaseAndInterval(base::TimeTicks timebase, |
64 void setSwapBuffersCompleteSupported(bool); | 64 base::TimeDelta interval); |
| 65 void SetSwapBuffersCompleteSupported(bool supported); |
65 | 66 |
66 protected: | 67 protected: |
67 friend class FrameRateControllerTimeSourceAdapter; | 68 friend class FrameRateControllerTimeSourceAdapter; |
68 void onTimerTick(); | 69 void OnTimerTick(); |
69 | 70 |
70 void postManualTick(); | 71 void PostManualTick(); |
71 void manualTick(); | 72 void ManualTick(); |
72 | 73 |
73 FrameRateControllerClient* m_client; | 74 FrameRateControllerClient* client_; |
74 int m_numFramesPending; | 75 int num_frames_pending_; |
75 int m_maxFramesPending; | 76 int max_frames_pending_; |
76 scoped_refptr<TimeSource> m_timeSource; | 77 scoped_refptr<TimeSource> time_source_; |
77 scoped_ptr<FrameRateControllerTimeSourceAdapter> m_timeSourceClientAdapter; | 78 scoped_ptr<FrameRateControllerTimeSourceAdapter> time_source_client_adapter_; |
78 bool m_active; | 79 bool active_; |
79 bool m_swapBuffersCompleteSupported; | 80 bool swap_buffers_complete_supported_; |
80 | 81 |
81 // Members for unthrottled frame-rate. | 82 // Members for unthrottled frame-rate. |
82 bool m_isTimeSourceThrottling; | 83 bool is_time_source_throttling_; |
83 base::WeakPtrFactory<FrameRateController> m_weakFactory; | 84 base::WeakPtrFactory<FrameRateController> weak_factory_; |
84 Thread* m_thread; | 85 Thread* thread_; |
85 | 86 |
86 DISALLOW_COPY_AND_ASSIGN(FrameRateController); | 87 DISALLOW_COPY_AND_ASSIGN(FrameRateController); |
87 }; | 88 }; |
88 | 89 |
89 } // namespace cc | 90 } // namespace cc |
90 | 91 |
91 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ | 92 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ |
OLD | NEW |