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 max_requested_pipeline_stage(NO_PIPELINE_STAGE
),
80 current_pipeline_stage(NO_PIPELINE_STAGE
),
81 final_pipeline_stage(NO_PIPELINE_STAGE
),
83 prepare_tiles_pending(false),
85 weak_factory(proxy
) {}
87 ThreadProxy::MainThreadOnly::~MainThreadOnly() {}
89 ThreadProxy::MainThreadOrBlockedMainThread::MainThreadOrBlockedMainThread(
91 : layer_tree_host(host
),
92 commit_waits_for_activation(false),
93 main_thread_inside_commit(false) {}
95 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {}
97 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(
99 int layer_tree_host_id
,
100 RenderingStatsInstrumentation
* rendering_stats_instrumentation
,
101 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
)
102 : layer_tree_host_id(layer_tree_host_id
),
103 commit_completion_event(NULL
),
104 completion_event_for_commit_held_on_tree_activation(NULL
),
105 next_frame_is_newly_committed_frame(false),
107 input_throttled_until_commit(false),
108 smoothness_priority_expiration_notifier(
109 proxy
->ImplThreadTaskRunner(),
110 base::Bind(&ThreadProxy::RenewTreePriority
, base::Unretained(proxy
)),
111 base::TimeDelta::FromMilliseconds(
112 kSmoothnessTakesPriorityExpirationDelay
* 1000)),
113 external_begin_frame_source(external_begin_frame_source
.Pass()),
114 rendering_stats_instrumentation(rendering_stats_instrumentation
),
115 weak_factory(proxy
) {
118 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {}
120 ThreadProxy::~ThreadProxy() {
121 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
122 DCHECK(IsMainThread());
123 DCHECK(!main().started
);
126 void ThreadProxy::FinishAllRendering() {
127 DCHECK(Proxy::IsMainThread());
128 DCHECK(!main().defer_commits
);
130 // Make sure all GL drawing is finished on the impl thread.
131 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
132 CompletionEvent completion
;
133 Proxy::ImplThreadTaskRunner()->PostTask(
135 base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread
,
136 impl_thread_weak_ptr_
,
141 bool ThreadProxy::IsStarted() const {
142 DCHECK(Proxy::IsMainThread());
143 return main().started
;
146 bool ThreadProxy::CommitToActiveTree() const {
147 // With ThreadProxy, we use a pending tree and activate it once it's ready to
148 // draw to allow input to modify the active tree and draw during raster.
152 void ThreadProxy::SetLayerTreeHostClientReady() {
153 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady");
154 Proxy::ImplThreadTaskRunner()->PostTask(
156 base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread
,
157 impl_thread_weak_ptr_
));
160 void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() {
161 TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReadyOnImplThread");
162 impl().scheduler
->SetCanStart();
165 void ThreadProxy::SetVisible(bool visible
) {
166 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible
);
167 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
169 CompletionEvent completion
;
170 Proxy::ImplThreadTaskRunner()->PostTask(
172 base::Bind(&ThreadProxy::SetVisibleOnImplThread
,
173 impl_thread_weak_ptr_
,
179 void ThreadProxy::SetVisibleOnImplThread(CompletionEvent
* completion
,
181 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible
);
182 impl().layer_tree_host_impl
->SetVisible(visible
);
183 impl().scheduler
->SetVisible(visible
);
184 completion
->Signal();
187 void ThreadProxy::SetThrottleFrameProduction(bool throttle
) {
188 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle",
190 Proxy::ImplThreadTaskRunner()->PostTask(
192 base::Bind(&ThreadProxy::SetThrottleFrameProductionOnImplThread
,
193 impl_thread_weak_ptr_
, throttle
));
196 void ThreadProxy::SetThrottleFrameProductionOnImplThread(bool throttle
) {
197 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread",
198 "throttle", throttle
);
199 impl().scheduler
->SetThrottleFrameProduction(throttle
);
202 void ThreadProxy::DidLoseOutputSurface() {
203 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface");
204 DCHECK(IsMainThread());
205 layer_tree_host()->DidLoseOutputSurface();
208 void ThreadProxy::RequestNewOutputSurface() {
209 DCHECK(IsMainThread());
210 layer_tree_host()->RequestNewOutputSurface();
213 void ThreadProxy::SetOutputSurface(scoped_ptr
<OutputSurface
> output_surface
) {
214 Proxy::ImplThreadTaskRunner()->PostTask(
216 base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread
,
217 impl_thread_weak_ptr_
, base::Passed(&output_surface
)));
220 scoped_ptr
<OutputSurface
> ThreadProxy::ReleaseOutputSurface() {
221 DCHECK(IsMainThread());
222 DCHECK(layer_tree_host()->output_surface_lost());
224 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
225 CompletionEvent completion
;
226 scoped_ptr
<OutputSurface
> output_surface
;
227 Proxy::ImplThreadTaskRunner()->PostTask(
229 base::Bind(&ThreadProxy::ReleaseOutputSurfaceOnImplThread
,
230 impl_thread_weak_ptr_
, &completion
, &output_surface
));
232 return output_surface
;
235 void ThreadProxy::DidInitializeOutputSurface(
237 const RendererCapabilities
& capabilities
) {
238 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeOutputSurface");
239 DCHECK(IsMainThread());
242 layer_tree_host()->DidFailToInitializeOutputSurface();
245 main().renderer_capabilities_main_thread_copy
= capabilities
;
246 layer_tree_host()->DidInitializeOutputSurface();
249 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy(
250 const RendererCapabilities
& capabilities
) {
251 main().renderer_capabilities_main_thread_copy
= capabilities
;
254 bool ThreadProxy::SendCommitRequestToImplThreadIfNeeded(
255 CommitPipelineStage required_stage
) {
256 DCHECK(IsMainThread());
257 DCHECK_NE(NO_PIPELINE_STAGE
, required_stage
);
258 bool already_posted
=
259 main().max_requested_pipeline_stage
!= NO_PIPELINE_STAGE
;
260 main().max_requested_pipeline_stage
=
261 std::max(main().max_requested_pipeline_stage
, required_stage
);
264 Proxy::ImplThreadTaskRunner()->PostTask(
266 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread
,
267 impl_thread_weak_ptr_
));
271 void ThreadProxy::DidCompletePageScaleAnimation() {
272 DCHECK(IsMainThread());
273 layer_tree_host()->DidCompletePageScaleAnimation();
276 const RendererCapabilities
& ThreadProxy::GetRendererCapabilities() const {
277 DCHECK(IsMainThread());
278 DCHECK(!layer_tree_host()->output_surface_lost());
279 return main().renderer_capabilities_main_thread_copy
;
282 void ThreadProxy::SetNeedsAnimate() {
283 DCHECK(IsMainThread());
284 if (SendCommitRequestToImplThreadIfNeeded(ANIMATE_PIPELINE_STAGE
)) {
285 TRACE_EVENT_INSTANT0("cc", "ThreadProxy::SetNeedsAnimate",
286 TRACE_EVENT_SCOPE_THREAD
);
290 void ThreadProxy::SetNeedsUpdateLayers() {
291 DCHECK(IsMainThread());
292 // If we are currently animating, make sure we also update the layers.
293 if (main().current_pipeline_stage
== ANIMATE_PIPELINE_STAGE
) {
294 main().final_pipeline_stage
=
295 std::max(main().final_pipeline_stage
, UPDATE_LAYERS_PIPELINE_STAGE
);
298 if (SendCommitRequestToImplThreadIfNeeded(UPDATE_LAYERS_PIPELINE_STAGE
)) {
299 TRACE_EVENT_INSTANT0("cc", "ThreadProxy::SetNeedsUpdateLayers",
300 TRACE_EVENT_SCOPE_THREAD
);
304 void ThreadProxy::SetNeedsCommit() {
305 DCHECK(IsMainThread());
306 // If we are currently animating, make sure we don't skip the commit. Note
307 // that requesting a commit during the layer update stage means we need to
308 // schedule another full commit.
309 if (main().current_pipeline_stage
== ANIMATE_PIPELINE_STAGE
) {
310 main().final_pipeline_stage
=
311 std::max(main().final_pipeline_stage
, COMMIT_PIPELINE_STAGE
);
314 if (SendCommitRequestToImplThreadIfNeeded(COMMIT_PIPELINE_STAGE
)) {
315 TRACE_EVENT_INSTANT0("cc", "ThreadProxy::SetNeedsCommit",
316 TRACE_EVENT_SCOPE_THREAD
);
320 void ThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
321 DCHECK(IsImplThread());
322 Proxy::MainThreadTaskRunner()->PostTask(
324 base::Bind(&ThreadProxy::SetRendererCapabilitiesMainThreadCopy
,
325 main_thread_weak_ptr_
,
327 .layer_tree_host_impl
->GetRendererCapabilities()
328 .MainThreadCapabilities()));
331 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() {
332 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread");
333 DCHECK(IsImplThread());
334 Proxy::MainThreadTaskRunner()->PostTask(
336 base::Bind(&ThreadProxy::DidLoseOutputSurface
, main_thread_weak_ptr_
));
337 impl().scheduler
->DidLoseOutputSurface();
340 void ThreadProxy::CommitVSyncParameters(base::TimeTicks timebase
,
341 base::TimeDelta interval
) {
342 impl().scheduler
->CommitVSyncParameters(timebase
, interval
);
345 void ThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time
) {
346 impl().scheduler
->SetEstimatedParentDrawTime(draw_time
);
349 void ThreadProxy::SetMaxSwapsPendingOnImplThread(int max
) {
350 impl().scheduler
->SetMaxSwapsPending(max
);
353 void ThreadProxy::DidSwapBuffersOnImplThread() {
354 impl().scheduler
->DidSwapBuffers();
357 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() {
358 TRACE_EVENT0("cc,benchmark",
359 "ThreadProxy::DidSwapBuffersCompleteOnImplThread");
360 DCHECK(IsImplThread());
361 impl().scheduler
->DidSwapBuffersComplete();
362 Proxy::MainThreadTaskRunner()->PostTask(
364 base::Bind(&ThreadProxy::DidCompleteSwapBuffers
, main_thread_weak_ptr_
));
367 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs
& args
) {
368 impl().layer_tree_host_impl
->WillBeginImplFrame(args
);
369 if (impl().last_processed_begin_main_frame_args
.IsValid()) {
370 // Last processed begin main frame args records the frame args that we sent
371 // to the main thread for the last frame that we've processed. If that is
372 // set, that means the current frame is one past the frame in which we've
373 // finished the processing.
374 impl().layer_tree_host_impl
->RecordMainFrameTiming(
375 impl().last_processed_begin_main_frame_args
,
376 impl().layer_tree_host_impl
->CurrentBeginFrameArgs());
377 impl().last_processed_begin_main_frame_args
= BeginFrameArgs();
381 void ThreadProxy::OnCanDrawStateChanged(bool can_draw
) {
383 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw
);
384 DCHECK(IsImplThread());
385 impl().scheduler
->SetCanDraw(can_draw
);
388 void ThreadProxy::NotifyReadyToActivate() {
389 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate");
390 impl().scheduler
->NotifyReadyToActivate();
393 void ThreadProxy::NotifyReadyToDraw() {
394 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToDraw");
395 impl().scheduler
->NotifyReadyToDraw();
398 void ThreadProxy::SetNeedsCommitOnImplThread() {
399 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread");
400 DCHECK(IsImplThread());
401 impl().scheduler
->SetNeedsBeginMainFrame();
404 void ThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames
) {
405 TRACE_EVENT1("cc", "ThreadProxy::SetVideoNeedsBeginFrames",
406 "needs_begin_frames", needs_begin_frames
);
407 DCHECK(IsImplThread());
408 // In tests the layer tree is destroyed after the scheduler is.
409 if (impl().scheduler
)
410 impl().scheduler
->SetVideoNeedsBeginFrames(needs_begin_frames
);
413 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
414 scoped_ptr
<AnimationEventsVector
> events
) {
416 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
417 DCHECK(IsImplThread());
418 Proxy::MainThreadTaskRunner()->PostTask(
420 base::Bind(&ThreadProxy::SetAnimationEvents
,
421 main_thread_weak_ptr_
,
422 base::Passed(&events
)));
425 bool ThreadProxy::IsInsideDraw() { return impl().inside_draw
; }
427 void ThreadProxy::SetNeedsRedraw(const gfx::Rect
& damage_rect
) {
428 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw");
429 DCHECK(IsMainThread());
430 Proxy::ImplThreadTaskRunner()->PostTask(
432 base::Bind(&ThreadProxy::SetNeedsRedrawRectOnImplThread
,
433 impl_thread_weak_ptr_
,
437 void ThreadProxy::SetNextCommitWaitsForActivation() {
438 DCHECK(IsMainThread());
439 DCHECK(!blocked_main().main_thread_inside_commit
);
440 blocked_main().commit_waits_for_activation
= true;
443 void ThreadProxy::SetDeferCommits(bool defer_commits
) {
444 DCHECK(IsMainThread());
445 if (main().defer_commits
== defer_commits
)
448 main().defer_commits
= defer_commits
;
449 if (main().defer_commits
)
450 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this);
452 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this);
454 Proxy::ImplThreadTaskRunner()->PostTask(
456 base::Bind(&ThreadProxy::SetDeferCommitsOnImplThread
,
457 impl_thread_weak_ptr_
,
461 void ThreadProxy::SetDeferCommitsOnImplThread(bool defer_commits
) const {
462 DCHECK(IsImplThread());
463 impl().scheduler
->SetDeferCommits(defer_commits
);
466 bool ThreadProxy::CommitRequested() const {
467 DCHECK(IsMainThread());
468 // TODO(skyostil): Split this into something like CommitRequested() and
469 // CommitInProgress().
470 return main().current_pipeline_stage
!= NO_PIPELINE_STAGE
||
471 main().max_requested_pipeline_stage
>= COMMIT_PIPELINE_STAGE
;
474 bool ThreadProxy::BeginMainFrameRequested() const {
475 DCHECK(IsMainThread());
476 return main().max_requested_pipeline_stage
!= NO_PIPELINE_STAGE
;
479 void ThreadProxy::SetNeedsRedrawOnImplThread() {
480 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedrawOnImplThread");
481 DCHECK(IsImplThread());
482 impl().scheduler
->SetNeedsRedraw();
485 void ThreadProxy::SetNeedsAnimateOnImplThread() {
486 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimateOnImplThread");
487 DCHECK(IsImplThread());
488 impl().scheduler
->SetNeedsAnimate();
491 void ThreadProxy::SetNeedsPrepareTilesOnImplThread() {
492 DCHECK(IsImplThread());
493 impl().scheduler
->SetNeedsPrepareTiles();
496 void ThreadProxy::SetNeedsRedrawRectOnImplThread(const gfx::Rect
& damage_rect
) {
497 DCHECK(IsImplThread());
498 impl().layer_tree_host_impl
->SetViewportDamage(damage_rect
);
499 SetNeedsRedrawOnImplThread();
502 void ThreadProxy::MainThreadHasStoppedFlinging() {
503 DCHECK(IsMainThread());
504 Proxy::ImplThreadTaskRunner()->PostTask(
506 base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread
,
507 impl_thread_weak_ptr_
));
510 void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() {
511 DCHECK(IsImplThread());
512 impl().layer_tree_host_impl
->MainThreadHasStoppedFlinging();
515 void ThreadProxy::NotifyInputThrottledUntilCommit() {
516 DCHECK(IsMainThread());
517 Proxy::ImplThreadTaskRunner()->PostTask(
519 base::Bind(&ThreadProxy::SetInputThrottledUntilCommitOnImplThread
,
520 impl_thread_weak_ptr_
,
524 void ThreadProxy::SetInputThrottledUntilCommitOnImplThread(bool is_throttled
) {
525 DCHECK(IsImplThread());
526 if (is_throttled
== impl().input_throttled_until_commit
)
528 impl().input_throttled_until_commit
= is_throttled
;
532 LayerTreeHost
* ThreadProxy::layer_tree_host() {
533 return blocked_main().layer_tree_host
;
536 const LayerTreeHost
* ThreadProxy::layer_tree_host() const {
537 return blocked_main().layer_tree_host
;
540 ThreadProxy::MainThreadOnly
& ThreadProxy::main() {
541 DCHECK(IsMainThread());
542 return main_thread_only_vars_unsafe_
;
544 const ThreadProxy::MainThreadOnly
& ThreadProxy::main() const {
545 DCHECK(IsMainThread());
546 return main_thread_only_vars_unsafe_
;
549 ThreadProxy::MainThreadOrBlockedMainThread
& ThreadProxy::blocked_main() {
550 DCHECK(IsMainThread() || IsMainThreadBlocked());
551 return main_thread_or_blocked_vars_unsafe_
;
554 const ThreadProxy::MainThreadOrBlockedMainThread
& ThreadProxy::blocked_main()
556 DCHECK(IsMainThread() || IsMainThreadBlocked());
557 return main_thread_or_blocked_vars_unsafe_
;
560 ThreadProxy::CompositorThreadOnly
& ThreadProxy::impl() {
561 DCHECK(IsImplThread());
562 return compositor_thread_vars_unsafe_
;
565 const ThreadProxy::CompositorThreadOnly
& ThreadProxy::impl() const {
566 DCHECK(IsImplThread());
567 return compositor_thread_vars_unsafe_
;
570 void ThreadProxy::Start() {
571 DCHECK(IsMainThread());
572 DCHECK(Proxy::HasImplThread());
574 // Create LayerTreeHostImpl.
575 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
576 CompletionEvent completion
;
577 Proxy::ImplThreadTaskRunner()->PostTask(
579 base::Bind(&ThreadProxy::InitializeImplOnImplThread
,
580 base::Unretained(this),
584 main_thread_weak_ptr_
= main().weak_factory
.GetWeakPtr();
586 main().started
= true;
589 void ThreadProxy::Stop() {
590 TRACE_EVENT0("cc", "ThreadProxy::Stop");
591 DCHECK(IsMainThread());
592 DCHECK(main().started
);
594 // Synchronously finishes pending GL operations and deletes the impl.
595 // The two steps are done as separate post tasks, so that tasks posted
596 // by the GL implementation due to the Finish can be executed by the
597 // renderer before shutting it down.
599 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
601 CompletionEvent completion
;
602 Proxy::ImplThreadTaskRunner()->PostTask(
604 base::Bind(&ThreadProxy::FinishGLOnImplThread
,
605 impl_thread_weak_ptr_
,
610 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
612 CompletionEvent completion
;
613 Proxy::ImplThreadTaskRunner()->PostTask(
615 base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread
,
616 impl_thread_weak_ptr_
,
621 main().weak_factory
.InvalidateWeakPtrs();
622 blocked_main().layer_tree_host
= NULL
;
623 main().started
= false;
626 void ThreadProxy::ForceSerializeOnSwapBuffers() {
627 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
628 CompletionEvent completion
;
629 Proxy::ImplThreadTaskRunner()->PostTask(
631 base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread
,
632 impl_thread_weak_ptr_
,
637 void ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread(
638 CompletionEvent
* completion
) {
639 if (impl().layer_tree_host_impl
->renderer())
640 impl().layer_tree_host_impl
->renderer()->DoNoOp();
641 completion
->Signal();
644 bool ThreadProxy::SupportsImplScrolling() const {
648 void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent
* completion
) {
649 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
650 DCHECK(IsImplThread());
651 impl().layer_tree_host_impl
->FinishAllRendering();
652 completion
->Signal();
655 void ThreadProxy::ScheduledActionSendBeginMainFrame() {
656 unsigned int begin_frame_id
= nextBeginFrameId
++;
657 benchmark_instrumentation::ScopedBeginFrameTask
begin_frame_task(
658 benchmark_instrumentation::kSendBeginFrame
, begin_frame_id
);
659 scoped_ptr
<BeginMainFrameAndCommitState
> begin_main_frame_state(
660 new BeginMainFrameAndCommitState
);
661 begin_main_frame_state
->begin_frame_id
= begin_frame_id
;
662 begin_main_frame_state
->begin_frame_args
=
663 impl().layer_tree_host_impl
->CurrentBeginFrameArgs();
664 begin_main_frame_state
->scroll_info
=
665 impl().layer_tree_host_impl
->ProcessScrollDeltas();
666 begin_main_frame_state
->memory_allocation_limit_bytes
=
667 impl().layer_tree_host_impl
->memory_allocation_limit_bytes();
668 begin_main_frame_state
->evicted_ui_resources
=
669 impl().layer_tree_host_impl
->EvictedUIResourcesExist();
670 // TODO(vmpstr): This needs to be fixed if
671 // main_frame_before_activation_enabled is set, since we might run this code
672 // twice before recording a duration. crbug.com/469824
673 impl().last_begin_main_frame_args
= begin_main_frame_state
->begin_frame_args
;
674 Proxy::MainThreadTaskRunner()->PostTask(
676 base::Bind(&ThreadProxy::BeginMainFrame
,
677 main_thread_weak_ptr_
,
678 base::Passed(&begin_main_frame_state
)));
679 devtools_instrumentation::DidRequestMainThreadFrame(
680 impl().layer_tree_host_id
);
683 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() {
684 Proxy::MainThreadTaskRunner()->PostTask(
685 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameNotExpectedSoon
,
686 main_thread_weak_ptr_
));
689 void ThreadProxy::BeginMainFrame(
690 scoped_ptr
<BeginMainFrameAndCommitState
> begin_main_frame_state
) {
691 benchmark_instrumentation::ScopedBeginFrameTask
begin_frame_task(
692 benchmark_instrumentation::kDoBeginFrame
,
693 begin_main_frame_state
->begin_frame_id
);
694 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame");
695 DCHECK(IsMainThread());
696 DCHECK_EQ(NO_PIPELINE_STAGE
, main().current_pipeline_stage
);
698 if (main().defer_commits
) {
699 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
700 TRACE_EVENT_SCOPE_THREAD
);
701 Proxy::ImplThreadTaskRunner()->PostTask(
702 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
703 impl_thread_weak_ptr_
,
704 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT
));
708 // If the commit finishes, LayerTreeHost will transfer its swap promises to
709 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the
710 // remaining swap promises.
711 ScopedAbortRemainingSwapPromises
swap_promise_checker(layer_tree_host());
713 main().final_pipeline_stage
= main().max_requested_pipeline_stage
;
714 main().max_requested_pipeline_stage
= NO_PIPELINE_STAGE
;
716 if (!layer_tree_host()->visible()) {
717 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD
);
718 Proxy::ImplThreadTaskRunner()->PostTask(
719 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
720 impl_thread_weak_ptr_
,
721 CommitEarlyOutReason::ABORTED_NOT_VISIBLE
));
725 if (layer_tree_host()->output_surface_lost()) {
726 TRACE_EVENT_INSTANT0(
727 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD
);
728 Proxy::ImplThreadTaskRunner()->PostTask(
730 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
731 impl_thread_weak_ptr_
,
732 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST
));
736 main().current_pipeline_stage
= ANIMATE_PIPELINE_STAGE
;
738 layer_tree_host()->ApplyScrollAndScale(
739 begin_main_frame_state
->scroll_info
.get());
741 layer_tree_host()->WillBeginMainFrame();
743 layer_tree_host()->BeginMainFrame(begin_main_frame_state
->begin_frame_args
);
744 layer_tree_host()->AnimateLayers(
745 begin_main_frame_state
->begin_frame_args
.frame_time
);
747 // Recreate all UI resources if there were evicted UI resources when the impl
748 // thread initiated the commit.
749 if (begin_main_frame_state
->evicted_ui_resources
)
750 layer_tree_host()->RecreateUIResources();
752 layer_tree_host()->Layout();
753 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame");
755 bool can_cancel_this_commit
=
756 main().final_pipeline_stage
< COMMIT_PIPELINE_STAGE
&&
757 !begin_main_frame_state
->evicted_ui_resources
;
759 main().current_pipeline_stage
= UPDATE_LAYERS_PIPELINE_STAGE
;
760 bool should_update_layers
=
761 main().final_pipeline_stage
>= UPDATE_LAYERS_PIPELINE_STAGE
;
762 bool updated
= should_update_layers
&& layer_tree_host()->UpdateLayers();
764 layer_tree_host()->WillCommit();
765 devtools_instrumentation::ScopedCommitTrace
commit_task(
766 layer_tree_host()->id());
768 main().current_pipeline_stage
= COMMIT_PIPELINE_STAGE
;
769 if (!updated
&& can_cancel_this_commit
) {
770 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD
);
771 Proxy::ImplThreadTaskRunner()->PostTask(
772 FROM_HERE
, base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread
,
773 impl_thread_weak_ptr_
,
774 CommitEarlyOutReason::FINISHED_NO_UPDATES
));
776 // Although the commit is internally aborted, this is because it has been
777 // detected to be a no-op. From the perspective of an embedder, this commit
778 // went through, and input should no longer be throttled, etc.
779 main().current_pipeline_stage
= NO_PIPELINE_STAGE
;
780 layer_tree_host()->CommitComplete();
781 layer_tree_host()->DidBeginMainFrame();
782 layer_tree_host()->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE
);
786 // Notify the impl thread that the main thread is ready to commit. This will
787 // begin the commit process, which is blocking from the main thread's
788 // point of view, but asynchronously performed on the impl thread,
789 // coordinated by the Scheduler.
791 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit");
793 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
795 // This CapturePostTasks should be destroyed before CommitComplete() is
796 // called since that goes out to the embedder, and we want the embedder
797 // to receive its callbacks before that.
798 BlockingTaskRunner::CapturePostTasks
blocked(
799 blocking_main_thread_task_runner());
801 CompletionEvent completion
;
802 Proxy::ImplThreadTaskRunner()->PostTask(
803 FROM_HERE
, base::Bind(&ThreadProxy::StartCommitOnImplThread
,
804 impl_thread_weak_ptr_
, &completion
));
808 main().current_pipeline_stage
= NO_PIPELINE_STAGE
;
809 layer_tree_host()->CommitComplete();
810 layer_tree_host()->DidBeginMainFrame();
813 void ThreadProxy::BeginMainFrameNotExpectedSoon() {
814 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon");
815 DCHECK(IsMainThread());
816 layer_tree_host()->BeginMainFrameNotExpectedSoon();
819 void ThreadProxy::StartCommitOnImplThread(CompletionEvent
* completion
) {
820 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
821 DCHECK(!impl().commit_completion_event
);
822 DCHECK(IsImplThread() && IsMainThreadBlocked());
823 DCHECK(impl().scheduler
);
824 DCHECK(impl().scheduler
->CommitPending());
826 if (!impl().layer_tree_host_impl
) {
827 TRACE_EVENT_INSTANT0(
828 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD
);
829 completion
->Signal();
833 // Ideally, we should inform to impl thread when BeginMainFrame is started.
834 // But, we can avoid a PostTask in here.
835 impl().scheduler
->NotifyBeginMainFrameStarted();
836 impl().commit_completion_event
= completion
;
837 impl().scheduler
->NotifyReadyToCommit();
840 void ThreadProxy::BeginMainFrameAbortedOnImplThread(
841 CommitEarlyOutReason reason
) {
842 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason",
843 CommitEarlyOutReasonToString(reason
));
844 DCHECK(IsImplThread());
845 DCHECK(impl().scheduler
);
846 DCHECK(impl().scheduler
->CommitPending());
847 DCHECK(!impl().layer_tree_host_impl
->pending_tree());
849 if (CommitEarlyOutHandledCommit(reason
)) {
850 SetInputThrottledUntilCommitOnImplThread(false);
851 impl().last_processed_begin_main_frame_args
=
852 impl().last_begin_main_frame_args
;
854 impl().layer_tree_host_impl
->BeginMainFrameAborted(reason
);
855 impl().scheduler
->BeginMainFrameAborted(reason
);
858 void ThreadProxy::ScheduledActionAnimate() {
859 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate");
860 DCHECK(IsImplThread());
862 impl().layer_tree_host_impl
->Animate();
865 void ThreadProxy::ScheduledActionCommit() {
866 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit");
867 DCHECK(IsImplThread());
868 DCHECK(IsMainThreadBlocked());
869 DCHECK(impl().commit_completion_event
);
871 blocked_main().main_thread_inside_commit
= true;
872 impl().layer_tree_host_impl
->BeginCommit();
873 layer_tree_host()->FinishCommitOnImplThread(
874 impl().layer_tree_host_impl
.get());
875 blocked_main().main_thread_inside_commit
= false;
877 bool hold_commit
= blocked_main().commit_waits_for_activation
;
878 blocked_main().commit_waits_for_activation
= false;
881 // For some layer types in impl-side painting, the commit is held until
882 // the sync tree is activated. It's also possible that the
883 // sync tree has already activated if there was no work to be done.
884 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD
);
885 impl().completion_event_for_commit_held_on_tree_activation
=
886 impl().commit_completion_event
;
887 impl().commit_completion_event
= NULL
;
889 impl().commit_completion_event
->Signal();
890 impl().commit_completion_event
= NULL
;
893 impl().scheduler
->DidCommit();
895 // Delay this step until afer the main thread has been released as it's
896 // often a good bit of work to update the tree and prepare the new frame.
897 impl().layer_tree_host_impl
->CommitComplete();
899 SetInputThrottledUntilCommitOnImplThread(false);
901 impl().next_frame_is_newly_committed_frame
= true;
904 void ThreadProxy::ScheduledActionActivateSyncTree() {
905 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree");
906 DCHECK(IsImplThread());
907 impl().layer_tree_host_impl
->ActivateSyncTree();
910 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
911 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation");
912 DCHECK(IsImplThread());
913 Proxy::MainThreadTaskRunner()->PostTask(
915 base::Bind(&ThreadProxy::RequestNewOutputSurface
, main_thread_weak_ptr_
));
918 DrawResult
ThreadProxy::DrawSwapInternal(bool forced_draw
) {
919 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap");
922 DCHECK(IsImplThread());
923 DCHECK(impl().layer_tree_host_impl
.get());
925 base::AutoReset
<bool> mark_inside(&impl().inside_draw
, true);
927 if (impl().layer_tree_host_impl
->pending_tree()) {
928 bool update_lcd_text
= false;
929 impl().layer_tree_host_impl
->pending_tree()->UpdateDrawProperties(
933 // This method is called on a forced draw, regardless of whether we are able
934 // to produce a frame, as the calling site on main thread is blocked until its
935 // request completes, and we signal completion here. If CanDraw() is false, we
936 // will indicate success=false to the caller, but we must still signal
937 // completion to avoid deadlock.
939 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
940 // frame, so can only be used when such a frame is possible. Since
941 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
942 // CanDraw() as well.
944 LayerTreeHostImpl::FrameData frame
;
945 bool draw_frame
= false;
947 if (impl().layer_tree_host_impl
->CanDraw()) {
948 result
= impl().layer_tree_host_impl
->PrepareToDraw(&frame
);
949 draw_frame
= forced_draw
|| result
== DRAW_SUCCESS
;
951 result
= DRAW_ABORTED_CANT_DRAW
;
955 impl().layer_tree_host_impl
->DrawLayers(&frame
);
956 result
= DRAW_SUCCESS
;
958 DCHECK_NE(DRAW_SUCCESS
, result
);
960 impl().layer_tree_host_impl
->DidDrawAllLayers(frame
);
962 bool start_ready_animations
= draw_frame
;
963 impl().layer_tree_host_impl
->UpdateAnimationState(start_ready_animations
);
966 impl().layer_tree_host_impl
->SwapBuffers(frame
);
968 // Tell the main thread that the the newly-commited frame was drawn.
969 if (impl().next_frame_is_newly_committed_frame
) {
970 impl().next_frame_is_newly_committed_frame
= false;
971 Proxy::MainThreadTaskRunner()->PostTask(
973 base::Bind(&ThreadProxy::DidCommitAndDrawFrame
, main_thread_weak_ptr_
));
976 DCHECK_NE(INVALID_RESULT
, result
);
980 void ThreadProxy::ScheduledActionPrepareTiles() {
981 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles");
982 impl().layer_tree_host_impl
->PrepareTiles();
985 DrawResult
ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
986 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
988 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to
989 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should
990 // never generate this call when it can't draw.
991 DCHECK(impl().layer_tree_host_impl
->CanDraw());
993 bool forced_draw
= false;
994 return DrawSwapInternal(forced_draw
);
997 DrawResult
ThreadProxy::ScheduledActionDrawAndSwapForced() {
998 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced");
999 bool forced_draw
= true;
1000 return DrawSwapInternal(forced_draw
);
1003 void ThreadProxy::ScheduledActionInvalidateOutputSurface() {
1004 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface");
1005 DCHECK(impl().layer_tree_host_impl
->output_surface());
1006 impl().layer_tree_host_impl
->output_surface()->Invalidate();
1009 void ThreadProxy::DidFinishImplFrame() {
1010 impl().layer_tree_host_impl
->DidFinishImplFrame();
1013 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs
& args
) {
1014 NOTREACHED() << "Only used by SingleThreadProxy";
1017 void ThreadProxy::SetAuthoritativeVSyncInterval(
1018 const base::TimeDelta
& interval
) {
1019 NOTREACHED() << "Only used by SingleThreadProxy";
1022 void ThreadProxy::DidCommitAndDrawFrame() {
1023 DCHECK(IsMainThread());
1024 layer_tree_host()->DidCommitAndDrawFrame();
1027 void ThreadProxy::DidCompleteSwapBuffers() {
1028 DCHECK(IsMainThread());
1029 layer_tree_host()->DidCompleteSwapBuffers();
1032 void ThreadProxy::SetAnimationEvents(scoped_ptr
<AnimationEventsVector
> events
) {
1033 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents");
1034 DCHECK(IsMainThread());
1035 layer_tree_host()->SetAnimationEvents(events
.Pass());
1038 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent
* completion
) {
1039 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
1040 DCHECK(IsImplThread());
1041 impl().layer_tree_host_impl
=
1042 layer_tree_host()->CreateLayerTreeHostImpl(this);
1044 SchedulerSettings
scheduler_settings(
1045 layer_tree_host()->settings().ToSchedulerSettings());
1047 scoped_ptr
<CompositorTimingHistory
> compositor_timing_history(
1048 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA
,
1049 impl().rendering_stats_instrumentation
));
1051 impl().scheduler
= Scheduler::Create(
1052 this, scheduler_settings
, impl().layer_tree_host_id
,
1053 ImplThreadTaskRunner(), impl().external_begin_frame_source
.get(),
1054 compositor_timing_history
.Pass());
1056 impl().scheduler
->SetVisible(impl().layer_tree_host_impl
->visible());
1057 impl_thread_weak_ptr_
= impl().weak_factory
.GetWeakPtr();
1058 completion
->Signal();
1061 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1062 scoped_ptr
<OutputSurface
> output_surface
) {
1063 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread");
1064 DCHECK(IsImplThread());
1066 LayerTreeHostImpl
* host_impl
= impl().layer_tree_host_impl
.get();
1067 bool success
= host_impl
->InitializeRenderer(output_surface
.Pass());
1068 RendererCapabilities capabilities
;
1071 host_impl
->GetRendererCapabilities().MainThreadCapabilities();
1074 Proxy::MainThreadTaskRunner()->PostTask(
1076 base::Bind(&ThreadProxy::DidInitializeOutputSurface
,
1077 main_thread_weak_ptr_
,
1082 impl().scheduler
->DidCreateAndInitializeOutputSurface();
1085 void ThreadProxy::ReleaseOutputSurfaceOnImplThread(
1086 CompletionEvent
* completion
,
1087 scoped_ptr
<OutputSurface
>* output_surface
) {
1088 DCHECK(IsImplThread());
1090 // Unlike DidLoseOutputSurfaceOnImplThread, we don't need to call
1091 // LayerTreeHost::DidLoseOutputSurface since it already knows.
1092 impl().scheduler
->DidLoseOutputSurface();
1093 *output_surface
= impl().layer_tree_host_impl
->ReleaseOutputSurface();
1094 completion
->Signal();
1097 void ThreadProxy::FinishGLOnImplThread(CompletionEvent
* completion
) {
1098 TRACE_EVENT0("cc", "ThreadProxy::FinishGLOnImplThread");
1099 DCHECK(IsImplThread());
1100 if (impl().layer_tree_host_impl
->output_surface()) {
1101 ContextProvider
* context_provider
=
1102 impl().layer_tree_host_impl
->output_surface()->context_provider();
1103 if (context_provider
)
1104 context_provider
->ContextGL()->Finish();
1106 completion
->Signal();
1109 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent
* completion
) {
1110 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1111 DCHECK(IsImplThread());
1112 DCHECK(IsMainThreadBlocked());
1113 impl().scheduler
= nullptr;
1114 impl().external_begin_frame_source
= nullptr;
1115 impl().layer_tree_host_impl
= nullptr;
1116 impl().weak_factory
.InvalidateWeakPtrs();
1117 // We need to explicitly shutdown the notifier to destroy any weakptrs it is
1118 // holding while still on the compositor thread. This also ensures any
1119 // callbacks holding a ThreadProxy pointer are cancelled.
1120 impl().smoothness_priority_expiration_notifier
.Shutdown();
1121 completion
->Signal();
1124 ThreadProxy::BeginMainFrameAndCommitState::BeginMainFrameAndCommitState()
1125 : memory_allocation_limit_bytes(0),
1126 evicted_ui_resources(false) {}
1128 ThreadProxy::BeginMainFrameAndCommitState::~BeginMainFrameAndCommitState() {}
1130 bool ThreadProxy::MainFrameWillHappenForTesting() {
1131 DCHECK(IsMainThread());
1132 CompletionEvent completion
;
1133 bool main_frame_will_happen
= false;
1135 DebugScopedSetMainThreadBlocked
main_thread_blocked(this);
1136 Proxy::ImplThreadTaskRunner()->PostTask(
1138 base::Bind(&ThreadProxy::MainFrameWillHappenOnImplThreadForTesting
,
1139 impl_thread_weak_ptr_
,
1141 &main_frame_will_happen
));
1144 return main_frame_will_happen
;
1147 void ThreadProxy::SetChildrenNeedBeginFrames(bool children_need_begin_frames
) {
1148 NOTREACHED() << "Only used by SingleThreadProxy";
1151 void ThreadProxy::MainFrameWillHappenOnImplThreadForTesting(
1152 CompletionEvent
* completion
,
1153 bool* main_frame_will_happen
) {
1154 DCHECK(IsImplThread());
1155 if (impl().layer_tree_host_impl
->output_surface()) {
1156 *main_frame_will_happen
= impl().scheduler
->MainFrameForTestingWillHappen();
1158 *main_frame_will_happen
= false;
1160 completion
->Signal();
1163 void ThreadProxy::RenewTreePriority() {
1164 DCHECK(IsImplThread());
1165 bool smoothness_takes_priority
=
1166 impl().layer_tree_host_impl
->pinch_gesture_active() ||
1167 impl().layer_tree_host_impl
->page_scale_animation_active() ||
1168 impl().layer_tree_host_impl
->IsActivelyScrolling();
1170 // Schedule expiration if smoothness currently takes priority.
1171 if (smoothness_takes_priority
)
1172 impl().smoothness_priority_expiration_notifier
.Schedule();
1174 // We use the same priority for both trees by default.
1175 TreePriority priority
= SAME_PRIORITY_FOR_BOTH_TREES
;
1177 // Smoothness takes priority if we have an expiration for it scheduled.
1178 if (impl().smoothness_priority_expiration_notifier
.HasPendingNotification())
1179 priority
= SMOOTHNESS_TAKES_PRIORITY
;
1181 // New content always takes priority when there is an invalid viewport size or
1182 // ui resources have been evicted.
1183 if (impl().layer_tree_host_impl
->active_tree()->ViewportSizeInvalid() ||
1184 impl().layer_tree_host_impl
->EvictedUIResourcesExist() ||
1185 impl().input_throttled_until_commit
) {
1186 // Once we enter NEW_CONTENTS_TAKES_PRIORITY mode, visible tiles on active
1187 // tree might be freed. We need to set RequiresHighResToDraw to ensure that
1188 // high res tiles will be required to activate pending tree.
1189 impl().layer_tree_host_impl
->SetRequiresHighResToDraw();
1190 priority
= NEW_CONTENT_TAKES_PRIORITY
;
1193 impl().layer_tree_host_impl
->SetTreePriority(priority
);
1195 // Only put the scheduler in impl latency prioritization mode if we don't
1196 // have a scroll listener. This gives the scroll listener a better chance of
1197 // handling scroll updates within the same frame. The tree itself is still
1198 // kept in prefer smoothness mode to allow checkerboarding.
1199 impl().scheduler
->SetImplLatencyTakesPriority(
1200 priority
== SMOOTHNESS_TAKES_PRIORITY
&&
1201 !impl().layer_tree_host_impl
->scroll_affects_scroll_handler());
1203 // Notify the the client of this compositor via the output surface.
1204 // TODO(epenner): Route this to compositor-thread instead of output-surface
1205 // after GTFO refactor of compositor-thread (http://crbug/170828).
1206 if (impl().layer_tree_host_impl
->output_surface()) {
1208 .layer_tree_host_impl
->output_surface()
1209 ->UpdateSmoothnessTakesPriority(priority
== SMOOTHNESS_TAKES_PRIORITY
);
1213 void ThreadProxy::PostDelayedAnimationTaskOnImplThread(
1214 const base::Closure
& task
,
1215 base::TimeDelta delay
) {
1216 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE
, task
, delay
);
1219 void ThreadProxy::DidActivateSyncTree() {
1220 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread");
1221 DCHECK(IsImplThread());
1223 if (impl().completion_event_for_commit_held_on_tree_activation
) {
1224 TRACE_EVENT_INSTANT0(
1225 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD
);
1226 impl().completion_event_for_commit_held_on_tree_activation
->Signal();
1227 impl().completion_event_for_commit_held_on_tree_activation
= NULL
;
1230 impl().last_processed_begin_main_frame_args
=
1231 impl().last_begin_main_frame_args
;
1234 void ThreadProxy::WillPrepareTiles() {
1235 DCHECK(IsImplThread());
1236 impl().scheduler
->WillPrepareTiles();
1239 void ThreadProxy::DidPrepareTiles() {
1240 DCHECK(IsImplThread());
1241 impl().scheduler
->DidPrepareTiles();
1244 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
1245 DCHECK(IsImplThread());
1246 Proxy::MainThreadTaskRunner()->PostTask(
1247 FROM_HERE
, base::Bind(&ThreadProxy::DidCompletePageScaleAnimation
,
1248 main_thread_weak_ptr_
));
1251 void ThreadProxy::OnDrawForOutputSurface() {
1252 DCHECK(IsImplThread());
1253 impl().scheduler
->OnDrawForOutputSurface();
1256 void ThreadProxy::PostFrameTimingEventsOnImplThread(
1257 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
1258 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
) {
1259 DCHECK(IsImplThread());
1260 Proxy::MainThreadTaskRunner()->PostTask(
1262 base::Bind(&ThreadProxy::PostFrameTimingEvents
, main_thread_weak_ptr_
,
1263 base::Passed(composite_events
.Pass()),
1264 base::Passed(main_frame_events
.Pass())));
1267 void ThreadProxy::PostFrameTimingEvents(
1268 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> composite_events
,
1269 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> main_frame_events
) {
1270 DCHECK(IsMainThread());
1271 layer_tree_host()->RecordFrameTimingEvents(composite_events
.Pass(),
1272 main_frame_events
.Pass());