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

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

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

Powered by Google App Engine
This is Rietveld 408576698