OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/debug/benchmark_instrumentation.h" | 9 #include "cc/debug/benchmark_instrumentation.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 return make_scoped_ptr( | 26 return make_scoped_ptr( |
27 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); | 27 new SingleThreadProxy(layer_tree_host, client)).PassAs<Proxy>(); |
28 } | 28 } |
29 | 29 |
30 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, | 30 SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, |
31 LayerTreeHostSingleThreadClient* client) | 31 LayerTreeHostSingleThreadClient* client) |
32 : Proxy(NULL), | 32 : Proxy(NULL), |
33 layer_tree_host_(layer_tree_host), | 33 layer_tree_host_(layer_tree_host), |
34 client_(client), | 34 client_(client), |
35 next_frame_is_newly_committed_frame_(false), | 35 next_frame_is_newly_committed_frame_(false), |
36 inside_draw_(false) { | 36 inside_draw_(false), |
37 defer_commits_(false), | |
38 commit_was_deferred_(false), | |
39 commit_requested_(false), | |
40 weak_factory_(this) { | |
37 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 41 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
38 DCHECK(Proxy::IsMainThread()); | 42 DCHECK(Proxy::IsMainThread()); |
39 DCHECK(layer_tree_host); | 43 DCHECK(layer_tree_host); |
40 | 44 |
41 // Impl-side painting not supported without threaded compositing. | 45 // Impl-side painting not supported without threaded compositing. |
42 CHECK(!layer_tree_host->settings().impl_side_painting) | 46 CHECK(!layer_tree_host->settings().impl_side_painting) |
43 << "Threaded compositing must be enabled to use impl-side painting."; | 47 << "Threaded compositing must be enabled to use impl-side painting."; |
44 } | 48 } |
45 | 49 |
46 void SingleThreadProxy::Start() { | 50 void SingleThreadProxy::Start() { |
(...skipping 19 matching lines...) Expand all Loading... | |
66 | 70 |
67 bool SingleThreadProxy::IsStarted() const { | 71 bool SingleThreadProxy::IsStarted() const { |
68 DCHECK(Proxy::IsMainThread()); | 72 DCHECK(Proxy::IsMainThread()); |
69 return layer_tree_host_impl_; | 73 return layer_tree_host_impl_; |
70 } | 74 } |
71 | 75 |
72 void SingleThreadProxy::SetLayerTreeHostClientReady() { | 76 void SingleThreadProxy::SetLayerTreeHostClientReady() { |
73 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); | 77 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
74 // Scheduling is controlled by the embedder in the single thread case, so | 78 // Scheduling is controlled by the embedder in the single thread case, so |
75 // nothing to do. | 79 // nothing to do. |
80 DCHECK(Proxy::IsMainThread()); | |
81 DebugScopedSetImplThread impl(this); | |
82 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | |
83 !scheduler_on_impl_thread_) { | |
84 SchedulerSettings scheduler_settings(layer_tree_host_->settings()); | |
85 scheduler_on_impl_thread_ = Scheduler::Create(this, | |
86 scheduler_settings, | |
87 layer_tree_host_->id(), | |
88 MainThreadTaskRunner()); | |
89 scheduler_on_impl_thread_->SetCanStart(); | |
90 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | |
91 } | |
76 } | 92 } |
77 | 93 |
78 void SingleThreadProxy::SetVisible(bool visible) { | 94 void SingleThreadProxy::SetVisible(bool visible) { |
79 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); | 95 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); |
80 DebugScopedSetImplThread impl(this); | 96 DebugScopedSetImplThread impl(this); |
81 layer_tree_host_impl_->SetVisible(visible); | 97 layer_tree_host_impl_->SetVisible(visible); |
82 | 98 if (scheduler_on_impl_thread_) |
99 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | |
83 // Changing visibility could change ShouldComposite(). | 100 // Changing visibility could change ShouldComposite(). |
84 UpdateBackgroundAnimateTicking(); | 101 UpdateBackgroundAnimateTicking(); |
85 } | 102 } |
86 | 103 |
87 void SingleThreadProxy::CreateAndInitializeOutputSurface() { | 104 void SingleThreadProxy::CreateAndInitializeOutputSurface() { |
88 TRACE_EVENT0( | 105 TRACE_EVENT0( |
89 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); | 106 "cc", "SingleThreadProxy::CreateAndInitializeOutputSurface"); |
90 DCHECK(Proxy::IsMainThread()); | 107 DCHECK(Proxy::IsMainThread()); |
91 DCHECK(layer_tree_host_->output_surface_lost()); | 108 DCHECK(layer_tree_host_->output_surface_lost()); |
92 | 109 |
93 scoped_ptr<OutputSurface> output_surface = | 110 scoped_ptr<OutputSurface> output_surface = |
94 layer_tree_host_->CreateOutputSurface(); | 111 layer_tree_host_->CreateOutputSurface(); |
95 | 112 |
96 renderer_capabilities_for_main_thread_ = RendererCapabilities(); | 113 renderer_capabilities_for_main_thread_ = RendererCapabilities(); |
97 | 114 |
98 bool success = !!output_surface; | 115 bool success = !!output_surface; |
99 if (success) { | 116 if (success) { |
100 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 117 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
101 DebugScopedSetImplThread impl(this); | 118 DebugScopedSetImplThread impl(this); |
102 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 119 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
103 layer_tree_host_impl_->resource_provider()); | 120 layer_tree_host_impl_->resource_provider()); |
104 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); | 121 success = layer_tree_host_impl_->InitializeRenderer(output_surface.Pass()); |
105 } | 122 } |
106 | 123 |
107 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); | 124 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
108 | 125 |
109 if (!success) { | 126 if (success) { |
110 // Force another recreation attempt to happen by requesting another commit. | 127 if (scheduler_on_impl_thread_) |
111 SetNeedsCommit(); | 128 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
129 } else if (Proxy::MainThreadTaskRunner()) { | |
130 Proxy::MainThreadTaskRunner()->PostTask( | |
131 FROM_HERE, | |
132 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
133 weak_factory_.GetWeakPtr())); | |
112 } | 134 } |
113 } | 135 } |
114 | 136 |
115 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { | 137 const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
116 DCHECK(Proxy::IsMainThread()); | 138 DCHECK(Proxy::IsMainThread()); |
117 DCHECK(!layer_tree_host_->output_surface_lost()); | 139 DCHECK(!layer_tree_host_->output_surface_lost()); |
118 return renderer_capabilities_for_main_thread_; | 140 return renderer_capabilities_for_main_thread_; |
119 } | 141 } |
120 | 142 |
121 void SingleThreadProxy::SetNeedsAnimate() { | 143 void SingleThreadProxy::SetNeedsAnimate() { |
122 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); | 144 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
123 DCHECK(Proxy::IsMainThread()); | 145 DCHECK(Proxy::IsMainThread()); |
124 client_->ScheduleAnimation(); | 146 client_->ScheduleAnimation(); |
147 SetNeedsCommit(); | |
125 } | 148 } |
126 | 149 |
127 void SingleThreadProxy::SetNeedsUpdateLayers() { | 150 void SingleThreadProxy::SetNeedsUpdateLayers() { |
128 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); | 151 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
129 DCHECK(Proxy::IsMainThread()); | 152 DCHECK(Proxy::IsMainThread()); |
130 client_->ScheduleComposite(); | 153 SetNeedsCommit(); |
131 } | 154 } |
132 | 155 |
133 void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { | 156 void SingleThreadProxy::DoCommit(base::TimeTicks frame_begin_time) { |
134 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 157 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
135 DCHECK(Proxy::IsMainThread()); | 158 DCHECK(Proxy::IsMainThread()); |
159 layer_tree_host_->WillBeginMainFrame(); | |
160 layer_tree_host_->UpdateClientAnimations(frame_begin_time); | |
161 layer_tree_host_->AnimateLayers(frame_begin_time); | |
162 layer_tree_host_->Layout(); | |
163 commit_requested_ = false; | |
164 | |
165 if (PrioritizedResourceManager* contents_texture_manager = | |
166 layer_tree_host_->contents_texture_manager()) { | |
167 contents_texture_manager->UnlinkAndClearEvictedBackings(); | |
168 contents_texture_manager->SetMaxMemoryLimitBytes( | |
169 layer_tree_host_impl_->memory_allocation_limit_bytes()); | |
170 contents_texture_manager->SetExternalPriorityCutoff( | |
171 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | |
172 } | |
173 | |
174 scoped_ptr<ResourceUpdateQueue> queue = | |
175 make_scoped_ptr(new ResourceUpdateQueue); | |
176 | |
177 layer_tree_host_->UpdateLayers(queue.get()); | |
178 | |
179 layer_tree_host_->WillCommit(); | |
180 | |
136 // Commit immediately. | 181 // Commit immediately. |
137 { | 182 { |
138 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 183 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
139 DebugScopedSetImplThread impl(this); | 184 DebugScopedSetImplThread impl(this); |
140 | 185 |
141 // This CapturePostTasks should be destroyed before CommitComplete() is | 186 // This CapturePostTasks should be destroyed before CommitComplete() is |
142 // called since that goes out to the embedder, and we want the embedder | 187 // called since that goes out to the embedder, and we want the embedder |
143 // to receive its callbacks before that. | 188 // to receive its callbacks before that. |
144 BlockingTaskRunner::CapturePostTasks blocked; | 189 BlockingTaskRunner::CapturePostTasks blocked; |
145 | 190 |
(...skipping 13 matching lines...) Expand all Loading... | |
159 layer_tree_host_impl_->resource_provider()); | 204 layer_tree_host_impl_->resource_provider()); |
160 update_controller->Finalize(); | 205 update_controller->Finalize(); |
161 | 206 |
162 if (layer_tree_host_impl_->EvictedUIResourcesExist()) | 207 if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
163 layer_tree_host_->RecreateUIResources(); | 208 layer_tree_host_->RecreateUIResources(); |
164 | 209 |
165 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 210 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
166 | 211 |
167 layer_tree_host_impl_->CommitComplete(); | 212 layer_tree_host_impl_->CommitComplete(); |
168 | 213 |
214 UpdateBackgroundAnimateTicking(); | |
215 | |
169 #if DCHECK_IS_ON | 216 #if DCHECK_IS_ON |
170 // In the single-threaded case, the scale and scroll deltas should never be | 217 // In the single-threaded case, the scale and scroll deltas should never be |
171 // touched on the impl layer tree. | 218 // touched on the impl layer tree. |
172 scoped_ptr<ScrollAndScaleSet> scroll_info = | 219 scoped_ptr<ScrollAndScaleSet> scroll_info = |
173 layer_tree_host_impl_->ProcessScrollDeltas(); | 220 layer_tree_host_impl_->ProcessScrollDeltas(); |
174 DCHECK(!scroll_info->scrolls.size()); | 221 DCHECK(!scroll_info->scrolls.size()); |
175 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 222 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
176 #endif | 223 #endif |
177 | 224 |
178 RenderingStatsInstrumentation* stats_instrumentation = | 225 RenderingStatsInstrumentation* stats_instrumentation = |
179 layer_tree_host_->rendering_stats_instrumentation(); | 226 layer_tree_host_->rendering_stats_instrumentation(); |
180 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( | 227 benchmark_instrumentation::IssueMainThreadRenderingStatsEvent( |
181 stats_instrumentation->main_thread_rendering_stats()); | 228 stats_instrumentation->main_thread_rendering_stats()); |
182 stats_instrumentation->AccumulateAndClearMainThreadStats(); | 229 stats_instrumentation->AccumulateAndClearMainThreadStats(); |
183 } | 230 } |
184 layer_tree_host_->CommitComplete(); | 231 layer_tree_host_->CommitComplete(); |
232 layer_tree_host_->DidBeginMainFrame(); | |
233 timing_history_.DidCommit(); | |
234 | |
185 next_frame_is_newly_committed_frame_ = true; | 235 next_frame_is_newly_committed_frame_ = true; |
186 } | 236 } |
187 | 237 |
188 void SingleThreadProxy::SetNeedsCommit() { | 238 void SingleThreadProxy::SetNeedsCommit() { |
189 DCHECK(Proxy::IsMainThread()); | 239 DCHECK(Proxy::IsMainThread()); |
240 DebugScopedSetImplThread impl(this); | |
190 client_->ScheduleComposite(); | 241 client_->ScheduleComposite(); |
242 if (scheduler_on_impl_thread_) | |
243 scheduler_on_impl_thread_->SetNeedsCommit(); | |
244 commit_requested_ = true; | |
191 } | 245 } |
192 | 246 |
193 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 247 void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
194 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); | 248 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
249 DCHECK(Proxy::IsMainThread()); | |
250 DebugScopedSetImplThread impl(this); | |
251 client_->ScheduleComposite(); | |
195 SetNeedsRedrawRectOnImplThread(damage_rect); | 252 SetNeedsRedrawRectOnImplThread(damage_rect); |
196 client_->ScheduleComposite(); | |
197 } | 253 } |
198 | 254 |
199 void SingleThreadProxy::SetNextCommitWaitsForActivation() { | 255 void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
200 // There is no activation here other than commit. So do nothing. | 256 // There is no activation here other than commit. So do nothing. |
257 DCHECK(Proxy::IsMainThread()); | |
201 } | 258 } |
202 | 259 |
203 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { | 260 void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
204 // Thread-only feature. | 261 DCHECK(Proxy::IsMainThread()); |
205 NOTREACHED(); | 262 // Deferring commits only makes sense if there's a scheduler. |
263 if (!scheduler_on_impl_thread_) | |
264 return; | |
265 if (defer_commits_ == defer_commits) | |
266 return; | |
267 | |
268 if (defer_commits) | |
269 TRACE_EVENT_ASYNC_BEGIN0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
270 else | |
271 TRACE_EVENT_ASYNC_END0("cc", "SingleThreadProxy::SetDeferCommits", this); | |
272 | |
273 defer_commits_ = defer_commits; | |
274 if (!defer_commits_ && commit_was_deferred_) { | |
275 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
276 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
277 commit_was_deferred_ = false; | |
278 } | |
206 } | 279 } |
207 | 280 |
208 bool SingleThreadProxy::CommitRequested() const { return false; } | 281 bool SingleThreadProxy::CommitRequested() const { |
282 DCHECK(Proxy::IsMainThread()); | |
283 return commit_requested_; | |
284 } | |
209 | 285 |
210 bool SingleThreadProxy::BeginMainFrameRequested() const { return false; } | 286 bool SingleThreadProxy::BeginMainFrameRequested() const { |
287 DCHECK(Proxy::IsMainThread()); | |
288 return commit_requested_; | |
289 } | |
211 | 290 |
212 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { | 291 size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
213 return std::numeric_limits<size_t>::max(); | 292 return std::numeric_limits<size_t>::max(); |
214 } | 293 } |
215 | 294 |
216 void SingleThreadProxy::Stop() { | 295 void SingleThreadProxy::Stop() { |
217 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); | 296 TRACE_EVENT0("cc", "SingleThreadProxy::stop"); |
218 DCHECK(Proxy::IsMainThread()); | 297 DCHECK(Proxy::IsMainThread()); |
219 { | 298 { |
220 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 299 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
221 DebugScopedSetImplThread impl(this); | 300 DebugScopedSetImplThread impl(this); |
222 | 301 |
223 BlockingTaskRunner::CapturePostTasks blocked; | 302 BlockingTaskRunner::CapturePostTasks blocked; |
224 layer_tree_host_->DeleteContentsTexturesOnImplThread( | 303 layer_tree_host_->DeleteContentsTexturesOnImplThread( |
225 layer_tree_host_impl_->resource_provider()); | 304 layer_tree_host_impl_->resource_provider()); |
305 scheduler_on_impl_thread_.reset(); | |
226 layer_tree_host_impl_.reset(); | 306 layer_tree_host_impl_.reset(); |
227 } | 307 } |
228 layer_tree_host_ = NULL; | 308 layer_tree_host_ = NULL; |
229 } | 309 } |
230 | 310 |
231 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 311 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
232 TRACE_EVENT1( | 312 TRACE_EVENT1( |
233 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 313 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
234 DCHECK(Proxy::IsImplThread()); | 314 DCHECK(Proxy::IsImplThread()); |
235 UpdateBackgroundAnimateTicking(); | 315 UpdateBackgroundAnimateTicking(); |
316 if (scheduler_on_impl_thread_) | |
317 scheduler_on_impl_thread_->SetCanDraw(can_draw); | |
236 } | 318 } |
237 | 319 |
238 void SingleThreadProxy::NotifyReadyToActivate() { | 320 void SingleThreadProxy::NotifyReadyToActivate() { |
239 // Thread-only feature. | 321 // Impl-side painting only. |
240 NOTREACHED(); | 322 NOTREACHED(); |
241 } | 323 } |
242 | 324 |
243 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 325 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
244 client_->ScheduleComposite(); | 326 client_->ScheduleComposite(); |
327 if (scheduler_on_impl_thread_) | |
328 scheduler_on_impl_thread_->SetNeedsRedraw(); | |
245 } | 329 } |
246 | 330 |
247 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { | 331 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
248 SetNeedsRedrawOnImplThread(); | 332 SetNeedsRedrawOnImplThread(); |
249 } | 333 } |
250 | 334 |
251 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { | 335 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
252 // Thread-only/Impl-side-painting-only feature. | 336 // Impl-side painting only. |
253 NOTREACHED(); | 337 NOTREACHED(); |
254 } | 338 } |
255 | 339 |
256 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( | 340 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
257 const gfx::Rect& damage_rect) { | 341 const gfx::Rect& damage_rect) { |
258 // TODO(brianderson): Once we move render_widget scheduling into this class, | |
259 // we can treat redraw requests more efficiently than CommitAndRedraw | |
260 // requests. | |
261 layer_tree_host_impl_->SetViewportDamage(damage_rect); | 342 layer_tree_host_impl_->SetViewportDamage(damage_rect); |
262 SetNeedsCommit(); | 343 SetNeedsRedrawOnImplThread(); |
263 } | 344 } |
264 | 345 |
265 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { | 346 void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
266 // Impl-side painting only. | 347 // Impl-side painting only. |
267 NOTREACHED(); | 348 NOTREACHED(); |
268 } | 349 } |
269 | 350 |
270 void SingleThreadProxy::SetNeedsCommitOnImplThread() { | 351 void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
271 client_->ScheduleComposite(); | 352 client_->ScheduleComposite(); |
353 if (scheduler_on_impl_thread_) | |
354 scheduler_on_impl_thread_->SetNeedsCommit(); | |
272 } | 355 } |
273 | 356 |
274 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 357 void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
275 scoped_ptr<AnimationEventsVector> events) { | 358 scoped_ptr<AnimationEventsVector> events) { |
276 TRACE_EVENT0( | 359 TRACE_EVENT0( |
277 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 360 "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
278 DCHECK(Proxy::IsImplThread()); | 361 DCHECK(Proxy::IsImplThread()); |
279 DebugScopedSetMainThread main(this); | 362 DebugScopedSetMainThread main(this); |
280 layer_tree_host_->SetAnimationEvents(events.Pass()); | 363 layer_tree_host_->SetAnimationEvents(events.Pass()); |
281 } | 364 } |
(...skipping 16 matching lines...) Expand all Loading... | |
298 } | 381 } |
299 | 382 |
300 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 383 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
301 | 384 |
302 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { | 385 void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
303 DCHECK(IsImplThread()); | 386 DCHECK(IsImplThread()); |
304 renderer_capabilities_for_main_thread_ = | 387 renderer_capabilities_for_main_thread_ = |
305 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); | 388 layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
306 } | 389 } |
307 | 390 |
391 void SingleThreadProxy::DidActivateSyncTree() { | |
enne (OOO)
2014/07/10 20:37:42
This gets called now even for non impl-side painti
| |
392 // Impl-side painting only. | |
393 NOTREACHED(); | |
394 } | |
395 | |
396 void SingleThreadProxy::DidManageTiles() { | |
397 // Impl-side painting only. | |
398 NOTREACHED(); | |
399 } | |
400 | |
308 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 401 void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
309 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 402 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
310 // Cause a commit so we can notice the lost context. | 403 { |
311 SetNeedsCommitOnImplThread(); | 404 DebugScopedSetMainThread main(this); |
405 // This must happen before we notify the scheduler as it may try to recreate | |
406 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. | |
407 layer_tree_host_->DidLoseOutputSurface(); | |
408 } | |
312 client_->DidAbortSwapBuffers(); | 409 client_->DidAbortSwapBuffers(); |
410 if (scheduler_on_impl_thread_) | |
411 scheduler_on_impl_thread_->DidLoseOutputSurface(); | |
313 } | 412 } |
314 | 413 |
315 void SingleThreadProxy::DidSwapBuffersOnImplThread() { | 414 void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
415 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); | |
416 if (scheduler_on_impl_thread_) | |
417 scheduler_on_impl_thread_->DidSwapBuffers(); | |
316 client_->DidPostSwapBuffers(); | 418 client_->DidPostSwapBuffers(); |
317 } | 419 } |
318 | 420 |
319 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 421 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
320 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 422 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
321 client_->DidCompleteSwapBuffers(); | 423 if (scheduler_on_impl_thread_) |
424 scheduler_on_impl_thread_->DidSwapBuffersComplete(); | |
425 layer_tree_host_->DidCompleteSwapBuffers(); | |
322 } | 426 } |
323 | 427 |
324 // Called by the legacy scheduling path (e.g. where render_widget does the | 428 void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { |
325 // scheduling) | 429 TRACE_EVENT0("cc", "SingleThreadProxy::BeginFrame"); |
430 if (scheduler_on_impl_thread_) | |
431 scheduler_on_impl_thread_->BeginImplFrame(args); | |
432 } | |
433 | |
326 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 434 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
327 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); | 435 TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
328 DCHECK(Proxy::IsMainThread()); | 436 DCHECK(Proxy::IsMainThread()); |
329 DCHECK(!layer_tree_host_->output_surface_lost()); | 437 DCHECK(!layer_tree_host_->output_surface_lost()); |
330 | 438 |
331 layer_tree_host_->AnimateLayers(frame_begin_time); | 439 DoCommit(frame_begin_time); |
332 | |
333 if (PrioritizedResourceManager* contents_texture_manager = | |
334 layer_tree_host_->contents_texture_manager()) { | |
335 contents_texture_manager->UnlinkAndClearEvictedBackings(); | |
336 contents_texture_manager->SetMaxMemoryLimitBytes( | |
337 layer_tree_host_impl_->memory_allocation_limit_bytes()); | |
338 contents_texture_manager->SetExternalPriorityCutoff( | |
339 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | |
340 } | |
341 | |
342 scoped_ptr<ResourceUpdateQueue> queue = | |
343 make_scoped_ptr(new ResourceUpdateQueue); | |
344 layer_tree_host_->UpdateLayers(queue.get()); | |
345 layer_tree_host_->WillCommit(); | |
346 DoCommit(queue.Pass()); | |
347 layer_tree_host_->DidBeginMainFrame(); | |
348 | 440 |
349 LayerTreeHostImpl::FrameData frame; | 441 LayerTreeHostImpl::FrameData frame; |
350 if (DoComposite(frame_begin_time, &frame)) { | 442 DoComposite(frame_begin_time, &frame); |
351 { | |
352 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
353 DebugScopedSetImplThread impl(this); | |
354 | |
355 // This CapturePostTasks should be destroyed before | |
356 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | |
357 // and we want the embedder to receive its callbacks before that. | |
358 // NOTE: This maintains consistent ordering with the ThreadProxy since | |
359 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | |
360 // there as the main thread is not blocked, so any posted tasks inside | |
361 // the swap buffers will execute first. | |
362 BlockingTaskRunner::CapturePostTasks blocked; | |
363 | |
364 layer_tree_host_impl_->SwapBuffers(frame); | |
365 } | |
366 DidSwapFrame(); | |
367 } | |
368 } | 443 } |
369 | 444 |
370 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { | 445 scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
371 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 446 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
372 { | 447 { |
373 // The following line casts away const modifiers because it is just | 448 // The following line casts away const modifiers because it is just |
374 // setting debug state. We still want the AsValue() function and its | 449 // setting debug state. We still want the AsValue() function and its |
375 // call chain to be const throughout. | 450 // call chain to be const throughout. |
376 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 451 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
377 | 452 |
(...skipping 22 matching lines...) Expand all Loading... | |
400 return layer_tree_host_impl_->visible() && | 475 return layer_tree_host_impl_->visible() && |
401 layer_tree_host_impl_->CanDraw(); | 476 layer_tree_host_impl_->CanDraw(); |
402 } | 477 } |
403 | 478 |
404 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | 479 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
405 DCHECK(Proxy::IsImplThread()); | 480 DCHECK(Proxy::IsImplThread()); |
406 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | 481 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( |
407 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | 482 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
408 } | 483 } |
409 | 484 |
410 bool SingleThreadProxy::DoComposite( | 485 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
411 base::TimeTicks frame_begin_time, | 486 LayerTreeHostImpl::FrameData* frame) { |
412 LayerTreeHostImpl::FrameData* frame) { | |
413 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 487 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
414 DCHECK(!layer_tree_host_->output_surface_lost()); | 488 DCHECK(!layer_tree_host_->output_surface_lost()); |
415 | 489 |
416 bool lost_output_surface = false; | |
417 { | 490 { |
418 DebugScopedSetImplThread impl(this); | 491 DebugScopedSetImplThread impl(this); |
419 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 492 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
420 | 493 |
421 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 494 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
422 // frame, so can only be used when such a frame is possible. Since | 495 // frame, so can only be used when such a frame is possible. Since |
423 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 496 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
424 // CanDraw() as well. | 497 // CanDraw() as well. |
425 if (!ShouldComposite()) { | 498 if (!ShouldComposite()) { |
426 UpdateBackgroundAnimateTicking(); | 499 UpdateBackgroundAnimateTicking(); |
427 return false; | 500 return DRAW_ABORTED_CANT_DRAW; |
428 } | 501 } |
429 | 502 |
503 timing_history_.DidStartDrawing(); | |
504 | |
430 layer_tree_host_impl_->Animate( | 505 layer_tree_host_impl_->Animate( |
431 layer_tree_host_impl_->CurrentFrameTimeTicks()); | 506 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
432 UpdateBackgroundAnimateTicking(); | 507 UpdateBackgroundAnimateTicking(); |
433 | 508 |
434 if (!layer_tree_host_impl_->IsContextLost()) { | 509 if (!layer_tree_host_impl_->IsContextLost()) { |
435 layer_tree_host_impl_->PrepareToDraw(frame); | 510 layer_tree_host_impl_->PrepareToDraw(frame); |
436 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 511 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
437 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 512 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
438 } | 513 } |
439 lost_output_surface = layer_tree_host_impl_->IsContextLost(); | |
440 | 514 |
441 bool start_ready_animations = true; | 515 bool start_ready_animations = true; |
442 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 516 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
443 | 517 |
444 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 518 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
519 | |
520 timing_history_.DidFinishDrawing(); | |
445 } | 521 } |
446 | 522 |
447 if (lost_output_surface) { | 523 { |
448 layer_tree_host_->DidLoseOutputSurface(); | 524 DebugScopedSetImplThread impl(this); |
449 return false; | 525 |
526 if (layer_tree_host_impl_->IsContextLost()) { | |
527 DidLoseOutputSurfaceOnImplThread(); | |
528 } else { | |
529 // This CapturePostTasks should be destroyed before | |
530 // DidCommitAndDrawFrame() is called since that goes out to the embedder, | |
531 // and we want the embedder to receive its callbacks before that. | |
532 // NOTE: This maintains consistent ordering with the ThreadProxy since | |
533 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | |
534 // there as the main thread is not blocked, so any posted tasks inside | |
535 // the swap buffers will execute first. | |
536 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | |
537 | |
538 BlockingTaskRunner::CapturePostTasks blocked; | |
539 layer_tree_host_impl_->SwapBuffers(*frame); | |
540 } | |
450 } | 541 } |
542 DidCommitAndDrawFrame(); | |
451 | 543 |
452 return true; | 544 return DRAW_SUCCESS; |
453 } | 545 } |
454 | 546 |
455 void SingleThreadProxy::DidSwapFrame() { | 547 void SingleThreadProxy::DidCommitAndDrawFrame() { |
456 if (next_frame_is_newly_committed_frame_) { | 548 if (next_frame_is_newly_committed_frame_) { |
549 DebugScopedSetMainThread main(this); | |
457 next_frame_is_newly_committed_frame_ = false; | 550 next_frame_is_newly_committed_frame_ = false; |
458 layer_tree_host_->DidCommitAndDrawFrame(); | 551 layer_tree_host_->DidCommitAndDrawFrame(); |
459 } | 552 } |
460 } | 553 } |
461 | 554 |
462 bool SingleThreadProxy::CommitPendingForTesting() { return false; } | 555 bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
463 | 556 |
557 scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() { | |
558 DebugScopedSetImplThread impl(this); | |
559 if (!scheduler_on_impl_thread_) | |
560 return make_scoped_ptr(base::Value::CreateNullValue()).Pass(); | |
561 return scheduler_on_impl_thread_->AsValue().Pass(); | |
562 } | |
563 | |
564 void SingleThreadProxy::SetNeedsBeginFrame(bool enable) { | |
565 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | |
566 } | |
567 | |
568 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | |
569 layer_tree_host_impl_->WillBeginImplFrame(args); | |
570 } | |
571 | |
572 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { | |
573 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); | |
574 if (defer_commits_) { | |
575 DCHECK(!commit_was_deferred_); | |
576 commit_was_deferred_ = true; | |
577 layer_tree_host_->DidDeferCommit(); | |
578 return; | |
579 } | |
580 timing_history_.DidBeginMainFrame(); | |
581 | |
582 DCHECK(scheduler_on_impl_thread_); | |
583 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | |
584 scheduler_on_impl_thread_->NotifyReadyToCommit(); | |
585 } | |
586 | |
587 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | |
588 DebugScopedSetImplThread impl(this); | |
589 if (layer_tree_host_impl_->IsContextLost()) { | |
590 DidCommitAndDrawFrame(); | |
591 return DRAW_SUCCESS; | |
592 } | |
593 | |
594 LayerTreeHostImpl::FrameData frame; | |
595 return DoComposite(layer_tree_host_impl_->CurrentFrameTimeTicks(), &frame); | |
596 } | |
597 | |
598 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { | |
599 NOTREACHED(); | |
600 return INVALID_RESULT; | |
601 } | |
602 | |
603 void SingleThreadProxy::ScheduledActionCommit() { | |
604 DebugScopedSetMainThread main(this); | |
605 DoCommit(layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
606 } | |
607 | |
608 void SingleThreadProxy::ScheduledActionAnimate() { | |
609 TRACE_EVENT0("cc", "ScheduledActionAnimate"); | |
610 layer_tree_host_impl_->Animate( | |
611 layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
612 } | |
613 | |
614 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { | |
615 // Impl-side painting only. | |
616 NOTREACHED(); | |
617 } | |
618 | |
619 void SingleThreadProxy::ScheduledActionActivatePendingTree() { | |
620 // Impl-side painting only. | |
621 NOTREACHED(); | |
622 } | |
623 | |
624 void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | |
625 DebugScopedSetMainThread main(this); | |
626 DCHECK(scheduler_on_impl_thread_); | |
627 // If possible, create the output surface in a post task. Synchronously | |
628 // creating the output surface makes tests more awkward since this differs | |
629 // from the ThreadProxy behavior. However, sometimes there is no | |
630 // task runner. | |
631 if (Proxy::MainThreadTaskRunner()) { | |
632 Proxy::MainThreadTaskRunner()->PostTask( | |
633 FROM_HERE, | |
634 base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, | |
635 weak_factory_.GetWeakPtr())); | |
636 } else { | |
637 CreateAndInitializeOutputSurface(); | |
638 } | |
639 } | |
640 | |
641 void SingleThreadProxy::ScheduledActionManageTiles() { | |
642 // Impl-side painting only. | |
643 NOTREACHED(); | |
644 } | |
645 | |
646 void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { | |
647 } | |
648 | |
649 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { | |
650 return timing_history_.DrawDurationEstimate(); | |
651 } | |
652 | |
653 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | |
654 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | |
655 } | |
656 | |
657 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | |
658 return timing_history_.CommitToActivateDurationEstimate(); | |
659 } | |
660 | |
661 void SingleThreadProxy::DidBeginImplFrameDeadline() { | |
662 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
663 } | |
664 | |
464 } // namespace cc | 665 } // namespace cc |
OLD | NEW |