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/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "cc/base/thread.h" | |
14 #include "cc/input/input_handler.h" | 13 #include "cc/input/input_handler.h" |
15 #include "cc/output/context_provider.h" | 14 #include "cc/output/context_provider.h" |
16 #include "cc/output/output_surface.h" | 15 #include "cc/output/output_surface.h" |
17 #include "cc/quads/draw_quad.h" | 16 #include "cc/quads/draw_quad.h" |
18 #include "cc/resources/prioritized_resource_manager.h" | 17 #include "cc/resources/prioritized_resource_manager.h" |
19 #include "cc/scheduler/delay_based_time_source.h" | 18 #include "cc/scheduler/delay_based_time_source.h" |
20 #include "cc/scheduler/frame_rate_controller.h" | 19 #include "cc/scheduler/frame_rate_controller.h" |
21 #include "cc/scheduler/scheduler.h" | 20 #include "cc/scheduler/scheduler.h" |
22 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
23 #include "cc/trees/layer_tree_impl.h" | 22 #include "cc/trees/layer_tree_impl.h" |
(...skipping 24 matching lines...) Expand all Loading... |
48 struct ThreadProxy::CommitPendingRequest { | 47 struct ThreadProxy::CommitPendingRequest { |
49 CompletionEvent completion; | 48 CompletionEvent completion; |
50 bool commit_pending; | 49 bool commit_pending; |
51 }; | 50 }; |
52 | 51 |
53 struct ThreadProxy::SchedulerStateRequest { | 52 struct ThreadProxy::SchedulerStateRequest { |
54 CompletionEvent completion; | 53 CompletionEvent completion; |
55 std::string state; | 54 std::string state; |
56 }; | 55 }; |
57 | 56 |
58 scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, | 57 scoped_ptr<Proxy> ThreadProxy::Create( |
59 scoped_ptr<Thread> impl_thread) { | 58 LayerTreeHost* layer_tree_host, |
| 59 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
60 return make_scoped_ptr( | 60 return make_scoped_ptr( |
61 new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); | 61 new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); |
62 } | 62 } |
63 | 63 |
64 ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host, | 64 ThreadProxy::ThreadProxy( |
65 scoped_ptr<Thread> impl_thread) | 65 LayerTreeHost* layer_tree_host, |
66 : Proxy(impl_thread.Pass()), | 66 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 67 : Proxy(impl_task_runner), |
67 animate_requested_(false), | 68 animate_requested_(false), |
68 commit_requested_(false), | 69 commit_requested_(false), |
69 commit_request_sent_to_impl_thread_(false), | 70 commit_request_sent_to_impl_thread_(false), |
70 created_offscreen_context_provider_(false), | 71 created_offscreen_context_provider_(false), |
71 layer_tree_host_(layer_tree_host), | 72 layer_tree_host_(layer_tree_host), |
72 started_(false), | 73 started_(false), |
73 textures_acquired_(true), | 74 textures_acquired_(true), |
74 in_composite_and_readback_(false), | 75 in_composite_and_readback_(false), |
75 manage_tiles_pending_(false), | 76 manage_tiles_pending_(false), |
76 weak_factory_on_impl_thread_(this), | 77 weak_factory_on_impl_thread_(this), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 111 |
111 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { | 112 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { |
112 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); | 113 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); |
113 return false; | 114 return false; |
114 } | 115 } |
115 | 116 |
116 // Perform a synchronous commit. | 117 // Perform a synchronous commit. |
117 { | 118 { |
118 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 119 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
119 CompletionEvent begin_frame_sent_to_main_thread_completion; | 120 CompletionEvent begin_frame_sent_to_main_thread_completion; |
120 Proxy::ImplThread()->PostTask( | 121 Proxy::ImplThreadTaskRunner()->PostTask( |
| 122 FROM_HERE, |
121 base::Bind(&ThreadProxy::ForceCommitOnImplThread, | 123 base::Bind(&ThreadProxy::ForceCommitOnImplThread, |
122 impl_thread_weak_ptr_, | 124 impl_thread_weak_ptr_, |
123 &begin_frame_sent_to_main_thread_completion)); | 125 &begin_frame_sent_to_main_thread_completion)); |
124 begin_frame_sent_to_main_thread_completion.Wait(); | 126 begin_frame_sent_to_main_thread_completion.Wait(); |
125 } | 127 } |
126 in_composite_and_readback_ = true; | 128 in_composite_and_readback_ = true; |
127 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); | 129 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); |
128 in_composite_and_readback_ = false; | 130 in_composite_and_readback_ = false; |
129 | 131 |
130 // Perform a synchronous readback. | 132 // Perform a synchronous readback. |
131 ReadbackRequest request; | 133 ReadbackRequest request; |
132 request.rect = rect; | 134 request.rect = rect; |
133 request.pixels = pixels; | 135 request.pixels = pixels; |
134 { | 136 { |
135 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 137 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
136 Proxy::ImplThread()->PostTask( | 138 Proxy::ImplThreadTaskRunner()->PostTask( |
| 139 FROM_HERE, |
137 base::Bind(&ThreadProxy::RequestReadbackOnImplThread, | 140 base::Bind(&ThreadProxy::RequestReadbackOnImplThread, |
138 impl_thread_weak_ptr_, | 141 impl_thread_weak_ptr_, |
139 &request)); | 142 &request)); |
140 request.completion.Wait(); | 143 request.completion.Wait(); |
141 } | 144 } |
142 return request.success; | 145 return request.success; |
143 } | 146 } |
144 | 147 |
145 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { | 148 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { |
146 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); | 149 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); |
(...skipping 23 matching lines...) Expand all Loading... |
170 scheduler_on_impl_thread_->SetNeedsForcedRedraw(); | 173 scheduler_on_impl_thread_->SetNeedsForcedRedraw(); |
171 } | 174 } |
172 | 175 |
173 void ThreadProxy::FinishAllRendering() { | 176 void ThreadProxy::FinishAllRendering() { |
174 DCHECK(Proxy::IsMainThread()); | 177 DCHECK(Proxy::IsMainThread()); |
175 DCHECK(!defer_commits_); | 178 DCHECK(!defer_commits_); |
176 | 179 |
177 // Make sure all GL drawing is finished on the impl thread. | 180 // Make sure all GL drawing is finished on the impl thread. |
178 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 181 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
179 CompletionEvent completion; | 182 CompletionEvent completion; |
180 Proxy::ImplThread()->PostTask( | 183 Proxy::ImplThreadTaskRunner()->PostTask( |
| 184 FROM_HERE, |
181 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, | 185 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, |
182 impl_thread_weak_ptr_, | 186 impl_thread_weak_ptr_, |
183 &completion)); | 187 &completion)); |
184 completion.Wait(); | 188 completion.Wait(); |
185 } | 189 } |
186 | 190 |
187 bool ThreadProxy::IsStarted() const { | 191 bool ThreadProxy::IsStarted() const { |
188 DCHECK(Proxy::IsMainThread()); | 192 DCHECK(Proxy::IsMainThread()); |
189 return started_; | 193 return started_; |
190 } | 194 } |
191 | 195 |
192 void ThreadProxy::SetLayerTreeHostClientReady() { | 196 void ThreadProxy::SetLayerTreeHostClientReady() { |
193 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); | 197 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); |
194 Proxy::ImplThread()->PostTask(base::Bind( | 198 Proxy::ImplThreadTaskRunner()->PostTask( |
195 &ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, | 199 FROM_HERE, |
196 impl_thread_weak_ptr_)); | 200 base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, |
| 201 impl_thread_weak_ptr_)); |
197 } | 202 } |
198 | 203 |
199 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { | 204 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { |
200 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); | 205 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread"); |
201 scheduler_on_impl_thread_->SetCanStart(); | 206 scheduler_on_impl_thread_->SetCanStart(); |
202 } | 207 } |
203 | 208 |
204 void ThreadProxy::SetVisible(bool visible) { | 209 void ThreadProxy::SetVisible(bool visible) { |
205 TRACE_EVENT0("cc", "ThreadProxy::SetVisible"); | 210 TRACE_EVENT0("cc", "ThreadProxy::SetVisible"); |
206 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 211 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
207 CompletionEvent completion; | 212 CompletionEvent completion; |
208 Proxy::ImplThread()->PostTask(base::Bind(&ThreadProxy::SetVisibleOnImplThread, | 213 Proxy::ImplThreadTaskRunner()->PostTask( |
209 impl_thread_weak_ptr_, | 214 FROM_HERE, |
210 &completion, | 215 base::Bind(&ThreadProxy::SetVisibleOnImplThread, |
211 visible)); | 216 impl_thread_weak_ptr_, |
| 217 &completion, |
| 218 visible)); |
212 completion.Wait(); | 219 completion.Wait(); |
213 } | 220 } |
214 | 221 |
215 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, | 222 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent* completion, |
216 bool visible) { | 223 bool visible) { |
217 TRACE_EVENT0("cc", "ThreadProxy::SetVisibleOnImplThread"); | 224 TRACE_EVENT0("cc", "ThreadProxy::SetVisibleOnImplThread"); |
218 layer_tree_host_impl_->SetVisible(visible); | 225 layer_tree_host_impl_->SetVisible(visible); |
219 scheduler_on_impl_thread_->SetVisible(visible); | 226 scheduler_on_impl_thread_->SetVisible(visible); |
220 completion->Signal(); | 227 completion->Signal(); |
221 } | 228 } |
(...skipping 25 matching lines...) Expand all Loading... |
247 } | 254 } |
248 | 255 |
249 success = false; | 256 success = false; |
250 { | 257 { |
251 // Make a blocking call to InitializeOutputSurfaceOnImplThread. The results | 258 // Make a blocking call to InitializeOutputSurfaceOnImplThread. The results |
252 // of that call are pushed into the success and capabilities local | 259 // of that call are pushed into the success and capabilities local |
253 // variables. | 260 // variables. |
254 CompletionEvent completion; | 261 CompletionEvent completion; |
255 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 262 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
256 | 263 |
257 Proxy::ImplThread()->PostTask( | 264 Proxy::ImplThreadTaskRunner()->PostTask( |
| 265 FROM_HERE, |
258 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, | 266 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, |
259 impl_thread_weak_ptr_, | 267 impl_thread_weak_ptr_, |
260 &completion, | 268 &completion, |
261 base::Passed(&output_surface), | 269 base::Passed(&output_surface), |
262 offscreen_context_provider, | 270 offscreen_context_provider, |
263 &success, | 271 &success, |
264 &capabilities)); | 272 &capabilities)); |
265 completion.Wait(); | 273 completion.Wait(); |
266 } | 274 } |
267 | 275 |
268 OnOutputSurfaceInitializeAttempted(success, capabilities); | 276 OnOutputSurfaceInitializeAttempted(success, capabilities); |
269 } | 277 } |
270 | 278 |
271 void ThreadProxy::OnOutputSurfaceInitializeAttempted( | 279 void ThreadProxy::OnOutputSurfaceInitializeAttempted( |
272 bool success, | 280 bool success, |
273 const RendererCapabilities& capabilities) { | 281 const RendererCapabilities& capabilities) { |
274 DCHECK(IsMainThread()); | 282 DCHECK(IsMainThread()); |
275 DCHECK(layer_tree_host_); | 283 DCHECK(layer_tree_host_); |
276 | 284 |
277 if (success) { | 285 if (success) { |
278 renderer_capabilities_main_thread_copy_ = capabilities; | 286 renderer_capabilities_main_thread_copy_ = capabilities; |
279 } | 287 } |
280 | 288 |
281 LayerTreeHost::CreateResult result = | 289 LayerTreeHost::CreateResult result = |
282 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); | 290 layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
283 if (result == LayerTreeHost::CreateFailedButTryAgain) { | 291 if (result == LayerTreeHost::CreateFailedButTryAgain) { |
284 if (!output_surface_creation_callback_.callback().is_null()) { | 292 if (!output_surface_creation_callback_.callback().is_null()) { |
285 Proxy::MainThread()->PostTask( | 293 Proxy::MainThreadTaskRunner()->PostTask( |
286 output_surface_creation_callback_.callback()); | 294 FROM_HERE, output_surface_creation_callback_.callback()); |
287 } | 295 } |
288 } else { | 296 } else { |
289 output_surface_creation_callback_.Cancel(); | 297 output_surface_creation_callback_.Cancel(); |
290 } | 298 } |
291 } | 299 } |
292 | 300 |
293 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { | 301 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { |
294 DCHECK(IsMainThread()); | 302 DCHECK(IsMainThread()); |
295 DCHECK(!layer_tree_host_->output_surface_lost()); | 303 DCHECK(!layer_tree_host_->output_surface_lost()); |
296 return renderer_capabilities_main_thread_copy_; | 304 return renderer_capabilities_main_thread_copy_; |
297 } | 305 } |
298 | 306 |
299 void ThreadProxy::SetNeedsAnimate() { | 307 void ThreadProxy::SetNeedsAnimate() { |
300 DCHECK(IsMainThread()); | 308 DCHECK(IsMainThread()); |
301 if (animate_requested_) | 309 if (animate_requested_) |
302 return; | 310 return; |
303 | 311 |
304 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); | 312 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); |
305 animate_requested_ = true; | 313 animate_requested_ = true; |
306 | 314 |
307 if (commit_request_sent_to_impl_thread_) | 315 if (commit_request_sent_to_impl_thread_) |
308 return; | 316 return; |
309 commit_request_sent_to_impl_thread_ = true; | 317 commit_request_sent_to_impl_thread_ = true; |
310 Proxy::ImplThread()->PostTask(base::Bind( | 318 Proxy::ImplThreadTaskRunner()->PostTask( |
311 &ThreadProxy::SetNeedsCommitOnImplThread, impl_thread_weak_ptr_)); | 319 FROM_HERE, |
| 320 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
| 321 impl_thread_weak_ptr_)); |
312 } | 322 } |
313 | 323 |
314 void ThreadProxy::SetNeedsCommit() { | 324 void ThreadProxy::SetNeedsCommit() { |
315 DCHECK(IsMainThread()); | 325 DCHECK(IsMainThread()); |
316 if (commit_requested_) | 326 if (commit_requested_) |
317 return; | 327 return; |
318 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); | 328 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit"); |
319 commit_requested_ = true; | 329 commit_requested_ = true; |
320 | 330 |
321 if (commit_request_sent_to_impl_thread_) | 331 if (commit_request_sent_to_impl_thread_) |
322 return; | 332 return; |
323 commit_request_sent_to_impl_thread_ = true; | 333 commit_request_sent_to_impl_thread_ = true; |
324 Proxy::ImplThread()->PostTask(base::Bind( | 334 Proxy::ImplThreadTaskRunner()->PostTask( |
325 &ThreadProxy::SetNeedsCommitOnImplThread, impl_thread_weak_ptr_)); | 335 FROM_HERE, |
| 336 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
| 337 impl_thread_weak_ptr_)); |
326 } | 338 } |
327 | 339 |
328 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { | 340 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
329 DCHECK(IsImplThread()); | 341 DCHECK(IsImplThread()); |
330 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 342 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
331 Proxy::ImplThread()->PostTask( | 343 Proxy::ImplThreadTaskRunner()->PostTask( |
| 344 FROM_HERE, |
332 base::Bind(&ThreadProxy::CheckOutputSurfaceStatusOnImplThread, | 345 base::Bind(&ThreadProxy::CheckOutputSurfaceStatusOnImplThread, |
333 impl_thread_weak_ptr_)); | 346 impl_thread_weak_ptr_)); |
334 } | 347 } |
335 | 348 |
336 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { | 349 void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { |
337 DCHECK(IsImplThread()); | 350 DCHECK(IsImplThread()); |
338 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); | 351 TRACE_EVENT0("cc", "ThreadProxy::CheckOutputSurfaceStatusOnImplThread"); |
339 if (!layer_tree_host_impl_->IsContextLost()) | 352 if (!layer_tree_host_impl_->IsContextLost()) |
340 return; | 353 return; |
341 cc::ContextProvider* offscreen_contexts = | 354 cc::ContextProvider* offscreen_contexts = |
342 layer_tree_host_impl_->resource_provider() ? | 355 layer_tree_host_impl_->resource_provider() ? |
343 layer_tree_host_impl_->resource_provider()-> | 356 layer_tree_host_impl_->resource_provider()-> |
344 offscreen_context_provider() : NULL; | 357 offscreen_context_provider() : NULL; |
345 | 358 |
346 if (offscreen_contexts) | 359 if (offscreen_contexts) |
347 offscreen_contexts->VerifyContexts(); | 360 offscreen_contexts->VerifyContexts(); |
348 scheduler_on_impl_thread_->DidLoseOutputSurface(); | 361 scheduler_on_impl_thread_->DidLoseOutputSurface(); |
349 } | 362 } |
350 | 363 |
351 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { | 364 void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { |
352 DCHECK(IsImplThread()); | 365 DCHECK(IsImplThread()); |
353 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); | 366 TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); |
354 Proxy::MainThread()->PostTask( | 367 Proxy::MainThreadTaskRunner()->PostTask( |
| 368 FROM_HERE, |
355 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); | 369 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); |
356 } | 370 } |
357 | 371 |
358 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { | 372 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { |
359 DCHECK(IsImplThread()); | 373 DCHECK(IsImplThread()); |
360 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", | 374 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", |
361 "enable", enable); | 375 "enable", enable); |
362 layer_tree_host_impl_->SetNeedsBeginFrame(enable); | 376 layer_tree_host_impl_->SetNeedsBeginFrame(enable); |
363 } | 377 } |
364 | 378 |
(...skipping 24 matching lines...) Expand all Loading... |
389 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); | 403 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); |
390 scheduler_on_impl_thread_->SetNeedsCommit(); | 404 scheduler_on_impl_thread_->SetNeedsCommit(); |
391 } | 405 } |
392 | 406 |
393 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 407 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
394 scoped_ptr<AnimationEventsVector> events, | 408 scoped_ptr<AnimationEventsVector> events, |
395 base::Time wall_clock_time) { | 409 base::Time wall_clock_time) { |
396 DCHECK(IsImplThread()); | 410 DCHECK(IsImplThread()); |
397 TRACE_EVENT0("cc", | 411 TRACE_EVENT0("cc", |
398 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 412 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
399 Proxy::MainThread()->PostTask(base::Bind(&ThreadProxy::SetAnimationEvents, | 413 Proxy::MainThreadTaskRunner()->PostTask( |
400 main_thread_weak_ptr_, | 414 FROM_HERE, |
401 base::Passed(&events), | 415 base::Bind(&ThreadProxy::SetAnimationEvents, |
402 wall_clock_time)); | 416 main_thread_weak_ptr_, |
| 417 base::Passed(&events), |
| 418 wall_clock_time)); |
403 } | 419 } |
404 | 420 |
405 bool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, | 421 bool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, |
406 int priority_cutoff) { | 422 int priority_cutoff) { |
407 DCHECK(IsImplThread()); | 423 DCHECK(IsImplThread()); |
408 | 424 |
409 if (!layer_tree_host_->contents_texture_manager()) | 425 if (!layer_tree_host_->contents_texture_manager()) |
410 return false; | 426 return false; |
411 if (!layer_tree_host_impl_->resource_provider()) | 427 if (!layer_tree_host_impl_->resource_provider()) |
412 return false; | 428 return false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 layer_tree_host_->contents_texture_manager()-> | 473 layer_tree_host_->contents_texture_manager()-> |
458 MemoryVisibleAndNearbyBytes(), | 474 MemoryVisibleAndNearbyBytes(), |
459 layer_tree_host_->contents_texture_manager()->MemoryUseBytes()); | 475 layer_tree_host_->contents_texture_manager()->MemoryUseBytes()); |
460 } | 476 } |
461 | 477 |
462 bool ThreadProxy::IsInsideDraw() { return inside_draw_; } | 478 bool ThreadProxy::IsInsideDraw() { return inside_draw_; } |
463 | 479 |
464 void ThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { | 480 void ThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { |
465 DCHECK(IsMainThread()); | 481 DCHECK(IsMainThread()); |
466 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw"); | 482 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw"); |
467 Proxy::ImplThread()->PostTask(base::Bind( | 483 Proxy::ImplThreadTaskRunner()->PostTask( |
468 &ThreadProxy::SetNeedsRedrawRectOnImplThread, | 484 FROM_HERE, |
469 impl_thread_weak_ptr_, damage_rect)); | 485 base::Bind(&ThreadProxy::SetNeedsRedrawRectOnImplThread, |
| 486 impl_thread_weak_ptr_, |
| 487 damage_rect)); |
470 } | 488 } |
471 | 489 |
472 void ThreadProxy::SetDeferCommits(bool defer_commits) { | 490 void ThreadProxy::SetDeferCommits(bool defer_commits) { |
473 DCHECK(IsMainThread()); | 491 DCHECK(IsMainThread()); |
474 DCHECK_NE(defer_commits_, defer_commits); | 492 DCHECK_NE(defer_commits_, defer_commits); |
475 defer_commits_ = defer_commits; | 493 defer_commits_ = defer_commits; |
476 | 494 |
477 if (defer_commits_) | 495 if (defer_commits_) |
478 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); | 496 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this); |
479 else | 497 else |
480 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); | 498 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); |
481 | 499 |
482 if (!defer_commits_ && pending_deferred_commit_) | 500 if (!defer_commits_ && pending_deferred_commit_) |
483 Proxy::MainThread()->PostTask( | 501 Proxy::MainThreadTaskRunner()->PostTask( |
| 502 FROM_HERE, |
484 base::Bind(&ThreadProxy::BeginFrameOnMainThread, | 503 base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
485 main_thread_weak_ptr_, | 504 main_thread_weak_ptr_, |
486 base::Passed(&pending_deferred_commit_))); | 505 base::Passed(&pending_deferred_commit_))); |
487 } | 506 } |
488 | 507 |
489 bool ThreadProxy::CommitRequested() const { | 508 bool ThreadProxy::CommitRequested() const { |
490 DCHECK(IsMainThread()); | 509 DCHECK(IsMainThread()); |
491 return commit_requested_; | 510 return commit_requested_; |
492 } | 511 } |
493 | 512 |
(...skipping 16 matching lines...) Expand all Loading... |
510 } | 529 } |
511 | 530 |
512 void ThreadProxy::DidInitializeVisibleTileOnImplThread() { | 531 void ThreadProxy::DidInitializeVisibleTileOnImplThread() { |
513 DCHECK(IsImplThread()); | 532 DCHECK(IsImplThread()); |
514 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeVisibleTileOnImplThread"); | 533 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeVisibleTileOnImplThread"); |
515 scheduler_on_impl_thread_->SetNeedsRedraw(); | 534 scheduler_on_impl_thread_->SetNeedsRedraw(); |
516 } | 535 } |
517 | 536 |
518 void ThreadProxy::MainThreadHasStoppedFlinging() { | 537 void ThreadProxy::MainThreadHasStoppedFlinging() { |
519 DCHECK(IsMainThread()); | 538 DCHECK(IsMainThread()); |
520 Proxy::ImplThread()->PostTask( | 539 Proxy::ImplThreadTaskRunner()->PostTask( |
| 540 FROM_HERE, |
521 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, | 541 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, |
522 impl_thread_weak_ptr_)); | 542 impl_thread_weak_ptr_)); |
523 } | 543 } |
524 | 544 |
525 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { | 545 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { |
526 DCHECK(IsImplThread()); | 546 DCHECK(IsImplThread()); |
527 layer_tree_host_impl_->MainThreadHasStoppedFlinging(); | 547 layer_tree_host_impl_->MainThreadHasStoppedFlinging(); |
528 } | 548 } |
529 | 549 |
530 void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { | 550 void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { |
531 DCHECK(IsMainThread()); | 551 DCHECK(IsMainThread()); |
532 DCHECK(Proxy::ImplThread()); | 552 DCHECK(Proxy::HasImplThread()); |
533 DCHECK(first_output_surface); | 553 DCHECK(first_output_surface); |
534 // Create LayerTreeHostImpl. | 554 // Create LayerTreeHostImpl. |
535 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 555 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
536 CompletionEvent completion; | 556 CompletionEvent completion; |
537 Proxy::ImplThread()->PostTask( | 557 Proxy::ImplThreadTaskRunner()->PostTask( |
| 558 FROM_HERE, |
538 base::Bind(&ThreadProxy::InitializeImplOnImplThread, | 559 base::Bind(&ThreadProxy::InitializeImplOnImplThread, |
539 base::Unretained(this), | 560 base::Unretained(this), |
540 &completion)); | 561 &completion)); |
541 completion.Wait(); | 562 completion.Wait(); |
542 | 563 |
543 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 564 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
544 first_output_surface_ = first_output_surface.Pass(); | 565 first_output_surface_ = first_output_surface.Pass(); |
545 | 566 |
546 started_ = true; | 567 started_ = true; |
547 } | 568 } |
548 | 569 |
549 void ThreadProxy::Stop() { | 570 void ThreadProxy::Stop() { |
550 TRACE_EVENT0("cc", "ThreadProxy::Stop"); | 571 TRACE_EVENT0("cc", "ThreadProxy::Stop"); |
551 DCHECK(IsMainThread()); | 572 DCHECK(IsMainThread()); |
552 DCHECK(started_); | 573 DCHECK(started_); |
553 | 574 |
554 // Synchronously finishes pending GL operations and deletes the impl. | 575 // Synchronously finishes pending GL operations and deletes the impl. |
555 // The two steps are done as separate post tasks, so that tasks posted | 576 // The two steps are done as separate post tasks, so that tasks posted |
556 // by the GL implementation due to the Finish can be executed by the | 577 // by the GL implementation due to the Finish can be executed by the |
557 // renderer before shutting it down. | 578 // renderer before shutting it down. |
558 { | 579 { |
559 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 580 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
560 | 581 |
561 CompletionEvent completion; | 582 CompletionEvent completion; |
562 Proxy::ImplThread()->PostTask( | 583 Proxy::ImplThreadTaskRunner()->PostTask( |
| 584 FROM_HERE, |
563 base::Bind(&ThreadProxy::FinishGLOnImplThread, | 585 base::Bind(&ThreadProxy::FinishGLOnImplThread, |
564 impl_thread_weak_ptr_, | 586 impl_thread_weak_ptr_, |
565 &completion)); | 587 &completion)); |
566 completion.Wait(); | 588 completion.Wait(); |
567 } | 589 } |
568 { | 590 { |
569 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 591 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
570 | 592 |
571 CompletionEvent completion; | 593 CompletionEvent completion; |
572 Proxy::ImplThread()->PostTask( | 594 Proxy::ImplThreadTaskRunner()->PostTask( |
| 595 FROM_HERE, |
573 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, | 596 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, |
574 impl_thread_weak_ptr_, | 597 impl_thread_weak_ptr_, |
575 &completion)); | 598 &completion)); |
576 completion.Wait(); | 599 completion.Wait(); |
577 } | 600 } |
578 | 601 |
579 weak_factory_.InvalidateWeakPtrs(); | 602 weak_factory_.InvalidateWeakPtrs(); |
580 | 603 |
581 DCHECK(!layer_tree_host_impl_.get()); // verify that the impl deleted. | 604 DCHECK(!layer_tree_host_impl_.get()); // verify that the impl deleted. |
582 layer_tree_host_ = NULL; | 605 layer_tree_host_ = NULL; |
583 started_ = false; | 606 started_ = false; |
584 } | 607 } |
585 | 608 |
586 void ThreadProxy::ForceSerializeOnSwapBuffers() { | 609 void ThreadProxy::ForceSerializeOnSwapBuffers() { |
587 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 610 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
588 CompletionEvent completion; | 611 CompletionEvent completion; |
589 Proxy::ImplThread()->PostTask( | 612 Proxy::ImplThreadTaskRunner()->PostTask( |
| 613 FROM_HERE, |
590 base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread, | 614 base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread, |
591 impl_thread_weak_ptr_, | 615 impl_thread_weak_ptr_, |
592 &completion)); | 616 &completion)); |
593 completion.Wait(); | 617 completion.Wait(); |
594 } | 618 } |
595 | 619 |
596 void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread( | 620 void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread( |
597 CompletionEvent* completion) { | 621 CompletionEvent* completion) { |
598 if (layer_tree_host_impl_->renderer()) | 622 if (layer_tree_host_impl_->renderer()) |
599 layer_tree_host_impl_->renderer()->DoNoOp(); | 623 layer_tree_host_impl_->renderer()->DoNoOp(); |
(...skipping 11 matching lines...) Expand all Loading... |
611 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); | 635 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); |
612 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( | 636 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( |
613 new BeginFrameAndCommitState); | 637 new BeginFrameAndCommitState); |
614 begin_frame_state->monotonic_frame_begin_time = | 638 begin_frame_state->monotonic_frame_begin_time = |
615 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); | 639 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); |
616 begin_frame_state->scroll_info = | 640 begin_frame_state->scroll_info = |
617 layer_tree_host_impl_->ProcessScrollDeltas(); | 641 layer_tree_host_impl_->ProcessScrollDeltas(); |
618 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); | 642 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); |
619 begin_frame_state->memory_allocation_limit_bytes = | 643 begin_frame_state->memory_allocation_limit_bytes = |
620 layer_tree_host_impl_->memory_allocation_limit_bytes(); | 644 layer_tree_host_impl_->memory_allocation_limit_bytes(); |
621 Proxy::MainThread()->PostTask( | 645 Proxy::MainThreadTaskRunner()->PostTask( |
| 646 FROM_HERE, |
622 base::Bind(&ThreadProxy::BeginFrameOnMainThread, | 647 base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
623 main_thread_weak_ptr_, | 648 main_thread_weak_ptr_, |
624 base::Passed(&begin_frame_state))); | 649 base::Passed(&begin_frame_state))); |
625 | 650 |
626 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { | 651 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { |
627 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); | 652 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); |
628 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = NULL; | 653 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = NULL; |
629 } | 654 } |
630 } | 655 } |
631 | 656 |
(...skipping 25 matching lines...) Expand all Loading... |
657 animate_requested_ = false; | 682 animate_requested_ = false; |
658 | 683 |
659 if (begin_frame_state) | 684 if (begin_frame_state) |
660 layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info); | 685 layer_tree_host_->ApplyScrollAndScale(*begin_frame_state->scroll_info); |
661 | 686 |
662 if (!in_composite_and_readback_ && !layer_tree_host_->visible()) { | 687 if (!in_composite_and_readback_ && !layer_tree_host_->visible()) { |
663 commit_requested_ = false; | 688 commit_requested_ = false; |
664 commit_request_sent_to_impl_thread_ = false; | 689 commit_request_sent_to_impl_thread_ = false; |
665 | 690 |
666 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); | 691 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); |
667 Proxy::ImplThread()->PostTask(base::Bind( | 692 Proxy::ImplThreadTaskRunner()->PostTask( |
668 &ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, | 693 FROM_HERE, |
669 impl_thread_weak_ptr_)); | 694 base::Bind(&ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, |
| 695 impl_thread_weak_ptr_)); |
670 return; | 696 return; |
671 } | 697 } |
672 | 698 |
673 layer_tree_host_->WillBeginFrame(); | 699 layer_tree_host_->WillBeginFrame(); |
674 | 700 |
675 if (begin_frame_state) { | 701 if (begin_frame_state) { |
676 layer_tree_host_->UpdateClientAnimations( | 702 layer_tree_host_->UpdateClientAnimations( |
677 begin_frame_state->monotonic_frame_begin_time); | 703 begin_frame_state->monotonic_frame_begin_time); |
678 layer_tree_host_->AnimateLayers( | 704 layer_tree_host_->AnimateLayers( |
679 begin_frame_state->monotonic_frame_begin_time); | 705 begin_frame_state->monotonic_frame_begin_time); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 { | 759 { |
734 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread::commit"); | 760 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnMainThread::commit"); |
735 | 761 |
736 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 762 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
737 | 763 |
738 RenderingStatsInstrumentation* stats_instrumentation = | 764 RenderingStatsInstrumentation* stats_instrumentation = |
739 layer_tree_host_->rendering_stats_instrumentation(); | 765 layer_tree_host_->rendering_stats_instrumentation(); |
740 base::TimeTicks start_time = stats_instrumentation->StartRecording(); | 766 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
741 | 767 |
742 CompletionEvent completion; | 768 CompletionEvent completion; |
743 Proxy::ImplThread()->PostTask( | 769 Proxy::ImplThreadTaskRunner()->PostTask( |
| 770 FROM_HERE, |
744 base::Bind(&ThreadProxy::StartCommitOnImplThread, | 771 base::Bind(&ThreadProxy::StartCommitOnImplThread, |
745 impl_thread_weak_ptr_, | 772 impl_thread_weak_ptr_, |
746 &completion, | 773 &completion, |
747 queue.release(), | 774 queue.release(), |
748 offscreen_context_provider)); | 775 offscreen_context_provider)); |
749 completion.Wait(); | 776 completion.Wait(); |
750 | 777 |
751 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); | 778 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
752 stats_instrumentation->AddCommit(duration); | 779 stats_instrumentation->AddCommit(duration); |
753 } | 780 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 821 |
795 layer_tree_host_->contents_texture_manager()-> | 822 layer_tree_host_->contents_texture_manager()-> |
796 PushTexturePrioritiesToBackings(); | 823 PushTexturePrioritiesToBackings(); |
797 } | 824 } |
798 | 825 |
799 commit_completion_event_on_impl_thread_ = completion; | 826 commit_completion_event_on_impl_thread_ = completion; |
800 if (layer_tree_host_impl_->resource_provider()) { | 827 if (layer_tree_host_impl_->resource_provider()) { |
801 current_resource_update_controller_on_impl_thread_ = | 828 current_resource_update_controller_on_impl_thread_ = |
802 ResourceUpdateController::Create( | 829 ResourceUpdateController::Create( |
803 this, | 830 this, |
804 Proxy::ImplThread()->TaskRunner(), | 831 Proxy::ImplThreadTaskRunner(), |
805 queue.Pass(), | 832 queue.Pass(), |
806 layer_tree_host_impl_->resource_provider()); | 833 layer_tree_host_impl_->resource_provider()); |
807 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( | 834 current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( |
808 scheduler_on_impl_thread_->AnticipatedDrawTime()); | 835 scheduler_on_impl_thread_->AnticipatedDrawTime()); |
809 } else { | 836 } else { |
810 // Normally the ResourceUpdateController notifies when commit should | 837 // Normally the ResourceUpdateController notifies when commit should |
811 // finish, but in tile-free software rendering there is no resource | 838 // finish, but in tile-free software rendering there is no resource |
812 // update step so jump straight to the notification. | 839 // update step so jump straight to the notification. |
813 scheduler_on_impl_thread_->FinishCommit(); | 840 scheduler_on_impl_thread_->FinishCommit(); |
814 } | 841 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 } | 897 } |
871 | 898 |
872 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { | 899 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { |
873 DCHECK(IsImplThread()); | 900 DCHECK(IsImplThread()); |
874 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); | 901 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); |
875 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); | 902 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); |
876 } | 903 } |
877 | 904 |
878 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { | 905 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
879 DCHECK(IsImplThread()); | 906 DCHECK(IsImplThread()); |
880 Proxy::MainThread()->PostTask( | 907 Proxy::MainThreadTaskRunner()->PostTask( |
| 908 FROM_HERE, |
881 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, | 909 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, |
882 main_thread_weak_ptr_)); | 910 main_thread_weak_ptr_)); |
883 } | 911 } |
884 | 912 |
885 ScheduledActionDrawAndSwapResult | 913 ScheduledActionDrawAndSwapResult |
886 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { | 914 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { |
887 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); | 915 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); |
888 | 916 |
889 ScheduledActionDrawAndSwapResult result; | 917 ScheduledActionDrawAndSwapResult result; |
890 result.did_draw = false; | 918 result.did_draw = false; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 } else if (draw_frame) { | 1001 } else if (draw_frame) { |
974 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); | 1002 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); |
975 | 1003 |
976 if (frame.contains_incomplete_tile) | 1004 if (frame.contains_incomplete_tile) |
977 DidSwapUseIncompleteTileOnImplThread(); | 1005 DidSwapUseIncompleteTileOnImplThread(); |
978 } | 1006 } |
979 | 1007 |
980 // Tell the main thread that the the newly-commited frame was drawn. | 1008 // Tell the main thread that the the newly-commited frame was drawn. |
981 if (next_frame_is_newly_committed_frame_on_impl_thread_) { | 1009 if (next_frame_is_newly_committed_frame_on_impl_thread_) { |
982 next_frame_is_newly_committed_frame_on_impl_thread_ = false; | 1010 next_frame_is_newly_committed_frame_on_impl_thread_ = false; |
983 Proxy::MainThread()->PostTask( | 1011 Proxy::MainThreadTaskRunner()->PostTask( |
| 1012 FROM_HERE, |
984 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 1013 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
985 } | 1014 } |
986 | 1015 |
987 if (draw_frame) { | 1016 if (draw_frame) { |
988 CheckOutputSurfaceStatusOnImplThread(); | 1017 CheckOutputSurfaceStatusOnImplThread(); |
989 | 1018 |
990 base::TimeDelta draw_duration = base::TimeTicks::HighResNow() - start_time; | 1019 base::TimeDelta draw_duration = base::TimeTicks::HighResNow() - start_time; |
991 draw_duration_history_.InsertSample(draw_duration); | 1020 draw_duration_history_.InsertSample(draw_duration); |
992 base::TimeDelta draw_duration_overestimate; | 1021 base::TimeDelta draw_duration_overestimate; |
993 base::TimeDelta draw_duration_underestimate; | 1022 base::TimeDelta draw_duration_underestimate; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 // previously committed frame that is still undrawn. This is necessary to | 1057 // previously committed frame that is still undrawn. This is necessary to |
1029 // ensure that the main thread does not monopolize access to the textures. | 1058 // ensure that the main thread does not monopolize access to the textures. |
1030 DCHECK(IsMainThread()); | 1059 DCHECK(IsMainThread()); |
1031 | 1060 |
1032 if (textures_acquired_) | 1061 if (textures_acquired_) |
1033 return; | 1062 return; |
1034 | 1063 |
1035 TRACE_EVENT0("cc", "ThreadProxy::AcquireLayerTextures"); | 1064 TRACE_EVENT0("cc", "ThreadProxy::AcquireLayerTextures"); |
1036 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1065 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
1037 CompletionEvent completion; | 1066 CompletionEvent completion; |
1038 Proxy::ImplThread()->PostTask( | 1067 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1068 FROM_HERE, |
1039 base::Bind(&ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread, | 1069 base::Bind(&ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread, |
1040 impl_thread_weak_ptr_, | 1070 impl_thread_weak_ptr_, |
1041 &completion)); | 1071 &completion)); |
1042 // Block until it is safe to write to layer textures from the main thread. | 1072 // Block until it is safe to write to layer textures from the main thread. |
1043 completion.Wait(); | 1073 completion.Wait(); |
1044 | 1074 |
1045 textures_acquired_ = true; | 1075 textures_acquired_ = true; |
1046 } | 1076 } |
1047 | 1077 |
1048 void ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread( | 1078 void ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 | 1145 |
1116 void ThreadProxy::CreateAndInitializeOutputSurface() { | 1146 void ThreadProxy::CreateAndInitializeOutputSurface() { |
1117 TRACE_EVENT0("cc", "ThreadProxy::CreateAndInitializeOutputSurface"); | 1147 TRACE_EVENT0("cc", "ThreadProxy::CreateAndInitializeOutputSurface"); |
1118 DCHECK(IsMainThread()); | 1148 DCHECK(IsMainThread()); |
1119 | 1149 |
1120 // Check that output surface has not been recreated by CompositeAndReadback | 1150 // Check that output surface has not been recreated by CompositeAndReadback |
1121 // after this task is posted but before it is run. | 1151 // after this task is posted but before it is run. |
1122 bool has_initialized_output_surface_on_impl_thread = true; | 1152 bool has_initialized_output_surface_on_impl_thread = true; |
1123 { | 1153 { |
1124 CompletionEvent completion; | 1154 CompletionEvent completion; |
1125 Proxy::ImplThread()->PostTask( | 1155 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1156 FROM_HERE, |
1126 base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, | 1157 base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, |
1127 impl_thread_weak_ptr_, | 1158 impl_thread_weak_ptr_, |
1128 &completion, | 1159 &completion, |
1129 &has_initialized_output_surface_on_impl_thread)); | 1160 &has_initialized_output_surface_on_impl_thread)); |
1130 completion.Wait(); | 1161 completion.Wait(); |
1131 } | 1162 } |
1132 if (has_initialized_output_surface_on_impl_thread) | 1163 if (has_initialized_output_surface_on_impl_thread) |
1133 return; | 1164 return; |
1134 | 1165 |
1135 layer_tree_host_->DidLoseOutputSurface(); | 1166 layer_tree_host_->DidLoseOutputSurface(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 | 1272 |
1242 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} | 1273 ThreadProxy::BeginFrameAndCommitState::~BeginFrameAndCommitState() {} |
1243 | 1274 |
1244 scoped_ptr<base::Value> ThreadProxy::AsValue() const { | 1275 scoped_ptr<base::Value> ThreadProxy::AsValue() const { |
1245 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 1276 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
1246 | 1277 |
1247 CompletionEvent completion; | 1278 CompletionEvent completion; |
1248 { | 1279 { |
1249 DebugScopedSetMainThreadBlocked main_thread_blocked( | 1280 DebugScopedSetMainThreadBlocked main_thread_blocked( |
1250 const_cast<ThreadProxy*>(this)); | 1281 const_cast<ThreadProxy*>(this)); |
1251 Proxy::ImplThread()->PostTask(base::Bind(&ThreadProxy::AsValueOnImplThread, | 1282 Proxy::ImplThreadTaskRunner()->PostTask( |
1252 impl_thread_weak_ptr_, | 1283 FROM_HERE, |
1253 &completion, | 1284 base::Bind(&ThreadProxy::AsValueOnImplThread, |
1254 state.get())); | 1285 impl_thread_weak_ptr_, |
| 1286 &completion, |
| 1287 state.get())); |
1255 completion.Wait(); | 1288 completion.Wait(); |
1256 } | 1289 } |
1257 return state.PassAs<base::Value>(); | 1290 return state.PassAs<base::Value>(); |
1258 } | 1291 } |
1259 | 1292 |
1260 void ThreadProxy::AsValueOnImplThread(CompletionEvent* completion, | 1293 void ThreadProxy::AsValueOnImplThread(CompletionEvent* completion, |
1261 base::DictionaryValue* state) const { | 1294 base::DictionaryValue* state) const { |
1262 state->Set("layer_tree_host_impl", | 1295 state->Set("layer_tree_host_impl", |
1263 layer_tree_host_impl_->AsValue().release()); | 1296 layer_tree_host_impl_->AsValue().release()); |
1264 completion->Signal(); | 1297 completion->Signal(); |
1265 } | 1298 } |
1266 | 1299 |
1267 bool ThreadProxy::CommitPendingForTesting() { | 1300 bool ThreadProxy::CommitPendingForTesting() { |
1268 DCHECK(IsMainThread()); | 1301 DCHECK(IsMainThread()); |
1269 CommitPendingRequest commit_pending_request; | 1302 CommitPendingRequest commit_pending_request; |
1270 { | 1303 { |
1271 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1304 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
1272 Proxy::ImplThread()->PostTask( | 1305 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1306 FROM_HERE, |
1273 base::Bind(&ThreadProxy::CommitPendingOnImplThreadForTesting, | 1307 base::Bind(&ThreadProxy::CommitPendingOnImplThreadForTesting, |
1274 impl_thread_weak_ptr_, | 1308 impl_thread_weak_ptr_, |
1275 &commit_pending_request)); | 1309 &commit_pending_request)); |
1276 commit_pending_request.completion.Wait(); | 1310 commit_pending_request.completion.Wait(); |
1277 } | 1311 } |
1278 return commit_pending_request.commit_pending; | 1312 return commit_pending_request.commit_pending; |
1279 } | 1313 } |
1280 | 1314 |
1281 void ThreadProxy::CommitPendingOnImplThreadForTesting( | 1315 void ThreadProxy::CommitPendingOnImplThreadForTesting( |
1282 CommitPendingRequest* request) { | 1316 CommitPendingRequest* request) { |
1283 DCHECK(IsImplThread()); | 1317 DCHECK(IsImplThread()); |
1284 if (layer_tree_host_impl_->output_surface()) | 1318 if (layer_tree_host_impl_->output_surface()) |
1285 request->commit_pending = scheduler_on_impl_thread_->CommitPending(); | 1319 request->commit_pending = scheduler_on_impl_thread_->CommitPending(); |
1286 else | 1320 else |
1287 request->commit_pending = false; | 1321 request->commit_pending = false; |
1288 request->completion.Signal(); | 1322 request->completion.Signal(); |
1289 } | 1323 } |
1290 | 1324 |
1291 std::string ThreadProxy::SchedulerStateAsStringForTesting() { | 1325 std::string ThreadProxy::SchedulerStateAsStringForTesting() { |
1292 if (IsImplThread()) | 1326 if (IsImplThread()) |
1293 return scheduler_on_impl_thread_->StateAsStringForTesting(); | 1327 return scheduler_on_impl_thread_->StateAsStringForTesting(); |
1294 | 1328 |
1295 SchedulerStateRequest scheduler_state_request; | 1329 SchedulerStateRequest scheduler_state_request; |
1296 { | 1330 { |
1297 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1331 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
1298 Proxy::ImplThread()->PostTask( | 1332 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1333 FROM_HERE, |
1299 base::Bind(&ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting, | 1334 base::Bind(&ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting, |
1300 impl_thread_weak_ptr_, | 1335 impl_thread_weak_ptr_, |
1301 &scheduler_state_request)); | 1336 &scheduler_state_request)); |
1302 scheduler_state_request.completion.Wait(); | 1337 scheduler_state_request.completion.Wait(); |
1303 } | 1338 } |
1304 return scheduler_state_request.state; | 1339 return scheduler_state_request.state; |
1305 } | 1340 } |
1306 | 1341 |
1307 void ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting( | 1342 void ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting( |
1308 SchedulerStateRequest* request) { | 1343 SchedulerStateRequest* request) { |
1309 DCHECK(IsImplThread()); | 1344 DCHECK(IsImplThread()); |
1310 request->state = scheduler_on_impl_thread_->StateAsStringForTesting(); | 1345 request->state = scheduler_on_impl_thread_->StateAsStringForTesting(); |
1311 request->completion.Signal(); | 1346 request->completion.Signal(); |
1312 } | 1347 } |
1313 | 1348 |
1314 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { | 1349 skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { |
1315 DCHECK(IsMainThread()); | 1350 DCHECK(IsMainThread()); |
1316 CompletionEvent completion; | 1351 CompletionEvent completion; |
1317 skia::RefPtr<SkPicture> picture; | 1352 skia::RefPtr<SkPicture> picture; |
1318 { | 1353 { |
1319 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 1354 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
1320 Proxy::ImplThread()->PostTask( | 1355 Proxy::ImplThreadTaskRunner()->PostTask( |
| 1356 FROM_HERE, |
1321 base::Bind(&ThreadProxy::CapturePictureOnImplThread, | 1357 base::Bind(&ThreadProxy::CapturePictureOnImplThread, |
1322 impl_thread_weak_ptr_, | 1358 impl_thread_weak_ptr_, |
1323 &completion, | 1359 &completion, |
1324 &picture)); | 1360 &picture)); |
1325 completion.Wait(); | 1361 completion.Wait(); |
1326 } | 1362 } |
1327 return picture; | 1363 return picture; |
1328 } | 1364 } |
1329 | 1365 |
1330 void ThreadProxy::CapturePictureOnImplThread(CompletionEvent* completion, | 1366 void ThreadProxy::CapturePictureOnImplThread(CompletionEvent* completion, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 | 1410 |
1375 base::TimeDelta delay = smoothness_takes_priority_expiration_time_ - now; | 1411 base::TimeDelta delay = smoothness_takes_priority_expiration_time_ - now; |
1376 | 1412 |
1377 // Need to make sure a delayed task is posted when we have smoothness | 1413 // Need to make sure a delayed task is posted when we have smoothness |
1378 // takes priority expiration time in the future. | 1414 // takes priority expiration time in the future. |
1379 if (delay <= base::TimeDelta()) | 1415 if (delay <= base::TimeDelta()) |
1380 return; | 1416 return; |
1381 if (renew_tree_priority_on_impl_thread_pending_) | 1417 if (renew_tree_priority_on_impl_thread_pending_) |
1382 return; | 1418 return; |
1383 | 1419 |
1384 Proxy::ImplThread()->PostDelayedTask( | 1420 Proxy::ImplThreadTaskRunner()->PostDelayedTask( |
| 1421 FROM_HERE, |
1385 base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread, | 1422 base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread, |
1386 weak_factory_on_impl_thread_.GetWeakPtr()), | 1423 weak_factory_on_impl_thread_.GetWeakPtr()), |
1387 delay); | 1424 delay); |
1388 | 1425 |
1389 renew_tree_priority_on_impl_thread_pending_ = true; | 1426 renew_tree_priority_on_impl_thread_pending_ = true; |
1390 } | 1427 } |
1391 | 1428 |
1392 void ThreadProxy::RenewTreePriorityOnImplThread() { | 1429 void ThreadProxy::RenewTreePriorityOnImplThread() { |
1393 DCHECK(renew_tree_priority_on_impl_thread_pending_); | 1430 DCHECK(renew_tree_priority_on_impl_thread_pending_); |
1394 renew_tree_priority_on_impl_thread_pending_ = false; | 1431 renew_tree_priority_on_impl_thread_pending_ = false; |
1395 | 1432 |
1396 RenewTreePriority(); | 1433 RenewTreePriority(); |
1397 } | 1434 } |
1398 | 1435 |
1399 void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) { | 1436 void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) { |
1400 Proxy::ImplThread()->PostDelayedTask( | 1437 Proxy::ImplThreadTaskRunner()->PostDelayedTask( |
| 1438 FROM_HERE, |
1401 base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, | 1439 base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, |
1402 impl_thread_weak_ptr_), | 1440 impl_thread_weak_ptr_), |
1403 delay); | 1441 delay); |
1404 } | 1442 } |
1405 | 1443 |
1406 void ThreadProxy::StartScrollbarAnimationOnImplThread() { | 1444 void ThreadProxy::StartScrollbarAnimationOnImplThread() { |
1407 layer_tree_host_impl_->StartScrollbarAnimation(); | 1445 layer_tree_host_impl_->StartScrollbarAnimation(); |
1408 } | 1446 } |
1409 | 1447 |
1410 void ThreadProxy::DidActivatePendingTree() { | 1448 void ThreadProxy::DidActivatePendingTree() { |
1411 DCHECK(IsImplThread()); | 1449 DCHECK(IsImplThread()); |
1412 TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread"); | 1450 TRACE_EVENT0("cc", "ThreadProxy::DidActivatePendingTreeOnImplThread"); |
1413 | 1451 |
1414 if (completion_event_for_commit_held_on_tree_activation_ && | 1452 if (completion_event_for_commit_held_on_tree_activation_ && |
1415 !layer_tree_host_impl_->pending_tree()) { | 1453 !layer_tree_host_impl_->pending_tree()) { |
1416 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", | 1454 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", |
1417 TRACE_EVENT_SCOPE_THREAD); | 1455 TRACE_EVENT_SCOPE_THREAD); |
1418 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 1456 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
1419 completion_event_for_commit_held_on_tree_activation_->Signal(); | 1457 completion_event_for_commit_held_on_tree_activation_->Signal(); |
1420 completion_event_for_commit_held_on_tree_activation_ = NULL; | 1458 completion_event_for_commit_held_on_tree_activation_ = NULL; |
1421 } | 1459 } |
1422 } | 1460 } |
1423 | 1461 |
1424 } // namespace cc | 1462 } // namespace cc |
OLD | NEW |