| 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 class FrameRateController; | |
| 19 | 18 |
| 20 class CC_EXPORT FrameRateControllerClient { | 19 class CC_EXPORT FrameRateControllerClient { |
| 20 public: |
| 21 // Throttled is true when we have a maximum number of frames pending. |
| 22 virtual void BeginFrame(bool throttled) = 0; |
| 23 |
| 21 protected: | 24 protected: |
| 22 virtual ~FrameRateControllerClient() {} | 25 virtual ~FrameRateControllerClient() {} |
| 23 | |
| 24 public: | |
| 25 // Throttled is true when we have a maximum number of frames pending. | |
| 26 virtual void FrameRateControllerTick(bool throttled) = 0; | |
| 27 }; | 26 }; |
| 28 | 27 |
| 29 class FrameRateControllerTimeSourceAdapter; | 28 class FrameRateControllerTimeSourceAdapter; |
| 30 | 29 |
| 31 // The FrameRateController is used in cases where we self-tick (i.e. BeginFrame | |
| 32 // is not sent by a parent compositor. | |
| 33 class CC_EXPORT FrameRateController { | 30 class CC_EXPORT FrameRateController { |
| 34 public: | 31 public: |
| 35 enum { | 32 enum { |
| 36 DEFAULT_MAX_FRAMES_PENDING = 2 | 33 DEFAULT_MAX_FRAMES_PENDING = 2 |
| 37 }; | 34 }; |
| 38 | 35 |
| 39 explicit FrameRateController(scoped_refptr<TimeSource> timer); | 36 explicit FrameRateController(scoped_refptr<TimeSource> timer); |
| 40 // Alternate form of FrameRateController with unthrottled frame-rate. | 37 // Alternate form of FrameRateController with unthrottled frame-rate. |
| 41 explicit FrameRateController(Thread* thread); | 38 explicit FrameRateController(Thread* thread); |
| 42 virtual ~FrameRateController(); | 39 virtual ~FrameRateController(); |
| 43 | 40 |
| 44 void SetClient(FrameRateControllerClient* client) { client_ = client; } | 41 void SetClient(FrameRateControllerClient* client) { client_ = client; } |
| 45 | 42 |
| 46 void SetActive(bool active); | 43 void SetActive(bool active); |
| 47 bool IsActive() { return active_; } | |
| 48 | 44 |
| 49 // Use the following methods to adjust target frame rate. | 45 // Use the following methods to adjust target frame rate. |
| 50 // | 46 // |
| 51 // Multiple frames can be in-progress, but for every DidSwapBuffers, a | 47 // Multiple frames can be in-progress, but for every DidSwapBuffers, a |
| 52 // DidFinishFrame should be posted. | 48 // DidFinishFrame should be posted. |
| 53 // | 49 // |
| 54 // If the rendering pipeline crashes, call DidAbortAllPendingFrames. | 50 // If the rendering pipeline crashes, call DidAbortAllPendingFrames. |
| 55 void DidSwapBuffers(); | 51 void DidSwapBuffers(); |
| 56 void DidSwapBuffersComplete(); | 52 void DidSwapBuffersComplete(); |
| 57 void DidAbortAllPendingFrames(); | 53 void DidAbortAllPendingFrames(); |
| 58 void SetMaxSwapsPending(int max_swaps_pending); // 0 for unlimited. | 54 void SetMaxFramesPending(int max_frames_pending); // 0 for unlimited. |
| 59 int MaxSwapsPending() const { return max_swaps_pending_; } | 55 int MaxFramesPending() const { return max_frames_pending_; } |
| 60 int NumSwapsPendingForTesting() const { return num_frames_pending_; } | 56 int NumFramesPendingForTesting() const { return num_frames_pending_; } |
| 61 | 57 |
| 62 // This returns null for unthrottled frame-rate. | 58 // This returns null for unthrottled frame-rate. |
| 63 base::TimeTicks NextTickTime(); | 59 base::TimeTicks NextTickTime(); |
| 64 | 60 |
| 65 // This returns now for unthrottled frame-rate. | 61 // This returns now for unthrottled frame-rate. |
| 66 base::TimeTicks LastTickTime(); | 62 base::TimeTicks LastTickTime(); |
| 67 | 63 |
| 68 void SetTimebaseAndInterval(base::TimeTicks timebase, | 64 void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 69 base::TimeDelta interval); | 65 base::TimeDelta interval); |
| 70 | 66 |
| 71 protected: | 67 protected: |
| 72 friend class FrameRateControllerTimeSourceAdapter; | 68 friend class FrameRateControllerTimeSourceAdapter; |
| 73 void OnTimerTick(); | 69 void OnTimerTick(); |
| 74 | 70 |
| 75 void PostManualTick(); | 71 void PostManualTick(); |
| 76 void ManualTick(); | 72 void ManualTick(); |
| 77 | 73 |
| 78 FrameRateControllerClient* client_; | 74 FrameRateControllerClient* client_; |
| 79 int num_frames_pending_; | 75 int num_frames_pending_; |
| 80 int max_swaps_pending_; | 76 int max_frames_pending_; |
| 81 scoped_refptr<TimeSource> time_source_; | 77 scoped_refptr<TimeSource> time_source_; |
| 82 scoped_ptr<FrameRateControllerTimeSourceAdapter> time_source_client_adapter_; | 78 scoped_ptr<FrameRateControllerTimeSourceAdapter> time_source_client_adapter_; |
| 83 bool active_; | 79 bool active_; |
| 84 | 80 |
| 85 // Members for unthrottled frame-rate. | 81 // Members for unthrottled frame-rate. |
| 86 bool is_time_source_throttling_; | 82 bool is_time_source_throttling_; |
| 87 base::WeakPtrFactory<FrameRateController> weak_factory_; | 83 base::WeakPtrFactory<FrameRateController> weak_factory_; |
| 88 Thread* thread_; | 84 Thread* thread_; |
| 89 | 85 |
| 90 private: | |
| 91 DISALLOW_COPY_AND_ASSIGN(FrameRateController); | 86 DISALLOW_COPY_AND_ASSIGN(FrameRateController); |
| 92 }; | 87 }; |
| 93 | 88 |
| 94 } // namespace cc | 89 } // namespace cc |
| 95 | 90 |
| 96 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ | 91 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ |
| OLD | NEW |