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

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

Issue 267783004: Refactoring the way begin frame sources inside scheduler work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing as per Brian's comments. Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #ifndef CC_SCHEDULER_FRAME_SOURCE_H_
6 #define CC_SCHEDULER_FRAME_SOURCE_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/debug/trace_event.h"
12 #include "base/logging.h"
13 #include "cc/output/begin_frame_args.h"
14 #include "cc/scheduler/delay_based_time_source.h"
15 #include "ui/compositor/compositor_vsync_manager.h"
16
17 namespace cc {
18
19 /**
20 *
21 */
22 class CC_EXPORT BeginFrameObserver {
23 public:
24 virtual const BeginFrameArgs& LastBeginFrameArgs() const = 0;
25 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0;
26
27 // Tracing support
28 virtual void AsValueInto(base::debug::TracedValue* dict) const = 0;
29 };
30
31 /**
32 *
33 */
34 class CC_EXPORT BeginFrameSource {
35 public:
36 virtual ~BeginFrameSource() {}
37
38 // Should the frame source be sending begin frames?
39 virtual bool NeedsBeginFrames() const = 0;
40 virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0;
41 // This method provides backpressure to a frame source rather than toggling
42 // SetNeedsBeginFrames. It is used by systems like the BackToBackFrameSource
43 // to make sure only one frame is pending at a time.
44 virtual void DidFinishFrame(size_t remaining_frames) = 0;
45
46 void AddObserver(BeginFrameObserver* obs);
47 void RemoveObserver(BeginFrameObserver* obs);
48
49 // Tracing support
50 virtual void AsValueInto(base::debug::TracedValue* dict) const = 0;
51
52 protected:
53 BeginFrameSource();
54 void CallOnBeginFrame(const BeginFrameArgs& args);
55 BeginFrameObserver* observer_;
56
57 private:
58 bool inside_as_value_into_;
59 };
60
61 /**
62 * A frame source which sends a BeginFrame as soon as remaining frames reaches
63 * zero.
64 */
65 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSource {
66 public:
67 static scoped_ptr<BackToBackBeginFrameSource> Create(
68 base::SingleThreadTaskRunner* task_runner);
69 virtual ~BackToBackBeginFrameSource();
70
71 // BeginFrameSource
72 virtual bool NeedsBeginFrames() const OVERRIDE;
73 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE;
74 virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE;
75
76 // Tracing
77 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE;
78
79 protected:
80 explicit BackToBackBeginFrameSource(
81 base::SingleThreadTaskRunner* task_runner);
82 virtual base::TimeTicks Now(); // Now overridable for testing
83
84 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_;
85 base::SingleThreadTaskRunner* task_runner_;
86
87 bool needs_begin_frames_;
88 bool send_begin_frame_posted_;
89
90 void ScheduleBeginFrame();
91 void BeginFrame();
92 };
93
94 /**
95 * A frame source which is locked an external vsync source and generates
96 * BeginFrameArgs for it.
97 */
98 class CC_EXPORT SyntheticBeginFrameSource
99 : public BeginFrameSource,
100 public ui::CompositorVSyncManager::Observer,
101 public TimeSourceClient {
102 public:
103 static scoped_ptr<SyntheticBeginFrameSource> Create(
104 base::SingleThreadTaskRunner* task_runner,
105 base::TimeTicks initial_vsync_timebase,
106 base::TimeDelta initial_vsync_interval);
107 virtual ~SyntheticBeginFrameSource();
108
109 // BeginFrameSource
110 virtual bool NeedsBeginFrames() const OVERRIDE;
111 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE;
112 virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE{};
113
114 // Tracing
115 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE;
116
117 // ui::CompositorVSyncManager::Observer
118 virtual void OnUpdateVSyncParameters(
119 base::TimeTicks new_vsync_timebase,
120 base::TimeDelta new_vsync_interval) OVERRIDE;
121
122 // TimeSourceClient
123 virtual void OnTimerTick() OVERRIDE;
124
125 protected:
126 explicit SyntheticBeginFrameSource(
127 scoped_refptr<DelayBasedTimeSource> time_source);
128
129 void SendBeginFrameFromTick(base::TimeTicks frame_time);
130
131 scoped_refptr<DelayBasedTimeSource> time_source_;
132 };
133
134 /**
135 * A virtual frame source which lets you switch between multiple other frame
136 * sources while making sure the BeginFrameArgs stays increasing (possibly
137 * enforcing minimum boundry between BeginFrameArgs messages).
138 *
139 * The mux is an BeginFrameObserver as it needs to proxy the OnBeginFrame calls
140 * to preserves the monoticity of the BeginFrameArgs when switching sources.
brianderson 2014/09/18 21:54:19 to preserve
mithro-old 2014/09/19 02:45:40 Done.
141 */
142 class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSource,
143 public BeginFrameObserver {
144 public:
145 static scoped_ptr<BeginFrameSourceMultiplexer> Create();
146 virtual ~BeginFrameSourceMultiplexer();
147
148 void SetMinimumInterval(base::TimeDelta new_minimum_interval);
149
150 void AddSource(BeginFrameSource* new_source);
151 void RemoveSource(BeginFrameSource* existing_source);
152 void SetActiveSource(BeginFrameSource* new_source);
153 const BeginFrameSource* ActiveSource();
154
155 // BeginFrameObserver
156 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE;
157 virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE;
158
159 // BeginFrameSource
160 virtual bool NeedsBeginFrames() const OVERRIDE;
161 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE;
162 virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE;
163
164 // Tracing
165 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE;
166
167 protected:
168 BeginFrameSourceMultiplexer();
169 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval);
170 bool HasSource(BeginFrameSource* source);
171
172 base::TimeDelta minimum_interval_;
173
174 BeginFrameSource* active_source_;
175 std::set<BeginFrameSource*> source_list_;
176 };
177
178 } // namespace cc
179
180 #endif // CC_SCHEDULER_FRAME_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698