DrMemory: Fix a typo in the End2EndTest name.
[chromium-blink-merge.git] / cc / scheduler / scheduler.h
blob3bf4f7fd54fcc9e76692552aec2378daefd6235a
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
3 // found in the LICENSE file.
5 #ifndef CC_SCHEDULER_SCHEDULER_H_
6 #define CC_SCHEDULER_SCHEDULER_H_
8 #include <deque>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/cancelable_callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "cc/base/cc_export.h"
16 #include "cc/output/begin_frame_args.h"
17 #include "cc/scheduler/begin_frame_source.h"
18 #include "cc/scheduler/begin_frame_tracker.h"
19 #include "cc/scheduler/delay_based_time_source.h"
20 #include "cc/scheduler/draw_result.h"
21 #include "cc/scheduler/scheduler_settings.h"
22 #include "cc/scheduler/scheduler_state_machine.h"
24 namespace base {
25 namespace trace_event {
26 class ConvertableToTraceFormat;
28 class SingleThreadTaskRunner;
31 namespace cc {
33 class CompositorTimingHistory;
35 class SchedulerClient {
36 public:
37 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0;
38 virtual void ScheduledActionSendBeginMainFrame() = 0;
39 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0;
40 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0;
41 virtual void ScheduledActionAnimate() = 0;
42 virtual void ScheduledActionCommit() = 0;
43 virtual void ScheduledActionActivateSyncTree() = 0;
44 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0;
45 virtual void ScheduledActionPrepareTiles() = 0;
46 virtual void ScheduledActionInvalidateOutputSurface() = 0;
47 virtual void DidFinishImplFrame() = 0;
48 virtual void SendBeginFramesToChildren(const BeginFrameArgs& args) = 0;
49 virtual void SendBeginMainFrameNotExpectedSoon() = 0;
51 protected:
52 virtual ~SchedulerClient() {}
55 class CC_EXPORT Scheduler : public BeginFrameObserverBase {
56 public:
57 static scoped_ptr<Scheduler> Create(
58 SchedulerClient* client,
59 const SchedulerSettings& scheduler_settings,
60 int layer_tree_host_id,
61 base::SingleThreadTaskRunner* task_runner,
62 BeginFrameSource* external_frame_source,
63 scoped_ptr<CompositorTimingHistory> compositor_timing_history);
65 ~Scheduler() override;
67 // BeginFrameObserverBase
68 bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) override;
70 void OnDrawForOutputSurface();
72 const SchedulerSettings& settings() const { return settings_; }
74 void CommitVSyncParameters(base::TimeTicks timebase,
75 base::TimeDelta interval);
76 void SetEstimatedParentDrawTime(base::TimeDelta draw_time);
78 void SetCanStart();
80 void SetVisible(bool visible);
81 void SetCanDraw(bool can_draw);
82 void NotifyReadyToActivate();
83 void NotifyReadyToDraw();
84 void SetThrottleFrameProduction(bool throttle);
86 void SetNeedsCommit();
88 void SetNeedsRedraw();
90 void SetNeedsAnimate();
92 void SetNeedsPrepareTiles();
94 void SetWaitForReadyToDraw();
96 void SetMaxSwapsPending(int max);
97 void DidSwapBuffers();
98 void DidSwapBuffersComplete();
100 void SetImplLatencyTakesPriority(bool impl_latency_takes_priority);
102 void NotifyReadyToCommit();
103 void BeginMainFrameAborted(CommitEarlyOutReason reason);
105 void DidPrepareTiles();
106 void DidLoseOutputSurface();
107 void DidCreateAndInitializeOutputSurface();
109 // Tests do not want to shut down until all possible BeginMainFrames have
110 // occured to prevent flakiness.
111 bool MainFrameForTestingWillHappen() const {
112 return state_machine_.CommitPending() ||
113 state_machine_.CouldSendBeginMainFrame();
116 bool CommitPending() const { return state_machine_.CommitPending(); }
117 bool RedrawPending() const { return state_machine_.RedrawPending(); }
118 bool PrepareTilesPending() const {
119 return state_machine_.PrepareTilesPending();
121 bool MainThreadIsInHighLatencyMode() const {
122 return state_machine_.MainThreadIsInHighLatencyMode();
124 bool BeginImplFrameDeadlinePending() const {
125 return !begin_impl_frame_deadline_task_.IsCancelled();
127 bool ImplLatencyTakesPriority() const {
128 return state_machine_.impl_latency_takes_priority();
131 void NotifyBeginMainFrameStarted();
133 base::TimeTicks LastBeginImplFrameTime();
135 void SetDeferCommits(bool defer_commits);
137 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
138 void AsValueInto(base::trace_event::TracedValue* value) const override;
140 void SetContinuousPainting(bool continuous_painting) {
141 state_machine_.SetContinuousPainting(continuous_painting);
144 void SetChildrenNeedBeginFrames(bool children_need_begin_frames);
145 void SetVideoNeedsBeginFrames(bool video_needs_begin_frames);
147 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval);
149 protected:
150 Scheduler(SchedulerClient* client,
151 const SchedulerSettings& scheduler_settings,
152 int layer_tree_host_id,
153 base::SingleThreadTaskRunner* task_runner,
154 BeginFrameSource* external_frame_source,
155 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source,
156 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source,
157 scoped_ptr<CompositorTimingHistory> compositor_timing_history);
159 // Virtual for testing.
160 virtual base::TimeTicks Now() const;
162 const SchedulerSettings settings_;
163 SchedulerClient* client_;
164 int layer_tree_host_id_;
165 base::SingleThreadTaskRunner* task_runner_;
166 BeginFrameSource* external_frame_source_;
167 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source_;
168 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source_;
170 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_;
171 bool throttle_frame_production_;
173 base::TimeDelta authoritative_vsync_interval_;
174 base::TimeTicks last_vsync_timebase_;
176 scoped_ptr<CompositorTimingHistory> compositor_timing_history_;
177 base::TimeDelta estimated_parent_draw_time_;
179 std::deque<BeginFrameArgs> begin_retro_frame_args_;
180 SchedulerStateMachine::BeginImplFrameDeadlineMode
181 begin_impl_frame_deadline_mode_;
182 BeginFrameTracker begin_impl_frame_tracker_;
184 base::Closure begin_retro_frame_closure_;
185 base::Closure begin_impl_frame_deadline_closure_;
186 base::CancelableClosure begin_retro_frame_task_;
187 base::CancelableClosure begin_impl_frame_deadline_task_;
189 SchedulerStateMachine state_machine_;
190 bool inside_process_scheduled_actions_;
191 SchedulerStateMachine::Action inside_action_;
193 private:
194 void ScheduleBeginImplFrameDeadline();
195 void ScheduleBeginImplFrameDeadlineIfNeeded();
196 void SetupNextBeginFrameIfNeeded();
197 void PostBeginRetroFrameIfNeeded();
198 void DrawAndSwapIfPossible();
199 void DrawAndSwapForced();
200 void ProcessScheduledActions();
201 bool CanCommitAndActivateBeforeDeadline() const;
202 void AdvanceCommitStateIfPossible();
203 bool IsBeginMainFrameSentOrStarted() const;
204 void BeginRetroFrame();
205 void BeginImplFrameWithDeadline(const BeginFrameArgs& args);
206 void BeginImplFrameSynchronous(const BeginFrameArgs& args);
207 void BeginImplFrame(const BeginFrameArgs& args);
208 void FinishImplFrame();
209 void OnBeginImplFrameDeadline();
210 void PollToAdvanceCommitState();
212 base::TimeDelta EstimatedParentDrawTime() {
213 return estimated_parent_draw_time_;
216 bool IsInsideAction(SchedulerStateMachine::Action action) {
217 return inside_action_ == action;
220 BeginFrameSource* primary_frame_source() {
221 if (settings_.use_external_begin_frame_source) {
222 DCHECK(external_frame_source_);
223 return external_frame_source_;
225 return synthetic_frame_source_.get();
228 base::WeakPtrFactory<Scheduler> weak_factory_;
230 DISALLOW_COPY_AND_ASSIGN(Scheduler);
233 } // namespace cc
235 #endif // CC_SCHEDULER_SCHEDULER_H_