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/bind.h"
13 #include "base/command_line.h"
14 #include "base/debug/trace_event.h"
15 #include "base/debug/trace_event_argument.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h"
18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "cc/animation/animation_registrar.h"
21 #include "cc/animation/layer_animation_controller.h"
22 #include "cc/base/math_util.h"
23 #include "cc/debug/devtools_instrumentation.h"
24 #include "cc/debug/rendering_stats_instrumentation.h"
25 #include "cc/input/layer_selection_bound.h"
26 #include "cc/input/top_controls_manager.h"
27 #include "cc/layers/heads_up_display_layer.h"
28 #include "cc/layers/heads_up_display_layer_impl.h"
29 #include "cc/layers/layer.h"
30 #include "cc/layers/layer_iterator.h"
31 #include "cc/layers/painted_scrollbar_layer.h"
32 #include "cc/layers/render_surface.h"
33 #include "cc/resources/prioritized_resource_manager.h"
34 #include "cc/resources/ui_resource_request.h"
35 #include "cc/trees/layer_tree_host_client.h"
36 #include "cc/trees/layer_tree_host_common.h"
37 #include "cc/trees/layer_tree_host_impl.h"
38 #include "cc/trees/layer_tree_impl.h"
39 #include "cc/trees/occlusion_tracker.h"
40 #include "cc/trees/single_thread_proxy.h"
41 #include "cc/trees/thread_proxy.h"
42 #include "cc/trees/tree_synchronizer.h"
43 #include "ui/gfx/size_conversions.h"
46 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number
;
51 RendererCapabilities::RendererCapabilities(ResourceFormat best_texture_format
,
52 bool allow_partial_texture_updates
,
54 bool using_shared_memory_resources
)
55 : best_texture_format(best_texture_format
),
56 allow_partial_texture_updates(allow_partial_texture_updates
),
57 max_texture_size(max_texture_size
),
58 using_shared_memory_resources(using_shared_memory_resources
) {}
60 RendererCapabilities::RendererCapabilities()
61 : best_texture_format(RGBA_8888
),
62 allow_partial_texture_updates(false),
64 using_shared_memory_resources(false) {}
66 RendererCapabilities::~RendererCapabilities() {}
68 scoped_ptr
<LayerTreeHost
> LayerTreeHost::CreateThreaded(
69 LayerTreeHostClient
* client
,
70 SharedBitmapManager
* manager
,
71 const LayerTreeSettings
& settings
,
72 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
73 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
) {
74 DCHECK(main_task_runner
.get());
75 DCHECK(impl_task_runner
.get());
76 scoped_ptr
<LayerTreeHost
> layer_tree_host(
77 new LayerTreeHost(client
, manager
, settings
));
78 layer_tree_host
->InitializeThreaded(main_task_runner
, impl_task_runner
);
79 return layer_tree_host
.Pass();
82 scoped_ptr
<LayerTreeHost
> LayerTreeHost::CreateSingleThreaded(
83 LayerTreeHostClient
* client
,
84 LayerTreeHostSingleThreadClient
* single_thread_client
,
85 SharedBitmapManager
* manager
,
86 const LayerTreeSettings
& settings
,
87 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
) {
88 scoped_ptr
<LayerTreeHost
> layer_tree_host(
89 new LayerTreeHost(client
, manager
, settings
));
90 layer_tree_host
->InitializeSingleThreaded(single_thread_client
,
92 return layer_tree_host
.Pass();
95 LayerTreeHost::LayerTreeHost(LayerTreeHostClient
* client
,
96 SharedBitmapManager
* manager
,
97 const LayerTreeSettings
& settings
)
98 : micro_benchmark_controller_(this),
99 next_ui_resource_id_(1),
100 inside_begin_main_frame_(false),
101 needs_full_tree_sync_(true),
103 source_frame_number_(0),
104 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
105 output_surface_lost_(true),
106 num_failed_recreate_attempts_(0),
108 debug_state_(settings
.initial_debug_state
),
109 top_controls_layout_height_(0.f
),
110 device_scale_factor_(1.f
),
112 page_scale_factor_(1.f
),
113 min_page_scale_factor_(1.f
),
114 max_page_scale_factor_(1.f
),
115 has_gpu_rasterization_trigger_(false),
116 content_is_suitable_for_gpu_rasterization_(true),
117 gpu_rasterization_histogram_recorded_(false),
118 background_color_(SK_ColorWHITE
),
119 has_transparent_background_(false),
120 partial_texture_update_requests_(0),
121 in_paint_layer_contents_(false),
122 total_frames_used_for_lcd_text_metrics_(0),
123 id_(s_layer_tree_host_sequence_number
.GetNext() + 1),
124 next_commit_forces_redraw_(false),
125 shared_bitmap_manager_(manager
) {
126 if (settings_
.accelerated_animation_enabled
)
127 animation_registrar_
= AnimationRegistrar::Create();
128 rendering_stats_instrumentation_
->set_record_rendering_stats(
129 debug_state_
.RecordRenderingStats());
132 void LayerTreeHost::InitializeThreaded(
133 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
134 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
) {
136 ThreadProxy::Create(this, main_task_runner
, impl_task_runner
));
139 void LayerTreeHost::InitializeSingleThreaded(
140 LayerTreeHostSingleThreadClient
* single_thread_client
,
141 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
) {
143 SingleThreadProxy::Create(this, single_thread_client
, main_task_runner
));
146 void LayerTreeHost::InitializeForTesting(scoped_ptr
<Proxy
> proxy_for_testing
) {
147 InitializeProxy(proxy_for_testing
.Pass());
150 void LayerTreeHost::InitializeProxy(scoped_ptr
<Proxy
> proxy
) {
151 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
153 proxy_
= proxy
.Pass();
155 if (settings_
.accelerated_animation_enabled
) {
156 animation_registrar_
->set_supports_scroll_animations(
157 proxy_
->SupportsImplScrolling());
161 LayerTreeHost::~LayerTreeHost() {
162 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
164 DCHECK(swap_promise_monitor_
.empty());
166 BreakSwapPromises(SwapPromise::COMMIT_FAILS
);
168 overhang_ui_resource_
.reset();
170 if (root_layer_
.get())
171 root_layer_
->SetLayerTreeHost(NULL
);
174 DCHECK(proxy_
->IsMainThread());
178 // We must clear any pointers into the layer tree prior to destroying it.
179 RegisterViewportLayers(NULL
, NULL
, NULL
);
181 if (root_layer_
.get()) {
182 // The layer tree must be destroyed before the layer tree host. We've
183 // made a contract with our animation controllers that the registrar
184 // will outlive them, and we must make good.
189 void LayerTreeHost::SetLayerTreeHostClientReady() {
190 proxy_
->SetLayerTreeHostClientReady();
193 static void LayerTreeHostOnOutputSurfaceCreatedCallback(Layer
* layer
) {
194 layer
->OnOutputSurfaceCreated();
197 void LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted(bool success
) {
198 DCHECK(output_surface_lost_
);
200 "LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted",
205 // Tolerate a certain number of recreation failures to work around races
206 // in the output-surface-lost machinery.
207 ++num_failed_recreate_attempts_
;
208 if (num_failed_recreate_attempts_
>= 5)
209 LOG(FATAL
) << "Failed to create a fallback OutputSurface.";
210 client_
->DidFailToInitializeOutputSurface();
214 output_surface_lost_
= false;
216 if (!contents_texture_manager_
&& !settings_
.impl_side_painting
) {
217 contents_texture_manager_
=
218 PrioritizedResourceManager::Create(proxy_
.get());
219 surface_memory_placeholder_
=
220 contents_texture_manager_
->CreateTexture(gfx::Size(), RGBA_8888
);
224 LayerTreeHostCommon::CallFunctionForSubtree(
225 root_layer(), base::Bind(&LayerTreeHostOnOutputSurfaceCreatedCallback
));
228 client_
->DidInitializeOutputSurface();
231 void LayerTreeHost::DeleteContentsTexturesOnImplThread(
232 ResourceProvider
* resource_provider
) {
233 DCHECK(proxy_
->IsImplThread());
234 if (contents_texture_manager_
)
235 contents_texture_manager_
->ClearAllMemory(resource_provider
);
238 void LayerTreeHost::DidBeginMainFrame() {
239 client_
->DidBeginMainFrame();
242 void LayerTreeHost::BeginMainFrame(const BeginFrameArgs
& args
) {
243 inside_begin_main_frame_
= true;
244 client_
->BeginMainFrame(args
);
245 inside_begin_main_frame_
= false;
248 void LayerTreeHost::DidStopFlinging() {
249 proxy_
->MainThreadHasStoppedFlinging();
252 void LayerTreeHost::Layout() {
256 void LayerTreeHost::BeginCommitOnImplThread(LayerTreeHostImpl
* host_impl
) {
257 DCHECK(proxy_
->IsImplThread());
258 TRACE_EVENT0("cc", "LayerTreeHost::CommitTo");
261 // This function commits the LayerTreeHost to an impl tree. When modifying
262 // this function, keep in mind that the function *runs* on the impl thread! Any
263 // code that is logically a main thread operation, e.g. deletion of a Layer,
264 // should be delayed until the LayerTreeHost::CommitComplete, which will run
265 // after the commit, but on the main thread.
266 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl
* host_impl
) {
267 DCHECK(proxy_
->IsImplThread());
269 // If there are linked evicted backings, these backings' resources may be put
270 // into the impl tree, so we can't draw yet. Determine this before clearing
271 // all evicted backings.
272 bool new_impl_tree_has_no_evicted_resources
= false;
273 if (contents_texture_manager_
) {
274 new_impl_tree_has_no_evicted_resources
=
275 !contents_texture_manager_
->LinkedEvictedBackingsExist();
277 // If the memory limit has been increased since this now-finishing
278 // commit began, and the extra now-available memory would have been used,
279 // then request another commit.
280 if (contents_texture_manager_
->MaxMemoryLimitBytes() <
281 host_impl
->memory_allocation_limit_bytes() &&
282 contents_texture_manager_
->MaxMemoryLimitBytes() <
283 contents_texture_manager_
->MaxMemoryNeededBytes()) {
284 host_impl
->SetNeedsCommit();
287 host_impl
->set_max_memory_needed_bytes(
288 contents_texture_manager_
->MaxMemoryNeededBytes());
290 contents_texture_manager_
->UpdateBackingsState(
291 host_impl
->resource_provider());
292 contents_texture_manager_
->ReduceMemory(host_impl
->resource_provider());
295 LayerTreeImpl
* sync_tree
= host_impl
->sync_tree();
297 if (next_commit_forces_redraw_
) {
298 sync_tree
->ForceRedrawNextActivation();
299 next_commit_forces_redraw_
= false;
302 sync_tree
->set_source_frame_number(source_frame_number());
304 if (needs_full_tree_sync_
) {
305 sync_tree
->SetRootLayer(TreeSynchronizer::SynchronizeTrees(
306 root_layer(), sync_tree
->DetachLayerTree(), sync_tree
));
310 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
311 TreeSynchronizer::PushProperties(root_layer(), sync_tree
->root_layer());
314 sync_tree
->set_needs_full_tree_sync(needs_full_tree_sync_
);
315 needs_full_tree_sync_
= false;
317 if (hud_layer_
.get()) {
318 LayerImpl
* hud_impl
= LayerTreeHostCommon::FindLayerInSubtree(
319 sync_tree
->root_layer(), hud_layer_
->id());
320 sync_tree
->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl
*>(hud_impl
));
322 sync_tree
->set_hud_layer(NULL
);
325 sync_tree
->set_background_color(background_color_
);
326 sync_tree
->set_has_transparent_background(has_transparent_background_
);
328 if (page_scale_layer_
.get() && inner_viewport_scroll_layer_
.get()) {
329 sync_tree
->SetViewportLayersFromIds(page_scale_layer_
->id(),
330 inner_viewport_scroll_layer_
->id(),
331 outer_viewport_scroll_layer_
.get()
332 ? outer_viewport_scroll_layer_
->id()
333 : Layer::INVALID_ID
);
335 sync_tree
->ClearViewportLayers();
338 sync_tree
->RegisterSelection(selection_start_
, selection_end_
);
340 float page_scale_delta
=
341 sync_tree
->page_scale_delta() / sync_tree
->sent_page_scale_delta();
342 sync_tree
->SetPageScaleValues(page_scale_factor_
,
343 min_page_scale_factor_
,
344 max_page_scale_factor_
,
346 sync_tree
->set_sent_page_scale_delta(1.f
);
348 sync_tree
->PassSwapPromises(&swap_promise_list_
);
350 host_impl
->SetUseGpuRasterization(UseGpuRasterization());
351 RecordGpuRasterizationHistogram();
353 host_impl
->SetViewportSize(device_viewport_size_
);
354 host_impl
->SetTopControlsLayoutHeight(top_controls_layout_height_
);
355 host_impl
->SetDeviceScaleFactor(device_scale_factor_
);
356 host_impl
->SetDebugState(debug_state_
);
357 if (pending_page_scale_animation_
) {
358 host_impl
->StartPageScaleAnimation(
359 pending_page_scale_animation_
->target_offset
,
360 pending_page_scale_animation_
->use_anchor
,
361 pending_page_scale_animation_
->scale
,
362 pending_page_scale_animation_
->duration
);
363 pending_page_scale_animation_
.reset();
366 if (!ui_resource_request_queue_
.empty()) {
367 sync_tree
->set_ui_resource_request_queue(ui_resource_request_queue_
);
368 ui_resource_request_queue_
.clear();
370 if (overhang_ui_resource_
) {
371 host_impl
->SetOverhangUIResource(
372 overhang_ui_resource_
->id(),
373 GetUIResourceSize(overhang_ui_resource_
->id()));
376 DCHECK(!sync_tree
->ViewportSizeInvalid());
378 if (new_impl_tree_has_no_evicted_resources
) {
379 if (sync_tree
->ContentsTexturesPurged())
380 sync_tree
->ResetContentsTexturesPurged();
383 sync_tree
->set_has_ever_been_drawn(false);
385 micro_benchmark_controller_
.ScheduleImplBenchmarks(host_impl
);
388 void LayerTreeHost::WillCommit() {
389 client_
->WillCommit();
392 void LayerTreeHost::UpdateHudLayer() {
393 if (debug_state_
.ShowHudInfo()) {
394 if (!hud_layer_
.get())
395 hud_layer_
= HeadsUpDisplayLayer::Create();
397 if (root_layer_
.get() && !hud_layer_
->parent())
398 root_layer_
->AddChild(hud_layer_
);
399 } else if (hud_layer_
.get()) {
400 hud_layer_
->RemoveFromParent();
405 void LayerTreeHost::CommitComplete() {
406 source_frame_number_
++;
407 client_
->DidCommit();
410 scoped_ptr
<OutputSurface
> LayerTreeHost::CreateOutputSurface() {
411 return client_
->CreateOutputSurface(num_failed_recreate_attempts_
>= 4);
414 scoped_ptr
<LayerTreeHostImpl
> LayerTreeHost::CreateLayerTreeHostImpl(
415 LayerTreeHostImplClient
* client
) {
416 DCHECK(proxy_
->IsImplThread());
417 scoped_ptr
<LayerTreeHostImpl
> host_impl
=
418 LayerTreeHostImpl::Create(settings_
,
421 rendering_stats_instrumentation_
.get(),
422 shared_bitmap_manager_
,
424 host_impl
->SetUseGpuRasterization(UseGpuRasterization());
425 shared_bitmap_manager_
= NULL
;
426 if (settings_
.calculate_top_controls_position
&&
427 host_impl
->top_controls_manager()) {
428 top_controls_manager_weak_ptr_
=
429 host_impl
->top_controls_manager()->AsWeakPtr();
431 input_handler_weak_ptr_
= host_impl
->AsWeakPtr();
432 return host_impl
.Pass();
435 void LayerTreeHost::DidLoseOutputSurface() {
436 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface");
437 DCHECK(proxy_
->IsMainThread());
439 if (output_surface_lost_
)
442 num_failed_recreate_attempts_
= 0;
443 output_surface_lost_
= true;
447 void LayerTreeHost::FinishAllRendering() {
448 proxy_
->FinishAllRendering();
451 void LayerTreeHost::SetDeferCommits(bool defer_commits
) {
452 proxy_
->SetDeferCommits(defer_commits
);
455 void LayerTreeHost::DidDeferCommit() {}
457 void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
458 std::stack
<Layer
*> layer_stack
;
459 layer_stack
.push(root_layer());
460 while (!layer_stack
.empty()) {
461 Layer
* current_layer
= layer_stack
.top();
463 current_layer
->SetNeedsDisplay();
464 for (unsigned int i
= 0; i
< current_layer
->children().size(); i
++) {
465 layer_stack
.push(current_layer
->child_at(i
));
470 const RendererCapabilities
& LayerTreeHost::GetRendererCapabilities() const {
471 return proxy_
->GetRendererCapabilities();
474 void LayerTreeHost::SetNeedsAnimate() {
475 proxy_
->SetNeedsAnimate();
476 NotifySwapPromiseMonitorsOfSetNeedsCommit();
479 void LayerTreeHost::SetNeedsUpdateLayers() {
480 proxy_
->SetNeedsUpdateLayers();
481 NotifySwapPromiseMonitorsOfSetNeedsCommit();
484 void LayerTreeHost::SetNeedsCommit() {
485 if (!prepaint_callback_
.IsCancelled()) {
486 TRACE_EVENT_INSTANT0("cc",
487 "LayerTreeHost::SetNeedsCommit::cancel prepaint",
488 TRACE_EVENT_SCOPE_THREAD
);
489 prepaint_callback_
.Cancel();
491 proxy_
->SetNeedsCommit();
492 NotifySwapPromiseMonitorsOfSetNeedsCommit();
495 void LayerTreeHost::SetNeedsFullTreeSync() {
496 needs_full_tree_sync_
= true;
500 void LayerTreeHost::SetNeedsRedraw() {
501 SetNeedsRedrawRect(gfx::Rect(device_viewport_size_
));
504 void LayerTreeHost::SetNeedsRedrawRect(const gfx::Rect
& damage_rect
) {
505 proxy_
->SetNeedsRedraw(damage_rect
);
508 bool LayerTreeHost::CommitRequested() const {
509 return proxy_
->CommitRequested();
512 bool LayerTreeHost::BeginMainFrameRequested() const {
513 return proxy_
->BeginMainFrameRequested();
517 void LayerTreeHost::SetNextCommitWaitsForActivation() {
518 proxy_
->SetNextCommitWaitsForActivation();
521 void LayerTreeHost::SetNextCommitForcesRedraw() {
522 next_commit_forces_redraw_
= true;
525 void LayerTreeHost::SetAnimationEvents(
526 scoped_ptr
<AnimationEventsVector
> events
) {
527 DCHECK(proxy_
->IsMainThread());
528 for (size_t event_index
= 0; event_index
< events
->size(); ++event_index
) {
529 int event_layer_id
= (*events
)[event_index
].layer_id
;
531 // Use the map of all controllers, not just active ones, since non-active
532 // controllers may still receive events for impl-only animations.
533 const AnimationRegistrar::AnimationControllerMap
& animation_controllers
=
534 animation_registrar_
->all_animation_controllers();
535 AnimationRegistrar::AnimationControllerMap::const_iterator iter
=
536 animation_controllers
.find(event_layer_id
);
537 if (iter
!= animation_controllers
.end()) {
538 switch ((*events
)[event_index
].type
) {
539 case AnimationEvent::Started
:
540 (*iter
).second
->NotifyAnimationStarted((*events
)[event_index
]);
543 case AnimationEvent::Finished
:
544 (*iter
).second
->NotifyAnimationFinished((*events
)[event_index
]);
547 case AnimationEvent::Aborted
:
548 (*iter
).second
->NotifyAnimationAborted((*events
)[event_index
]);
551 case AnimationEvent::PropertyUpdate
:
552 (*iter
).second
->NotifyAnimationPropertyUpdate((*events
)[event_index
]);
559 void LayerTreeHost::SetRootLayer(scoped_refptr
<Layer
> root_layer
) {
560 if (root_layer_
.get() == root_layer
.get())
563 if (root_layer_
.get())
564 root_layer_
->SetLayerTreeHost(NULL
);
565 root_layer_
= root_layer
;
566 if (root_layer_
.get()) {
567 DCHECK(!root_layer_
->parent());
568 root_layer_
->SetLayerTreeHost(this);
571 if (hud_layer_
.get())
572 hud_layer_
->RemoveFromParent();
574 // Reset gpu rasterization flag.
575 // This flag is sticky until a new tree comes along.
576 content_is_suitable_for_gpu_rasterization_
= true;
577 gpu_rasterization_histogram_recorded_
= false;
579 SetNeedsFullTreeSync();
582 void LayerTreeHost::SetDebugState(const LayerTreeDebugState
& debug_state
) {
583 LayerTreeDebugState new_debug_state
=
584 LayerTreeDebugState::Unite(settings_
.initial_debug_state
, debug_state
);
586 if (LayerTreeDebugState::Equal(debug_state_
, new_debug_state
))
589 debug_state_
= new_debug_state
;
591 rendering_stats_instrumentation_
->set_record_rendering_stats(
592 debug_state_
.RecordRenderingStats());
595 proxy_
->SetDebugState(debug_state
);
598 bool LayerTreeHost::UseGpuRasterization() const {
599 if (settings_
.gpu_rasterization_forced
) {
601 } else if (settings_
.gpu_rasterization_enabled
) {
602 return has_gpu_rasterization_trigger_
&&
603 content_is_suitable_for_gpu_rasterization_
;
609 void LayerTreeHost::SetHasGpuRasterizationTrigger(bool has_trigger
) {
610 if (has_trigger
== has_gpu_rasterization_trigger_
)
613 has_gpu_rasterization_trigger_
= has_trigger
;
614 TRACE_EVENT_INSTANT1("cc",
615 "LayerTreeHost::SetHasGpuRasterizationTrigger",
616 TRACE_EVENT_SCOPE_THREAD
,
618 has_gpu_rasterization_trigger_
);
621 void LayerTreeHost::SetViewportSize(const gfx::Size
& device_viewport_size
) {
622 if (device_viewport_size
== device_viewport_size_
)
625 device_viewport_size_
= device_viewport_size
;
630 void LayerTreeHost::SetTopControlsLayoutHeight(
631 float top_controls_layout_height
) {
632 if (top_controls_layout_height_
== top_controls_layout_height
)
635 top_controls_layout_height_
= top_controls_layout_height
;
639 void LayerTreeHost::ApplyPageScaleDeltaFromImplSide(float page_scale_delta
) {
640 DCHECK(CommitRequested());
641 page_scale_factor_
*= page_scale_delta
;
644 void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor
,
645 float min_page_scale_factor
,
646 float max_page_scale_factor
) {
647 if (page_scale_factor
== page_scale_factor_
&&
648 min_page_scale_factor
== min_page_scale_factor_
&&
649 max_page_scale_factor
== max_page_scale_factor_
)
652 page_scale_factor_
= page_scale_factor
;
653 min_page_scale_factor_
= min_page_scale_factor
;
654 max_page_scale_factor_
= max_page_scale_factor
;
658 void LayerTreeHost::SetOverhangBitmap(const SkBitmap
& bitmap
) {
659 DCHECK(bitmap
.width() && bitmap
.height());
660 DCHECK_EQ(bitmap
.bytesPerPixel(), 4);
662 SkBitmap bitmap_copy
;
663 if (bitmap
.isImmutable()) {
664 bitmap_copy
= bitmap
;
666 bitmap
.copyTo(&bitmap_copy
);
667 bitmap_copy
.setImmutable();
670 UIResourceBitmap
overhang_bitmap(bitmap_copy
);
671 overhang_bitmap
.SetWrapMode(UIResourceBitmap::REPEAT
);
672 overhang_ui_resource_
= ScopedUIResource::Create(this, overhang_bitmap
);
675 void LayerTreeHost::SetVisible(bool visible
) {
676 if (visible_
== visible
)
681 proxy_
->SetVisible(visible
);
684 void LayerTreeHost::StartPageScaleAnimation(const gfx::Vector2d
& target_offset
,
687 base::TimeDelta duration
) {
688 pending_page_scale_animation_
.reset(new PendingPageScaleAnimation
);
689 pending_page_scale_animation_
->target_offset
= target_offset
;
690 pending_page_scale_animation_
->use_anchor
= use_anchor
;
691 pending_page_scale_animation_
->scale
= scale
;
692 pending_page_scale_animation_
->duration
= duration
;
697 void LayerTreeHost::NotifyInputThrottledUntilCommit() {
698 proxy_
->NotifyInputThrottledUntilCommit();
701 void LayerTreeHost::Composite(base::TimeTicks frame_begin_time
) {
702 DCHECK(!proxy_
->HasImplThread());
703 // This function is only valid when not using the scheduler.
704 DCHECK(!settings_
.single_thread_proxy_scheduler
);
705 SingleThreadProxy
* proxy
= static_cast<SingleThreadProxy
*>(proxy_
.get());
707 SetLayerTreeHostClientReady();
709 if (output_surface_lost_
)
710 proxy
->CreateAndInitializeOutputSurface();
711 if (output_surface_lost_
)
714 proxy
->CompositeImmediately(frame_begin_time
);
717 bool LayerTreeHost::UpdateLayers(ResourceUpdateQueue
* queue
) {
718 DCHECK(!output_surface_lost_
);
723 DCHECK(!root_layer()->parent());
725 bool result
= UpdateLayers(root_layer(), queue
);
727 micro_benchmark_controller_
.DidUpdateLayers();
729 return result
|| next_commit_forces_redraw_
;
732 static Layer
* FindFirstScrollableLayer(Layer
* layer
) {
736 if (layer
->scrollable())
739 for (size_t i
= 0; i
< layer
->children().size(); ++i
) {
740 Layer
* found
= FindFirstScrollableLayer(layer
->children()[i
].get());
748 void LayerTreeHost::RecordGpuRasterizationHistogram() {
749 // Gpu rasterization is only supported when impl-side painting is enabled.
750 if (gpu_rasterization_histogram_recorded_
|| !settings_
.impl_side_painting
)
753 // Record how widely gpu rasterization is enabled.
754 // This number takes device/gpu whitelisting/backlisting into account.
755 // Note that we do not consider the forced gpu rasterization mode, which is
756 // mostly used for debugging purposes.
757 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled",
758 settings_
.gpu_rasterization_enabled
);
759 if (settings_
.gpu_rasterization_enabled
) {
760 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered",
761 has_gpu_rasterization_trigger_
);
762 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationSuitableContent",
763 content_is_suitable_for_gpu_rasterization_
);
764 // Record how many pages actually get gpu rasterization when enabled.
765 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed",
766 (has_gpu_rasterization_trigger_
&&
767 content_is_suitable_for_gpu_rasterization_
));
770 gpu_rasterization_histogram_recorded_
= true;
773 void LayerTreeHost::CalculateLCDTextMetricsCallback(Layer
* layer
) {
774 if (!layer
->SupportsLCDText())
777 lcd_text_metrics_
.total_num_cc_layers
++;
778 if (layer
->draw_properties().can_use_lcd_text
) {
779 lcd_text_metrics_
.total_num_cc_layers_can_use_lcd_text
++;
780 if (layer
->contents_opaque())
781 lcd_text_metrics_
.total_num_cc_layers_will_use_lcd_text
++;
785 bool LayerTreeHost::UsingSharedMemoryResources() {
786 return GetRendererCapabilities().using_shared_memory_resources
;
789 bool LayerTreeHost::UpdateLayers(Layer
* root_layer
,
790 ResourceUpdateQueue
* queue
) {
791 TRACE_EVENT1("cc", "LayerTreeHost::UpdateLayers",
792 "source_frame_number", source_frame_number());
794 RenderSurfaceLayerList update_list
;
798 Layer
* root_scroll
= FindFirstScrollableLayer(root_layer
);
799 Layer
* page_scale_layer
= page_scale_layer_
.get();
800 if (!page_scale_layer
&& root_scroll
)
801 page_scale_layer
= root_scroll
->parent();
803 if (hud_layer_
.get()) {
804 hud_layer_
->PrepareForCalculateDrawProperties(
805 device_viewport_size(), device_scale_factor_
);
808 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::CalcDrawProps");
809 bool can_render_to_separate_surface
= true;
810 // TODO(vmpstr): Passing 0 as the current render surface layer list id means
811 // that we won't be able to detect if a layer is part of |update_list|.
812 // Change this if this information is required.
813 int render_surface_layer_list_id
= 0;
814 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(
816 device_viewport_size(),
818 device_scale_factor_
,
821 GetRendererCapabilities().max_texture_size
,
822 settings_
.can_use_lcd_text
,
823 can_render_to_separate_surface
,
824 settings_
.layer_transforms_should_scale_layer_contents
,
826 render_surface_layer_list_id
);
827 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
829 if (total_frames_used_for_lcd_text_metrics_
<=
830 kTotalFramesToUseForLCDTextMetrics
) {
831 LayerTreeHostCommon::CallFunctionForSubtree(
833 base::Bind(&LayerTreeHost::CalculateLCDTextMetricsCallback
,
834 base::Unretained(this)));
835 total_frames_used_for_lcd_text_metrics_
++;
838 if (total_frames_used_for_lcd_text_metrics_
==
839 kTotalFramesToUseForLCDTextMetrics
) {
840 total_frames_used_for_lcd_text_metrics_
++;
842 UMA_HISTOGRAM_PERCENTAGE(
843 "Renderer4.LCDText.PercentageOfCandidateLayers",
844 lcd_text_metrics_
.total_num_cc_layers_can_use_lcd_text
* 100.0 /
845 lcd_text_metrics_
.total_num_cc_layers
);
846 UMA_HISTOGRAM_PERCENTAGE(
847 "Renderer4.LCDText.PercentageOfAALayers",
848 lcd_text_metrics_
.total_num_cc_layers_will_use_lcd_text
* 100.0 /
849 lcd_text_metrics_
.total_num_cc_layers_can_use_lcd_text
);
853 // Reset partial texture update requests.
854 partial_texture_update_requests_
= 0;
856 bool did_paint_content
= false;
857 bool need_more_updates
= false;
859 update_list
, queue
, &did_paint_content
, &need_more_updates
);
860 if (need_more_updates
) {
861 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::posting prepaint task");
862 prepaint_callback_
.Reset(base::Bind(&LayerTreeHost::TriggerPrepaint
,
863 base::Unretained(this)));
864 static base::TimeDelta prepaint_delay
=
865 base::TimeDelta::FromMilliseconds(100);
866 base::MessageLoop::current()->PostDelayedTask(
867 FROM_HERE
, prepaint_callback_
.callback(), prepaint_delay
);
870 return did_paint_content
;
873 void LayerTreeHost::TriggerPrepaint() {
874 prepaint_callback_
.Cancel();
875 TRACE_EVENT0("cc", "LayerTreeHost::TriggerPrepaint");
879 static void LayerTreeHostReduceMemoryCallback(Layer
* layer
) {
880 layer
->ReduceMemoryUsage();
883 void LayerTreeHost::ReduceMemoryUsage() {
887 LayerTreeHostCommon::CallFunctionForSubtree(
889 base::Bind(&LayerTreeHostReduceMemoryCallback
));
892 void LayerTreeHost::SetPrioritiesForSurfaces(size_t surface_memory_bytes
) {
893 DCHECK(surface_memory_placeholder_
);
895 // Surfaces have a place holder for their memory since they are managed
896 // independantly but should still be tracked and reduce other memory usage.
897 surface_memory_placeholder_
->SetTextureManager(
898 contents_texture_manager_
.get());
899 surface_memory_placeholder_
->set_request_priority(
900 PriorityCalculator::RenderSurfacePriority());
901 surface_memory_placeholder_
->SetToSelfManagedMemoryPlaceholder(
902 surface_memory_bytes
);
905 void LayerTreeHost::SetPrioritiesForLayers(
906 const RenderSurfaceLayerList
& update_list
) {
907 PriorityCalculator calculator
;
908 typedef LayerIterator
<Layer
> LayerIteratorType
;
909 LayerIteratorType end
= LayerIteratorType::End(&update_list
);
910 for (LayerIteratorType it
= LayerIteratorType::Begin(&update_list
);
913 if (it
.represents_itself()) {
914 it
->SetTexturePriorities(calculator
);
915 } else if (it
.represents_target_render_surface()) {
916 if (it
->mask_layer())
917 it
->mask_layer()->SetTexturePriorities(calculator
);
918 if (it
->replica_layer() && it
->replica_layer()->mask_layer())
919 it
->replica_layer()->mask_layer()->SetTexturePriorities(calculator
);
924 void LayerTreeHost::PrioritizeTextures(
925 const RenderSurfaceLayerList
& render_surface_layer_list
) {
926 if (!contents_texture_manager_
)
929 contents_texture_manager_
->ClearPriorities();
931 size_t memory_for_render_surfaces_metric
=
932 CalculateMemoryForRenderSurfaces(render_surface_layer_list
);
934 SetPrioritiesForLayers(render_surface_layer_list
);
935 SetPrioritiesForSurfaces(memory_for_render_surfaces_metric
);
937 contents_texture_manager_
->PrioritizeTextures();
940 size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
941 const RenderSurfaceLayerList
& update_list
) {
942 size_t readback_bytes
= 0;
943 size_t max_background_texture_bytes
= 0;
944 size_t contents_texture_bytes
= 0;
946 // Start iteration at 1 to skip the root surface as it does not have a texture
948 for (size_t i
= 1; i
< update_list
.size(); ++i
) {
949 Layer
* render_surface_layer
= update_list
.at(i
);
950 RenderSurface
* render_surface
= render_surface_layer
->render_surface();
953 Resource::MemorySizeBytes(render_surface
->content_rect().size(),
955 contents_texture_bytes
+= bytes
;
957 if (render_surface_layer
->background_filters().IsEmpty())
960 if (bytes
> max_background_texture_bytes
)
961 max_background_texture_bytes
= bytes
;
962 if (!readback_bytes
) {
963 readback_bytes
= Resource::MemorySizeBytes(device_viewport_size_
,
967 return readback_bytes
+ max_background_texture_bytes
+ contents_texture_bytes
;
970 void LayerTreeHost::PaintMasksForRenderSurface(Layer
* render_surface_layer
,
971 ResourceUpdateQueue
* queue
,
972 bool* did_paint_content
,
973 bool* need_more_updates
) {
974 // Note: Masks and replicas only exist for layers that own render surfaces. If
975 // we reach this point in code, we already know that at least something will
976 // be drawn into this render surface, so the mask and replica should be
979 Layer
* mask_layer
= render_surface_layer
->mask_layer();
981 *did_paint_content
|= mask_layer
->Update(queue
, NULL
);
982 *need_more_updates
|= mask_layer
->NeedMoreUpdates();
985 Layer
* replica_mask_layer
=
986 render_surface_layer
->replica_layer() ?
987 render_surface_layer
->replica_layer()->mask_layer() : NULL
;
988 if (replica_mask_layer
) {
989 *did_paint_content
|= replica_mask_layer
->Update(queue
, NULL
);
990 *need_more_updates
|= replica_mask_layer
->NeedMoreUpdates();
994 void LayerTreeHost::PaintLayerContents(
995 const RenderSurfaceLayerList
& render_surface_layer_list
,
996 ResourceUpdateQueue
* queue
,
997 bool* did_paint_content
,
998 bool* need_more_updates
) {
999 OcclusionTracker
<Layer
> occlusion_tracker(
1000 root_layer_
->render_surface()->content_rect());
1001 occlusion_tracker
.set_minimum_tracking_size(
1002 settings_
.minimum_occlusion_tracking_size
);
1004 PrioritizeTextures(render_surface_layer_list
);
1006 in_paint_layer_contents_
= true;
1008 // Iterates front-to-back to allow for testing occlusion and performing
1009 // culling during the tree walk.
1010 typedef LayerIterator
<Layer
> LayerIteratorType
;
1011 LayerIteratorType end
= LayerIteratorType::End(&render_surface_layer_list
);
1012 for (LayerIteratorType it
=
1013 LayerIteratorType::Begin(&render_surface_layer_list
);
1016 occlusion_tracker
.EnterLayer(it
);
1018 if (it
.represents_target_render_surface()) {
1019 PaintMasksForRenderSurface(
1020 *it
, queue
, did_paint_content
, need_more_updates
);
1021 } else if (it
.represents_itself()) {
1022 DCHECK(!it
->paint_properties().bounds
.IsEmpty());
1023 *did_paint_content
|= it
->Update(queue
, &occlusion_tracker
);
1024 *need_more_updates
|= it
->NeedMoreUpdates();
1025 // Note the '&&' with previous is-suitable state.
1026 // This means that once the layer-tree becomes unsuitable for gpu
1027 // rasterization due to some content, it will continue to be unsuitable
1028 // even if that content is replaced by gpu-friendly content.
1029 // This is to avoid switching back-and-forth between gpu and sw
1030 // rasterization which may be both bad for performance and visually
1032 content_is_suitable_for_gpu_rasterization_
&=
1033 it
->IsSuitableForGpuRasterization();
1036 occlusion_tracker
.LeaveLayer(it
);
1039 in_paint_layer_contents_
= false;
1042 void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet
* info
) {
1043 if (!root_layer_
.get())
1046 ScopedPtrVector
<SwapPromise
>::iterator it
= info
->swap_promises
.begin();
1047 for (; it
!= info
->swap_promises
.end(); ++it
) {
1048 scoped_ptr
<SwapPromise
> swap_promise(info
->swap_promises
.take(it
));
1049 TRACE_EVENT_FLOW_STEP0("input",
1051 TRACE_ID_DONT_MANGLE(swap_promise
->TraceId()),
1052 "Main thread scroll update");
1053 QueueSwapPromise(swap_promise
.Pass());
1056 gfx::Vector2d inner_viewport_scroll_delta
;
1057 gfx::Vector2d outer_viewport_scroll_delta
;
1059 for (size_t i
= 0; i
< info
->scrolls
.size(); ++i
) {
1060 Layer
* layer
= LayerTreeHostCommon::FindLayerInSubtree(
1061 root_layer_
.get(), info
->scrolls
[i
].layer_id
);
1064 if (layer
== outer_viewport_scroll_layer_
.get()) {
1065 outer_viewport_scroll_delta
+= info
->scrolls
[i
].scroll_delta
;
1066 } else if (layer
== inner_viewport_scroll_layer_
.get()) {
1067 inner_viewport_scroll_delta
+= info
->scrolls
[i
].scroll_delta
;
1069 layer
->SetScrollOffsetFromImplSide(layer
->scroll_offset() +
1070 info
->scrolls
[i
].scroll_delta
);
1074 if (!inner_viewport_scroll_delta
.IsZero() ||
1075 !outer_viewport_scroll_delta
.IsZero() || info
->page_scale_delta
!= 1.f
) {
1076 // SetScrollOffsetFromImplSide above could have destroyed the tree,
1077 // so re-get this layer before doing anything to it.
1079 // Preemptively apply the scroll offset and scale delta here before sending
1080 // it to the client. If the client comes back and sets it to the same
1081 // value, then the layer can early out without needing a full commit.
1082 DCHECK(inner_viewport_scroll_layer_
.get()); // We should always have this.
1084 inner_viewport_scroll_layer_
->SetScrollOffsetFromImplSide(
1085 inner_viewport_scroll_layer_
->scroll_offset() +
1086 inner_viewport_scroll_delta
);
1087 if (outer_viewport_scroll_layer_
.get()) {
1088 outer_viewport_scroll_layer_
->SetScrollOffsetFromImplSide(
1089 outer_viewport_scroll_layer_
->scroll_offset() +
1090 outer_viewport_scroll_delta
);
1092 ApplyPageScaleDeltaFromImplSide(info
->page_scale_delta
);
1094 client_
->ApplyScrollAndScale(
1095 inner_viewport_scroll_delta
+ outer_viewport_scroll_delta
,
1096 info
->page_scale_delta
);
1100 void LayerTreeHost::StartRateLimiter() {
1101 if (inside_begin_main_frame_
)
1104 if (!rate_limit_timer_
.IsRunning()) {
1105 rate_limit_timer_
.Start(FROM_HERE
,
1108 &LayerTreeHost::RateLimit
);
1112 void LayerTreeHost::StopRateLimiter() {
1113 rate_limit_timer_
.Stop();
1116 void LayerTreeHost::RateLimit() {
1117 // Force a no-op command on the compositor context, so that any ratelimiting
1118 // commands will wait for the compositing context, and therefore for the
1120 proxy_
->ForceSerializeOnSwapBuffers();
1121 client_
->RateLimitSharedMainThreadContext();
1124 bool LayerTreeHost::AlwaysUsePartialTextureUpdates() {
1125 if (!proxy_
->GetRendererCapabilities().allow_partial_texture_updates
)
1127 return !proxy_
->HasImplThread();
1130 size_t LayerTreeHost::MaxPartialTextureUpdates() const {
1131 size_t max_partial_texture_updates
= 0;
1132 if (proxy_
->GetRendererCapabilities().allow_partial_texture_updates
&&
1133 !settings_
.impl_side_painting
) {
1134 max_partial_texture_updates
=
1135 std::min(settings_
.max_partial_texture_updates
,
1136 proxy_
->MaxPartialTextureUpdates());
1138 return max_partial_texture_updates
;
1141 bool LayerTreeHost::RequestPartialTextureUpdate() {
1142 if (partial_texture_update_requests_
>= MaxPartialTextureUpdates())
1145 partial_texture_update_requests_
++;
1149 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor
) {
1150 if (device_scale_factor
== device_scale_factor_
)
1152 device_scale_factor_
= device_scale_factor
;
1157 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints
,
1158 TopControlsState current
,
1160 if (!settings_
.calculate_top_controls_position
)
1163 // Top controls are only used in threaded mode.
1164 proxy_
->ImplThreadTaskRunner()->PostTask(
1166 base::Bind(&TopControlsManager::UpdateTopControlsState
,
1167 top_controls_manager_weak_ptr_
,
1173 void LayerTreeHost::AsValueInto(base::debug::TracedValue
* state
) const {
1174 state
->BeginDictionary("proxy");
1175 proxy_
->AsValueInto(state
);
1176 state
->EndDictionary();
1179 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time
) {
1180 if (!settings_
.accelerated_animation_enabled
||
1181 animation_registrar_
->active_animation_controllers().empty())
1184 TRACE_EVENT0("cc", "LayerTreeHost::AnimateLayers");
1186 AnimationRegistrar::AnimationControllerMap copy
=
1187 animation_registrar_
->active_animation_controllers();
1188 for (AnimationRegistrar::AnimationControllerMap::iterator iter
= copy
.begin();
1191 (*iter
).second
->Animate(monotonic_time
);
1192 bool start_ready_animations
= true;
1193 (*iter
).second
->UpdateState(start_ready_animations
, NULL
);
1197 UIResourceId
LayerTreeHost::CreateUIResource(UIResourceClient
* client
) {
1200 UIResourceId next_id
= next_ui_resource_id_
++;
1201 DCHECK(ui_resource_client_map_
.find(next_id
) ==
1202 ui_resource_client_map_
.end());
1204 bool resource_lost
= false;
1205 UIResourceRequest
request(UIResourceRequest::UIResourceCreate
,
1207 client
->GetBitmap(next_id
, resource_lost
));
1208 ui_resource_request_queue_
.push_back(request
);
1210 UIResourceClientData data
;
1211 data
.client
= client
;
1212 data
.size
= request
.GetBitmap().GetSize();
1214 ui_resource_client_map_
[request
.GetId()] = data
;
1215 return request
.GetId();
1218 // Deletes a UI resource. May safely be called more than once.
1219 void LayerTreeHost::DeleteUIResource(UIResourceId uid
) {
1220 UIResourceClientMap::iterator iter
= ui_resource_client_map_
.find(uid
);
1221 if (iter
== ui_resource_client_map_
.end())
1224 UIResourceRequest
request(UIResourceRequest::UIResourceDelete
, uid
);
1225 ui_resource_request_queue_
.push_back(request
);
1226 ui_resource_client_map_
.erase(iter
);
1229 void LayerTreeHost::RecreateUIResources() {
1230 for (UIResourceClientMap::iterator iter
= ui_resource_client_map_
.begin();
1231 iter
!= ui_resource_client_map_
.end();
1233 UIResourceId uid
= iter
->first
;
1234 const UIResourceClientData
& data
= iter
->second
;
1235 bool resource_lost
= true;
1236 UIResourceRequest
request(UIResourceRequest::UIResourceCreate
,
1238 data
.client
->GetBitmap(uid
, resource_lost
));
1239 ui_resource_request_queue_
.push_back(request
);
1243 // Returns the size of a resource given its id.
1244 gfx::Size
LayerTreeHost::GetUIResourceSize(UIResourceId uid
) const {
1245 UIResourceClientMap::const_iterator iter
= ui_resource_client_map_
.find(uid
);
1246 if (iter
== ui_resource_client_map_
.end())
1249 const UIResourceClientData
& data
= iter
->second
;
1253 void LayerTreeHost::RegisterViewportLayers(
1254 scoped_refptr
<Layer
> page_scale_layer
,
1255 scoped_refptr
<Layer
> inner_viewport_scroll_layer
,
1256 scoped_refptr
<Layer
> outer_viewport_scroll_layer
) {
1257 page_scale_layer_
= page_scale_layer
;
1258 inner_viewport_scroll_layer_
= inner_viewport_scroll_layer
;
1259 outer_viewport_scroll_layer_
= outer_viewport_scroll_layer
;
1262 void LayerTreeHost::RegisterSelection(const LayerSelectionBound
& start
,
1263 const LayerSelectionBound
& end
) {
1264 if (selection_start_
== start
&& selection_end_
== end
)
1267 selection_start_
= start
;
1268 selection_end_
= end
;
1272 int LayerTreeHost::ScheduleMicroBenchmark(
1273 const std::string
& benchmark_name
,
1274 scoped_ptr
<base::Value
> value
,
1275 const MicroBenchmark::DoneCallback
& callback
) {
1276 return micro_benchmark_controller_
.ScheduleRun(
1277 benchmark_name
, value
.Pass(), callback
);
1280 bool LayerTreeHost::SendMessageToMicroBenchmark(int id
,
1281 scoped_ptr
<base::Value
> value
) {
1282 return micro_benchmark_controller_
.SendMessage(id
, value
.Pass());
1285 void LayerTreeHost::InsertSwapPromiseMonitor(SwapPromiseMonitor
* monitor
) {
1286 swap_promise_monitor_
.insert(monitor
);
1289 void LayerTreeHost::RemoveSwapPromiseMonitor(SwapPromiseMonitor
* monitor
) {
1290 swap_promise_monitor_
.erase(monitor
);
1293 void LayerTreeHost::NotifySwapPromiseMonitorsOfSetNeedsCommit() {
1294 std::set
<SwapPromiseMonitor
*>::iterator it
= swap_promise_monitor_
.begin();
1295 for (; it
!= swap_promise_monitor_
.end(); it
++)
1296 (*it
)->OnSetNeedsCommitOnMain();
1299 void LayerTreeHost::QueueSwapPromise(scoped_ptr
<SwapPromise
> swap_promise
) {
1300 DCHECK(swap_promise
);
1301 swap_promise_list_
.push_back(swap_promise
.Pass());
1304 void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason
) {
1305 for (size_t i
= 0; i
< swap_promise_list_
.size(); i
++)
1306 swap_promise_list_
[i
]->DidNotSwap(reason
);
1307 swap_promise_list_
.clear();