Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: cc/trees/thread_proxy.cc

Issue 1417053005: cc: Split ThreadProxy into ProxyMain and ProxyImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change ThreadedChannel::GetProxyImpl to GetProxyImplForTesting Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/trees/thread_proxy.h"
6
7 #include <algorithm>
8 #include <string>
9
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/input/top_controls_manager.h"
19 #include "cc/output/context_provider.h"
20 #include "cc/output/output_surface.h"
21 #include "cc/output/swap_promise.h"
22 #include "cc/quads/draw_quad.h"
23 #include "cc/scheduler/commit_earlyout_reason.h"
24 #include "cc/scheduler/compositor_timing_history.h"
25 #include "cc/scheduler/scheduler.h"
26 #include "cc/trees/blocking_task_runner.h"
27 #include "cc/trees/layer_tree_host.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "cc/trees/scoped_abort_remaining_swap_promises.h"
30 #include "gpu/command_buffer/client/gles2_interface.h"
31
32 namespace cc {
33
34 namespace {
35
36 // Measured in seconds.
37 const double kSmoothnessTakesPriorityExpirationDelay = 0.25;
38
39 unsigned int nextBeginFrameId = 0;
40
41 } // namespace
42
43 struct ThreadProxy::SchedulerStateRequest {
44 CompletionEvent completion;
45 scoped_ptr<base::Value> state;
46 };
47
48 scoped_ptr<Proxy> ThreadProxy::Create(
49 LayerTreeHost* layer_tree_host,
50 TaskRunnerProvider* task_runner_provider,
51 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
52 return make_scoped_ptr(new ThreadProxy(layer_tree_host, task_runner_provider,
53 external_begin_frame_source.Pass()));
54 }
55
56 ThreadProxy::ThreadProxy(
57 LayerTreeHost* layer_tree_host,
58 TaskRunnerProvider* task_runner_provider,
59 scoped_ptr<BeginFrameSource> external_begin_frame_source)
60 : task_runner_provider_(task_runner_provider),
61 main_thread_only_vars_unsafe_(this, layer_tree_host),
62 compositor_thread_vars_unsafe_(
63 this,
64 layer_tree_host->id(),
65 layer_tree_host->rendering_stats_instrumentation(),
66 external_begin_frame_source.Pass()) {
67 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy");
68 DCHECK(task_runner_provider_);
69 DCHECK(task_runner_provider_->IsMainThread());
70 DCHECK(this->main().layer_tree_host);
71 // TODO(khushalsagar): Move this to LayerTreeHost#InitializeThreaded once
72 // ThreadProxy is split. LayerTreeHost creates the channel and passes it to
73 // ProxyMain#SetChannel.
74 SetChannel(ThreadedChannel::Create(this, task_runner_provider_));
75 }
76
77 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy,
78 LayerTreeHost* layer_tree_host)
79 : layer_tree_host_id(layer_tree_host->id()),
80 layer_tree_host(layer_tree_host),
81 max_requested_pipeline_stage(NO_PIPELINE_STAGE),
82 current_pipeline_stage(NO_PIPELINE_STAGE),
83 final_pipeline_stage(NO_PIPELINE_STAGE),
84 commit_waits_for_activation(false),
85 started(false),
86 prepare_tiles_pending(false),
87 defer_commits(false),
88 weak_factory(proxy) {}
89
90 ThreadProxy::MainThreadOnly::~MainThreadOnly() {}
91
92 ThreadProxy::BlockedMainCommitOnly::BlockedMainCommitOnly()
93 : layer_tree_host(nullptr) {}
94
95 ThreadProxy::BlockedMainCommitOnly::~BlockedMainCommitOnly() {}
96
97 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly(
98 ThreadProxy* proxy,
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 next_commit_waits_for_activation(false),
104 commit_completion_event(nullptr),
105 next_frame_is_newly_committed_frame(false),
106 inside_draw(false),
107 input_throttled_until_commit(false),
108 smoothness_priority_expiration_notifier(
109 proxy->task_runner_provider()
110 ->ImplThreadTaskRunner(),
111 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)),
112 base::TimeDelta::FromMilliseconds(
113 kSmoothnessTakesPriorityExpirationDelay * 1000)),
114 external_begin_frame_source(external_begin_frame_source.Pass()),
115 rendering_stats_instrumentation(rendering_stats_instrumentation),
116 weak_factory(proxy) {}
117
118 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {}
119
120 ThreadProxy::~ThreadProxy() {
121 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy");
122 DCHECK(task_runner_provider_->IsMainThread());
123 DCHECK(!main().started);
124 }
125
126 void ThreadProxy::SetChannel(scoped_ptr<ThreadedChannel> threaded_channel) {
127 threaded_channel_ = threaded_channel.Pass();
128 main().channel_main = threaded_channel_.get();
129 }
130
131 void ThreadProxy::FinishAllRendering() {
132 DCHECK(task_runner_provider_->IsMainThread());
133 DCHECK(!main().defer_commits);
134
135 // Make sure all GL drawing is finished on the impl thread.
136 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
137 CompletionEvent completion;
138 main().channel_main->FinishAllRenderingOnImpl(&completion);
139 completion.Wait();
140 }
141
142 bool ThreadProxy::IsStarted() const {
143 DCHECK(task_runner_provider_->IsMainThread());
144 return main().started;
145 }
146
147 bool ThreadProxy::CommitToActiveTree() const {
148 // With ThreadProxy, we use a pending tree and activate it once it's ready to
149 // draw to allow input to modify the active tree and draw during raster.
150 return false;
151 }
152
153 void ThreadProxy::SetVisible(bool visible) {
154 TRACE_EVENT1("cc", "ThreadProxy::SetVisible", "visible", visible);
155 main().channel_main->SetVisibleOnImpl(visible);
156 }
157
158 void ThreadProxy::SetVisibleOnImpl(bool visible) {
159 TRACE_EVENT1("cc", "ThreadProxy::SetVisibleOnImplThread", "visible", visible);
160 impl().layer_tree_host_impl->SetVisible(visible);
161 impl().scheduler->SetVisible(visible);
162 }
163
164 void ThreadProxy::SetThrottleFrameProduction(bool throttle) {
165 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProduction", "throttle",
166 throttle);
167 main().channel_main->SetThrottleFrameProductionOnImpl(throttle);
168 }
169
170 void ThreadProxy::SetThrottleFrameProductionOnImpl(bool throttle) {
171 TRACE_EVENT1("cc", "ThreadProxy::SetThrottleFrameProductionOnImplThread",
172 "throttle", throttle);
173 impl().scheduler->SetThrottleFrameProduction(throttle);
174 }
175
176 void ThreadProxy::DidLoseOutputSurface() {
177 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurface");
178 DCHECK(task_runner_provider_->IsMainThread());
179 main().layer_tree_host->DidLoseOutputSurface();
180 }
181
182 void ThreadProxy::RequestNewOutputSurface() {
183 DCHECK(task_runner_provider_->IsMainThread());
184 main().layer_tree_host->RequestNewOutputSurface();
185 }
186
187 void ThreadProxy::SetOutputSurface(OutputSurface* output_surface) {
188 main().channel_main->InitializeOutputSurfaceOnImpl(output_surface);
189 }
190
191 void ThreadProxy::ReleaseOutputSurface() {
192 DCHECK(task_runner_provider_->IsMainThread());
193 DCHECK(main().layer_tree_host->output_surface_lost());
194
195 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
196 CompletionEvent completion;
197 main().channel_main->ReleaseOutputSurfaceOnImpl(&completion);
198 completion.Wait();
199 }
200
201 void ThreadProxy::DidInitializeOutputSurface(
202 bool success,
203 const RendererCapabilities& capabilities) {
204 TRACE_EVENT0("cc", "ThreadProxy::DidInitializeOutputSurface");
205 DCHECK(task_runner_provider_->IsMainThread());
206
207 if (!success) {
208 main().layer_tree_host->DidFailToInitializeOutputSurface();
209 return;
210 }
211 main().renderer_capabilities_main_thread_copy = capabilities;
212 main().layer_tree_host->DidInitializeOutputSurface();
213 }
214
215 void ThreadProxy::SetRendererCapabilitiesMainCopy(
216 const RendererCapabilities& capabilities) {
217 main().renderer_capabilities_main_thread_copy = capabilities;
218 }
219
220 bool ThreadProxy::SendCommitRequestToImplThreadIfNeeded(
221 CommitPipelineStage required_stage) {
222 DCHECK(task_runner_provider_->IsMainThread());
223 DCHECK_NE(NO_PIPELINE_STAGE, required_stage);
224 bool already_posted =
225 main().max_requested_pipeline_stage != NO_PIPELINE_STAGE;
226 main().max_requested_pipeline_stage =
227 std::max(main().max_requested_pipeline_stage, required_stage);
228 if (already_posted)
229 return false;
230 main().channel_main->SetNeedsCommitOnImpl();
231 return true;
232 }
233
234 void ThreadProxy::SetNeedsCommitOnImpl() {
235 SetNeedsCommitOnImplThread();
236 }
237
238 void ThreadProxy::DidCompletePageScaleAnimation() {
239 DCHECK(task_runner_provider_->IsMainThread());
240 main().layer_tree_host->DidCompletePageScaleAnimation();
241 }
242
243 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const {
244 DCHECK(task_runner_provider_->IsMainThread());
245 DCHECK(!main().layer_tree_host->output_surface_lost());
246 return main().renderer_capabilities_main_thread_copy;
247 }
248
249 void ThreadProxy::SetNeedsAnimate() {
250 DCHECK(task_runner_provider_->IsMainThread());
251 if (SendCommitRequestToImplThreadIfNeeded(ANIMATE_PIPELINE_STAGE)) {
252 TRACE_EVENT_INSTANT0("cc", "ThreadProxy::SetNeedsAnimate",
253 TRACE_EVENT_SCOPE_THREAD);
254 }
255 }
256
257 void ThreadProxy::SetNeedsUpdateLayers() {
258 DCHECK(task_runner_provider_->IsMainThread());
259 // If we are currently animating, make sure we also update the layers.
260 if (main().current_pipeline_stage == ANIMATE_PIPELINE_STAGE) {
261 main().final_pipeline_stage =
262 std::max(main().final_pipeline_stage, UPDATE_LAYERS_PIPELINE_STAGE);
263 return;
264 }
265 if (SendCommitRequestToImplThreadIfNeeded(UPDATE_LAYERS_PIPELINE_STAGE)) {
266 TRACE_EVENT_INSTANT0("cc", "ThreadProxy::SetNeedsUpdateLayers",
267 TRACE_EVENT_SCOPE_THREAD);
268 }
269 }
270
271 void ThreadProxy::SetNeedsCommit() {
272 DCHECK(task_runner_provider_->IsMainThread());
273 // If we are currently animating, make sure we don't skip the commit. Note
274 // that requesting a commit during the layer update stage means we need to
275 // schedule another full commit.
276 if (main().current_pipeline_stage == ANIMATE_PIPELINE_STAGE) {
277 main().final_pipeline_stage =
278 std::max(main().final_pipeline_stage, COMMIT_PIPELINE_STAGE);
279 return;
280 }
281 if (SendCommitRequestToImplThreadIfNeeded(COMMIT_PIPELINE_STAGE)) {
282 TRACE_EVENT_INSTANT0("cc", "ThreadProxy::SetNeedsCommit",
283 TRACE_EVENT_SCOPE_THREAD);
284 }
285 }
286
287 void ThreadProxy::UpdateRendererCapabilitiesOnImplThread() {
288 DCHECK(task_runner_provider_->IsImplThread());
289 impl().channel_impl->SetRendererCapabilitiesMainCopy(
290 impl()
291 .layer_tree_host_impl->GetRendererCapabilities()
292 .MainThreadCapabilities());
293 }
294
295 void ThreadProxy::DidLoseOutputSurfaceOnImplThread() {
296 TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread");
297 DCHECK(task_runner_provider_->IsImplThread());
298 impl().channel_impl->DidLoseOutputSurface();
299 impl().scheduler->DidLoseOutputSurface();
300 }
301
302 void ThreadProxy::CommitVSyncParameters(base::TimeTicks timebase,
303 base::TimeDelta interval) {
304 impl().scheduler->CommitVSyncParameters(timebase, interval);
305 }
306
307 void ThreadProxy::SetEstimatedParentDrawTime(base::TimeDelta draw_time) {
308 impl().scheduler->SetEstimatedParentDrawTime(draw_time);
309 }
310
311 void ThreadProxy::SetMaxSwapsPendingOnImplThread(int max) {
312 impl().scheduler->SetMaxSwapsPending(max);
313 }
314
315 void ThreadProxy::DidSwapBuffersOnImplThread() {
316 impl().scheduler->DidSwapBuffers();
317 }
318
319 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() {
320 TRACE_EVENT0("cc,benchmark",
321 "ThreadProxy::DidSwapBuffersCompleteOnImplThread");
322 DCHECK(task_runner_provider_->IsImplThread());
323 impl().scheduler->DidSwapBuffersComplete();
324 impl().channel_impl->DidCompleteSwapBuffers();
325 }
326
327 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
328 impl().layer_tree_host_impl->WillBeginImplFrame(args);
329 if (impl().last_processed_begin_main_frame_args.IsValid()) {
330 // Last processed begin main frame args records the frame args that we sent
331 // to the main thread for the last frame that we've processed. If that is
332 // set, that means the current frame is one past the frame in which we've
333 // finished the processing.
334 impl().layer_tree_host_impl->RecordMainFrameTiming(
335 impl().last_processed_begin_main_frame_args, args);
336 impl().last_processed_begin_main_frame_args = BeginFrameArgs();
337 }
338 }
339
340 void ThreadProxy::OnResourcelessSoftareDrawStateChanged(
341 bool resourceless_draw) {
342 DCHECK(task_runner_provider_->IsImplThread());
343 impl().scheduler->SetResourcelessSoftareDraw(resourceless_draw);
344 }
345
346 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
347 TRACE_EVENT1(
348 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
349 DCHECK(task_runner_provider_->IsImplThread());
350 impl().scheduler->SetCanDraw(can_draw);
351 }
352
353 void ThreadProxy::NotifyReadyToActivate() {
354 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate");
355 impl().scheduler->NotifyReadyToActivate();
356 }
357
358 void ThreadProxy::NotifyReadyToDraw() {
359 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToDraw");
360 impl().scheduler->NotifyReadyToDraw();
361 }
362
363 void ThreadProxy::SetNeedsCommitOnImplThread() {
364 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread");
365 DCHECK(task_runner_provider_->IsImplThread());
366 impl().scheduler->SetNeedsBeginMainFrame();
367 }
368
369 void ThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) {
370 TRACE_EVENT1("cc", "ThreadProxy::SetVideoNeedsBeginFrames",
371 "needs_begin_frames", needs_begin_frames);
372 DCHECK(task_runner_provider_->IsImplThread());
373 // In tests the layer tree is destroyed after the scheduler is.
374 if (impl().scheduler)
375 impl().scheduler->SetVideoNeedsBeginFrames(needs_begin_frames);
376 }
377
378 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
379 scoped_ptr<AnimationEventsVector> events) {
380 TRACE_EVENT0("cc",
381 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread");
382 DCHECK(task_runner_provider_->IsImplThread());
383 impl().channel_impl->SetAnimationEvents(events.Pass());
384 }
385
386 bool ThreadProxy::IsInsideDraw() { return impl().inside_draw; }
387
388 void ThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) {
389 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw");
390 DCHECK(task_runner_provider_->IsMainThread());
391 main().channel_main->SetNeedsRedrawOnImpl(damage_rect);
392 }
393
394 void ThreadProxy::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) {
395 DCHECK(task_runner_provider_->IsImplThread());
396 SetNeedsRedrawRectOnImplThread(damage_rect);
397 }
398
399 void ThreadProxy::SetNextCommitWaitsForActivation() {
400 DCHECK(task_runner_provider_->IsMainThread());
401 main().commit_waits_for_activation = true;
402 }
403
404 void ThreadProxy::SetDeferCommits(bool defer_commits) {
405 DCHECK(task_runner_provider_->IsMainThread());
406 if (main().defer_commits == defer_commits)
407 return;
408
409 main().defer_commits = defer_commits;
410 if (main().defer_commits)
411 TRACE_EVENT_ASYNC_BEGIN0("cc", "ThreadProxy::SetDeferCommits", this);
412 else
413 TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this);
414
415 main().channel_main->SetDeferCommitsOnImpl(defer_commits);
416 }
417
418 void ThreadProxy::SetDeferCommitsOnImpl(bool defer_commits) const {
419 DCHECK(task_runner_provider_->IsImplThread());
420 impl().scheduler->SetDeferCommits(defer_commits);
421 }
422
423 bool ThreadProxy::CommitRequested() const {
424 DCHECK(task_runner_provider_->IsMainThread());
425 // TODO(skyostil): Split this into something like CommitRequested() and
426 // CommitInProgress().
427 return main().current_pipeline_stage != NO_PIPELINE_STAGE ||
428 main().max_requested_pipeline_stage >= COMMIT_PIPELINE_STAGE;
429 }
430
431 bool ThreadProxy::BeginMainFrameRequested() const {
432 DCHECK(task_runner_provider_->IsMainThread());
433 return main().max_requested_pipeline_stage != NO_PIPELINE_STAGE;
434 }
435
436 void ThreadProxy::SetNeedsRedrawOnImplThread() {
437 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedrawOnImplThread");
438 DCHECK(task_runner_provider_->IsImplThread());
439 impl().scheduler->SetNeedsRedraw();
440 }
441
442 void ThreadProxy::SetNeedsAnimateOnImplThread() {
443 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimateOnImplThread");
444 DCHECK(task_runner_provider_->IsImplThread());
445 impl().scheduler->SetNeedsAnimate();
446 }
447
448 void ThreadProxy::SetNeedsPrepareTilesOnImplThread() {
449 DCHECK(task_runner_provider_->IsImplThread());
450 impl().scheduler->SetNeedsPrepareTiles();
451 }
452
453 void ThreadProxy::SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) {
454 DCHECK(task_runner_provider_->IsImplThread());
455 impl().layer_tree_host_impl->SetViewportDamage(damage_rect);
456 SetNeedsRedrawOnImplThread();
457 }
458
459 void ThreadProxy::MainThreadHasStoppedFlinging() {
460 DCHECK(task_runner_provider_->IsMainThread());
461 main().channel_main->MainThreadHasStoppedFlingingOnImpl();
462 }
463
464 void ThreadProxy::MainThreadHasStoppedFlingingOnImpl() {
465 DCHECK(task_runner_provider_->IsImplThread());
466 impl().layer_tree_host_impl->MainThreadHasStoppedFlinging();
467 }
468
469 void ThreadProxy::NotifyInputThrottledUntilCommit() {
470 DCHECK(task_runner_provider_->IsMainThread());
471 main().channel_main->SetInputThrottledUntilCommitOnImpl(true);
472 }
473
474 void ThreadProxy::SetInputThrottledUntilCommitOnImpl(bool is_throttled) {
475 DCHECK(task_runner_provider_->IsImplThread());
476 if (is_throttled == impl().input_throttled_until_commit)
477 return;
478 impl().input_throttled_until_commit = is_throttled;
479 RenewTreePriority();
480 }
481
482 ThreadProxy::MainThreadOnly& ThreadProxy::main() {
483 DCHECK(task_runner_provider_->IsMainThread());
484 return main_thread_only_vars_unsafe_;
485 }
486 const ThreadProxy::MainThreadOnly& ThreadProxy::main() const {
487 DCHECK(task_runner_provider_->IsMainThread());
488 return main_thread_only_vars_unsafe_;
489 }
490
491 ThreadProxy::BlockedMainCommitOnly& ThreadProxy::blocked_main_commit() {
492 DCHECK(impl().commit_completion_event);
493 DCHECK(task_runner_provider_->IsMainThreadBlocked());
494 return main_thread_blocked_commit_vars_unsafe_;
495 }
496
497 ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() {
498 DCHECK(task_runner_provider_->IsImplThread());
499 return compositor_thread_vars_unsafe_;
500 }
501
502 const ThreadProxy::CompositorThreadOnly& ThreadProxy::impl() const {
503 DCHECK(task_runner_provider_->IsImplThread());
504 return compositor_thread_vars_unsafe_;
505 }
506
507 void ThreadProxy::Start() {
508 DCHECK(task_runner_provider_->IsMainThread());
509 DCHECK(task_runner_provider_->HasImplThread());
510
511 // Create LayerTreeHostImpl.
512 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
513 CompletionEvent completion;
514 main().channel_main->InitializeImplOnImpl(&completion,
515 main().layer_tree_host);
516 completion.Wait();
517
518 main_thread_weak_ptr_ = main().weak_factory.GetWeakPtr();
519
520 main().started = true;
521 }
522
523 void ThreadProxy::Stop() {
524 TRACE_EVENT0("cc", "ThreadProxy::Stop");
525 DCHECK(task_runner_provider_->IsMainThread());
526 DCHECK(main().started);
527
528 // Synchronously finishes pending GL operations and deletes the impl.
529 // The two steps are done as separate post tasks, so that tasks posted
530 // by the GL implementation due to the Finish can be executed by the
531 // renderer before shutting it down.
532 {
533 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
534 CompletionEvent completion;
535 main().channel_main->FinishGLOnImpl(&completion);
536 completion.Wait();
537 }
538 {
539 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
540
541 CompletionEvent completion;
542 main().channel_main->LayerTreeHostClosedOnImpl(&completion);
543 completion.Wait();
544 }
545
546 main().weak_factory.InvalidateWeakPtrs();
547 main().layer_tree_host = nullptr;
548 main().started = false;
549 }
550
551 bool ThreadProxy::SupportsImplScrolling() const {
552 return true;
553 }
554
555 void ThreadProxy::FinishAllRenderingOnImpl(CompletionEvent* completion) {
556 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
557 DCHECK(task_runner_provider_->IsImplThread());
558 impl().layer_tree_host_impl->FinishAllRendering();
559 completion->Signal();
560 }
561
562 void ThreadProxy::ScheduledActionSendBeginMainFrame(
563 const BeginFrameArgs& args) {
564 unsigned int begin_frame_id = nextBeginFrameId++;
565 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task(
566 benchmark_instrumentation::kSendBeginFrame, begin_frame_id);
567 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state(
568 new BeginMainFrameAndCommitState);
569 begin_main_frame_state->begin_frame_id = begin_frame_id;
570 begin_main_frame_state->begin_frame_args = args;
571 begin_main_frame_state->scroll_info =
572 impl().layer_tree_host_impl->ProcessScrollDeltas();
573 begin_main_frame_state->memory_allocation_limit_bytes =
574 impl().layer_tree_host_impl->memory_allocation_limit_bytes();
575 begin_main_frame_state->evicted_ui_resources =
576 impl().layer_tree_host_impl->EvictedUIResourcesExist();
577 // TODO(vmpstr): This needs to be fixed if
578 // main_frame_before_activation_enabled is set, since we might run this code
579 // twice before recording a duration. crbug.com/469824
580 impl().last_begin_main_frame_args = begin_main_frame_state->begin_frame_args;
581 impl().channel_impl->BeginMainFrame(begin_main_frame_state.Pass());
582 devtools_instrumentation::DidRequestMainThreadFrame(
583 impl().layer_tree_host_id);
584 }
585
586 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() {
587 impl().channel_impl->BeginMainFrameNotExpectedSoon();
588 }
589
590 void ThreadProxy::BeginMainFrame(
591 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {
592 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task(
593 benchmark_instrumentation::kDoBeginFrame,
594 begin_main_frame_state->begin_frame_id);
595
596 base::TimeTicks begin_main_frame_start_time = base::TimeTicks::Now();
597
598 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame");
599 DCHECK(task_runner_provider_->IsMainThread());
600 DCHECK_EQ(NO_PIPELINE_STAGE, main().current_pipeline_stage);
601
602 if (main().defer_commits) {
603 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
604 TRACE_EVENT_SCOPE_THREAD);
605 main().channel_main->BeginMainFrameAbortedOnImpl(
606 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT,
607 begin_main_frame_start_time);
608 return;
609 }
610
611 // If the commit finishes, LayerTreeHost will transfer its swap promises to
612 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the
613 // remaining swap promises.
614 ScopedAbortRemainingSwapPromises swap_promise_checker(main().layer_tree_host);
615
616 main().final_pipeline_stage = main().max_requested_pipeline_stage;
617 main().max_requested_pipeline_stage = NO_PIPELINE_STAGE;
618
619 if (!main().layer_tree_host->visible()) {
620 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
621 main().channel_main->BeginMainFrameAbortedOnImpl(
622 CommitEarlyOutReason::ABORTED_NOT_VISIBLE, begin_main_frame_start_time);
623 return;
624 }
625
626 if (main().layer_tree_host->output_surface_lost()) {
627 TRACE_EVENT_INSTANT0(
628 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
629 main().channel_main->BeginMainFrameAbortedOnImpl(
630 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST,
631 begin_main_frame_start_time);
632 return;
633 }
634
635 main().current_pipeline_stage = ANIMATE_PIPELINE_STAGE;
636
637 main().layer_tree_host->ApplyScrollAndScale(
638 begin_main_frame_state->scroll_info.get());
639
640 main().layer_tree_host->WillBeginMainFrame();
641
642 main().layer_tree_host->BeginMainFrame(
643 begin_main_frame_state->begin_frame_args);
644 main().layer_tree_host->AnimateLayers(
645 begin_main_frame_state->begin_frame_args.frame_time);
646
647 // Recreate all UI resources if there were evicted UI resources when the impl
648 // thread initiated the commit.
649 if (begin_main_frame_state->evicted_ui_resources)
650 main().layer_tree_host->RecreateUIResources();
651
652 main().layer_tree_host->RequestMainFrameUpdate();
653 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame");
654
655 bool can_cancel_this_commit =
656 main().final_pipeline_stage < COMMIT_PIPELINE_STAGE &&
657 !begin_main_frame_state->evicted_ui_resources;
658
659 main().current_pipeline_stage = UPDATE_LAYERS_PIPELINE_STAGE;
660 bool should_update_layers =
661 main().final_pipeline_stage >= UPDATE_LAYERS_PIPELINE_STAGE;
662 bool updated = should_update_layers && main().layer_tree_host->UpdateLayers();
663
664 main().layer_tree_host->WillCommit();
665 devtools_instrumentation::ScopedCommitTrace commit_task(
666 main().layer_tree_host->id());
667
668 main().current_pipeline_stage = COMMIT_PIPELINE_STAGE;
669 if (!updated && can_cancel_this_commit) {
670 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD);
671 main().channel_main->BeginMainFrameAbortedOnImpl(
672 CommitEarlyOutReason::FINISHED_NO_UPDATES, begin_main_frame_start_time);
673
674 // Although the commit is internally aborted, this is because it has been
675 // detected to be a no-op. From the perspective of an embedder, this commit
676 // went through, and input should no longer be throttled, etc.
677 main().current_pipeline_stage = NO_PIPELINE_STAGE;
678 main().layer_tree_host->CommitComplete();
679 main().layer_tree_host->DidBeginMainFrame();
680 main().layer_tree_host->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE);
681 return;
682 }
683
684 // Notify the impl thread that the main thread is ready to commit. This will
685 // begin the commit process, which is blocking from the main thread's
686 // point of view, but asynchronously performed on the impl thread,
687 // coordinated by the Scheduler.
688 {
689 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit");
690
691 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
692
693 // This CapturePostTasks should be destroyed before CommitComplete() is
694 // called since that goes out to the embedder, and we want the embedder
695 // to receive its callbacks before that.
696 BlockingTaskRunner::CapturePostTasks blocked(
697 task_runner_provider_->blocking_main_thread_task_runner());
698
699 CompletionEvent completion;
700 main().channel_main->StartCommitOnImpl(&completion, main().layer_tree_host,
701 begin_main_frame_start_time,
702 main().commit_waits_for_activation);
703 completion.Wait();
704 main().commit_waits_for_activation = false;
705 }
706
707 main().current_pipeline_stage = NO_PIPELINE_STAGE;
708 main().layer_tree_host->CommitComplete();
709 main().layer_tree_host->DidBeginMainFrame();
710 }
711
712 void ThreadProxy::BeginMainFrameNotExpectedSoon() {
713 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon");
714 DCHECK(task_runner_provider_->IsMainThread());
715 main().layer_tree_host->BeginMainFrameNotExpectedSoon();
716 }
717
718 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion,
719 LayerTreeHost* layer_tree_host,
720 base::TimeTicks main_thread_start_time,
721 bool hold_commit_for_activation) {
722 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
723 DCHECK(!impl().commit_completion_event);
724 DCHECK(task_runner_provider_->IsImplThread() &&
725 task_runner_provider_->IsMainThreadBlocked());
726 DCHECK(impl().scheduler);
727 DCHECK(impl().scheduler->CommitPending());
728
729 if (hold_commit_for_activation) {
730 // This commit may be aborted. Store the value for
731 // hold_commit_for_activation so that whenever the next commit is started,
732 // the main thread will be unblocked only after pending tree activation.
733 impl().next_commit_waits_for_activation = hold_commit_for_activation;
734 }
735
736 if (!impl().layer_tree_host_impl) {
737 TRACE_EVENT_INSTANT0(
738 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD);
739 completion->Signal();
740 return;
741 }
742
743 // Ideally, we should inform to impl thread when BeginMainFrame is started.
744 // But, we can avoid a PostTask in here.
745 impl().scheduler->NotifyBeginMainFrameStarted(main_thread_start_time);
746 impl().commit_completion_event = completion;
747 DCHECK(!blocked_main_commit().layer_tree_host);
748 blocked_main_commit().layer_tree_host = layer_tree_host;
749 impl().scheduler->NotifyReadyToCommit();
750 }
751
752 void ThreadProxy::BeginMainFrameAbortedOnImpl(
753 CommitEarlyOutReason reason,
754 base::TimeTicks main_thread_start_time) {
755 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason",
756 CommitEarlyOutReasonToString(reason));
757 DCHECK(task_runner_provider_->IsImplThread());
758 DCHECK(impl().scheduler);
759 DCHECK(impl().scheduler->CommitPending());
760 DCHECK(!impl().layer_tree_host_impl->pending_tree());
761
762 if (CommitEarlyOutHandledCommit(reason)) {
763 SetInputThrottledUntilCommitOnImpl(false);
764 impl().last_processed_begin_main_frame_args =
765 impl().last_begin_main_frame_args;
766 }
767 impl().layer_tree_host_impl->BeginMainFrameAborted(reason);
768 impl().scheduler->NotifyBeginMainFrameStarted(main_thread_start_time);
769 impl().scheduler->BeginMainFrameAborted(reason);
770 }
771
772 void ThreadProxy::ScheduledActionAnimate() {
773 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate");
774 DCHECK(task_runner_provider_->IsImplThread());
775
776 impl().layer_tree_host_impl->Animate();
777 }
778
779 void ThreadProxy::ScheduledActionCommit() {
780 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionCommit");
781 DCHECK(task_runner_provider_->IsImplThread());
782 DCHECK(task_runner_provider_->IsMainThreadBlocked());
783 DCHECK(impl().commit_completion_event);
784 DCHECK(blocked_main_commit().layer_tree_host);
785
786 impl().layer_tree_host_impl->BeginCommit();
787 blocked_main_commit().layer_tree_host->FinishCommitOnImplThread(
788 impl().layer_tree_host_impl.get());
789
790 // Remove the LayerTreeHost reference before the completion event is signaled
791 // and cleared. This is necessary since blocked_main_commit() allows access
792 // only while we have the completion event to ensure the main thread is
793 // blocked for a commit.
794 blocked_main_commit().layer_tree_host = nullptr;
795
796 if (impl().next_commit_waits_for_activation) {
797 // For some layer types in impl-side painting, the commit is held until
798 // the sync tree is activated. It's also possible that the
799 // sync tree has already activated if there was no work to be done.
800 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD);
801 } else {
802 impl().commit_completion_event->Signal();
803 impl().commit_completion_event = nullptr;
804 }
805
806 impl().scheduler->DidCommit();
807
808 // Delay this step until afer the main thread has been released as it's
809 // often a good bit of work to update the tree and prepare the new frame.
810 impl().layer_tree_host_impl->CommitComplete();
811
812 SetInputThrottledUntilCommitOnImpl(false);
813
814 impl().next_frame_is_newly_committed_frame = true;
815 }
816
817 void ThreadProxy::ScheduledActionActivateSyncTree() {
818 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivateSyncTree");
819 DCHECK(task_runner_provider_->IsImplThread());
820 impl().layer_tree_host_impl->ActivateSyncTree();
821 }
822
823 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
824 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation");
825 DCHECK(task_runner_provider_->IsImplThread());
826 impl().channel_impl->RequestNewOutputSurface();
827 }
828
829 DrawResult ThreadProxy::DrawSwapInternal(bool forced_draw) {
830 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap");
831 DrawResult result;
832
833 DCHECK(task_runner_provider_->IsImplThread());
834 DCHECK(impl().layer_tree_host_impl.get());
835
836 base::AutoReset<bool> mark_inside(&impl().inside_draw, true);
837
838 if (impl().layer_tree_host_impl->pending_tree()) {
839 bool update_lcd_text = false;
840 impl().layer_tree_host_impl->pending_tree()->UpdateDrawProperties(
841 update_lcd_text);
842 }
843
844 // This method is called on a forced draw, regardless of whether we are able
845 // to produce a frame, as the calling site on main thread is blocked until its
846 // request completes, and we signal completion here. If CanDraw() is false, we
847 // will indicate success=false to the caller, but we must still signal
848 // completion to avoid deadlock.
849
850 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
851 // frame, so can only be used when such a frame is possible. Since
852 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
853 // CanDraw() as well.
854
855 LayerTreeHostImpl::FrameData frame;
856 bool draw_frame = false;
857
858 if (impl().layer_tree_host_impl->CanDraw()) {
859 result = impl().layer_tree_host_impl->PrepareToDraw(&frame);
860 draw_frame = forced_draw || result == DRAW_SUCCESS;
861 } else {
862 result = DRAW_ABORTED_CANT_DRAW;
863 }
864
865 if (draw_frame) {
866 impl().layer_tree_host_impl->DrawLayers(&frame);
867 result = DRAW_SUCCESS;
868 } else {
869 DCHECK_NE(DRAW_SUCCESS, result);
870 }
871 impl().layer_tree_host_impl->DidDrawAllLayers(frame);
872
873 bool start_ready_animations = draw_frame;
874 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations);
875
876 if (draw_frame)
877 impl().layer_tree_host_impl->SwapBuffers(frame);
878
879 // Tell the main thread that the the newly-commited frame was drawn.
880 if (impl().next_frame_is_newly_committed_frame) {
881 impl().next_frame_is_newly_committed_frame = false;
882 impl().channel_impl->DidCommitAndDrawFrame();
883 }
884
885 DCHECK_NE(INVALID_RESULT, result);
886 return result;
887 }
888
889 void ThreadProxy::ScheduledActionPrepareTiles() {
890 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionPrepareTiles");
891 impl().layer_tree_host_impl->PrepareTiles();
892 }
893
894 DrawResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
895 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
896
897 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to
898 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should
899 // never generate this call when it can't draw.
900 DCHECK(impl().layer_tree_host_impl->CanDraw());
901
902 bool forced_draw = false;
903 return DrawSwapInternal(forced_draw);
904 }
905
906 DrawResult ThreadProxy::ScheduledActionDrawAndSwapForced() {
907 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced");
908 bool forced_draw = true;
909 return DrawSwapInternal(forced_draw);
910 }
911
912 void ThreadProxy::ScheduledActionInvalidateOutputSurface() {
913 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionInvalidateOutputSurface");
914 DCHECK(impl().layer_tree_host_impl->output_surface());
915 impl().layer_tree_host_impl->output_surface()->Invalidate();
916 }
917
918 void ThreadProxy::DidFinishImplFrame() {
919 impl().layer_tree_host_impl->DidFinishImplFrame();
920 }
921
922 void ThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) {
923 NOTREACHED() << "Only used by SingleThreadProxy";
924 }
925
926 void ThreadProxy::SetAuthoritativeVSyncInterval(
927 const base::TimeDelta& interval) {
928 NOTREACHED() << "Only used by SingleThreadProxy";
929 }
930
931 void ThreadProxy::DidCommitAndDrawFrame() {
932 DCHECK(task_runner_provider_->IsMainThread());
933 main().layer_tree_host->DidCommitAndDrawFrame();
934 }
935
936 void ThreadProxy::DidCompleteSwapBuffers() {
937 DCHECK(task_runner_provider_->IsMainThread());
938 main().layer_tree_host->DidCompleteSwapBuffers();
939 }
940
941 void ThreadProxy::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events) {
942 TRACE_EVENT0("cc", "ThreadProxy::SetAnimationEvents");
943 DCHECK(task_runner_provider_->IsMainThread());
944 main().layer_tree_host->SetAnimationEvents(events.Pass());
945 }
946
947 void ThreadProxy::InitializeImplOnImpl(CompletionEvent* completion,
948 LayerTreeHost* layer_tree_host) {
949 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread");
950 DCHECK(task_runner_provider_->IsImplThread());
951 DCHECK(task_runner_provider_->IsMainThreadBlocked());
952 DCHECK(layer_tree_host);
953
954 // TODO(khushalsagar): ThreadedChannel will create ProxyImpl here and pass a
955 // reference to itself.
956 impl().channel_impl = threaded_channel_.get();
957
958 impl().layer_tree_host_impl = layer_tree_host->CreateLayerTreeHostImpl(this);
959
960 SchedulerSettings scheduler_settings(
961 layer_tree_host->settings().ToSchedulerSettings());
962
963 scoped_ptr<CompositorTimingHistory> compositor_timing_history(
964 new CompositorTimingHistory(CompositorTimingHistory::RENDERER_UMA,
965 impl().rendering_stats_instrumentation));
966
967 impl().scheduler =
968 Scheduler::Create(this, scheduler_settings, impl().layer_tree_host_id,
969 task_runner_provider_->ImplThreadTaskRunner(),
970 impl().external_begin_frame_source.get(),
971 compositor_timing_history.Pass());
972
973 DCHECK_EQ(impl().scheduler->visible(),
974 impl().layer_tree_host_impl->visible());
975 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr();
976 completion->Signal();
977 }
978
979 void ThreadProxy::InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) {
980 TRACE_EVENT0("cc", "ThreadProxy::InitializeOutputSurfaceOnImplThread");
981 DCHECK(task_runner_provider_->IsImplThread());
982
983 LayerTreeHostImpl* host_impl = impl().layer_tree_host_impl.get();
984 bool success = host_impl->InitializeRenderer(output_surface);
985 RendererCapabilities capabilities;
986 if (success) {
987 capabilities =
988 host_impl->GetRendererCapabilities().MainThreadCapabilities();
989 }
990
991 impl().channel_impl->DidInitializeOutputSurface(success, capabilities);
992
993 if (success)
994 impl().scheduler->DidCreateAndInitializeOutputSurface();
995 }
996
997 void ThreadProxy::ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) {
998 DCHECK(task_runner_provider_->IsImplThread());
999
1000 // Unlike DidLoseOutputSurfaceOnImplThread, we don't need to call
1001 // LayerTreeHost::DidLoseOutputSurface since it already knows.
1002 impl().scheduler->DidLoseOutputSurface();
1003 impl().layer_tree_host_impl->ReleaseOutputSurface();
1004 completion->Signal();
1005 }
1006
1007 void ThreadProxy::FinishGLOnImpl(CompletionEvent* completion) {
1008 TRACE_EVENT0("cc", "ThreadProxy::FinishGLOnImplThread");
1009 DCHECK(task_runner_provider_->IsImplThread());
1010 if (impl().layer_tree_host_impl->output_surface()) {
1011 ContextProvider* context_provider =
1012 impl().layer_tree_host_impl->output_surface()->context_provider();
1013 if (context_provider)
1014 context_provider->ContextGL()->Finish();
1015 }
1016 completion->Signal();
1017 }
1018
1019 void ThreadProxy::LayerTreeHostClosedOnImpl(CompletionEvent* completion) {
1020 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread");
1021 DCHECK(task_runner_provider_->IsImplThread());
1022 DCHECK(task_runner_provider_->IsMainThreadBlocked());
1023 impl().scheduler = nullptr;
1024 impl().external_begin_frame_source = nullptr;
1025 impl().layer_tree_host_impl = nullptr;
1026 impl().weak_factory.InvalidateWeakPtrs();
1027 // We need to explicitly shutdown the notifier to destroy any weakptrs it is
1028 // holding while still on the compositor thread. This also ensures any
1029 // callbacks holding a ThreadProxy pointer are cancelled.
1030 impl().smoothness_priority_expiration_notifier.Shutdown();
1031 completion->Signal();
1032 }
1033
1034 bool ThreadProxy::MainFrameWillHappenForTesting() {
1035 DCHECK(task_runner_provider_->IsMainThread());
1036 bool main_frame_will_happen = false;
1037 {
1038 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
1039 CompletionEvent completion;
1040 main().channel_main->MainFrameWillHappenOnImplForTesting(
1041 &completion, &main_frame_will_happen);
1042 completion.Wait();
1043 }
1044 return main_frame_will_happen;
1045 }
1046
1047 void ThreadProxy::SetChildrenNeedBeginFrames(bool children_need_begin_frames) {
1048 NOTREACHED() << "Only used by SingleThreadProxy";
1049 }
1050
1051 void ThreadProxy::MainFrameWillHappenOnImplForTesting(
1052 CompletionEvent* completion,
1053 bool* main_frame_will_happen) {
1054 DCHECK(task_runner_provider_->IsImplThread());
1055 if (impl().layer_tree_host_impl->output_surface()) {
1056 *main_frame_will_happen = impl().scheduler->MainFrameForTestingWillHappen();
1057 } else {
1058 *main_frame_will_happen = false;
1059 }
1060 completion->Signal();
1061 }
1062
1063 void ThreadProxy::RenewTreePriority() {
1064 DCHECK(task_runner_provider_->IsImplThread());
1065 bool smoothness_takes_priority =
1066 impl().layer_tree_host_impl->pinch_gesture_active() ||
1067 impl().layer_tree_host_impl->page_scale_animation_active() ||
1068 impl().layer_tree_host_impl->IsActivelyScrolling();
1069
1070 // Schedule expiration if smoothness currently takes priority.
1071 if (smoothness_takes_priority)
1072 impl().smoothness_priority_expiration_notifier.Schedule();
1073
1074 // We use the same priority for both trees by default.
1075 TreePriority priority = SAME_PRIORITY_FOR_BOTH_TREES;
1076
1077 // Smoothness takes priority if we have an expiration for it scheduled.
1078 if (impl().smoothness_priority_expiration_notifier.HasPendingNotification())
1079 priority = SMOOTHNESS_TAKES_PRIORITY;
1080
1081 // New content always takes priority when there is an invalid viewport size or
1082 // ui resources have been evicted.
1083 if (impl().layer_tree_host_impl->active_tree()->ViewportSizeInvalid() ||
1084 impl().layer_tree_host_impl->EvictedUIResourcesExist() ||
1085 impl().input_throttled_until_commit) {
1086 // Once we enter NEW_CONTENTS_TAKES_PRIORITY mode, visible tiles on active
1087 // tree might be freed. We need to set RequiresHighResToDraw to ensure that
1088 // high res tiles will be required to activate pending tree.
1089 impl().layer_tree_host_impl->SetRequiresHighResToDraw();
1090 priority = NEW_CONTENT_TAKES_PRIORITY;
1091 }
1092
1093 impl().layer_tree_host_impl->SetTreePriority(priority);
1094
1095 // Only put the scheduler in impl latency prioritization mode if we don't
1096 // have a scroll listener. This gives the scroll listener a better chance of
1097 // handling scroll updates within the same frame. The tree itself is still
1098 // kept in prefer smoothness mode to allow checkerboarding.
1099 impl().scheduler->SetImplLatencyTakesPriority(
1100 priority == SMOOTHNESS_TAKES_PRIORITY &&
1101 !impl().layer_tree_host_impl->scroll_affects_scroll_handler());
1102
1103 // Notify the the client of this compositor via the output surface.
1104 // TODO(epenner): Route this to compositor-thread instead of output-surface
1105 // after GTFO refactor of compositor-thread (http://crbug/170828).
1106 if (impl().layer_tree_host_impl->output_surface()) {
1107 impl()
1108 .layer_tree_host_impl->output_surface()
1109 ->UpdateSmoothnessTakesPriority(priority == SMOOTHNESS_TAKES_PRIORITY);
1110 }
1111 }
1112
1113 void ThreadProxy::PostDelayedAnimationTaskOnImplThread(
1114 const base::Closure& task,
1115 base::TimeDelta delay) {
1116 task_runner_provider_->ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE,
1117 task, delay);
1118 }
1119
1120 void ThreadProxy::DidActivateSyncTree() {
1121 TRACE_EVENT0("cc", "ThreadProxy::DidActivateSyncTreeOnImplThread");
1122 DCHECK(task_runner_provider_->IsImplThread());
1123
1124 if (impl().next_commit_waits_for_activation) {
1125 TRACE_EVENT_INSTANT0(
1126 "cc", "ReleaseCommitbyActivation", TRACE_EVENT_SCOPE_THREAD);
1127 DCHECK(impl().commit_completion_event);
1128 impl().commit_completion_event->Signal();
1129 impl().commit_completion_event = nullptr;
1130 impl().next_commit_waits_for_activation = false;
1131 }
1132
1133 impl().last_processed_begin_main_frame_args =
1134 impl().last_begin_main_frame_args;
1135 }
1136
1137 void ThreadProxy::WillPrepareTiles() {
1138 DCHECK(task_runner_provider_->IsImplThread());
1139 impl().scheduler->WillPrepareTiles();
1140 }
1141
1142 void ThreadProxy::DidPrepareTiles() {
1143 DCHECK(task_runner_provider_->IsImplThread());
1144 impl().scheduler->DidPrepareTiles();
1145 }
1146
1147 void ThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
1148 DCHECK(task_runner_provider_->IsImplThread());
1149 impl().channel_impl->DidCompletePageScaleAnimation();
1150 }
1151
1152 void ThreadProxy::OnDrawForOutputSurface() {
1153 DCHECK(task_runner_provider_->IsImplThread());
1154 impl().scheduler->OnDrawForOutputSurface();
1155 }
1156
1157 void ThreadProxy::UpdateTopControlsState(TopControlsState constraints,
1158 TopControlsState current,
1159 bool animate) {
1160 main().channel_main->UpdateTopControlsStateOnImpl(constraints, current,
1161 animate);
1162 }
1163
1164 void ThreadProxy::UpdateTopControlsStateOnImpl(TopControlsState constraints,
1165 TopControlsState current,
1166 bool animate) {
1167 DCHECK(task_runner_provider_->IsImplThread());
1168 impl().layer_tree_host_impl->top_controls_manager()->UpdateTopControlsState(
1169 constraints, current, animate);
1170 }
1171
1172 void ThreadProxy::PostFrameTimingEventsOnImplThread(
1173 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
1174 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
1175 DCHECK(task_runner_provider_->IsImplThread());
1176 impl().channel_impl->PostFrameTimingEventsOnMain(composite_events.Pass(),
1177 main_frame_events.Pass());
1178 }
1179
1180 void ThreadProxy::PostFrameTimingEventsOnMain(
1181 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
1182 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
1183 DCHECK(task_runner_provider_->IsMainThread());
1184 main().layer_tree_host->RecordFrameTimingEvents(composite_events.Pass(),
1185 main_frame_events.Pass());
1186 }
1187
1188 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() {
1189 return main_thread_weak_ptr_;
1190 }
1191
1192 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() {
1193 return impl_thread_weak_ptr_;
1194 }
1195
1196 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698