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/layer_tree_host.h"
11 #include "base/atomic_sequence_num.h"
12 #include "base/auto_reset.h"
13 #include "base/bind.h"
14 #include "base/command_line.h"
15 #include "base/location.h"
16 #include "base/metrics/histogram.h"
17 #include "base/single_thread_task_runner.h"
18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/thread_task_runner_handle.h"
21 #include "base/trace_event/trace_event.h"
22 #include "base/trace_event/trace_event_argument.h"
23 #include "cc/animation/animation_registrar.h"
24 #include "cc/animation/layer_animation_controller.h"
25 #include "cc/base/math_util.h"
26 #include "cc/debug/devtools_instrumentation.h"
27 #include "cc/debug/frame_viewer_instrumentation.h"
28 #include "cc/debug/rendering_stats_instrumentation.h"
29 #include "cc/input/layer_selection_bound.h"
30 #include "cc/input/page_scale_animation.h"
31 #include "cc/input/top_controls_manager.h"
32 #include "cc/layers/heads_up_display_layer.h"
33 #include "cc/layers/heads_up_display_layer_impl.h"
34 #include "cc/layers/layer.h"
35 #include "cc/layers/layer_iterator.h"
36 #include "cc/layers/painted_scrollbar_layer.h"
37 #include "cc/layers/render_surface.h"
38 #include "cc/resources/prioritized_resource_manager.h"
39 #include "cc/resources/ui_resource_request.h"
40 #include "cc/scheduler/begin_frame_source.h"
41 #include "cc/trees/draw_property_utils.h"
42 #include "cc/trees/layer_tree_host_client.h"
43 #include "cc/trees/layer_tree_host_common.h"
44 #include "cc/trees/layer_tree_host_impl.h"
45 #include "cc/trees/layer_tree_impl.h"
46 #include "cc/trees/occlusion_tracker.h"
47 #include "cc/trees/single_thread_proxy.h"
48 #include "cc/trees/thread_proxy.h"
49 #include "cc/trees/tree_synchronizer.h"
50 #include "ui/gfx/geometry/size_conversions.h"
51 #include "ui/gfx/geometry/vector2d_conversions.h"
54 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number
;
59 LayerTreeHost::InitParams::InitParams() {
62 LayerTreeHost::InitParams::~InitParams() {
65 scoped_ptr
<LayerTreeHost
> LayerTreeHost::CreateThreaded(
66 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
,
68 DCHECK(params
->main_task_runner
.get());
69 DCHECK(impl_task_runner
.get());
70 DCHECK(params
->settings
);
71 scoped_ptr
<LayerTreeHost
> layer_tree_host(new LayerTreeHost(params
));
72 layer_tree_host
->InitializeThreaded(
73 params
->main_task_runner
, impl_task_runner
,
74 params
->external_begin_frame_source
.Pass());
75 return layer_tree_host
.Pass();
78 scoped_ptr
<LayerTreeHost
> LayerTreeHost::CreateSingleThreaded(
79 LayerTreeHostSingleThreadClient
* single_thread_client
,
81 DCHECK(params
->settings
);
82 scoped_ptr
<LayerTreeHost
> layer_tree_host(new LayerTreeHost(params
));
83 layer_tree_host
->InitializeSingleThreaded(
84 single_thread_client
, params
->main_task_runner
,
85 params
->external_begin_frame_source
.Pass());
86 return layer_tree_host
.Pass();
89 LayerTreeHost::LayerTreeHost(InitParams
* params
)
90 : micro_benchmark_controller_(this),
91 next_ui_resource_id_(1),
92 inside_begin_main_frame_(false),
93 needs_full_tree_sync_(true),
94 needs_meta_info_recomputation_(true),
95 client_(params
->client
),
96 source_frame_number_(0),
97 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
98 output_surface_lost_(true),
99 settings_(*params
->settings
),
100 debug_state_(settings_
.initial_debug_state
),
101 top_controls_shrink_blink_size_(false),
102 top_controls_height_(0.f
),
103 top_controls_shown_ratio_(0.f
),
104 device_scale_factor_(1.f
),
106 page_scale_factor_(1.f
),
107 min_page_scale_factor_(1.f
),
108 max_page_scale_factor_(1.f
),
109 has_gpu_rasterization_trigger_(false),
110 content_is_suitable_for_gpu_rasterization_(true),
111 gpu_rasterization_histogram_recorded_(false),
112 background_color_(SK_ColorWHITE
),
113 has_transparent_background_(false),
114 partial_texture_update_requests_(0),
115 did_complete_scale_animation_(false),
116 in_paint_layer_contents_(false),
117 id_(s_layer_tree_host_sequence_number
.GetNext() + 1),
118 next_commit_forces_redraw_(false),
119 shared_bitmap_manager_(params
->shared_bitmap_manager
),
120 gpu_memory_buffer_manager_(params
->gpu_memory_buffer_manager
),
121 task_graph_runner_(params
->task_graph_runner
),
122 surface_id_namespace_(0u),
123 next_surface_sequence_(1u) {
124 if (settings_
.accelerated_animation_enabled
)
125 animation_registrar_
= AnimationRegistrar::Create();
126 rendering_stats_instrumentation_
->set_record_rendering_stats(
127 debug_state_
.RecordRenderingStats());
130 void LayerTreeHost::InitializeThreaded(
131 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
132 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
,
133 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
) {
134 InitializeProxy(ThreadProxy::Create(this,
137 external_begin_frame_source
.Pass()));
140 void LayerTreeHost::InitializeSingleThreaded(
141 LayerTreeHostSingleThreadClient
* single_thread_client
,
142 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
143 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
) {
145 SingleThreadProxy::Create(this,
146 single_thread_client
,
148 external_begin_frame_source
.Pass()));
151 void LayerTreeHost::InitializeForTesting(scoped_ptr
<Proxy
> proxy_for_testing
) {
152 InitializeProxy(proxy_for_testing
.Pass());
155 void LayerTreeHost::InitializeProxy(scoped_ptr
<Proxy
> proxy
) {
156 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
158 proxy_
= proxy
.Pass();
160 if (settings_
.accelerated_animation_enabled
) {
161 animation_registrar_
->set_supports_scroll_animations(
162 proxy_
->SupportsImplScrolling());
166 LayerTreeHost::~LayerTreeHost() {
167 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
169 if (root_layer_
.get())
170 root_layer_
->SetLayerTreeHost(NULL
);
172 DCHECK(swap_promise_monitor_
.empty());
174 BreakSwapPromises(SwapPromise::COMMIT_FAILS
);
177 DCHECK(proxy_
->IsMainThread());
181 // We must clear any pointers into the layer tree prior to destroying it.
182 RegisterViewportLayers(NULL
, NULL
, NULL
, NULL
);
184 if (root_layer_
.get()) {
185 // The layer tree must be destroyed before the layer tree host. We've
186 // made a contract with our animation controllers that the registrar
187 // will outlive them, and we must make good.
192 void LayerTreeHost::SetLayerTreeHostClientReady() {
193 proxy_
->SetLayerTreeHostClientReady();
196 void LayerTreeHost::DeleteContentsTexturesOnImplThread(
197 ResourceProvider
* resource_provider
) {
198 DCHECK(proxy_
->IsImplThread());
199 if (contents_texture_manager_
)
200 contents_texture_manager_
->ClearAllMemory(resource_provider
);
203 void LayerTreeHost::WillBeginMainFrame() {
204 devtools_instrumentation::WillBeginMainThreadFrame(id(),
205 source_frame_number());
206 client_
->WillBeginMainFrame();
209 void LayerTreeHost::DidBeginMainFrame() {
210 client_
->DidBeginMainFrame();
213 void LayerTreeHost::BeginMainFrameNotExpectedSoon() {
214 client_
->BeginMainFrameNotExpectedSoon();
217 void LayerTreeHost::BeginMainFrame(const BeginFrameArgs
& args
) {
218 inside_begin_main_frame_
= true;
219 client_
->BeginMainFrame(args
);
220 inside_begin_main_frame_
= false;
223 void LayerTreeHost::DidStopFlinging() {
224 proxy_
->MainThreadHasStoppedFlinging();
227 void LayerTreeHost::Layout() {
231 void LayerTreeHost::BeginCommitOnImplThread(LayerTreeHostImpl
* host_impl
) {
232 DCHECK(proxy_
->IsImplThread());
233 TRACE_EVENT0("cc", "LayerTreeHost::CommitTo");
236 // This function commits the LayerTreeHost to an impl tree. When modifying
237 // this function, keep in mind that the function *runs* on the impl thread! Any
238 // code that is logically a main thread operation, e.g. deletion of a Layer,
239 // should be delayed until the LayerTreeHost::CommitComplete, which will run
240 // after the commit, but on the main thread.
241 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl
* host_impl
) {
242 DCHECK(proxy_
->IsImplThread());
244 // If there are linked evicted backings, these backings' resources may be put
245 // into the impl tree, so we can't draw yet. Determine this before clearing
246 // all evicted backings.
247 bool new_impl_tree_has_no_evicted_resources
= false;
248 if (contents_texture_manager_
) {
249 new_impl_tree_has_no_evicted_resources
=
250 !contents_texture_manager_
->LinkedEvictedBackingsExist();
252 // If the memory limit has been increased since this now-finishing
253 // commit began, and the extra now-available memory would have been used,
254 // then request another commit.
255 if (contents_texture_manager_
->MaxMemoryLimitBytes() <
256 host_impl
->memory_allocation_limit_bytes() &&
257 contents_texture_manager_
->MaxMemoryLimitBytes() <
258 contents_texture_manager_
->MaxMemoryNeededBytes()) {
259 host_impl
->SetNeedsCommit();
262 host_impl
->set_max_memory_needed_bytes(
263 contents_texture_manager_
->MaxMemoryNeededBytes());
265 contents_texture_manager_
->UpdateBackingsState(
266 host_impl
->resource_provider());
267 contents_texture_manager_
->ReduceMemory(host_impl
->resource_provider());
271 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace
);
273 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
275 LayerTreeHostCommon::CallFunctionForSubtree(
276 root_layer(), [](Layer
* layer
) { layer
->DidBeginTracing(); });
279 LayerTreeImpl
* sync_tree
= host_impl
->sync_tree();
281 if (next_commit_forces_redraw_
) {
282 sync_tree
->ForceRedrawNextActivation();
283 next_commit_forces_redraw_
= false;
286 sync_tree
->set_source_frame_number(source_frame_number());
288 if (needs_full_tree_sync_
) {
289 sync_tree
->SetRootLayer(TreeSynchronizer::SynchronizeTrees(
290 root_layer(), sync_tree
->DetachLayerTree(), sync_tree
));
292 sync_tree
->set_needs_full_tree_sync(needs_full_tree_sync_
);
293 needs_full_tree_sync_
= false;
295 if (hud_layer_
.get()) {
296 LayerImpl
* hud_impl
= LayerTreeHostCommon::FindLayerInSubtree(
297 sync_tree
->root_layer(), hud_layer_
->id());
298 sync_tree
->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl
*>(hud_impl
));
300 sync_tree
->set_hud_layer(NULL
);
303 sync_tree
->set_background_color(background_color_
);
304 sync_tree
->set_has_transparent_background(has_transparent_background_
);
306 if (page_scale_layer_
.get() && inner_viewport_scroll_layer_
.get()) {
307 sync_tree
->SetViewportLayersFromIds(
308 overscroll_elasticity_layer_
.get() ? overscroll_elasticity_layer_
->id()
310 page_scale_layer_
->id(), inner_viewport_scroll_layer_
->id(),
311 outer_viewport_scroll_layer_
.get() ? outer_viewport_scroll_layer_
->id()
312 : Layer::INVALID_ID
);
313 DCHECK(inner_viewport_scroll_layer_
->IsContainerForFixedPositionLayers());
315 sync_tree
->ClearViewportLayers();
318 sync_tree
->RegisterSelection(selection_
);
320 sync_tree
->PushPageScaleFromMainThread(
321 page_scale_factor_
, min_page_scale_factor_
, max_page_scale_factor_
);
322 sync_tree
->elastic_overscroll()->PushFromMainThread(elastic_overscroll_
);
323 if (sync_tree
->IsActiveTree())
324 sync_tree
->elastic_overscroll()->PushPendingToActive();
326 sync_tree
->PassSwapPromises(&swap_promise_list_
);
328 sync_tree
->set_top_controls_shrink_blink_size(
329 top_controls_shrink_blink_size_
);
330 sync_tree
->set_top_controls_height(top_controls_height_
);
331 sync_tree
->PushTopControlsFromMainThread(top_controls_shown_ratio_
);
333 host_impl
->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_
);
334 host_impl
->SetContentIsSuitableForGpuRasterization(
335 content_is_suitable_for_gpu_rasterization_
);
336 RecordGpuRasterizationHistogram();
338 host_impl
->SetViewportSize(device_viewport_size_
);
339 host_impl
->SetDeviceScaleFactor(device_scale_factor_
);
340 host_impl
->SetDebugState(debug_state_
);
341 if (pending_page_scale_animation_
) {
342 sync_tree
->SetPendingPageScaleAnimation(
343 pending_page_scale_animation_
.Pass());
346 if (!ui_resource_request_queue_
.empty()) {
347 sync_tree
->set_ui_resource_request_queue(ui_resource_request_queue_
);
348 ui_resource_request_queue_
.clear();
351 DCHECK(!sync_tree
->ViewportSizeInvalid());
353 if (new_impl_tree_has_no_evicted_resources
) {
354 if (sync_tree
->ContentsTexturesPurged())
355 sync_tree
->ResetContentsTexturesPurged();
358 sync_tree
->set_has_ever_been_drawn(false);
359 sync_tree
->SetPropertyTrees(property_trees_
);
362 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
363 TreeSynchronizer::PushProperties(root_layer(), sync_tree
->root_layer());
366 micro_benchmark_controller_
.ScheduleImplBenchmarks(host_impl
);
369 void LayerTreeHost::WillCommit() {
370 client_
->WillCommit();
373 void LayerTreeHost::UpdateHudLayer() {
374 if (debug_state_
.ShowHudInfo()) {
375 if (!hud_layer_
.get())
376 hud_layer_
= HeadsUpDisplayLayer::Create();
378 if (root_layer_
.get() && !hud_layer_
->parent())
379 root_layer_
->AddChild(hud_layer_
);
380 } else if (hud_layer_
.get()) {
381 hud_layer_
->RemoveFromParent();
386 void LayerTreeHost::CommitComplete() {
387 source_frame_number_
++;
388 client_
->DidCommit();
389 if (did_complete_scale_animation_
) {
390 client_
->DidCompletePageScaleAnimation();
391 did_complete_scale_animation_
= false;
395 void LayerTreeHost::SetOutputSurface(scoped_ptr
<OutputSurface
> surface
) {
396 TRACE_EVENT0("cc", "LayerTreeHost::SetOutputSurface");
397 DCHECK(output_surface_lost_
);
400 proxy_
->SetOutputSurface(surface
.Pass());
403 void LayerTreeHost::RequestNewOutputSurface() {
404 client_
->RequestNewOutputSurface();
407 void LayerTreeHost::DidInitializeOutputSurface() {
408 output_surface_lost_
= false;
410 if (!contents_texture_manager_
&& !settings_
.impl_side_painting
) {
411 contents_texture_manager_
=
412 PrioritizedResourceManager::Create(proxy_
.get());
413 surface_memory_placeholder_
=
414 contents_texture_manager_
->CreateTexture(gfx::Size(), RGBA_8888
);
418 LayerTreeHostCommon::CallFunctionForSubtree(
419 root_layer(), [](Layer
* layer
) { layer
->OnOutputSurfaceCreated(); });
422 client_
->DidInitializeOutputSurface();
425 void LayerTreeHost::DidFailToInitializeOutputSurface() {
426 DCHECK(output_surface_lost_
);
427 client_
->DidFailToInitializeOutputSurface();
430 scoped_ptr
<LayerTreeHostImpl
> LayerTreeHost::CreateLayerTreeHostImpl(
431 LayerTreeHostImplClient
* client
) {
432 DCHECK(proxy_
->IsImplThread());
433 scoped_ptr
<LayerTreeHostImpl
> host_impl
= LayerTreeHostImpl::Create(
434 settings_
, client
, proxy_
.get(), rendering_stats_instrumentation_
.get(),
435 shared_bitmap_manager_
, gpu_memory_buffer_manager_
, task_graph_runner_
,
437 host_impl
->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_
);
438 host_impl
->SetContentIsSuitableForGpuRasterization(
439 content_is_suitable_for_gpu_rasterization_
);
440 shared_bitmap_manager_
= NULL
;
441 gpu_memory_buffer_manager_
= NULL
;
442 task_graph_runner_
= NULL
;
443 top_controls_manager_weak_ptr_
=
444 host_impl
->top_controls_manager()->AsWeakPtr();
445 input_handler_weak_ptr_
= host_impl
->AsWeakPtr();
446 return host_impl
.Pass();
449 void LayerTreeHost::DidLoseOutputSurface() {
450 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface");
451 DCHECK(proxy_
->IsMainThread());
453 if (output_surface_lost_
)
456 output_surface_lost_
= true;
460 void LayerTreeHost::FinishAllRendering() {
461 proxy_
->FinishAllRendering();
464 void LayerTreeHost::SetDeferCommits(bool defer_commits
) {
465 proxy_
->SetDeferCommits(defer_commits
);
468 void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
469 std::stack
<Layer
*> layer_stack
;
470 layer_stack
.push(root_layer());
471 while (!layer_stack
.empty()) {
472 Layer
* current_layer
= layer_stack
.top();
474 current_layer
->SetNeedsDisplay();
475 for (unsigned int i
= 0; i
< current_layer
->children().size(); i
++) {
476 layer_stack
.push(current_layer
->child_at(i
));
481 const RendererCapabilities
& LayerTreeHost::GetRendererCapabilities() const {
482 return proxy_
->GetRendererCapabilities();
485 void LayerTreeHost::SetNeedsAnimate() {
486 proxy_
->SetNeedsAnimate();
487 NotifySwapPromiseMonitorsOfSetNeedsCommit();
490 void LayerTreeHost::SetNeedsUpdateLayers() {
491 proxy_
->SetNeedsUpdateLayers();
492 NotifySwapPromiseMonitorsOfSetNeedsCommit();
495 void LayerTreeHost::SetNeedsCommit() {
496 if (!prepaint_callback_
.IsCancelled()) {
497 TRACE_EVENT_INSTANT0("cc",
498 "LayerTreeHost::SetNeedsCommit::cancel prepaint",
499 TRACE_EVENT_SCOPE_THREAD
);
500 prepaint_callback_
.Cancel();
502 proxy_
->SetNeedsCommit();
503 NotifySwapPromiseMonitorsOfSetNeedsCommit();
506 void LayerTreeHost::SetNeedsFullTreeSync() {
507 needs_full_tree_sync_
= true;
508 needs_meta_info_recomputation_
= true;
510 property_trees_
.needs_rebuild
= true;
514 void LayerTreeHost::SetNeedsMetaInfoRecomputation(bool needs_recomputation
) {
515 needs_meta_info_recomputation_
= needs_recomputation
;
518 void LayerTreeHost::SetNeedsRedraw() {
519 SetNeedsRedrawRect(gfx::Rect(device_viewport_size_
));
522 void LayerTreeHost::SetNeedsRedrawRect(const gfx::Rect
& damage_rect
) {
523 proxy_
->SetNeedsRedraw(damage_rect
);
526 bool LayerTreeHost::CommitRequested() const {
527 return proxy_
->CommitRequested();
530 bool LayerTreeHost::BeginMainFrameRequested() const {
531 return proxy_
->BeginMainFrameRequested();
535 void LayerTreeHost::SetNextCommitWaitsForActivation() {
536 proxy_
->SetNextCommitWaitsForActivation();
539 void LayerTreeHost::SetNextCommitForcesRedraw() {
540 next_commit_forces_redraw_
= true;
543 void LayerTreeHost::SetAnimationEvents(
544 scoped_ptr
<AnimationEventsVector
> events
) {
545 DCHECK(proxy_
->IsMainThread());
546 animation_registrar_
->SetAnimationEvents(events
.Pass());
549 void LayerTreeHost::SetRootLayer(scoped_refptr
<Layer
> root_layer
) {
550 if (root_layer_
.get() == root_layer
.get())
553 if (root_layer_
.get())
554 root_layer_
->SetLayerTreeHost(NULL
);
555 root_layer_
= root_layer
;
556 if (root_layer_
.get()) {
557 DCHECK(!root_layer_
->parent());
558 root_layer_
->SetLayerTreeHost(this);
561 if (hud_layer_
.get())
562 hud_layer_
->RemoveFromParent();
564 // Reset gpu rasterization flag.
565 // This flag is sticky until a new tree comes along.
566 content_is_suitable_for_gpu_rasterization_
= true;
567 gpu_rasterization_histogram_recorded_
= false;
569 SetNeedsFullTreeSync();
572 void LayerTreeHost::SetDebugState(const LayerTreeDebugState
& debug_state
) {
573 LayerTreeDebugState new_debug_state
=
574 LayerTreeDebugState::Unite(settings_
.initial_debug_state
, debug_state
);
576 if (LayerTreeDebugState::Equal(debug_state_
, new_debug_state
))
579 debug_state_
= new_debug_state
;
581 rendering_stats_instrumentation_
->set_record_rendering_stats(
582 debug_state_
.RecordRenderingStats());
585 proxy_
->SetDebugState(debug_state
);
588 void LayerTreeHost::SetHasGpuRasterizationTrigger(bool has_trigger
) {
589 if (has_trigger
== has_gpu_rasterization_trigger_
)
592 has_gpu_rasterization_trigger_
= has_trigger
;
593 TRACE_EVENT_INSTANT1("cc",
594 "LayerTreeHost::SetHasGpuRasterizationTrigger",
595 TRACE_EVENT_SCOPE_THREAD
,
597 has_gpu_rasterization_trigger_
);
600 void LayerTreeHost::SetViewportSize(const gfx::Size
& device_viewport_size
) {
601 if (device_viewport_size
== device_viewport_size_
)
604 device_viewport_size_
= device_viewport_size
;
606 property_trees_
.needs_rebuild
= true;
610 void LayerTreeHost::SetTopControlsHeight(float height
, bool shrink
) {
611 if (top_controls_height_
== height
&&
612 top_controls_shrink_blink_size_
== shrink
)
615 top_controls_height_
= height
;
616 top_controls_shrink_blink_size_
= shrink
;
620 void LayerTreeHost::SetTopControlsShownRatio(float ratio
) {
621 if (top_controls_shown_ratio_
== ratio
)
624 top_controls_shown_ratio_
= ratio
;
628 void LayerTreeHost::ApplyPageScaleDeltaFromImplSide(float page_scale_delta
) {
629 DCHECK(CommitRequested());
630 if (page_scale_delta
== 1.f
)
632 page_scale_factor_
*= page_scale_delta
;
633 property_trees_
.needs_rebuild
= true;
636 void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor
,
637 float min_page_scale_factor
,
638 float max_page_scale_factor
) {
639 if (page_scale_factor
== page_scale_factor_
&&
640 min_page_scale_factor
== min_page_scale_factor_
&&
641 max_page_scale_factor
== max_page_scale_factor_
)
644 page_scale_factor_
= page_scale_factor
;
645 min_page_scale_factor_
= min_page_scale_factor
;
646 max_page_scale_factor_
= max_page_scale_factor
;
647 property_trees_
.needs_rebuild
= true;
651 void LayerTreeHost::SetVisible(bool visible
) {
652 if (visible_
== visible
)
657 proxy_
->SetVisible(visible
);
660 void LayerTreeHost::SetThrottleFrameProduction(bool throttle
) {
661 proxy_
->SetThrottleFrameProduction(throttle
);
664 void LayerTreeHost::StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
667 base::TimeDelta duration
) {
668 pending_page_scale_animation_
.reset(
669 new PendingPageScaleAnimation(
678 void LayerTreeHost::NotifyInputThrottledUntilCommit() {
679 proxy_
->NotifyInputThrottledUntilCommit();
682 void LayerTreeHost::Composite(base::TimeTicks frame_begin_time
) {
683 DCHECK(!proxy_
->HasImplThread());
684 // This function is only valid when not using the scheduler.
685 DCHECK(!settings_
.single_thread_proxy_scheduler
);
686 SingleThreadProxy
* proxy
= static_cast<SingleThreadProxy
*>(proxy_
.get());
688 SetLayerTreeHostClientReady();
689 proxy
->CompositeImmediately(frame_begin_time
);
692 bool LayerTreeHost::UpdateLayers(ResourceUpdateQueue
* queue
) {
693 DCHECK(!output_surface_lost_
);
698 DCHECK(!root_layer()->parent());
700 bool result
= UpdateLayers(root_layer(), queue
);
702 micro_benchmark_controller_
.DidUpdateLayers();
704 return result
|| next_commit_forces_redraw_
;
707 void LayerTreeHost::DidCompletePageScaleAnimation() {
708 did_complete_scale_animation_
= true;
711 static Layer
* FindFirstScrollableLayer(Layer
* layer
) {
715 if (layer
->scrollable())
718 for (size_t i
= 0; i
< layer
->children().size(); ++i
) {
719 Layer
* found
= FindFirstScrollableLayer(layer
->children()[i
].get());
727 void LayerTreeHost::RecordGpuRasterizationHistogram() {
728 // Gpu rasterization is only supported when impl-side painting is enabled.
729 if (gpu_rasterization_histogram_recorded_
|| !settings_
.impl_side_painting
)
732 // Record how widely gpu rasterization is enabled.
733 // This number takes device/gpu whitelisting/backlisting into account.
734 // Note that we do not consider the forced gpu rasterization mode, which is
735 // mostly used for debugging purposes.
736 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled",
737 settings_
.gpu_rasterization_enabled
);
738 if (settings_
.gpu_rasterization_enabled
) {
739 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered",
740 has_gpu_rasterization_trigger_
);
741 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationSuitableContent",
742 content_is_suitable_for_gpu_rasterization_
);
743 // Record how many pages actually get gpu rasterization when enabled.
744 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed",
745 (has_gpu_rasterization_trigger_
&&
746 content_is_suitable_for_gpu_rasterization_
));
749 gpu_rasterization_histogram_recorded_
= true;
752 bool LayerTreeHost::UsingSharedMemoryResources() {
753 return GetRendererCapabilities().using_shared_memory_resources
;
756 bool LayerTreeHost::UpdateLayers(Layer
* root_layer
,
757 ResourceUpdateQueue
* queue
) {
758 TRACE_EVENT1("cc", "LayerTreeHost::UpdateLayers",
759 "source_frame_number", source_frame_number());
761 RenderSurfaceLayerList render_surface_layer_list
;
765 Layer
* root_scroll
= FindFirstScrollableLayer(root_layer
);
766 Layer
* page_scale_layer
= page_scale_layer_
.get();
767 if (!page_scale_layer
&& root_scroll
)
768 page_scale_layer
= root_scroll
->parent();
770 if (hud_layer_
.get()) {
771 hud_layer_
->PrepareForCalculateDrawProperties(device_viewport_size(),
772 device_scale_factor_
);
775 bool can_render_to_separate_surface
= true;
776 // TODO(vmpstr): Passing 0 as the current render surface layer list id means
777 // that we won't be able to detect if a layer is part of
778 // |render_surface_layer_list|. Change this if this information is
780 int render_surface_layer_list_id
= 0;
781 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(
782 root_layer
, device_viewport_size(), gfx::Transform(),
783 device_scale_factor_
, page_scale_factor_
, page_scale_layer
,
784 elastic_overscroll_
, overscroll_elasticity_layer_
.get(),
785 GetRendererCapabilities().max_texture_size
, settings_
.can_use_lcd_text
,
786 settings_
.layers_always_allowed_lcd_text
, can_render_to_separate_surface
,
787 settings_
.layer_transforms_should_scale_layer_contents
,
788 settings_
.verify_property_trees
, &render_surface_layer_list
,
789 render_surface_layer_list_id
, &property_trees_
);
791 // This is a temporary state of affairs until impl-side painting is shipped
792 // everywhere and main thread property trees can be used in all cases.
793 // This code here implies that even if verify property trees is on,
794 // no verification will occur and only property trees will be used on the
796 if (using_only_property_trees()) {
797 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::CalcDrawProps");
799 LayerTreeHostCommon::PreCalculateMetaInformation(root_layer
);
801 bool preserves_2d_axis_alignment
= false;
802 gfx::Transform identity_transform
;
803 LayerList update_layer_list
;
805 LayerTreeHostCommon::UpdateRenderSurfaces(
806 root_layer
, can_render_to_separate_surface
, identity_transform
,
807 preserves_2d_axis_alignment
);
809 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"),
810 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees");
811 BuildPropertyTreesAndComputeVisibleRects(
812 root_layer
, page_scale_layer
, page_scale_factor_
,
813 device_scale_factor_
, gfx::Rect(device_viewport_size_
),
814 identity_transform
, &property_trees_
, &update_layer_list
);
817 for (const auto& layer
: update_layer_list
)
818 layer
->SavePaintProperties();
820 base::AutoReset
<bool> painting(&in_paint_layer_contents_
, true);
821 bool did_paint_content
= false;
822 for (const auto& layer
: update_layer_list
) {
823 // TODO(enne): temporarily clobber draw properties visible rect.
824 layer
->draw_properties().visible_content_rect
=
825 layer
->visible_rect_from_property_trees();
826 did_paint_content
|= layer
->Update(queue
, nullptr);
827 content_is_suitable_for_gpu_rasterization_
&=
828 layer
->IsSuitableForGpuRasterization();
830 return did_paint_content
;
834 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::CalcDrawProps");
835 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
838 // Reset partial texture update requests.
839 partial_texture_update_requests_
= 0;
841 bool did_paint_content
= false;
842 bool need_more_updates
= false;
843 PaintLayerContents(render_surface_layer_list
, queue
, &did_paint_content
,
845 if (need_more_updates
) {
846 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::posting prepaint task");
847 prepaint_callback_
.Reset(base::Bind(&LayerTreeHost::TriggerPrepaint
,
848 base::Unretained(this)));
849 static base::TimeDelta prepaint_delay
=
850 base::TimeDelta::FromMilliseconds(100);
851 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
852 FROM_HERE
, prepaint_callback_
.callback(), prepaint_delay
);
855 return did_paint_content
;
858 void LayerTreeHost::TriggerPrepaint() {
859 prepaint_callback_
.Cancel();
860 TRACE_EVENT0("cc", "LayerTreeHost::TriggerPrepaint");
864 void LayerTreeHost::ReduceMemoryUsage() {
868 LayerTreeHostCommon::CallFunctionForSubtree(
869 root_layer(), [](Layer
* layer
) { layer
->ReduceMemoryUsage(); });
872 void LayerTreeHost::SetPrioritiesForSurfaces(size_t surface_memory_bytes
) {
873 DCHECK(surface_memory_placeholder_
);
875 // Surfaces have a place holder for their memory since they are managed
876 // independantly but should still be tracked and reduce other memory usage.
877 surface_memory_placeholder_
->SetTextureManager(
878 contents_texture_manager_
.get());
879 surface_memory_placeholder_
->set_request_priority(
880 PriorityCalculator::RenderSurfacePriority());
881 surface_memory_placeholder_
->SetToSelfManagedMemoryPlaceholder(
882 surface_memory_bytes
);
885 void LayerTreeHost::SetPrioritiesForLayers(
886 const RenderSurfaceLayerList
& update_list
) {
887 PriorityCalculator calculator
;
888 typedef LayerIterator
<Layer
> LayerIteratorType
;
889 LayerIteratorType end
= LayerIteratorType::End(&update_list
);
890 for (LayerIteratorType it
= LayerIteratorType::Begin(&update_list
);
893 if (it
.represents_itself()) {
894 it
->SetTexturePriorities(calculator
);
895 } else if (it
.represents_target_render_surface()) {
896 if (it
->mask_layer())
897 it
->mask_layer()->SetTexturePriorities(calculator
);
898 if (it
->replica_layer() && it
->replica_layer()->mask_layer())
899 it
->replica_layer()->mask_layer()->SetTexturePriorities(calculator
);
904 void LayerTreeHost::PrioritizeTextures(
905 const RenderSurfaceLayerList
& render_surface_layer_list
) {
906 if (!contents_texture_manager_
)
909 contents_texture_manager_
->ClearPriorities();
911 size_t memory_for_render_surfaces_metric
=
912 CalculateMemoryForRenderSurfaces(render_surface_layer_list
);
914 SetPrioritiesForLayers(render_surface_layer_list
);
915 SetPrioritiesForSurfaces(memory_for_render_surfaces_metric
);
917 contents_texture_manager_
->PrioritizeTextures();
920 size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
921 const RenderSurfaceLayerList
& update_list
) {
922 size_t readback_bytes
= 0;
923 size_t contents_texture_bytes
= 0;
925 // Start iteration at 1 to skip the root surface as it does not have a texture
927 for (size_t i
= 1; i
< update_list
.size(); ++i
) {
928 Layer
* render_surface_layer
= update_list
.at(i
);
929 RenderSurface
* render_surface
= render_surface_layer
->render_surface();
932 Resource::MemorySizeBytes(render_surface
->content_rect().size(),
934 contents_texture_bytes
+= bytes
;
936 if (render_surface_layer
->background_filters().IsEmpty() &&
937 render_surface_layer
->uses_default_blend_mode())
940 if (!readback_bytes
) {
941 readback_bytes
= Resource::MemorySizeBytes(device_viewport_size_
,
945 return readback_bytes
+ contents_texture_bytes
;
948 void LayerTreeHost::PaintMasksForRenderSurface(Layer
* render_surface_layer
,
949 ResourceUpdateQueue
* queue
,
950 bool* did_paint_content
,
951 bool* need_more_updates
) {
952 // Note: Masks and replicas only exist for layers that own render surfaces. If
953 // we reach this point in code, we already know that at least something will
954 // be drawn into this render surface, so the mask and replica should be
957 Layer
* mask_layer
= render_surface_layer
->mask_layer();
959 *did_paint_content
|= mask_layer
->Update(queue
, NULL
);
960 *need_more_updates
|= mask_layer
->NeedMoreUpdates();
963 Layer
* replica_mask_layer
=
964 render_surface_layer
->replica_layer() ?
965 render_surface_layer
->replica_layer()->mask_layer() : NULL
;
966 if (replica_mask_layer
) {
967 *did_paint_content
|= replica_mask_layer
->Update(queue
, NULL
);
968 *need_more_updates
|= replica_mask_layer
->NeedMoreUpdates();
972 void LayerTreeHost::PaintLayerContents(
973 const RenderSurfaceLayerList
& render_surface_layer_list
,
974 ResourceUpdateQueue
* queue
,
975 bool* did_paint_content
,
976 bool* need_more_updates
) {
977 OcclusionTracker
<Layer
> occlusion_tracker(
978 root_layer_
->render_surface()->content_rect());
979 occlusion_tracker
.set_minimum_tracking_size(
980 settings_
.minimum_occlusion_tracking_size
);
982 PrioritizeTextures(render_surface_layer_list
);
984 in_paint_layer_contents_
= true;
986 // Iterates front-to-back to allow for testing occlusion and performing
987 // culling during the tree walk.
988 typedef LayerIterator
<Layer
> LayerIteratorType
;
989 LayerIteratorType end
= LayerIteratorType::End(&render_surface_layer_list
);
990 for (LayerIteratorType it
=
991 LayerIteratorType::Begin(&render_surface_layer_list
);
994 occlusion_tracker
.EnterLayer(it
);
996 if (it
.represents_target_render_surface()) {
997 PaintMasksForRenderSurface(
998 *it
, queue
, did_paint_content
, need_more_updates
);
999 } else if (it
.represents_itself()) {
1000 DCHECK(!it
->paint_properties().bounds
.IsEmpty());
1001 *did_paint_content
|= it
->Update(queue
, &occlusion_tracker
);
1002 *need_more_updates
|= it
->NeedMoreUpdates();
1003 // Note the '&&' with previous is-suitable state.
1004 // This means that once the layer-tree becomes unsuitable for gpu
1005 // rasterization due to some content, it will continue to be unsuitable
1006 // even if that content is replaced by gpu-friendly content.
1007 // This is to avoid switching back-and-forth between gpu and sw
1008 // rasterization which may be both bad for performance and visually
1010 content_is_suitable_for_gpu_rasterization_
&=
1011 it
->IsSuitableForGpuRasterization();
1014 occlusion_tracker
.LeaveLayer(it
);
1017 in_paint_layer_contents_
= false;
1020 void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet
* info
) {
1021 ScopedPtrVector
<SwapPromise
>::iterator it
= info
->swap_promises
.begin();
1022 for (; it
!= info
->swap_promises
.end(); ++it
) {
1023 scoped_ptr
<SwapPromise
> swap_promise(info
->swap_promises
.take(it
));
1024 TRACE_EVENT_FLOW_STEP0("input",
1026 TRACE_ID_DONT_MANGLE(swap_promise
->TraceId()),
1027 "Main thread scroll update");
1028 QueueSwapPromise(swap_promise
.Pass());
1031 gfx::Vector2dF inner_viewport_scroll_delta
;
1032 gfx::Vector2dF outer_viewport_scroll_delta
;
1034 if (root_layer_
.get()) {
1035 for (size_t i
= 0; i
< info
->scrolls
.size(); ++i
) {
1036 Layer
* layer
= LayerTreeHostCommon::FindLayerInSubtree(
1037 root_layer_
.get(), info
->scrolls
[i
].layer_id
);
1040 if (layer
== outer_viewport_scroll_layer_
.get()) {
1041 outer_viewport_scroll_delta
+= info
->scrolls
[i
].scroll_delta
;
1042 } else if (layer
== inner_viewport_scroll_layer_
.get()) {
1043 inner_viewport_scroll_delta
+= info
->scrolls
[i
].scroll_delta
;
1045 layer
->SetScrollOffsetFromImplSide(
1046 gfx::ScrollOffsetWithDelta(layer
->scroll_offset(),
1047 info
->scrolls
[i
].scroll_delta
));
1052 if (!inner_viewport_scroll_delta
.IsZero() ||
1053 !outer_viewport_scroll_delta
.IsZero() || info
->page_scale_delta
!= 1.f
||
1054 !info
->elastic_overscroll_delta
.IsZero() || info
->top_controls_delta
) {
1055 // Preemptively apply the scroll offset and scale delta here before sending
1056 // it to the client. If the client comes back and sets it to the same
1057 // value, then the layer can early out without needing a full commit.
1058 if (inner_viewport_scroll_layer_
.get()) {
1059 inner_viewport_scroll_layer_
->SetScrollOffsetFromImplSide(
1060 gfx::ScrollOffsetWithDelta(
1061 inner_viewport_scroll_layer_
->scroll_offset(),
1062 inner_viewport_scroll_delta
));
1065 if (outer_viewport_scroll_layer_
.get()) {
1066 outer_viewport_scroll_layer_
->SetScrollOffsetFromImplSide(
1067 gfx::ScrollOffsetWithDelta(
1068 outer_viewport_scroll_layer_
->scroll_offset(),
1069 outer_viewport_scroll_delta
));
1072 ApplyPageScaleDeltaFromImplSide(info
->page_scale_delta
);
1073 elastic_overscroll_
+= info
->elastic_overscroll_delta
;
1074 if (!settings_
.use_pinch_virtual_viewport
) {
1075 // TODO(miletus): Make sure either this code path is totally gone,
1076 // or revisit the flooring here if the old pinch viewport code path
1077 // is causing problems with fractional scroll offset.
1078 client_
->ApplyViewportDeltas(
1079 gfx::ToFlooredVector2d(inner_viewport_scroll_delta
+
1080 outer_viewport_scroll_delta
),
1081 info
->page_scale_delta
, info
->top_controls_delta
);
1083 // TODO(ccameron): pass the elastic overscroll here so that input events
1084 // may be translated appropriately.
1085 client_
->ApplyViewportDeltas(
1086 inner_viewport_scroll_delta
, outer_viewport_scroll_delta
,
1087 info
->elastic_overscroll_delta
, info
->page_scale_delta
,
1088 info
->top_controls_delta
);
1093 void LayerTreeHost::StartRateLimiter() {
1094 if (inside_begin_main_frame_
)
1097 if (!rate_limit_timer_
.IsRunning()) {
1098 rate_limit_timer_
.Start(FROM_HERE
,
1101 &LayerTreeHost::RateLimit
);
1105 void LayerTreeHost::StopRateLimiter() {
1106 rate_limit_timer_
.Stop();
1109 void LayerTreeHost::RateLimit() {
1110 // Force a no-op command on the compositor context, so that any ratelimiting
1111 // commands will wait for the compositing context, and therefore for the
1113 proxy_
->ForceSerializeOnSwapBuffers();
1114 client_
->RateLimitSharedMainThreadContext();
1117 bool LayerTreeHost::AlwaysUsePartialTextureUpdates() {
1118 if (!proxy_
->GetRendererCapabilities().allow_partial_texture_updates
)
1120 return !proxy_
->HasImplThread();
1123 size_t LayerTreeHost::MaxPartialTextureUpdates() const {
1124 size_t max_partial_texture_updates
= 0;
1125 if (proxy_
->GetRendererCapabilities().allow_partial_texture_updates
&&
1126 !settings_
.impl_side_painting
) {
1127 max_partial_texture_updates
=
1128 std::min(settings_
.max_partial_texture_updates
,
1129 proxy_
->MaxPartialTextureUpdates());
1131 return max_partial_texture_updates
;
1134 bool LayerTreeHost::RequestPartialTextureUpdate() {
1135 if (partial_texture_update_requests_
>= MaxPartialTextureUpdates())
1138 partial_texture_update_requests_
++;
1142 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor
) {
1143 if (device_scale_factor
== device_scale_factor_
)
1145 device_scale_factor_
= device_scale_factor
;
1147 property_trees_
.needs_rebuild
= true;
1151 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints
,
1152 TopControlsState current
,
1154 // Top controls are only used in threaded mode.
1155 proxy_
->ImplThreadTaskRunner()->PostTask(
1157 base::Bind(&TopControlsManager::UpdateTopControlsState
,
1158 top_controls_manager_weak_ptr_
,
1164 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time
) {
1165 if (!settings_
.accelerated_animation_enabled
)
1168 AnimationEventsVector events
;
1169 if (animation_registrar_
->AnimateLayers(monotonic_time
)) {
1170 animation_registrar_
->UpdateAnimationState(true, &events
);
1171 if (!events
.empty())
1172 property_trees_
.needs_rebuild
= true;
1176 UIResourceId
LayerTreeHost::CreateUIResource(UIResourceClient
* client
) {
1179 UIResourceId next_id
= next_ui_resource_id_
++;
1180 DCHECK(ui_resource_client_map_
.find(next_id
) ==
1181 ui_resource_client_map_
.end());
1183 bool resource_lost
= false;
1184 UIResourceRequest
request(UIResourceRequest::UI_RESOURCE_CREATE
, next_id
,
1185 client
->GetBitmap(next_id
, resource_lost
));
1186 ui_resource_request_queue_
.push_back(request
);
1188 UIResourceClientData data
;
1189 data
.client
= client
;
1190 data
.size
= request
.GetBitmap().GetSize();
1192 ui_resource_client_map_
[request
.GetId()] = data
;
1193 return request
.GetId();
1196 // Deletes a UI resource. May safely be called more than once.
1197 void LayerTreeHost::DeleteUIResource(UIResourceId uid
) {
1198 UIResourceClientMap::iterator iter
= ui_resource_client_map_
.find(uid
);
1199 if (iter
== ui_resource_client_map_
.end())
1202 UIResourceRequest
request(UIResourceRequest::UI_RESOURCE_DELETE
, uid
);
1203 ui_resource_request_queue_
.push_back(request
);
1204 ui_resource_client_map_
.erase(iter
);
1207 void LayerTreeHost::RecreateUIResources() {
1208 for (UIResourceClientMap::iterator iter
= ui_resource_client_map_
.begin();
1209 iter
!= ui_resource_client_map_
.end();
1211 UIResourceId uid
= iter
->first
;
1212 const UIResourceClientData
& data
= iter
->second
;
1213 bool resource_lost
= true;
1214 UIResourceRequest
request(UIResourceRequest::UI_RESOURCE_CREATE
, uid
,
1215 data
.client
->GetBitmap(uid
, resource_lost
));
1216 ui_resource_request_queue_
.push_back(request
);
1220 // Returns the size of a resource given its id.
1221 gfx::Size
LayerTreeHost::GetUIResourceSize(UIResourceId uid
) const {
1222 UIResourceClientMap::const_iterator iter
= ui_resource_client_map_
.find(uid
);
1223 if (iter
== ui_resource_client_map_
.end())
1226 const UIResourceClientData
& data
= iter
->second
;
1230 void LayerTreeHost::RegisterViewportLayers(
1231 scoped_refptr
<Layer
> overscroll_elasticity_layer
,
1232 scoped_refptr
<Layer
> page_scale_layer
,
1233 scoped_refptr
<Layer
> inner_viewport_scroll_layer
,
1234 scoped_refptr
<Layer
> outer_viewport_scroll_layer
) {
1235 overscroll_elasticity_layer_
= overscroll_elasticity_layer
;
1236 page_scale_layer_
= page_scale_layer
;
1237 inner_viewport_scroll_layer_
= inner_viewport_scroll_layer
;
1238 outer_viewport_scroll_layer_
= outer_viewport_scroll_layer
;
1241 void LayerTreeHost::RegisterSelection(const LayerSelection
& selection
) {
1242 if (selection_
== selection
)
1245 selection_
= selection
;
1249 int LayerTreeHost::ScheduleMicroBenchmark(
1250 const std::string
& benchmark_name
,
1251 scoped_ptr
<base::Value
> value
,
1252 const MicroBenchmark::DoneCallback
& callback
) {
1253 return micro_benchmark_controller_
.ScheduleRun(
1254 benchmark_name
, value
.Pass(), callback
);
1257 bool LayerTreeHost::SendMessageToMicroBenchmark(int id
,
1258 scoped_ptr
<base::Value
> value
) {
1259 return micro_benchmark_controller_
.SendMessage(id
, value
.Pass());
1262 void LayerTreeHost::InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
) {
1263 swap_promise_monitor_
.insert(monitor
);
1266 void LayerTreeHost::RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
) {
1267 swap_promise_monitor_
.erase(monitor
);
1270 void LayerTreeHost::NotifySwapPromiseMonitorsOfSetNeedsCommit() {
1271 std::set
<SwapPromiseMonitor
*>::iterator it
= swap_promise_monitor_
.begin();
1272 for (; it
!= swap_promise_monitor_
.end(); it
++)
1273 (*it
)->OnSetNeedsCommitOnMain();
1276 void LayerTreeHost::QueueSwapPromise(scoped_ptr
<SwapPromise
> swap_promise
) {
1277 DCHECK(swap_promise
);
1278 swap_promise_list_
.push_back(swap_promise
.Pass());
1281 void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason
) {
1282 for (auto* swap_promise
: swap_promise_list_
)
1283 swap_promise
->DidNotSwap(reason
);
1284 swap_promise_list_
.clear();
1287 void LayerTreeHost::set_surface_id_namespace(uint32_t id_namespace
) {
1288 surface_id_namespace_
= id_namespace
;
1291 SurfaceSequence
LayerTreeHost::CreateSurfaceSequence() {
1292 return SurfaceSequence(surface_id_namespace_
, next_surface_sequence_
++);
1295 void LayerTreeHost::SetChildrenNeedBeginFrames(
1296 bool children_need_begin_frames
) const {
1297 proxy_
->SetChildrenNeedBeginFrames(children_need_begin_frames
);
1300 void LayerTreeHost::SendBeginFramesToChildren(
1301 const BeginFrameArgs
& args
) const {
1302 client_
->SendBeginFramesToChildren(args
);
1305 void LayerTreeHost::SetAuthoritativeVSyncInterval(
1306 const base::TimeDelta
& interval
) {
1307 proxy_
->SetAuthoritativeVSyncInterval(interval
);