Provide core API permissions to extensions_unittests
[chromium-blink-merge.git] / cc / trees / layer_tree_host.cc
blob343c503982851aeb8d4d3d6a586be6d475409db9
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"
7 #include <algorithm>
8 #include <stack>
9 #include <string>
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"
45 namespace {
46 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number;
49 namespace cc {
51 RendererCapabilities::RendererCapabilities(ResourceFormat best_texture_format,
52 bool allow_partial_texture_updates,
53 int max_texture_size,
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),
63 max_texture_size(0),
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);
75 DCHECK(impl_task_runner);
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,
91 main_task_runner);
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),
102 client_(client),
103 source_frame_number_(0),
104 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
105 output_surface_lost_(true),
106 num_failed_recreate_attempts_(0),
107 settings_(settings),
108 debug_state_(settings.initial_debug_state),
109 top_controls_layout_height_(0.f),
110 device_scale_factor_(1.f),
111 visible_(true),
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) {
135 InitializeProxy(
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) {
142 InitializeProxy(
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();
154 proxy_->Start();
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 CHECK(swap_promise_monitor_.empty());
166 BreakSwapPromises(SwapPromise::COMMIT_FAILS);
168 overhang_ui_resource_.reset();
170 if (root_layer_.get())
171 root_layer_->SetLayerTreeHost(NULL);
173 if (proxy_) {
174 DCHECK(proxy_->IsMainThread());
175 proxy_->Stop();
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.
185 root_layer_ = NULL;
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_);
199 TRACE_EVENT1("cc",
200 "LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted",
201 "success",
202 success);
204 if (!success) {
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();
211 return;
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);
223 if (root_layer()) {
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() {
253 client_->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));
321 } else {
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_ && inner_viewport_scroll_layer_) {
329 sync_tree->SetViewportLayersFromIds(
330 page_scale_layer_->id(),
331 inner_viewport_scroll_layer_->id(),
332 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
333 : Layer::INVALID_ID);
334 } else {
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_,
345 page_scale_delta);
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();
401 hud_layer_ = NULL;
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_,
419 client,
420 proxy_.get(),
421 rendering_stats_instrumentation_.get(),
422 shared_bitmap_manager_,
423 id_);
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_)
440 return;
442 num_failed_recreate_attempts_ = 0;
443 output_surface_lost_ = true;
444 SetNeedsCommit();
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();
462 layer_stack.pop();
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;
497 SetNeedsCommit();
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]);
541 break;
543 case AnimationEvent::Finished:
544 (*iter).second->NotifyAnimationFinished((*events)[event_index]);
545 break;
547 case AnimationEvent::Aborted:
548 (*iter).second->NotifyAnimationAborted((*events)[event_index]);
549 break;
551 case AnimationEvent::PropertyUpdate:
552 (*iter).second->NotifyAnimationPropertyUpdate((*events)[event_index]);
553 break;
559 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) {
560 if (root_layer_.get() == root_layer.get())
561 return;
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))
587 return;
589 debug_state_ = new_debug_state;
591 rendering_stats_instrumentation_->set_record_rendering_stats(
592 debug_state_.RecordRenderingStats());
594 SetNeedsCommit();
595 proxy_->SetDebugState(debug_state);
598 bool LayerTreeHost::UseGpuRasterization() const {
599 if (settings_.gpu_rasterization_forced) {
600 return true;
601 } else if (settings_.gpu_rasterization_enabled) {
602 return has_gpu_rasterization_trigger_ &&
603 content_is_suitable_for_gpu_rasterization_;
604 } else {
605 return false;
609 void LayerTreeHost::SetHasGpuRasterizationTrigger(bool has_trigger) {
610 if (has_trigger == has_gpu_rasterization_trigger_)
611 return;
613 has_gpu_rasterization_trigger_ = has_trigger;
614 TRACE_EVENT_INSTANT1("cc",
615 "LayerTreeHost::SetHasGpuRasterizationTrigger",
616 TRACE_EVENT_SCOPE_THREAD,
617 "has_trigger",
618 has_gpu_rasterization_trigger_);
621 void LayerTreeHost::SetViewportSize(const gfx::Size& device_viewport_size) {
622 if (device_viewport_size == device_viewport_size_)
623 return;
625 device_viewport_size_ = device_viewport_size;
627 SetNeedsCommit();
630 void LayerTreeHost::SetTopControlsLayoutHeight(
631 float top_controls_layout_height) {
632 if (top_controls_layout_height_ == top_controls_layout_height)
633 return;
635 top_controls_layout_height_ = top_controls_layout_height;
636 SetNeedsCommit();
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_)
650 return;
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;
655 SetNeedsCommit();
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;
665 } else {
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)
677 return;
678 visible_ = visible;
679 if (!visible)
680 ReduceMemoryUsage();
681 proxy_->SetVisible(visible);
684 void LayerTreeHost::StartPageScaleAnimation(const gfx::Vector2d& target_offset,
685 bool use_anchor,
686 float scale,
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;
694 SetNeedsCommit();
697 void LayerTreeHost::NotifyInputThrottledUntilCommit() {
698 proxy_->NotifyInputThrottledUntilCommit();
701 void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) {
702 DCHECK(!proxy_->HasImplThread());
703 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get());
705 if (output_surface_lost_)
706 proxy->CreateAndInitializeOutputSurface();
707 if (output_surface_lost_)
708 return;
710 proxy->CompositeImmediately(frame_begin_time);
713 bool LayerTreeHost::UpdateLayers(ResourceUpdateQueue* queue) {
714 DCHECK(!output_surface_lost_);
716 if (!root_layer())
717 return false;
719 DCHECK(!root_layer()->parent());
721 bool result = UpdateLayers(root_layer(), queue);
723 micro_benchmark_controller_.DidUpdateLayers();
725 return result || next_commit_forces_redraw_;
728 static Layer* FindFirstScrollableLayer(Layer* layer) {
729 if (!layer)
730 return NULL;
732 if (layer->scrollable())
733 return layer;
735 for (size_t i = 0; i < layer->children().size(); ++i) {
736 Layer* found = FindFirstScrollableLayer(layer->children()[i].get());
737 if (found)
738 return found;
741 return NULL;
744 void LayerTreeHost::RecordGpuRasterizationHistogram() {
745 // Gpu rasterization is only supported when impl-side painting is enabled.
746 if (gpu_rasterization_histogram_recorded_ || !settings_.impl_side_painting)
747 return;
749 // Record how widely gpu rasterization is enabled.
750 // This number takes device/gpu whitelisting/backlisting into account.
751 // Note that we do not consider the forced gpu rasterization mode, which is
752 // mostly used for debugging purposes.
753 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled",
754 settings_.gpu_rasterization_enabled);
755 if (settings_.gpu_rasterization_enabled) {
756 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered",
757 has_gpu_rasterization_trigger_);
758 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationSuitableContent",
759 content_is_suitable_for_gpu_rasterization_);
760 // Record how many pages actually get gpu rasterization when enabled.
761 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed",
762 (has_gpu_rasterization_trigger_ &&
763 content_is_suitable_for_gpu_rasterization_));
766 gpu_rasterization_histogram_recorded_ = true;
769 void LayerTreeHost::CalculateLCDTextMetricsCallback(Layer* layer) {
770 if (!layer->SupportsLCDText())
771 return;
773 lcd_text_metrics_.total_num_cc_layers++;
774 if (layer->draw_properties().can_use_lcd_text) {
775 lcd_text_metrics_.total_num_cc_layers_can_use_lcd_text++;
776 if (layer->contents_opaque())
777 lcd_text_metrics_.total_num_cc_layers_will_use_lcd_text++;
781 bool LayerTreeHost::UsingSharedMemoryResources() {
782 return GetRendererCapabilities().using_shared_memory_resources;
785 bool LayerTreeHost::UpdateLayers(Layer* root_layer,
786 ResourceUpdateQueue* queue) {
787 TRACE_EVENT1("cc", "LayerTreeHost::UpdateLayers",
788 "source_frame_number", source_frame_number());
790 RenderSurfaceLayerList update_list;
792 UpdateHudLayer();
794 Layer* root_scroll = FindFirstScrollableLayer(root_layer);
795 Layer* page_scale_layer = page_scale_layer_;
796 if (!page_scale_layer && root_scroll)
797 page_scale_layer = root_scroll->parent();
799 if (hud_layer_) {
800 hud_layer_->PrepareForCalculateDrawProperties(
801 device_viewport_size(), device_scale_factor_);
804 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::CalcDrawProps");
805 bool can_render_to_separate_surface = true;
806 // TODO(vmpstr): Passing 0 as the current render surface layer list id means
807 // that we won't be able to detect if a layer is part of |update_list|.
808 // Change this if this information is required.
809 int render_surface_layer_list_id = 0;
810 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(
811 root_layer,
812 device_viewport_size(),
813 gfx::Transform(),
814 device_scale_factor_,
815 page_scale_factor_,
816 page_scale_layer,
817 GetRendererCapabilities().max_texture_size,
818 settings_.can_use_lcd_text,
819 can_render_to_separate_surface,
820 settings_.layer_transforms_should_scale_layer_contents,
821 &update_list,
822 render_surface_layer_list_id);
823 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
825 if (total_frames_used_for_lcd_text_metrics_ <=
826 kTotalFramesToUseForLCDTextMetrics) {
827 LayerTreeHostCommon::CallFunctionForSubtree(
828 root_layer,
829 base::Bind(&LayerTreeHost::CalculateLCDTextMetricsCallback,
830 base::Unretained(this)));
831 total_frames_used_for_lcd_text_metrics_++;
834 if (total_frames_used_for_lcd_text_metrics_ ==
835 kTotalFramesToUseForLCDTextMetrics) {
836 total_frames_used_for_lcd_text_metrics_++;
838 UMA_HISTOGRAM_PERCENTAGE(
839 "Renderer4.LCDText.PercentageOfCandidateLayers",
840 lcd_text_metrics_.total_num_cc_layers_can_use_lcd_text * 100.0 /
841 lcd_text_metrics_.total_num_cc_layers);
842 UMA_HISTOGRAM_PERCENTAGE(
843 "Renderer4.LCDText.PercentageOfAALayers",
844 lcd_text_metrics_.total_num_cc_layers_will_use_lcd_text * 100.0 /
845 lcd_text_metrics_.total_num_cc_layers_can_use_lcd_text);
849 // Reset partial texture update requests.
850 partial_texture_update_requests_ = 0;
852 bool did_paint_content = false;
853 bool need_more_updates = false;
854 PaintLayerContents(
855 update_list, queue, &did_paint_content, &need_more_updates);
856 if (need_more_updates) {
857 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::posting prepaint task");
858 prepaint_callback_.Reset(base::Bind(&LayerTreeHost::TriggerPrepaint,
859 base::Unretained(this)));
860 static base::TimeDelta prepaint_delay =
861 base::TimeDelta::FromMilliseconds(100);
862 base::MessageLoop::current()->PostDelayedTask(
863 FROM_HERE, prepaint_callback_.callback(), prepaint_delay);
866 return did_paint_content;
869 void LayerTreeHost::TriggerPrepaint() {
870 prepaint_callback_.Cancel();
871 TRACE_EVENT0("cc", "LayerTreeHost::TriggerPrepaint");
872 SetNeedsCommit();
875 static void LayerTreeHostReduceMemoryCallback(Layer* layer) {
876 layer->ReduceMemoryUsage();
879 void LayerTreeHost::ReduceMemoryUsage() {
880 if (!root_layer())
881 return;
883 LayerTreeHostCommon::CallFunctionForSubtree(
884 root_layer(),
885 base::Bind(&LayerTreeHostReduceMemoryCallback));
888 void LayerTreeHost::SetPrioritiesForSurfaces(size_t surface_memory_bytes) {
889 DCHECK(surface_memory_placeholder_);
891 // Surfaces have a place holder for their memory since they are managed
892 // independantly but should still be tracked and reduce other memory usage.
893 surface_memory_placeholder_->SetTextureManager(
894 contents_texture_manager_.get());
895 surface_memory_placeholder_->set_request_priority(
896 PriorityCalculator::RenderSurfacePriority());
897 surface_memory_placeholder_->SetToSelfManagedMemoryPlaceholder(
898 surface_memory_bytes);
901 void LayerTreeHost::SetPrioritiesForLayers(
902 const RenderSurfaceLayerList& update_list) {
903 PriorityCalculator calculator;
904 typedef LayerIterator<Layer> LayerIteratorType;
905 LayerIteratorType end = LayerIteratorType::End(&update_list);
906 for (LayerIteratorType it = LayerIteratorType::Begin(&update_list);
907 it != end;
908 ++it) {
909 if (it.represents_itself()) {
910 it->SetTexturePriorities(calculator);
911 } else if (it.represents_target_render_surface()) {
912 if (it->mask_layer())
913 it->mask_layer()->SetTexturePriorities(calculator);
914 if (it->replica_layer() && it->replica_layer()->mask_layer())
915 it->replica_layer()->mask_layer()->SetTexturePriorities(calculator);
920 void LayerTreeHost::PrioritizeTextures(
921 const RenderSurfaceLayerList& render_surface_layer_list) {
922 if (!contents_texture_manager_)
923 return;
925 contents_texture_manager_->ClearPriorities();
927 size_t memory_for_render_surfaces_metric =
928 CalculateMemoryForRenderSurfaces(render_surface_layer_list);
930 SetPrioritiesForLayers(render_surface_layer_list);
931 SetPrioritiesForSurfaces(memory_for_render_surfaces_metric);
933 contents_texture_manager_->PrioritizeTextures();
936 size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
937 const RenderSurfaceLayerList& update_list) {
938 size_t readback_bytes = 0;
939 size_t max_background_texture_bytes = 0;
940 size_t contents_texture_bytes = 0;
942 // Start iteration at 1 to skip the root surface as it does not have a texture
943 // cost.
944 for (size_t i = 1; i < update_list.size(); ++i) {
945 Layer* render_surface_layer = update_list.at(i);
946 RenderSurface* render_surface = render_surface_layer->render_surface();
948 size_t bytes =
949 Resource::MemorySizeBytes(render_surface->content_rect().size(),
950 RGBA_8888);
951 contents_texture_bytes += bytes;
953 if (render_surface_layer->background_filters().IsEmpty())
954 continue;
956 if (bytes > max_background_texture_bytes)
957 max_background_texture_bytes = bytes;
958 if (!readback_bytes) {
959 readback_bytes = Resource::MemorySizeBytes(device_viewport_size_,
960 RGBA_8888);
963 return readback_bytes + max_background_texture_bytes + contents_texture_bytes;
966 void LayerTreeHost::PaintMasksForRenderSurface(Layer* render_surface_layer,
967 ResourceUpdateQueue* queue,
968 bool* did_paint_content,
969 bool* need_more_updates) {
970 // Note: Masks and replicas only exist for layers that own render surfaces. If
971 // we reach this point in code, we already know that at least something will
972 // be drawn into this render surface, so the mask and replica should be
973 // painted.
975 Layer* mask_layer = render_surface_layer->mask_layer();
976 if (mask_layer) {
977 *did_paint_content |= mask_layer->Update(queue, NULL);
978 *need_more_updates |= mask_layer->NeedMoreUpdates();
981 Layer* replica_mask_layer =
982 render_surface_layer->replica_layer() ?
983 render_surface_layer->replica_layer()->mask_layer() : NULL;
984 if (replica_mask_layer) {
985 *did_paint_content |= replica_mask_layer->Update(queue, NULL);
986 *need_more_updates |= replica_mask_layer->NeedMoreUpdates();
990 void LayerTreeHost::PaintLayerContents(
991 const RenderSurfaceLayerList& render_surface_layer_list,
992 ResourceUpdateQueue* queue,
993 bool* did_paint_content,
994 bool* need_more_updates) {
995 OcclusionTracker<Layer> occlusion_tracker(
996 root_layer_->render_surface()->content_rect());
997 occlusion_tracker.set_minimum_tracking_size(
998 settings_.minimum_occlusion_tracking_size);
1000 PrioritizeTextures(render_surface_layer_list);
1002 in_paint_layer_contents_ = true;
1004 // Iterates front-to-back to allow for testing occlusion and performing
1005 // culling during the tree walk.
1006 typedef LayerIterator<Layer> LayerIteratorType;
1007 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list);
1008 for (LayerIteratorType it =
1009 LayerIteratorType::Begin(&render_surface_layer_list);
1010 it != end;
1011 ++it) {
1012 occlusion_tracker.EnterLayer(it);
1014 if (it.represents_target_render_surface()) {
1015 PaintMasksForRenderSurface(
1016 *it, queue, did_paint_content, need_more_updates);
1017 } else if (it.represents_itself()) {
1018 DCHECK(!it->paint_properties().bounds.IsEmpty());
1019 *did_paint_content |= it->Update(queue, &occlusion_tracker);
1020 *need_more_updates |= it->NeedMoreUpdates();
1021 // Note the '&&' with previous is-suitable state.
1022 // This means that once the layer-tree becomes unsuitable for gpu
1023 // rasterization due to some content, it will continue to be unsuitable
1024 // even if that content is replaced by gpu-friendly content.
1025 // This is to avoid switching back-and-forth between gpu and sw
1026 // rasterization which may be both bad for performance and visually
1027 // jarring.
1028 content_is_suitable_for_gpu_rasterization_ &=
1029 it->IsSuitableForGpuRasterization();
1032 occlusion_tracker.LeaveLayer(it);
1035 in_paint_layer_contents_ = false;
1038 void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) {
1039 if (!root_layer_.get())
1040 return;
1042 ScopedPtrVector<SwapPromise>::iterator it = info->swap_promises.begin();
1043 for (; it != info->swap_promises.end(); ++it) {
1044 scoped_ptr<SwapPromise> swap_promise(info->swap_promises.take(it));
1045 TRACE_EVENT_FLOW_STEP0("input",
1046 "LatencyInfo.Flow",
1047 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()),
1048 "Main thread scroll update");
1049 QueueSwapPromise(swap_promise.Pass());
1052 gfx::Vector2d inner_viewport_scroll_delta;
1053 gfx::Vector2d outer_viewport_scroll_delta;
1055 for (size_t i = 0; i < info->scrolls.size(); ++i) {
1056 Layer* layer = LayerTreeHostCommon::FindLayerInSubtree(
1057 root_layer_.get(), info->scrolls[i].layer_id);
1058 if (!layer)
1059 continue;
1060 if (layer == outer_viewport_scroll_layer_.get()) {
1061 outer_viewport_scroll_delta += info->scrolls[i].scroll_delta;
1062 } else if (layer == inner_viewport_scroll_layer_.get()) {
1063 inner_viewport_scroll_delta += info->scrolls[i].scroll_delta;
1064 } else {
1065 layer->SetScrollOffsetFromImplSide(layer->scroll_offset() +
1066 info->scrolls[i].scroll_delta);
1070 if (!inner_viewport_scroll_delta.IsZero() ||
1071 !outer_viewport_scroll_delta.IsZero() || info->page_scale_delta != 1.f) {
1072 // SetScrollOffsetFromImplSide above could have destroyed the tree,
1073 // so re-get this layer before doing anything to it.
1075 // Preemptively apply the scroll offset and scale delta here before sending
1076 // it to the client. If the client comes back and sets it to the same
1077 // value, then the layer can early out without needing a full commit.
1078 DCHECK(inner_viewport_scroll_layer_); // We should always have this.
1080 inner_viewport_scroll_layer_->SetScrollOffsetFromImplSide(
1081 inner_viewport_scroll_layer_->scroll_offset() +
1082 inner_viewport_scroll_delta);
1083 if (outer_viewport_scroll_layer_) {
1084 outer_viewport_scroll_layer_->SetScrollOffsetFromImplSide(
1085 outer_viewport_scroll_layer_->scroll_offset() +
1086 outer_viewport_scroll_delta);
1088 ApplyPageScaleDeltaFromImplSide(info->page_scale_delta);
1090 client_->ApplyScrollAndScale(
1091 inner_viewport_scroll_delta + outer_viewport_scroll_delta,
1092 info->page_scale_delta);
1096 void LayerTreeHost::StartRateLimiter() {
1097 if (inside_begin_main_frame_)
1098 return;
1100 if (!rate_limit_timer_.IsRunning()) {
1101 rate_limit_timer_.Start(FROM_HERE,
1102 base::TimeDelta(),
1103 this,
1104 &LayerTreeHost::RateLimit);
1108 void LayerTreeHost::StopRateLimiter() {
1109 rate_limit_timer_.Stop();
1112 void LayerTreeHost::RateLimit() {
1113 // Force a no-op command on the compositor context, so that any ratelimiting
1114 // commands will wait for the compositing context, and therefore for the
1115 // SwapBuffers.
1116 proxy_->ForceSerializeOnSwapBuffers();
1117 client_->RateLimitSharedMainThreadContext();
1120 bool LayerTreeHost::AlwaysUsePartialTextureUpdates() {
1121 if (!proxy_->GetRendererCapabilities().allow_partial_texture_updates)
1122 return false;
1123 return !proxy_->HasImplThread();
1126 size_t LayerTreeHost::MaxPartialTextureUpdates() const {
1127 size_t max_partial_texture_updates = 0;
1128 if (proxy_->GetRendererCapabilities().allow_partial_texture_updates &&
1129 !settings_.impl_side_painting) {
1130 max_partial_texture_updates =
1131 std::min(settings_.max_partial_texture_updates,
1132 proxy_->MaxPartialTextureUpdates());
1134 return max_partial_texture_updates;
1137 bool LayerTreeHost::RequestPartialTextureUpdate() {
1138 if (partial_texture_update_requests_ >= MaxPartialTextureUpdates())
1139 return false;
1141 partial_texture_update_requests_++;
1142 return true;
1145 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) {
1146 if (device_scale_factor == device_scale_factor_)
1147 return;
1148 device_scale_factor_ = device_scale_factor;
1150 SetNeedsCommit();
1153 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
1154 TopControlsState current,
1155 bool animate) {
1156 if (!settings_.calculate_top_controls_position)
1157 return;
1159 // Top controls are only used in threaded mode.
1160 proxy_->ImplThreadTaskRunner()->PostTask(
1161 FROM_HERE,
1162 base::Bind(&TopControlsManager::UpdateTopControlsState,
1163 top_controls_manager_weak_ptr_,
1164 constraints,
1165 current,
1166 animate));
1169 void LayerTreeHost::AsValueInto(base::debug::TracedValue* state) const {
1170 state->BeginDictionary("proxy");
1171 proxy_->AsValueInto(state);
1172 state->EndDictionary();
1175 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
1176 if (!settings_.accelerated_animation_enabled ||
1177 animation_registrar_->active_animation_controllers().empty())
1178 return;
1180 TRACE_EVENT0("cc", "LayerTreeHost::AnimateLayers");
1182 AnimationRegistrar::AnimationControllerMap copy =
1183 animation_registrar_->active_animation_controllers();
1184 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
1185 iter != copy.end();
1186 ++iter) {
1187 (*iter).second->Animate(monotonic_time);
1188 bool start_ready_animations = true;
1189 (*iter).second->UpdateState(start_ready_animations, NULL);
1193 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) {
1194 DCHECK(client);
1196 UIResourceId next_id = next_ui_resource_id_++;
1197 DCHECK(ui_resource_client_map_.find(next_id) ==
1198 ui_resource_client_map_.end());
1200 bool resource_lost = false;
1201 UIResourceRequest request(UIResourceRequest::UIResourceCreate,
1202 next_id,
1203 client->GetBitmap(next_id, resource_lost));
1204 ui_resource_request_queue_.push_back(request);
1206 UIResourceClientData data;
1207 data.client = client;
1208 data.size = request.GetBitmap().GetSize();
1210 ui_resource_client_map_[request.GetId()] = data;
1211 return request.GetId();
1214 // Deletes a UI resource. May safely be called more than once.
1215 void LayerTreeHost::DeleteUIResource(UIResourceId uid) {
1216 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
1217 if (iter == ui_resource_client_map_.end())
1218 return;
1220 UIResourceRequest request(UIResourceRequest::UIResourceDelete, uid);
1221 ui_resource_request_queue_.push_back(request);
1222 ui_resource_client_map_.erase(iter);
1225 void LayerTreeHost::RecreateUIResources() {
1226 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin();
1227 iter != ui_resource_client_map_.end();
1228 ++iter) {
1229 UIResourceId uid = iter->first;
1230 const UIResourceClientData& data = iter->second;
1231 bool resource_lost = true;
1232 UIResourceRequest request(UIResourceRequest::UIResourceCreate,
1233 uid,
1234 data.client->GetBitmap(uid, resource_lost));
1235 ui_resource_request_queue_.push_back(request);
1239 // Returns the size of a resource given its id.
1240 gfx::Size LayerTreeHost::GetUIResourceSize(UIResourceId uid) const {
1241 UIResourceClientMap::const_iterator iter = ui_resource_client_map_.find(uid);
1242 if (iter == ui_resource_client_map_.end())
1243 return gfx::Size();
1245 const UIResourceClientData& data = iter->second;
1246 return data.size;
1249 void LayerTreeHost::RegisterViewportLayers(
1250 scoped_refptr<Layer> page_scale_layer,
1251 scoped_refptr<Layer> inner_viewport_scroll_layer,
1252 scoped_refptr<Layer> outer_viewport_scroll_layer) {
1253 page_scale_layer_ = page_scale_layer;
1254 inner_viewport_scroll_layer_ = inner_viewport_scroll_layer;
1255 outer_viewport_scroll_layer_ = outer_viewport_scroll_layer;
1258 void LayerTreeHost::RegisterSelection(const LayerSelectionBound& start,
1259 const LayerSelectionBound& end) {
1260 if (selection_start_ == start && selection_end_ == end)
1261 return;
1263 selection_start_ = start;
1264 selection_end_ = end;
1265 SetNeedsCommit();
1268 int LayerTreeHost::ScheduleMicroBenchmark(
1269 const std::string& benchmark_name,
1270 scoped_ptr<base::Value> value,
1271 const MicroBenchmark::DoneCallback& callback) {
1272 return micro_benchmark_controller_.ScheduleRun(
1273 benchmark_name, value.Pass(), callback);
1276 bool LayerTreeHost::SendMessageToMicroBenchmark(int id,
1277 scoped_ptr<base::Value> value) {
1278 return micro_benchmark_controller_.SendMessage(id, value.Pass());
1281 void LayerTreeHost::InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
1282 swap_promise_monitor_.insert(monitor);
1285 void LayerTreeHost::RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
1286 swap_promise_monitor_.erase(monitor);
1289 void LayerTreeHost::NotifySwapPromiseMonitorsOfSetNeedsCommit() {
1290 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
1291 for (; it != swap_promise_monitor_.end(); it++)
1292 (*it)->OnSetNeedsCommitOnMain();
1295 void LayerTreeHost::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
1296 DCHECK(swap_promise);
1297 swap_promise_list_.push_back(swap_promise.Pass());
1300 void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
1301 for (size_t i = 0; i < swap_promise_list_.size(); i++)
1302 swap_promise_list_[i]->DidNotSwap(reason);
1303 swap_promise_list_.clear();
1306 } // namespace cc