OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_TREES_SINGLE_THREAD_PROXY_H_ | |
6 #define CC_TREES_SINGLE_THREAD_PROXY_H_ | |
7 | |
8 #include <limits> | |
9 | |
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" | |
18 #include "cc/trees/proxy_timing_history.h" | |
19 | |
20 namespace cc { | |
21 | |
22 class BeginFrameSource; | |
23 class ContextProvider; | |
24 class LayerTreeHost; | |
25 class LayerTreeHostSingleThreadClient; | |
26 class ResourceUpdateQueue; | |
27 | |
28 class CC_EXPORT SingleThreadProxy : public Proxy, | |
29 NON_EXPORTED_BASE(LayerTreeHostImplClient), | |
30 SchedulerClient { | |
31 public: | |
32 static scoped_ptr<Proxy> Create( | |
33 LayerTreeHost* layer_tree_host, | |
34 LayerTreeHostSingleThreadClient* client, | |
35 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
36 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
37 ~SingleThreadProxy() override; | |
38 | |
39 // Proxy implementation | |
40 void FinishAllRendering() override; | |
41 bool IsStarted() const override; | |
42 bool CommitToActiveTree() const override; | |
43 void SetOutputSurface(scoped_ptr<OutputSurface>) override; | |
44 void SetLayerTreeHostClientReady() override; | |
45 void SetVisible(bool visible) override; | |
46 void SetThrottleFrameProduction(bool throttle) override; | |
47 const RendererCapabilities& GetRendererCapabilities() const override; | |
48 void SetNeedsAnimate() override; | |
49 void SetNeedsUpdateLayers() override; | |
50 void SetNeedsCommit() override; | |
51 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; | |
52 void SetNextCommitWaitsForActivation() override; | |
53 void NotifyInputThrottledUntilCommit() override {} | |
54 void SetDeferCommits(bool defer_commits) override; | |
55 bool CommitRequested() const override; | |
56 bool BeginMainFrameRequested() const override; | |
57 void MainThreadHasStoppedFlinging() override {} | |
58 void Start() override; | |
59 void Stop() override; | |
60 size_t MaxPartialTextureUpdates() const override; | |
61 void ForceSerializeOnSwapBuffers() override; | |
62 bool SupportsImplScrolling() const override; | |
63 bool MainFrameWillHappenForTesting() override; | |
64 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override; | |
65 | |
66 // SchedulerClient implementation | |
67 void WillBeginImplFrame(const BeginFrameArgs& args) override; | |
68 void ScheduledActionSendBeginMainFrame() override; | |
69 DrawResult ScheduledActionDrawAndSwapIfPossible() override; | |
70 DrawResult ScheduledActionDrawAndSwapForced() override; | |
71 void ScheduledActionCommit() override; | |
72 void ScheduledActionAnimate() override; | |
73 void ScheduledActionActivateSyncTree() override; | |
74 void ScheduledActionBeginOutputSurfaceCreation() override; | |
75 void ScheduledActionPrepareTiles() override; | |
76 void DidAnticipatedDrawTimeChange(base::TimeTicks time) override; | |
77 base::TimeDelta DrawDurationEstimate() override; | |
78 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override; | |
79 base::TimeDelta CommitToActivateDurationEstimate() override; | |
80 void DidBeginImplFrameDeadline() override; | |
81 void SendBeginFramesToChildren(const BeginFrameArgs& args) override; | |
82 void SendBeginMainFrameNotExpectedSoon() override; | |
83 | |
84 // LayerTreeHostImplClient implementation | |
85 void UpdateRendererCapabilitiesOnImplThread() override; | |
86 void DidLoseOutputSurfaceOnImplThread() override; | |
87 void CommitVSyncParameters(base::TimeTicks timebase, | |
88 base::TimeDelta interval) override; | |
89 void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override; | |
90 void SetMaxSwapsPendingOnImplThread(int max) override {} | |
91 void DidSwapBuffersOnImplThread() override; | |
92 void DidSwapBuffersCompleteOnImplThread() override; | |
93 void OnCanDrawStateChanged(bool can_draw) override; | |
94 void NotifyReadyToActivate() override; | |
95 void NotifyReadyToDraw() override; | |
96 void SetNeedsRedrawOnImplThread() override; | |
97 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& dirty_rect) override; | |
98 void SetNeedsAnimateOnImplThread() override; | |
99 void SetNeedsPrepareTilesOnImplThread() override; | |
100 void SetNeedsCommitOnImplThread() override; | |
101 void PostAnimationEventsToMainThreadOnImplThread( | |
102 scoped_ptr<AnimationEventsVector> events) override; | |
103 bool ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | |
104 int priority_cutoff) override; | |
105 bool IsInsideDraw() override; | |
106 void RenewTreePriority() override {} | |
107 void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, | |
108 base::TimeDelta delay) override {} | |
109 void DidActivateSyncTree() override; | |
110 void DidPrepareTiles() override; | |
111 void DidCompletePageScaleAnimationOnImplThread() override; | |
112 void SetDebugState(const LayerTreeDebugState& debug_state) override {} | |
113 | |
114 void RequestNewOutputSurface(); | |
115 | |
116 // Called by the legacy path where RenderWidget does the scheduling. | |
117 void CompositeImmediately(base::TimeTicks frame_begin_time); | |
118 | |
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); | |
125 | |
126 private: | |
127 void BeginMainFrame(); | |
128 void BeginMainFrameAbortedOnImplThread(CommitEarlyOutReason reason); | |
129 void DoAnimate(); | |
130 void DoBeginMainFrame(const BeginFrameArgs& begin_frame_args); | |
131 void DoCommit(); | |
132 DrawResult DoComposite(base::TimeTicks frame_begin_time, | |
133 LayerTreeHostImpl::FrameData* frame); | |
134 void DoSwap(); | |
135 void DidCommitAndDrawFrame(); | |
136 void CommitComplete(); | |
137 | |
138 bool ShouldComposite() const; | |
139 void ScheduleRequestNewOutputSurface(); | |
140 | |
141 // Accessed on main thread only. | |
142 LayerTreeHost* layer_tree_host_; | |
143 LayerTreeHostSingleThreadClient* client_; | |
144 | |
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_; | |
149 | |
150 // Accessed from both threads. | |
151 scoped_ptr<Scheduler> scheduler_on_impl_thread_; | |
152 ProxyTimingHistory timing_history_; | |
153 | |
154 scoped_ptr<BlockingTaskRunner::CapturePostTasks> commit_blocking_task_runner_; | |
155 scoped_ptr<ResourceUpdateQueue> queue_for_commit_; | |
156 bool next_frame_is_newly_committed_frame_; | |
157 | |
158 bool inside_draw_; | |
159 bool defer_commits_; | |
160 bool commit_requested_; | |
161 bool inside_synchronous_composite_; | |
162 | |
163 // True if a request to the LayerTreeHostClient to create an output surface | |
164 // is still outstanding. | |
165 bool output_surface_creation_requested_; | |
166 | |
167 // This is the callback for the scheduled RequestNewOutputSurface. | |
168 base::CancelableClosure output_surface_creation_callback_; | |
169 | |
170 scoped_ptr<BeginFrameSource> external_begin_frame_source_; | |
171 | |
172 base::WeakPtrFactory<SingleThreadProxy> weak_factory_; | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy); | |
175 }; | |
176 | |
177 // For use in the single-threaded case. In debug builds, it pretends that the | |
178 // code is running on the impl thread to satisfy assertion checks. | |
179 class DebugScopedSetImplThread { | |
180 public: | |
181 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) { | |
182 #if DCHECK_IS_ON() | |
183 previous_value_ = proxy_->impl_thread_is_overridden_; | |
184 proxy_->SetCurrentThreadIsImplThread(true); | |
185 #endif | |
186 } | |
187 ~DebugScopedSetImplThread() { | |
188 #if DCHECK_IS_ON() | |
189 proxy_->SetCurrentThreadIsImplThread(previous_value_); | |
190 #endif | |
191 } | |
192 | |
193 private: | |
194 bool previous_value_; | |
195 Proxy* proxy_; | |
196 | |
197 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread); | |
198 }; | |
199 | |
200 // For use in the single-threaded case. In debug builds, it pretends that the | |
201 // code is running on the main thread to satisfy assertion checks. | |
202 class DebugScopedSetMainThread { | |
203 public: | |
204 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) { | |
205 #if DCHECK_IS_ON() | |
206 previous_value_ = proxy_->impl_thread_is_overridden_; | |
207 proxy_->SetCurrentThreadIsImplThread(false); | |
208 #endif | |
209 } | |
210 ~DebugScopedSetMainThread() { | |
211 #if DCHECK_IS_ON() | |
212 proxy_->SetCurrentThreadIsImplThread(previous_value_); | |
213 #endif | |
214 } | |
215 | |
216 private: | |
217 bool previous_value_; | |
218 Proxy* proxy_; | |
219 | |
220 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread); | |
221 }; | |
222 | |
223 // For use in the single-threaded case. In debug builds, it pretends that the | |
224 // code is running on the impl thread and that the main thread is blocked to | |
225 // satisfy assertion checks | |
226 class DebugScopedSetImplThreadAndMainThreadBlocked { | |
227 public: | |
228 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy) | |
229 : impl_thread_(proxy), main_thread_blocked_(proxy) {} | |
230 | |
231 private: | |
232 DebugScopedSetImplThread impl_thread_; | |
233 DebugScopedSetMainThreadBlocked main_thread_blocked_; | |
234 | |
235 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked); | |
236 }; | |
237 | |
238 } // namespace cc | |
239 | |
240 #endif // CC_TREES_SINGLE_THREAD_PROXY_H_ | |
OLD | NEW |