Remove the 'gyp_config' concept from MB.
[chromium-blink-merge.git] / cc / trees / single_thread_proxy.h
blob913d1ce64565bc48eb60acb005cbe95ea21a5092
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_TREES_SINGLE_THREAD_PROXY_H_
6 #define CC_TREES_SINGLE_THREAD_PROXY_H_
8 #include <limits>
10 #include "base/cancelable_callback.h"
11 #include "base/time/time.h"
12 #include "cc/animation/animation_events.h"
13 #include "cc/output/begin_frame_args.h"
14 #include "cc/scheduler/scheduler.h"
15 #include "cc/trees/blocking_task_runner.h"
16 #include "cc/trees/layer_tree_host_impl.h"
17 #include "cc/trees/proxy.h"
19 namespace cc {
21 class BeginFrameSource;
22 class ContextProvider;
23 class LayerTreeHost;
24 class LayerTreeHostSingleThreadClient;
26 class CC_EXPORT SingleThreadProxy : public Proxy,
27 NON_EXPORTED_BASE(LayerTreeHostImplClient),
28 SchedulerClient {
29 public:
30 static scoped_ptr<Proxy> Create(
31 LayerTreeHost* layer_tree_host,
32 LayerTreeHostSingleThreadClient* client,
33 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
34 scoped_ptr<BeginFrameSource> external_begin_frame_source);
35 ~SingleThreadProxy() override;
37 // Proxy implementation
38 void FinishAllRendering() override;
39 bool IsStarted() const override;
40 bool CommitToActiveTree() const override;
41 void SetOutputSurface(scoped_ptr<OutputSurface>) override;
42 void SetLayerTreeHostClientReady() override;
43 void SetVisible(bool visible) override;
44 void SetThrottleFrameProduction(bool throttle) override;
45 const RendererCapabilities& GetRendererCapabilities() const override;
46 void SetNeedsAnimate() override;
47 void SetNeedsUpdateLayers() override;
48 void SetNeedsCommit() override;
49 void SetNeedsRedraw(const gfx::Rect& damage_rect) override;
50 void SetNextCommitWaitsForActivation() override;
51 void NotifyInputThrottledUntilCommit() override {}
52 void SetDeferCommits(bool defer_commits) override;
53 bool CommitRequested() const override;
54 bool BeginMainFrameRequested() const override;
55 void MainThreadHasStoppedFlinging() override {}
56 void Start() override;
57 void Stop() override;
58 void ForceSerializeOnSwapBuffers() override;
59 bool SupportsImplScrolling() const override;
60 bool MainFrameWillHappenForTesting() override;
61 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override;
62 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override;
64 // SchedulerClient implementation
65 void WillBeginImplFrame(const BeginFrameArgs& args) override;
66 void DidFinishImplFrame() override;
67 void ScheduledActionSendBeginMainFrame() override;
68 DrawResult ScheduledActionDrawAndSwapIfPossible() override;
69 DrawResult ScheduledActionDrawAndSwapForced() override;
70 void ScheduledActionCommit() override;
71 void ScheduledActionAnimate() override;
72 void ScheduledActionActivateSyncTree() override;
73 void ScheduledActionBeginOutputSurfaceCreation() override;
74 void ScheduledActionPrepareTiles() override;
75 void ScheduledActionInvalidateOutputSurface() override;
76 void SendBeginFramesToChildren(const BeginFrameArgs& args) override;
77 void SendBeginMainFrameNotExpectedSoon() override;
79 // LayerTreeHostImplClient implementation
80 void UpdateRendererCapabilitiesOnImplThread() override;
81 void DidLoseOutputSurfaceOnImplThread() override;
82 void CommitVSyncParameters(base::TimeTicks timebase,
83 base::TimeDelta interval) override;
84 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override;
85 void SetMaxSwapsPendingOnImplThread(int max) override;
86 void DidSwapBuffersOnImplThread() override;
87 void DidSwapBuffersCompleteOnImplThread() override;
88 void OnCanDrawStateChanged(bool can_draw) override;
89 void NotifyReadyToActivate() override;
90 void NotifyReadyToDraw() override;
91 void SetNeedsRedrawOnImplThread() override;
92 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override;
93 void SetNeedsAnimateOnImplThread() override;
94 void SetNeedsPrepareTilesOnImplThread() override;
95 void SetNeedsCommitOnImplThread() override;
96 void SetVideoNeedsBeginFrames(bool needs_begin_frames) override;
97 void PostAnimationEventsToMainThreadOnImplThread(
98 scoped_ptr<AnimationEventsVector> events) override;
99 bool IsInsideDraw() override;
100 void RenewTreePriority() override {}
101 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task,
102 base::TimeDelta delay) override {}
103 void DidActivateSyncTree() override;
104 void WillPrepareTiles() override;
105 void DidPrepareTiles() override;
106 void DidCompletePageScaleAnimationOnImplThread() override;
107 void OnDrawForOutputSurface() override;
108 void PostFrameTimingEventsOnImplThread(
109 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
110 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
111 override;
113 void RequestNewOutputSurface();
115 // Called by the legacy path where RenderWidget does the scheduling.
116 void LayoutAndUpdateLayers();
117 void CompositeImmediately(base::TimeTicks frame_begin_time);
119 protected:
120 SingleThreadProxy(
121 LayerTreeHost* layer_tree_host,
122 LayerTreeHostSingleThreadClient* client,
123 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
124 scoped_ptr<BeginFrameSource> external_begin_frame_source);
126 private:
127 void BeginMainFrame(const BeginFrameArgs& begin_frame_args);
128 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason);
129 void DoBeginMainFrame(const BeginFrameArgs& begin_frame_args);
130 void DoCommit();
131 DrawResult DoComposite(LayerTreeHostImpl::FrameData* frame);
132 void DoSwap();
133 void DidCommitAndDrawFrame();
134 void CommitComplete();
136 bool ShouldComposite() const;
137 void ScheduleRequestNewOutputSurface();
139 // Accessed on main thread only.
140 LayerTreeHost* layer_tree_host_;
141 LayerTreeHostSingleThreadClient* client_;
143 // Used on the Thread, but checked on main thread during
144 // initialization/shutdown.
145 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
146 RendererCapabilities renderer_capabilities_for_main_thread_;
148 // Accessed from both threads.
149 scoped_ptr<BeginFrameSource> external_begin_frame_source_;
150 scoped_ptr<Scheduler> scheduler_on_impl_thread_;
152 scoped_ptr<BlockingTaskRunner::CapturePostTasks> commit_blocking_task_runner_;
153 bool next_frame_is_newly_committed_frame_;
155 #if DCHECK_IS_ON()
156 bool inside_impl_frame_;
157 #endif
158 bool inside_draw_;
159 bool defer_commits_;
160 bool animate_requested_;
161 bool commit_requested_;
162 bool inside_synchronous_composite_;
164 // True if a request to the LayerTreeHostClient to create an output surface
165 // is still outstanding.
166 bool output_surface_creation_requested_;
168 // This is the callback for the scheduled RequestNewOutputSurface.
169 base::CancelableClosure output_surface_creation_callback_;
171 base::WeakPtrFactory<SingleThreadProxy> weak_factory_;
173 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
176 // For use in the single-threaded case. In debug builds, it pretends that the
177 // code is running on the impl thread to satisfy assertion checks.
178 class DebugScopedSetImplThread {
179 public:
180 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
181 #if DCHECK_IS_ON()
182 previous_value_ = proxy_->impl_thread_is_overridden_;
183 proxy_->SetCurrentThreadIsImplThread(true);
184 #endif
186 ~DebugScopedSetImplThread() {
187 #if DCHECK_IS_ON()
188 proxy_->SetCurrentThreadIsImplThread(previous_value_);
189 #endif
192 private:
193 bool previous_value_;
194 Proxy* proxy_;
196 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
199 // For use in the single-threaded case. In debug builds, it pretends that the
200 // code is running on the main thread to satisfy assertion checks.
201 class DebugScopedSetMainThread {
202 public:
203 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
204 #if DCHECK_IS_ON()
205 previous_value_ = proxy_->impl_thread_is_overridden_;
206 proxy_->SetCurrentThreadIsImplThread(false);
207 #endif
209 ~DebugScopedSetMainThread() {
210 #if DCHECK_IS_ON()
211 proxy_->SetCurrentThreadIsImplThread(previous_value_);
212 #endif
215 private:
216 bool previous_value_;
217 Proxy* proxy_;
219 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
222 // For use in the single-threaded case. In debug builds, it pretends that the
223 // code is running on the impl thread and that the main thread is blocked to
224 // satisfy assertion checks
225 class DebugScopedSetImplThreadAndMainThreadBlocked {
226 public:
227 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
228 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
230 private:
231 DebugScopedSetImplThread impl_thread_;
232 DebugScopedSetMainThreadBlocked main_thread_blocked_;
234 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
237 } // namespace cc
239 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_