Infobar material design refresh: bg color
[chromium-blink-merge.git] / cc / trees / single_thread_proxy.h
blobc8defe5d6283213f734ad42cc84de4eb3efc7fe0
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 SetDebugState(const LayerTreeDebugState& debug_state) override {}
115 void RequestNewOutputSurface();
117 // Called by the legacy path where RenderWidget does the scheduling.
118 void LayoutAndUpdateLayers();
119 void CompositeImmediately(base::TimeTicks frame_begin_time);
121 protected:
122 SingleThreadProxy(
123 LayerTreeHost* layer_tree_host,
124 LayerTreeHostSingleThreadClient* client,
125 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
126 scoped_ptr<BeginFrameSource> external_begin_frame_source);
128 private:
129 void BeginMainFrame(const BeginFrameArgs& begin_frame_args);
130 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason);
131 void DoBeginMainFrame(const BeginFrameArgs& begin_frame_args);
132 void DoCommit();
133 DrawResult DoComposite(LayerTreeHostImpl::FrameData* frame);
134 void DoSwap();
135 void DidCommitAndDrawFrame();
136 void CommitComplete();
138 bool ShouldComposite() const;
139 void ScheduleRequestNewOutputSurface();
141 // Accessed on main thread only.
142 LayerTreeHost* layer_tree_host_;
143 LayerTreeHostSingleThreadClient* client_;
145 // Used on the Thread, but checked on main thread during
146 // initialization/shutdown.
147 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
148 RendererCapabilities renderer_capabilities_for_main_thread_;
150 // Accessed from both threads.
151 scoped_ptr<BeginFrameSource> external_begin_frame_source_;
152 scoped_ptr<Scheduler> scheduler_on_impl_thread_;
154 scoped_ptr<BlockingTaskRunner::CapturePostTasks> commit_blocking_task_runner_;
155 bool next_frame_is_newly_committed_frame_;
157 #if DCHECK_IS_ON()
158 bool inside_impl_frame_;
159 #endif
160 bool inside_draw_;
161 bool defer_commits_;
162 bool animate_requested_;
163 bool commit_requested_;
164 bool inside_synchronous_composite_;
166 // True if a request to the LayerTreeHostClient to create an output surface
167 // is still outstanding.
168 bool output_surface_creation_requested_;
170 // This is the callback for the scheduled RequestNewOutputSurface.
171 base::CancelableClosure output_surface_creation_callback_;
173 base::WeakPtrFactory<SingleThreadProxy> weak_factory_;
175 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
178 // For use in the single-threaded case. In debug builds, it pretends that the
179 // code is running on the impl thread to satisfy assertion checks.
180 class DebugScopedSetImplThread {
181 public:
182 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
183 #if DCHECK_IS_ON()
184 previous_value_ = proxy_->impl_thread_is_overridden_;
185 proxy_->SetCurrentThreadIsImplThread(true);
186 #endif
188 ~DebugScopedSetImplThread() {
189 #if DCHECK_IS_ON()
190 proxy_->SetCurrentThreadIsImplThread(previous_value_);
191 #endif
194 private:
195 bool previous_value_;
196 Proxy* proxy_;
198 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
201 // For use in the single-threaded case. In debug builds, it pretends that the
202 // code is running on the main thread to satisfy assertion checks.
203 class DebugScopedSetMainThread {
204 public:
205 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
206 #if DCHECK_IS_ON()
207 previous_value_ = proxy_->impl_thread_is_overridden_;
208 proxy_->SetCurrentThreadIsImplThread(false);
209 #endif
211 ~DebugScopedSetMainThread() {
212 #if DCHECK_IS_ON()
213 proxy_->SetCurrentThreadIsImplThread(previous_value_);
214 #endif
217 private:
218 bool previous_value_;
219 Proxy* proxy_;
221 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
224 // For use in the single-threaded case. In debug builds, it pretends that the
225 // code is running on the impl thread and that the main thread is blocked to
226 // satisfy assertion checks
227 class DebugScopedSetImplThreadAndMainThreadBlocked {
228 public:
229 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
230 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
232 private:
233 DebugScopedSetImplThread impl_thread_;
234 DebugScopedSetMainThreadBlocked main_thread_blocked_;
236 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
239 } // namespace cc
241 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_