Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: cc/scheduler/frame_rate_controller.h

Issue 199523002: cc: Throttle swaps in Scheduler instead of OutputSurface (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Actually, unittests need CC_EXPORT. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler/draw_swap_readback_result.h ('k') | cc/scheduler/frame_rate_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/time.h" 11 #include "base/time/time.h"
12 #include "cc/base/cc_export.h" 12 #include "cc/base/cc_export.h"
13 #include "cc/output/begin_frame_args.h" 13 #include "cc/output/begin_frame_args.h"
14 #include "cc/scheduler/time_source.h"
14 15
15 namespace base { class SingleThreadTaskRunner; } 16 namespace base { class SingleThreadTaskRunner; }
16 17
17 namespace cc { 18 namespace cc {
18 19
19 class TimeSource; 20 class TimeSource;
20 class FrameRateController; 21 class FrameRateController;
21 22
22 class CC_EXPORT FrameRateControllerClient { 23 class CC_EXPORT FrameRateControllerClient {
23 protected: 24 protected:
24 virtual ~FrameRateControllerClient() {} 25 virtual ~FrameRateControllerClient() {}
25 26
26 public: 27 public:
27 // Throttled is true when we have a maximum number of frames pending. 28 virtual void FrameRateControllerTick(const BeginFrameArgs& args) = 0;
28 virtual void FrameRateControllerTick(bool throttled,
29 const BeginFrameArgs& args) = 0;
30 }; 29 };
31 30
32 class FrameRateControllerTimeSourceAdapter;
33
34 // The FrameRateController is used in cases where we self-tick (i.e. BeginFrame 31 // The FrameRateController is used in cases where we self-tick (i.e. BeginFrame
35 // is not sent by a parent compositor. 32 // is not sent by a parent compositor.
36 class CC_EXPORT FrameRateController { 33 class CC_EXPORT FrameRateController : TimeSourceClient {
37 public: 34 public:
38 explicit FrameRateController(scoped_refptr<TimeSource> timer); 35 explicit FrameRateController(scoped_refptr<TimeSource> timer);
39 // Alternate form of FrameRateController with unthrottled frame-rate.
40 explicit FrameRateController(base::SingleThreadTaskRunner* task_runner);
41 virtual ~FrameRateController(); 36 virtual ~FrameRateController();
42 37
43 void SetClient(FrameRateControllerClient* client) { client_ = client; } 38 void SetClient(FrameRateControllerClient* client) { client_ = client; }
44 39
45 // Returns a valid BeginFrame on activation to potentially be used 40 // Returns a valid BeginFrame on activation to potentially be used
46 // retroactively. 41 // retroactively.
47 BeginFrameArgs SetActive(bool active); 42 BeginFrameArgs SetActive(bool active);
48 43
49 bool IsActive() { return active_; } 44 bool IsActive() { return active_; }
50 45
51 // Use the following methods to adjust target frame rate.
52 //
53 // Multiple frames can be in-progress, but for every DidSwapBuffers, a
54 // DidFinishFrame should be posted.
55 //
56 // If the rendering pipeline crashes, call DidAbortAllPendingFrames.
57 void DidSwapBuffers();
58 void DidSwapBuffersComplete();
59 void DidAbortAllPendingFrames();
60 void SetMaxSwapsPending(int max_swaps_pending); // 0 for unlimited.
61 int MaxSwapsPending() const { return max_swaps_pending_; }
62 int NumSwapsPendingForTesting() const { return num_frames_pending_; }
63
64 void SetTimebaseAndInterval(base::TimeTicks timebase, 46 void SetTimebaseAndInterval(base::TimeTicks timebase,
65 base::TimeDelta interval); 47 base::TimeDelta interval);
66 void SetDeadlineAdjustment(base::TimeDelta delta); 48 void SetDeadlineAdjustment(base::TimeDelta delta);
67 49
50 virtual void OnTimerTick() OVERRIDE;
51
68 protected: 52 protected:
69 friend class FrameRateControllerTimeSourceAdapter;
70 void OnTimerTick();
71
72 void PostManualTick();
73 void ManualTick();
74
75 // This returns null for unthrottled frame-rate. 53 // This returns null for unthrottled frame-rate.
76 base::TimeTicks NextTickTime(); 54 base::TimeTicks NextTickTime();
77 // This returns now for unthrottled frame-rate. 55 // This returns now for unthrottled frame-rate.
78 base::TimeTicks LastTickTime(); 56 base::TimeTicks LastTickTime();
79 57
80 FrameRateControllerClient* client_; 58 FrameRateControllerClient* client_;
81 int num_frames_pending_;
82 int max_swaps_pending_;
83 base::TimeDelta interval_; 59 base::TimeDelta interval_;
84 base::TimeDelta deadline_adjustment_; 60 base::TimeDelta deadline_adjustment_;
85 scoped_refptr<TimeSource> time_source_; 61 scoped_refptr<TimeSource> time_source_;
86 scoped_ptr<FrameRateControllerTimeSourceAdapter> time_source_client_adapter_;
87 bool active_; 62 bool active_;
88 63
89 // Members for unthrottled frame-rate.
90 bool is_time_source_throttling_;
91 bool manual_tick_pending_;
92 base::SingleThreadTaskRunner* task_runner_;
93 base::WeakPtrFactory<FrameRateController> weak_factory_;
94
95 private: 64 private:
96 DISALLOW_COPY_AND_ASSIGN(FrameRateController); 65 DISALLOW_COPY_AND_ASSIGN(FrameRateController);
97 }; 66 };
98 67
99 } // namespace cc 68 } // namespace cc
100 69
101 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_ 70 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « cc/scheduler/draw_swap_readback_result.h ('k') | cc/scheduler/frame_rate_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698