1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/trees/thread_proxy.h"
10 #include "base/auto_reset.h"
11 #include "base/bind.h"
12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h"
14 #include "base/trace_event/trace_event_synthetic_delay.h"
15 #include "cc/debug/benchmark_instrumentation.h"
16 #include "cc/debug/devtools_instrumentation.h"
17 #include "cc/input/input_handler.h"
18 #include "cc/output/context_provider.h"
19 #include "cc/output/output_surface.h"
20 #include "cc/output/swap_promise.h"
21 #include "cc/quads/draw_quad.h"
22 #include "cc/scheduler/commit_earlyout_reason.h"
23 #include "cc/scheduler/compositor_timing_history.h"
24 #include "cc/scheduler/scheduler.h"
25 #include "cc/trees/blocking_task_runner.h"
26 #include "cc/trees/layer_tree_host.h"
27 #include "cc/trees/layer_tree_impl.h"
28 #include "cc/trees/scoped_abort_remaining_swap_promises.h"
29 #include "gpu/command_buffer/client/gles2_interface.h"
35 // Measured in seconds.
36 const double kSmoothnessTakesPriorityExpirationDelay
= 0.25;
38 unsigned int nextBeginFrameId
= 0;
42 struct ThreadProxy::SchedulerStateRequest
{
43 CompletionEvent completion
;
44 scoped_ptr
<base::Value
> state
;
47 scoped_ptr
<Proxy
> ThreadProxy::Create(
48 LayerTreeHost
* layer_tree_host
,
49 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
50 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
,
51 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
) {
52 return make_scoped_ptr(new ThreadProxy(layer_tree_host
,
55 external_begin_frame_source
.Pass()));
58 ThreadProxy::ThreadProxy(
59 LayerTreeHost
* layer_tree_host
,
60 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
61 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
,
62 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
)
63 : Proxy(main_task_runner
, impl_task_runner
),
64 main_thread_only_vars_unsafe_(this, layer_tree_host
->id()),
65 main_thread_or_blocked_vars_unsafe_(layer_tree_host
),
66 compositor_thread_vars_unsafe_(
68 layer_tree_host
->id(),
69 layer_tree_host
->rendering_stats_instrumentation(),
70 external_begin_frame_source
.Pass()) {
71 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
72 DCHECK(IsMainThread());
73 DCHECK(this->layer_tree_host());
76 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy
* proxy
,
77 int layer_tree_host_id
)
78 : layer_tree_host_id(layer_tree_host_id
),
79 animate_requested(false),
80 commit_requested(false),
81 commit_request_sent_to_impl_thread(false),
83 prepare_tiles_pending(false),
84 can_cancel_commit(true),
89 ThreadProxy::MainThreadOnly::~MainThreadOnly() {}
91 ThreadProxy::MainThreadOrBlockedMainThread::MainThreadOrBlockedMainThread(
93 : layer_tree_host(host
),
94 commit_waits_for_activation(false),
95 main_thread_inside_commit(false) {}
97 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {}
99 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(
101 int layer_tree_host_id
,
102 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
103 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
)
104 : layer_tree_host_id(layer_tree_host_id
),
105 commit_completion_event(NULL
),
106 completion_event_for_commit_held_on_tree_activation(NULL
),
107 next_frame_is_newly_committed_frame(false),
109 input_throttled_until_commit(false),
110 smoothness_priority_expiration_notifier(
111 proxy
->ImplThreadTaskRunner(),
112 base::Bind(&ThreadProxy::RenewTreePriority
, base::Unretained(proxy
)),
113 base::TimeDelta::FromMilliseconds(
114 kSmoothnessTakesPriorityExpirationDelay
* 1000)),
115 external_begin_frame_source(external_begin_frame_source
.Pass()),
116 rendering_stats_instrumentation(rendering_stats_instrumentation
),
117 weak_factory(proxy
) {
120 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {}
122 ThreadProxy::~ThreadProxy() {
123 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
124 DCHECK(IsMainThread());
125 DCHECK(!main().started
);
128 void ThreadProxy::FinishAllRendering() {
129 DCHECK(Proxy::IsMainThread());
130 DCHECK(!main().defer_commits
);
132 // Make sure all GL drawing is finished on the impl thread.
133 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
134 CompletionEvent completion
;
135 Proxy::ImplThreadTaskRunner()->PostTask(
137 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread
,
138 impl_thread_weak_ptr_
,
143 bool ThreadProxy::IsStarted() const {
144 DCHECK(Proxy::IsMainThread());
145 return main().started
;
148 bool ThreadProxy::CommitToActiveTree() const {
149 // With ThreadProxy, we use a pending tree and activate it once it's ready to
150 // draw to allow input to modify the active tree and draw during raster.
154 void ThreadProxy::SetLayerTreeHostClientReady() {
155 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady");
156 Proxy::ImplThreadTaskRunner()->PostTask(
158 base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread
,
159 impl_thread_weak_ptr_
));
162 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() {
163 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread");
164 impl().scheduler
->SetCanStart();
167 void ThreadProxy::SetVisible(bool visible
) {
168 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible
);
169 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
171 CompletionEvent completion
;
172 Proxy::ImplThreadTaskRunner()->PostTask(
174 base::Bind(&ThreadProxy::SetVisibleOnImplThread
,
175 impl_thread_weak_ptr_
,
181 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent
* completion
,
183 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible
);
184 impl().layer_tree_host_impl
->SetVisible(visible
);
185 impl().scheduler
->SetVisible(visible
);
186 completion
->Signal();
189 void ThreadProxy::SetThrottleFrameProduction(bool throttle
) {
190 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle",
192 Proxy::ImplThreadTaskRunner()->PostTask(
194 base::Bind(&ThreadProxy::SetThrottleFrameProductionOnImplThread
,
195 impl_thread_weak_ptr_
, throttle
));
198 void ThreadProxy::SetThrottleFrameProductionOnImplThread(bool throttle
) {
199 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread",
200 "throttle", throttle
);
201 impl().scheduler
->SetThrottleFrameProduction(throttle
);
204 void ThreadProxy::DidLoseOutputSurface() {
205 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface");
206 DCHECK(IsMainThread());
207 layer_tree_host()->DidLoseOutputSurface();
210 void ThreadProxy::RequestNewOutputSurface() {
211 DCHECK(IsMainThread());
212 layer_tree_host()->RequestNewOutputSurface();
215 void ThreadProxy::SetOutputSurface(scoped_ptr
<OutputSurface
> output_surface
) {
216 Proxy::ImplThreadTaskRunner()->PostTask(
218 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread
,
219 impl_thread_weak_ptr_
, base::Passed(&output_surface
)));
222 void ThreadProxy::DidInitializeOutputSurface(
224 const RendererCapabilities
& capabilities
) {
225 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeOutputSurface");
226 DCHECK(IsMainThread());
229 layer_tree_host()->DidFailToInitializeOutputSurface();
232 main().renderer_capabilities_main_thread_copy
= capabilities
;
233 layer_tree_host()->DidInitializeOutputSurface();
236 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy(
237 const RendererCapabilities
& capabilities
) {
238 main().renderer_capabilities_main_thread_copy
= capabilities
;
241 void ThreadProxy::SendCommitRequestToImplThreadIfNeeded() {
242 DCHECK(IsMainThread());
243 if (main().commit_request_sent_to_impl_thread
)
245 main().commit_request_sent_to_impl_thread
= true;
246 Proxy::ImplThreadTaskRunner()->PostTask(
248 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread
,
249 impl_thread_weak_ptr_
));
252 void ThreadProxy::DidCompletePageScaleAnimation() {
253 DCHECK(IsMainThread());
254 layer_tree_host()->DidCompletePageScaleAnimation();
257 const RendererCapabilities
& ThreadProxy::GetRendererCapabilities() const {
258 DCHECK(IsMainThread());
259 DCHECK(!layer_tree_host()->output_surface_lost());
260 return main().renderer_capabilities_main_thread_copy
;
263 void ThreadProxy::SetNeedsAnimate() {
264 DCHECK(IsMainThread());
265 if (main().animate_requested
)
268 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate");
269 main().animate_requested
= true;
270 SendCommitRequestToImplThreadIfNeeded();
273 void ThreadProxy::SetNeedsUpdateLayers() {
274 DCHECK(IsMainThread());
276 if (main().commit_request_sent_to_impl_thread
)
278 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsUpdateLayers");
280 SendCommitRequestToImplThreadIfNeeded();
283 void ThreadProxy::SetNeedsCommit() {
284 DCHECK(IsMainThread());
285 // Unconditionally set here to handle SetNeedsCommit calls during a commit.
286 main().can_cancel_commit
= false;
288 if (main().commit_requested
)
290 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommit");
291 main().commit_requested
= true;
293 SendCommitRequestToImplThreadIfNeeded();
296 void ThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
297 DCHECK(IsImplThread());
298 Proxy::MainThreadTaskRunner()->PostTask(
300 base::Bind(&ThreadProxy::SetRendererCapabilitiesMainThreadCopy
,
301 main_thread_weak_ptr_
,
303 .layer_tree_host_impl
->GetRendererCapabilities()
304 .MainThreadCapabilities()));
307 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() {
308 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread");
309 DCHECK(IsImplThread());
310 Proxy::MainThreadTaskRunner()->PostTask(
312 base::Bind(&ThreadProxy::DidLoseOutputSurface
, main_thread_weak_ptr_
));
313 impl().scheduler
->DidLoseOutputSurface();
316 void ThreadProxy::CommitVSyncParameters(base::TimeTicks timebase
,
317 base::TimeDelta interval
) {
318 impl().scheduler
->CommitVSyncParameters(timebase
, interval
);
321 void ThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time
) {
322 impl().scheduler
->SetEstimatedParentDrawTime(draw_time
);
325 void ThreadProxy::SetMaxSwapsPendingOnImplThread(int max
) {
326 impl().scheduler
->SetMaxSwapsPending(max
);
329 void ThreadProxy::DidSwapBuffersOnImplThread() {
330 impl().scheduler
->DidSwapBuffers();
333 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() {
334 TRACE_EVENT0("cc,benchmark",
335 "ThreadProxy::DidSwapBuffersCompleteOnImplThread");
336 DCHECK(IsImplThread());
337 impl().scheduler
->DidSwapBuffersComplete();
338 Proxy::MainThreadTaskRunner()->PostTask(
340 base::Bind(&ThreadProxy::DidCompleteSwapBuffers
, main_thread_weak_ptr_
));
343 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs
& args
) {
344 impl().layer_tree_host_impl
->WillBeginImplFrame(args
);
345 if (impl().last_processed_begin_main_frame_args
.IsValid()) {
346 // Last processed begin main frame args records the frame args that we sent
347 // to the main thread for the last frame that we've processed. If that is
348 // set, that means the current frame is one past the frame in which we've
349 // finished the processing.
350 impl().layer_tree_host_impl
->RecordMainFrameTiming(
351 impl().last_processed_begin_main_frame_args
,
352 impl().layer_tree_host_impl
->CurrentBeginFrameArgs());
353 impl().last_processed_begin_main_frame_args
= BeginFrameArgs();
357 void ThreadProxy::OnCanDrawStateChanged(bool can_draw
) {
359 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw
);
360 DCHECK(IsImplThread());
361 impl().scheduler
->SetCanDraw(can_draw
);
364 void ThreadProxy::NotifyReadyToActivate() {
365 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate");
366 impl().scheduler
->NotifyReadyToActivate();
369 void ThreadProxy::NotifyReadyToDraw() {
370 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToDraw");
371 impl().scheduler
->NotifyReadyToDraw();
374 void ThreadProxy::SetNeedsCommitOnImplThread() {
375 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread");
376 DCHECK(IsImplThread());
377 impl().scheduler
->SetNeedsBeginMainFrame();
380 void ThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames
) {
381 TRACE_EVENT1("cc", "ThreadProxy::SetVideoNeedsBeginFrames",
382 "needs_begin_frames", needs_begin_frames
);
383 DCHECK(IsImplThread());
384 // In tests the layer tree is destroyed after the scheduler is.
385 if (impl().scheduler
)
386 impl().scheduler
->SetVideoNeedsBeginFrames(needs_begin_frames
);
389 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
390 scoped_ptr
<AnimationEventsVector
> events
) {
392 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
393 DCHECK(IsImplThread());
394 Proxy::MainThreadTaskRunner()->PostTask(
396 base::Bind(&ThreadProxy::SetAnimationEvents
,
397 main_thread_weak_ptr_
,
398 base::Passed(&events
)));
401 bool ThreadProxy::IsInsideDraw() { return impl().inside_draw
; }
403 void ThreadProxy::SetNeedsRedraw(const gfx::Rect
& damage_rect
) {
404 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw");
405 DCHECK(IsMainThread());
406 Proxy::ImplThreadTaskRunner()->PostTask(
408 base::Bind(&ThreadProxy::SetNeedsRedrawRectOnImplThread
,
409 impl_thread_weak_ptr_
,
413 void ThreadProxy::SetNextCommitWaitsForActivation() {
414 DCHECK(IsMainThread());
415 DCHECK(!blocked_main().main_thread_inside_commit
);
416 blocked_main().commit_waits_for_activation
= true;
419 void ThreadProxy::SetDeferCommits(bool defer_commits
) {
420 DCHECK(IsMainThread());
421 if (main().defer_commits
== defer_commits
)
424 main().defer_commits
= defer_commits
;
425 if (main().defer_commits
)
426 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this);
428 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this);
430 Proxy::ImplThreadTaskRunner()->PostTask(
432 base::Bind(&ThreadProxy::SetDeferCommitsOnImplThread
,
433 impl_thread_weak_ptr_
,
437 void ThreadProxy::SetDeferCommitsOnImplThread(bool defer_commits
) const {
438 DCHECK(IsImplThread());
439 impl().scheduler
->SetDeferCommits(defer_commits
);
442 bool ThreadProxy::CommitRequested() const {
443 DCHECK(IsMainThread());
444 return main().commit_requested
;
447 bool ThreadProxy::BeginMainFrameRequested() const {
448 DCHECK(IsMainThread());
449 return main().commit_request_sent_to_impl_thread
;
452 void ThreadProxy::SetNeedsRedrawOnImplThread() {
453 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedrawOnImplThread");
454 DCHECK(IsImplThread());
455 impl().scheduler
->SetNeedsRedraw();
458 void ThreadProxy::SetNeedsAnimateOnImplThread() {
459 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimateOnImplThread");
460 DCHECK(IsImplThread());
461 impl().scheduler
->SetNeedsAnimate();
464 void ThreadProxy::SetNeedsPrepareTilesOnImplThread() {
465 DCHECK(IsImplThread());
466 impl().scheduler
->SetNeedsPrepareTiles();
469 void ThreadProxy::SetNeedsRedrawRectOnImplThread(const gfx::Rect
& damage_rect
) {
470 DCHECK(IsImplThread());
471 impl().layer_tree_host_impl
->SetViewportDamage(damage_rect
);
472 SetNeedsRedrawOnImplThread();
475 void ThreadProxy::MainThreadHasStoppedFlinging() {
476 DCHECK(IsMainThread());
477 Proxy::ImplThreadTaskRunner()->PostTask(
479 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread
,
480 impl_thread_weak_ptr_
));
483 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() {
484 DCHECK(IsImplThread());
485 impl().layer_tree_host_impl
->MainThreadHasStoppedFlinging();
488 void ThreadProxy::NotifyInputThrottledUntilCommit() {
489 DCHECK(IsMainThread());
490 Proxy::ImplThreadTaskRunner()->PostTask(
492 base::Bind(&ThreadProxy::SetInputThrottledUntilCommitOnImplThread
,
493 impl_thread_weak_ptr_
,
497 void ThreadProxy::SetInputThrottledUntilCommitOnImplThread(bool is_throttled
) {
498 DCHECK(IsImplThread());
499 if (is_throttled
== impl().input_throttled_until_commit
)
501 impl().input_throttled_until_commit
= is_throttled
;
505 LayerTreeHost
* ThreadProxy::layer_tree_host() {
506 return blocked_main().layer_tree_host
;
509 const LayerTreeHost
* ThreadProxy::layer_tree_host() const {
510 return blocked_main().layer_tree_host
;
513 ThreadProxy::MainThreadOnly
& ThreadProxy::main() {
514 DCHECK(IsMainThread());
515 return main_thread_only_vars_unsafe_
;
517 const ThreadProxy::MainThreadOnly
& ThreadProxy::main() const {
518 DCHECK(IsMainThread());
519 return main_thread_only_vars_unsafe_
;
522 ThreadProxy::MainThreadOrBlockedMainThread
& ThreadProxy::blocked_main() {
523 DCHECK(IsMainThread() || IsMainThreadBlocked());
524 return main_thread_or_blocked_vars_unsafe_
;
527 const ThreadProxy::MainThreadOrBlockedMainThread
& ThreadProxy::blocked_main()
529 DCHECK(IsMainThread() || IsMainThreadBlocked());
530 return main_thread_or_blocked_vars_unsafe_
;
533 ThreadProxy::CompositorThreadOnly
& ThreadProxy::impl() {
534 DCHECK(IsImplThread());
535 return compositor_thread_vars_unsafe_
;
538 const ThreadProxy::CompositorThreadOnly
& ThreadProxy::impl() const {
539 DCHECK(IsImplThread());
540 return compositor_thread_vars_unsafe_
;
543 void ThreadProxy::Start() {
544 DCHECK(IsMainThread());
545 DCHECK(Proxy::HasImplThread());
547 // Create LayerTreeHostImpl.
548 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
549 CompletionEvent completion
;
550 Proxy::ImplThreadTaskRunner()->PostTask(
552 base::Bind(&ThreadProxy::InitializeImplOnImplThread
,
553 base::Unretained(this),
557 main_thread_weak_ptr_
= main().weak_factory
.GetWeakPtr();
559 main().started
= true;
562 void ThreadProxy::Stop() {
563 TRACE_EVENT0("cc", "ThreadProxy::Stop");
564 DCHECK(IsMainThread());
565 DCHECK(main().started
);
567 // Synchronously finishes pending GL operations and deletes the impl.
568 // The two steps are done as separate post tasks, so that tasks posted
569 // by the GL implementation due to the Finish can be executed by the
570 // renderer before shutting it down.
572 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
574 CompletionEvent completion
;
575 Proxy::ImplThreadTaskRunner()->PostTask(
577 base::Bind(&ThreadProxy::FinishGLOnImplThread
,
578 impl_thread_weak_ptr_
,
583 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
585 CompletionEvent completion
;
586 Proxy::ImplThreadTaskRunner()->PostTask(
588 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread
,
589 impl_thread_weak_ptr_
,
594 main().weak_factory
.InvalidateWeakPtrs();
595 blocked_main().layer_tree_host
= NULL
;
596 main().started
= false;
599 void ThreadProxy::ForceSerializeOnSwapBuffers() {
600 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
601 CompletionEvent completion
;
602 Proxy::ImplThreadTaskRunner()->PostTask(
604 base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread
,
605 impl_thread_weak_ptr_
,
610 void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread(
611 CompletionEvent
* completion
) {
612 if (impl().layer_tree_host_impl
->renderer())
613 impl().layer_tree_host_impl
->renderer()->DoNoOp();
614 completion
->Signal();
617 bool ThreadProxy::SupportsImplScrolling() const {
621 void ThreadProxy::SetDebugState(const LayerTreeDebugState
& debug_state
) {
622 Proxy::ImplThreadTaskRunner()->PostTask(
624 base::Bind(&ThreadProxy::SetDebugStateOnImplThread
,
625 impl_thread_weak_ptr_
,
629 void ThreadProxy::SetDebugStateOnImplThread(
630 const LayerTreeDebugState
& debug_state
) {
631 DCHECK(IsImplThread());
632 impl().scheduler
->SetContinuousPainting(debug_state
.continuous_painting
);
635 void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent
* completion
) {
636 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
637 DCHECK(IsImplThread());
638 impl().layer_tree_host_impl
->FinishAllRendering();
639 completion
->Signal();
642 void ThreadProxy::ScheduledActionSendBeginMainFrame() {
643 unsigned int begin_frame_id
= nextBeginFrameId
++;
644 benchmark_instrumentation::ScopedBeginFrameTask
begin_frame_task(
645 benchmark_instrumentation::kSendBeginFrame
, begin_frame_id
);
646 scoped_ptr
<BeginMainFrameAndCommitState
> begin_main_frame_state(
647 new BeginMainFrameAndCommitState
);
648 begin_main_frame_state
->begin_frame_id
= begin_frame_id
;
649 begin_main_frame_state
->begin_frame_args
=
650 impl().layer_tree_host_impl
->CurrentBeginFrameArgs();
651 begin_main_frame_state
->scroll_info
=
652 impl().layer_tree_host_impl
->ProcessScrollDeltas();
653 begin_main_frame_state
->memory_allocation_limit_bytes
=
654 impl().layer_tree_host_impl
->memory_allocation_limit_bytes();
655 begin_main_frame_state
->evicted_ui_resources
=
656 impl().layer_tree_host_impl
->EvictedUIResourcesExist();
657 // TODO(vmpstr): This needs to be fixed if
658 // main_frame_before_activation_enabled is set, since we might run this code
659 // twice before recording a duration. crbug.com/469824
660 impl().last_begin_main_frame_args
= begin_main_frame_state
->begin_frame_args
;
661 Proxy::MainThreadTaskRunner()->PostTask(
663 base::Bind(&ThreadProxy::BeginMainFrame
,
664 main_thread_weak_ptr_
,
665 base::Passed(&begin_main_frame_state
)));
666 devtools_instrumentation::DidRequestMainThreadFrame(
667 impl().layer_tree_host_id
);
670 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() {
671 Proxy::MainThreadTaskRunner()->PostTask(
672 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameNotExpectedSoon
,
673 main_thread_weak_ptr_
));
676 void ThreadProxy::BeginMainFrame(
677 scoped_ptr
<BeginMainFrameAndCommitState
> begin_main_frame_state
) {
678 benchmark_instrumentation::ScopedBeginFrameTask
begin_frame_task(
679 benchmark_instrumentation::kDoBeginFrame
,
680 begin_main_frame_state
->begin_frame_id
);
681 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame");
682 DCHECK(IsMainThread());
684 if (main().defer_commits
) {
685 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
686 TRACE_EVENT_SCOPE_THREAD
);
687 Proxy::ImplThreadTaskRunner()->PostTask(
688 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
689 impl_thread_weak_ptr_
,
690 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT
));
694 // If the commit finishes, LayerTreeHost will transfer its swap promises to
695 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the
696 // remaining swap promises.
697 ScopedAbortRemainingSwapPromises
swap_promise_checker(layer_tree_host());
699 main().commit_requested
= false;
700 main().commit_request_sent_to_impl_thread
= false;
701 main().animate_requested
= false;
703 if (!layer_tree_host()->visible()) {
704 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD
);
705 Proxy::ImplThreadTaskRunner()->PostTask(
706 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
707 impl_thread_weak_ptr_
,
708 CommitEarlyOutReason::ABORTED_NOT_VISIBLE
));
712 if (layer_tree_host()->output_surface_lost()) {
713 TRACE_EVENT_INSTANT0(
714 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD
);
715 Proxy::ImplThreadTaskRunner()->PostTask(
717 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
718 impl_thread_weak_ptr_
,
719 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST
));
723 // Do not notify the impl thread of commit requests that occur during
724 // the apply/animate/layout part of the BeginMainFrameAndCommit process since
725 // those commit requests will get painted immediately. Once we have done
726 // the paint, main().commit_requested will be set to false to allow new commit
727 // requests to be scheduled.
728 // On the other hand, the animate_requested flag should remain cleared
729 // here so that any animation requests generated by the apply or animate
730 // callbacks will trigger another frame.
731 main().commit_requested
= true;
732 main().commit_request_sent_to_impl_thread
= true;
734 layer_tree_host()->ApplyScrollAndScale(
735 begin_main_frame_state
->scroll_info
.get());
737 layer_tree_host()->WillBeginMainFrame();
739 layer_tree_host()->BeginMainFrame(begin_main_frame_state
->begin_frame_args
);
740 layer_tree_host()->AnimateLayers(
741 begin_main_frame_state
->begin_frame_args
.frame_time
);
743 // Recreate all UI resources if there were evicted UI resources when the impl
744 // thread initiated the commit.
745 if (begin_main_frame_state
->evicted_ui_resources
)
746 layer_tree_host()->RecreateUIResources();
748 layer_tree_host()->Layout();
749 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame");
751 // Clear the commit flag after updating animations and layout here --- objects
752 // that only layout when painted will trigger another SetNeedsCommit inside
754 main().commit_requested
= false;
755 main().commit_request_sent_to_impl_thread
= false;
756 bool can_cancel_this_commit
=
757 main().can_cancel_commit
&& !begin_main_frame_state
->evicted_ui_resources
;
758 main().can_cancel_commit
= true;
760 bool updated
= layer_tree_host()->UpdateLayers();
762 layer_tree_host()->WillCommit();
763 devtools_instrumentation::ScopedCommitTrace
commit_task(
764 layer_tree_host()->id());
766 // Before calling animate, we set main().animate_requested to false. If it is
767 // true now, it means SetNeedAnimate was called again, but during a state when
768 // main().commit_request_sent_to_impl_thread = true. We need to force that
769 // call to happen again now so that the commit request is sent to the impl
771 if (main().animate_requested
) {
772 // Forces SetNeedsAnimate to consider posting a commit task.
773 main().animate_requested
= false;
777 if (!updated
&& can_cancel_this_commit
) {
778 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD
);
779 Proxy::ImplThreadTaskRunner()->PostTask(
780 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
781 impl_thread_weak_ptr_
,
782 CommitEarlyOutReason::FINISHED_NO_UPDATES
));
784 // Although the commit is internally aborted, this is because it has been
785 // detected to be a no-op. From the perspective of an embedder, this commit
786 // went through, and input should no longer be throttled, etc.
787 layer_tree_host()->CommitComplete();
788 layer_tree_host()->DidBeginMainFrame();
789 layer_tree_host()->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE
);
793 // Notify the impl thread that the main thread is ready to commit. This will
794 // begin the commit process, which is blocking from the main thread's
795 // point of view, but asynchronously performed on the impl thread,
796 // coordinated by the Scheduler.
798 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit");
800 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
802 // This CapturePostTasks should be destroyed before CommitComplete() is
803 // called since that goes out to the embedder, and we want the embedder
804 // to receive its callbacks before that.
805 BlockingTaskRunner::CapturePostTasks
blocked(
806 blocking_main_thread_task_runner());
808 CompletionEvent completion
;
809 Proxy::ImplThreadTaskRunner()->PostTask(
810 FROM_HERE
, base::Bind(&ThreadProxy::StartCommitOnImplThread
,
811 impl_thread_weak_ptr_
, &completion
));
815 layer_tree_host()->CommitComplete();
816 layer_tree_host()->DidBeginMainFrame();
819 void ThreadProxy::BeginMainFrameNotExpectedSoon() {
820 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon");
821 DCHECK(IsMainThread());
822 layer_tree_host()->BeginMainFrameNotExpectedSoon();
825 void ThreadProxy::StartCommitOnImplThread(CompletionEvent
* completion
) {
826 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
827 DCHECK(!impl().commit_completion_event
);
828 DCHECK(IsImplThread() && IsMainThreadBlocked());
829 DCHECK(impl().scheduler
);
830 DCHECK(impl().scheduler
->CommitPending());
832 if (!impl().layer_tree_host_impl
) {
833 TRACE_EVENT_INSTANT0(
834 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD
);
835 completion
->Signal();
839 // Ideally, we should inform to impl thread when BeginMainFrame is started.
840 // But, we can avoid a PostTask in here.
841 impl().scheduler
->NotifyBeginMainFrameStarted();
842 impl().commit_completion_event
= completion
;
843 impl().scheduler
->NotifyReadyToCommit();
846 void ThreadProxy::BeginMainFrameAbortedOnImplThread(
847 CommitEarlyOutReason reason
) {
848 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason",
849 CommitEarlyOutReasonToString(reason
));
850 DCHECK(IsImplThread());
851 DCHECK(impl().scheduler
);
852 DCHECK(impl().scheduler
->CommitPending());
853 DCHECK(!impl().layer_tree_host_impl
->pending_tree());
855 if (CommitEarlyOutHandledCommit(reason
)) {
856 SetInputThrottledUntilCommitOnImplThread(false);
857 impl().last_processed_begin_main_frame_args
=
858 impl().last_begin_main_frame_args
;
860 impl().layer_tree_host_impl
->BeginMainFrameAborted(reason
);
861 impl().scheduler
->BeginMainFrameAborted(reason
);
864 void ThreadProxy::ScheduledActionAnimate() {
865 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate");
866 DCHECK(IsImplThread());
868 // Don't animate if there is no root layer.
869 // TODO(mithro): Both Animate and UpdateAnimationState already have a
870 // "!active_tree_->root_layer()" check?
871 if (!impl().layer_tree_host_impl
->active_tree()->root_layer()) {
875 impl().animation_time
=
876 impl().layer_tree_host_impl
->CurrentBeginFrameArgs().frame_time
;
877 impl().layer_tree_host_impl
->Animate(impl().animation_time
);
879 // If animations are not visible, update the state now as
880 // ScheduledActionDrawAndSwapIfPossible will never be called.
881 if (!impl().layer_tree_host_impl
->AnimationsAreVisible()) {
882 impl().layer_tree_host_impl
->UpdateAnimationState(true);
886 void ThreadProxy::ScheduledActionCommit() {
887 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit");
888 DCHECK(IsImplThread());
889 DCHECK(IsMainThreadBlocked());
890 DCHECK(impl().commit_completion_event
);
892 blocked_main().main_thread_inside_commit
= true;
893 impl().layer_tree_host_impl
->BeginCommit();
894 layer_tree_host()->BeginCommitOnImplThread(impl().layer_tree_host_impl
.get());
895 layer_tree_host()->FinishCommitOnImplThread(
896 impl().layer_tree_host_impl
.get());
897 blocked_main().main_thread_inside_commit
= false;
899 bool hold_commit
= blocked_main().commit_waits_for_activation
;
900 blocked_main().commit_waits_for_activation
= false;
903 // For some layer types in impl-side painting, the commit is held until
904 // the sync tree is activated. It's also possible that the
905 // sync tree has already activated if there was no work to be done.
906 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD
);
907 impl().completion_event_for_commit_held_on_tree_activation
=
908 impl().commit_completion_event
;
909 impl().commit_completion_event
= NULL
;
911 impl().commit_completion_event
->Signal();
912 impl().commit_completion_event
= NULL
;
915 impl().scheduler
->DidCommit();
917 // Delay this step until afer the main thread has been released as it's
918 // often a good bit of work to update the tree and prepare the new frame.
919 impl().layer_tree_host_impl
->CommitComplete();
921 SetInputThrottledUntilCommitOnImplThread(false);
923 impl().next_frame_is_newly_committed_frame
= true;
926 void ThreadProxy::ScheduledActionActivateSyncTree() {
927 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree");
928 DCHECK(IsImplThread());
929 impl().layer_tree_host_impl
->ActivateSyncTree();
932 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
933 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation");
934 DCHECK(IsImplThread());
935 Proxy::MainThreadTaskRunner()->PostTask(
937 base::Bind(&ThreadProxy::RequestNewOutputSurface
, main_thread_weak_ptr_
));
940 DrawResult
ThreadProxy::DrawSwapInternal(bool forced_draw
) {
941 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap");
944 DCHECK(IsImplThread());
945 DCHECK(impl().layer_tree_host_impl
.get());
947 base::AutoReset
<bool> mark_inside(&impl().inside_draw
, true);
949 if (impl().layer_tree_host_impl
->pending_tree()) {
950 bool update_lcd_text
= false;
951 impl().layer_tree_host_impl
->pending_tree()->UpdateDrawProperties(
955 // This method is called on a forced draw, regardless of whether we are able
956 // to produce a frame, as the calling site on main thread is blocked until its
957 // request completes, and we signal completion here. If CanDraw() is false, we
958 // will indicate success=false to the caller, but we must still signal
959 // completion to avoid deadlock.
961 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
962 // frame, so can only be used when such a frame is possible. Since
963 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
964 // CanDraw() as well.
966 LayerTreeHostImpl::FrameData frame
;
967 bool draw_frame
= false;
969 if (impl().layer_tree_host_impl
->CanDraw()) {
970 result
= impl().layer_tree_host_impl
->PrepareToDraw(&frame
);
971 draw_frame
= forced_draw
|| result
== DRAW_SUCCESS
;
973 result
= DRAW_ABORTED_CANT_DRAW
;
977 impl().layer_tree_host_impl
->DrawLayers(&frame
);
978 result
= DRAW_SUCCESS
;
980 DCHECK_NE(DRAW_SUCCESS
, result
);
982 impl().layer_tree_host_impl
->DidDrawAllLayers(frame
);
984 bool start_ready_animations
= draw_frame
;
985 impl().layer_tree_host_impl
->UpdateAnimationState(start_ready_animations
);
988 impl().layer_tree_host_impl
->SwapBuffers(frame
);
990 // Tell the main thread that the the newly-commited frame was drawn.
991 if (impl().next_frame_is_newly_committed_frame
) {
992 impl().next_frame_is_newly_committed_frame
= false;
993 Proxy::MainThreadTaskRunner()->PostTask(
995 base::Bind(&ThreadProxy::DidCommitAndDrawFrame
, main_thread_weak_ptr_
));
998 DCHECK_NE(INVALID_RESULT
, result
);
1002 void ThreadProxy::ScheduledActionPrepareTiles() {
1003 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles");
1004 impl().layer_tree_host_impl
->PrepareTiles();
1007 DrawResult
ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
1008 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
1010 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to
1011 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should
1012 // never generate this call when it can't draw.
1013 DCHECK(impl().layer_tree_host_impl
->CanDraw());
1015 bool forced_draw
= false;
1016 return DrawSwapInternal(forced_draw
);
1019 DrawResult
ThreadProxy::ScheduledActionDrawAndSwapForced() {
1020 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced");
1021 bool forced_draw
= true;
1022 return DrawSwapInternal(forced_draw
);
1025 void ThreadProxy::ScheduledActionInvalidateOutputSurface() {
1026 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface");
1027 DCHECK(impl().layer_tree_host_impl
->output_surface());
1028 impl().layer_tree_host_impl
->output_surface()->Invalidate();
1031 void ThreadProxy::DidFinishImplFrame() {
1032 impl().layer_tree_host_impl
->DidFinishImplFrame();
1035 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs
& args
) {
1036 NOTREACHED() << "Only used by SingleThreadProxy";
1039 void ThreadProxy::SetAuthoritativeVSyncInterval(
1040 const base::TimeDelta
& interval
) {
1041 NOTREACHED() << "Only used by SingleThreadProxy";
1044 void ThreadProxy::DidCommitAndDrawFrame() {
1045 DCHECK(IsMainThread());
1046 layer_tree_host()->DidCommitAndDrawFrame();
1049 void ThreadProxy::DidCompleteSwapBuffers() {
1050 DCHECK(IsMainThread());
1051 layer_tree_host()->DidCompleteSwapBuffers();
1054 void ThreadProxy::SetAnimationEvents(scoped_ptr
<AnimationEventsVector
> events
) {
1055 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents");
1056 DCHECK(IsMainThread());
1057 layer_tree_host()->SetAnimationEvents(events
.Pass());
1060 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent
* completion
) {
1061 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1062 DCHECK(IsImplThread());
1063 impl().layer_tree_host_impl
=
1064 layer_tree_host()->CreateLayerTreeHostImpl(this);
1066 SchedulerSettings
scheduler_settings(
1067 layer_tree_host()->settings().ToSchedulerSettings());
1069 scoped_ptr
<CompositorTimingHistory
> compositor_timing_history(
1070 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA
,
1071 impl().rendering_stats_instrumentation
));
1073 impl().scheduler
= Scheduler::Create(
1074 this, scheduler_settings
, impl().layer_tree_host_id
,
1075 ImplThreadTaskRunner(), impl().external_begin_frame_source
.get(),
1076 compositor_timing_history
.Pass());
1078 impl().scheduler
->SetVisible(impl().layer_tree_host_impl
->visible());
1079 impl_thread_weak_ptr_
= impl().weak_factory
.GetWeakPtr();
1080 completion
->Signal();
1083 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1084 scoped_ptr
<OutputSurface
> output_surface
) {
1085 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread");
1086 DCHECK(IsImplThread());
1088 LayerTreeHostImpl
* host_impl
= impl().layer_tree_host_impl
.get();
1089 bool success
= host_impl
->InitializeRenderer(output_surface
.Pass());
1090 RendererCapabilities capabilities
;
1093 host_impl
->GetRendererCapabilities().MainThreadCapabilities();
1096 Proxy::MainThreadTaskRunner()->PostTask(
1098 base::Bind(&ThreadProxy::DidInitializeOutputSurface
,
1099 main_thread_weak_ptr_
,
1104 impl().scheduler
->DidCreateAndInitializeOutputSurface();
1107 void ThreadProxy::FinishGLOnImplThread(CompletionEvent
* completion
) {
1108 TRACE_EVENT0("cc", "ThreadProxy::FinishGLOnImplThread");
1109 DCHECK(IsImplThread());
1110 if (impl().layer_tree_host_impl
->output_surface()) {
1111 ContextProvider
* context_provider
=
1112 impl().layer_tree_host_impl
->output_surface()->context_provider();
1113 if (context_provider
)
1114 context_provider
->ContextGL()->Finish();
1116 completion
->Signal();
1119 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent
* completion
) {
1120 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1121 DCHECK(IsImplThread());
1122 DCHECK(IsMainThreadBlocked());
1123 impl().scheduler
= nullptr;
1124 impl().external_begin_frame_source
= nullptr;
1125 impl().layer_tree_host_impl
= nullptr;
1126 impl().weak_factory
.InvalidateWeakPtrs();
1127 // We need to explicitly shutdown the notifier to destroy any weakptrs it is
1128 // holding while still on the compositor thread. This also ensures any
1129 // callbacks holding a ThreadProxy pointer are cancelled.
1130 impl().smoothness_priority_expiration_notifier
.Shutdown();
1131 completion
->Signal();
1134 ThreadProxy::BeginMainFrameAndCommitState::BeginMainFrameAndCommitState()
1135 : memory_allocation_limit_bytes(0),
1136 evicted_ui_resources(false) {}
1138 ThreadProxy::BeginMainFrameAndCommitState::~BeginMainFrameAndCommitState() {}
1140 bool ThreadProxy::MainFrameWillHappenForTesting() {
1141 DCHECK(IsMainThread());
1142 CompletionEvent completion
;
1143 bool main_frame_will_happen
= false;
1145 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
1146 Proxy::ImplThreadTaskRunner()->PostTask(
1148 base::Bind(&ThreadProxy::MainFrameWillHappenOnImplThreadForTesting
,
1149 impl_thread_weak_ptr_
,
1151 &main_frame_will_happen
));
1154 return main_frame_will_happen
;
1157 void ThreadProxy::SetChildrenNeedBeginFrames(bool children_need_begin_frames
) {
1158 NOTREACHED() << "Only used by SingleThreadProxy";
1161 void ThreadProxy::MainFrameWillHappenOnImplThreadForTesting(
1162 CompletionEvent
* completion
,
1163 bool* main_frame_will_happen
) {
1164 DCHECK(IsImplThread());
1165 if (impl().layer_tree_host_impl
->output_surface()) {
1166 *main_frame_will_happen
= impl().scheduler
->MainFrameForTestingWillHappen();
1168 *main_frame_will_happen
= false;
1170 completion
->Signal();
1173 void ThreadProxy::RenewTreePriority() {
1174 DCHECK(IsImplThread());
1175 bool smoothness_takes_priority
=
1176 impl().layer_tree_host_impl
->pinch_gesture_active() ||
1177 impl().layer_tree_host_impl
->page_scale_animation_active() ||
1178 impl().layer_tree_host_impl
->IsActivelyScrolling();
1180 // Schedule expiration if smoothness currently takes priority.
1181 if (smoothness_takes_priority
)
1182 impl().smoothness_priority_expiration_notifier
.Schedule();
1184 // We use the same priority for both trees by default.
1185 TreePriority priority
= SAME_PRIORITY_FOR_BOTH_TREES
;
1187 // Smoothness takes priority if we have an expiration for it scheduled.
1188 if (impl().smoothness_priority_expiration_notifier
.HasPendingNotification())
1189 priority
= SMOOTHNESS_TAKES_PRIORITY
;
1191 // New content always takes priority when there is an invalid viewport size or
1192 // ui resources have been evicted.
1193 if (impl().layer_tree_host_impl
->active_tree()->ViewportSizeInvalid() ||
1194 impl().layer_tree_host_impl
->EvictedUIResourcesExist() ||
1195 impl().input_throttled_until_commit
) {
1196 // Once we enter NEW_CONTENTS_TAKES_PRIORITY mode, visible tiles on active
1197 // tree might be freed. We need to set RequiresHighResToDraw to ensure that
1198 // high res tiles will be required to activate pending tree.
1199 impl().layer_tree_host_impl
->SetRequiresHighResToDraw();
1200 priority
= NEW_CONTENT_TAKES_PRIORITY
;
1203 impl().layer_tree_host_impl
->SetTreePriority(priority
);
1205 // Only put the scheduler in impl latency prioritization mode if we don't
1206 // have a scroll listener. This gives the scroll listener a better chance of
1207 // handling scroll updates within the same frame. The tree itself is still
1208 // kept in prefer smoothness mode to allow checkerboarding.
1209 impl().scheduler
->SetImplLatencyTakesPriority(
1210 priority
== SMOOTHNESS_TAKES_PRIORITY
&&
1211 !impl().layer_tree_host_impl
->scroll_affects_scroll_handler());
1213 // Notify the the client of this compositor via the output surface.
1214 // TODO(epenner): Route this to compositor-thread instead of output-surface
1215 // after GTFO refactor of compositor-thread (http://crbug/170828).
1216 if (impl().layer_tree_host_impl
->output_surface()) {
1218 .layer_tree_host_impl
->output_surface()
1219 ->UpdateSmoothnessTakesPriority(priority
== SMOOTHNESS_TAKES_PRIORITY
);
1223 void ThreadProxy::PostDelayedAnimationTaskOnImplThread(
1224 const base::Closure
& task
,
1225 base::TimeDelta delay
) {
1226 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE
, task
, delay
);
1229 void ThreadProxy::DidActivateSyncTree() {
1230 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread");
1231 DCHECK(IsImplThread());
1233 if (impl().completion_event_for_commit_held_on_tree_activation
) {
1234 TRACE_EVENT_INSTANT0(
1235 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD
);
1236 impl().completion_event_for_commit_held_on_tree_activation
->Signal();
1237 impl().completion_event_for_commit_held_on_tree_activation
= NULL
;
1240 impl().last_processed_begin_main_frame_args
=
1241 impl().last_begin_main_frame_args
;
1244 void ThreadProxy::WillPrepareTiles() {
1245 DCHECK(IsImplThread());
1246 impl().scheduler
->WillPrepareTiles();
1249 void ThreadProxy::DidPrepareTiles() {
1250 DCHECK(IsImplThread());
1251 impl().scheduler
->DidPrepareTiles();
1254 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
1255 DCHECK(IsImplThread());
1256 Proxy::MainThreadTaskRunner()->PostTask(
1257 FROM_HERE
, base::Bind(&ThreadProxy::DidCompletePageScaleAnimation
,
1258 main_thread_weak_ptr_
));
1261 void ThreadProxy::OnDrawForOutputSurface() {
1262 DCHECK(IsImplThread());
1263 impl().scheduler
->OnDrawForOutputSurface();
1266 void ThreadProxy::PostFrameTimingEventsOnImplThread(
1267 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
1268 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
) {
1269 DCHECK(IsImplThread());
1270 Proxy::MainThreadTaskRunner()->PostTask(
1272 base::Bind(&ThreadProxy::PostFrameTimingEvents
, main_thread_weak_ptr_
,
1273 base::Passed(composite_events
.Pass()),
1274 base::Passed(main_frame_events
.Pass())));
1277 void ThreadProxy::PostFrameTimingEvents(
1278 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
1279 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
) {
1280 DCHECK(IsMainThread());
1281 layer_tree_host()->RecordFrameTimingEvents(composite_events
.Pass(),
1282 main_frame_events
.Pass());