Disable blink_perf.events on x64.
[chromium-blink-merge.git] / cc / trees / layer_tree_host.cc
blob53aea757cb33a54fa57261d215d83b4b2e0c0a4f
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/location.h"
15 #include "base/metrics/histogram.h"
16 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/thread_task_runner_handle.h"
20 #include "base/trace_event/trace_event.h"
21 #include "base/trace_event/trace_event_argument.h"
22 #include "cc/animation/animation_registrar.h"
23 #include "cc/animation/layer_animation_controller.h"
24 #include "cc/base/math_util.h"
25 #include "cc/debug/devtools_instrumentation.h"
26 #include "cc/debug/frame_viewer_instrumentation.h"
27 #include "cc/debug/rendering_stats_instrumentation.h"
28 #include "cc/input/layer_selection_bound.h"
29 #include "cc/input/page_scale_animation.h"
30 #include "cc/input/top_controls_manager.h"
31 #include "cc/layers/heads_up_display_layer.h"
32 #include "cc/layers/heads_up_display_layer_impl.h"
33 #include "cc/layers/layer.h"
34 #include "cc/layers/layer_iterator.h"
35 #include "cc/layers/painted_scrollbar_layer.h"
36 #include "cc/layers/render_surface.h"
37 #include "cc/resources/prioritized_resource_manager.h"
38 #include "cc/resources/ui_resource_request.h"
39 #include "cc/scheduler/begin_frame_source.h"
40 #include "cc/trees/layer_tree_host_client.h"
41 #include "cc/trees/layer_tree_host_common.h"
42 #include "cc/trees/layer_tree_host_impl.h"
43 #include "cc/trees/layer_tree_impl.h"
44 #include "cc/trees/occlusion_tracker.h"
45 #include "cc/trees/single_thread_proxy.h"
46 #include "cc/trees/thread_proxy.h"
47 #include "cc/trees/tree_synchronizer.h"
48 #include "ui/gfx/geometry/size_conversions.h"
49 #include "ui/gfx/geometry/vector2d_conversions.h"
51 namespace {
52 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number;
55 namespace cc {
57 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded(
58 LayerTreeHostClient* client,
59 SharedBitmapManager* shared_bitmap_manager,
60 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
61 TaskGraphRunner* task_graph_runner,
62 const LayerTreeSettings& settings,
63 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
64 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
65 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
66 DCHECK(main_task_runner.get());
67 DCHECK(impl_task_runner.get());
68 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(
69 client, shared_bitmap_manager, gpu_memory_buffer_manager,
70 task_graph_runner, settings));
71 layer_tree_host->InitializeThreaded(main_task_runner,
72 impl_task_runner,
73 external_begin_frame_source.Pass());
74 return layer_tree_host.Pass();
77 scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded(
78 LayerTreeHostClient* client,
79 LayerTreeHostSingleThreadClient* single_thread_client,
80 SharedBitmapManager* shared_bitmap_manager,
81 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
82 TaskGraphRunner* task_graph_runner,
83 const LayerTreeSettings& settings,
84 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
85 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
86 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(
87 client, shared_bitmap_manager, gpu_memory_buffer_manager,
88 task_graph_runner, settings));
89 layer_tree_host->InitializeSingleThreaded(single_thread_client,
90 main_task_runner,
91 external_begin_frame_source.Pass());
92 return layer_tree_host.Pass();
95 LayerTreeHost::LayerTreeHost(
96 LayerTreeHostClient* client,
97 SharedBitmapManager* shared_bitmap_manager,
98 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
99 TaskGraphRunner* task_graph_runner,
100 const LayerTreeSettings& settings)
101 : micro_benchmark_controller_(this),
102 next_ui_resource_id_(1),
103 inside_begin_main_frame_(false),
104 needs_full_tree_sync_(true),
105 client_(client),
106 source_frame_number_(0),
107 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
108 output_surface_lost_(true),
109 settings_(settings),
110 debug_state_(settings.initial_debug_state),
111 top_controls_shrink_blink_size_(false),
112 top_controls_height_(0.f),
113 top_controls_shown_ratio_(0.f),
114 device_scale_factor_(1.f),
115 visible_(true),
116 page_scale_factor_(1.f),
117 min_page_scale_factor_(1.f),
118 max_page_scale_factor_(1.f),
119 has_gpu_rasterization_trigger_(false),
120 content_is_suitable_for_gpu_rasterization_(true),
121 gpu_rasterization_histogram_recorded_(false),
122 background_color_(SK_ColorWHITE),
123 has_transparent_background_(false),
124 partial_texture_update_requests_(0),
125 did_complete_scale_animation_(false),
126 in_paint_layer_contents_(false),
127 id_(s_layer_tree_host_sequence_number.GetNext() + 1),
128 next_commit_forces_redraw_(false),
129 shared_bitmap_manager_(shared_bitmap_manager),
130 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
131 task_graph_runner_(task_graph_runner),
132 surface_id_namespace_(0u),
133 next_surface_sequence_(1u) {
134 if (settings_.accelerated_animation_enabled)
135 animation_registrar_ = AnimationRegistrar::Create();
136 rendering_stats_instrumentation_->set_record_rendering_stats(
137 debug_state_.RecordRenderingStats());
140 void LayerTreeHost::InitializeThreaded(
141 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
142 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
143 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
144 InitializeProxy(ThreadProxy::Create(this,
145 main_task_runner,
146 impl_task_runner,
147 external_begin_frame_source.Pass()));
150 void LayerTreeHost::InitializeSingleThreaded(
151 LayerTreeHostSingleThreadClient* single_thread_client,
152 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
153 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
154 InitializeProxy(
155 SingleThreadProxy::Create(this,
156 single_thread_client,
157 main_task_runner,
158 external_begin_frame_source.Pass()));
161 void LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) {
162 InitializeProxy(proxy_for_testing.Pass());
165 void LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) {
166 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
168 proxy_ = proxy.Pass();
169 proxy_->Start();
170 if (settings_.accelerated_animation_enabled) {
171 animation_registrar_->set_supports_scroll_animations(
172 proxy_->SupportsImplScrolling());
176 LayerTreeHost::~LayerTreeHost() {
177 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
179 if (root_layer_.get())
180 root_layer_->SetLayerTreeHost(NULL);
182 DCHECK(swap_promise_monitor_.empty());
184 BreakSwapPromises(SwapPromise::COMMIT_FAILS);
186 if (proxy_) {
187 DCHECK(proxy_->IsMainThread());
188 proxy_->Stop();
191 // We must clear any pointers into the layer tree prior to destroying it.
192 RegisterViewportLayers(NULL, NULL, NULL, NULL);
194 if (root_layer_.get()) {
195 // The layer tree must be destroyed before the layer tree host. We've
196 // made a contract with our animation controllers that the registrar
197 // will outlive them, and we must make good.
198 root_layer_ = NULL;
202 void LayerTreeHost::SetLayerTreeHostClientReady() {
203 proxy_->SetLayerTreeHostClientReady();
206 void LayerTreeHost::DeleteContentsTexturesOnImplThread(
207 ResourceProvider* resource_provider) {
208 DCHECK(proxy_->IsImplThread());
209 if (contents_texture_manager_)
210 contents_texture_manager_->ClearAllMemory(resource_provider);
213 void LayerTreeHost::WillBeginMainFrame() {
214 devtools_instrumentation::WillBeginMainThreadFrame(id(),
215 source_frame_number());
216 client_->WillBeginMainFrame();
219 void LayerTreeHost::DidBeginMainFrame() {
220 client_->DidBeginMainFrame();
223 void LayerTreeHost::BeginMainFrameNotExpectedSoon() {
224 client_->BeginMainFrameNotExpectedSoon();
227 void LayerTreeHost::BeginMainFrame(const BeginFrameArgs& args) {
228 inside_begin_main_frame_ = true;
229 client_->BeginMainFrame(args);
230 inside_begin_main_frame_ = false;
233 void LayerTreeHost::DidStopFlinging() {
234 proxy_->MainThreadHasStoppedFlinging();
237 void LayerTreeHost::Layout() {
238 client_->Layout();
241 void LayerTreeHost::BeginCommitOnImplThread(LayerTreeHostImpl* host_impl) {
242 DCHECK(proxy_->IsImplThread());
243 TRACE_EVENT0("cc", "LayerTreeHost::CommitTo");
246 // This function commits the LayerTreeHost to an impl tree. When modifying
247 // this function, keep in mind that the function *runs* on the impl thread! Any
248 // code that is logically a main thread operation, e.g. deletion of a Layer,
249 // should be delayed until the LayerTreeHost::CommitComplete, which will run
250 // after the commit, but on the main thread.
251 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
252 DCHECK(proxy_->IsImplThread());
254 // If there are linked evicted backings, these backings' resources may be put
255 // into the impl tree, so we can't draw yet. Determine this before clearing
256 // all evicted backings.
257 bool new_impl_tree_has_no_evicted_resources = false;
258 if (contents_texture_manager_) {
259 new_impl_tree_has_no_evicted_resources =
260 !contents_texture_manager_->LinkedEvictedBackingsExist();
262 // If the memory limit has been increased since this now-finishing
263 // commit began, and the extra now-available memory would have been used,
264 // then request another commit.
265 if (contents_texture_manager_->MaxMemoryLimitBytes() <
266 host_impl->memory_allocation_limit_bytes() &&
267 contents_texture_manager_->MaxMemoryLimitBytes() <
268 contents_texture_manager_->MaxMemoryNeededBytes()) {
269 host_impl->SetNeedsCommit();
272 host_impl->set_max_memory_needed_bytes(
273 contents_texture_manager_->MaxMemoryNeededBytes());
275 contents_texture_manager_->UpdateBackingsState(
276 host_impl->resource_provider());
277 contents_texture_manager_->ReduceMemory(host_impl->resource_provider());
280 bool is_new_trace;
281 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
282 if (is_new_trace &&
283 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
284 root_layer()) {
285 LayerTreeHostCommon::CallFunctionForSubtree(
286 root_layer(), [](Layer* layer) { layer->DidBeginTracing(); });
289 LayerTreeImpl* sync_tree = host_impl->sync_tree();
291 if (next_commit_forces_redraw_) {
292 sync_tree->ForceRedrawNextActivation();
293 next_commit_forces_redraw_ = false;
296 sync_tree->set_source_frame_number(source_frame_number());
298 if (needs_full_tree_sync_) {
299 sync_tree->SetRootLayer(TreeSynchronizer::SynchronizeTrees(
300 root_layer(), sync_tree->DetachLayerTree(), sync_tree));
302 sync_tree->set_needs_full_tree_sync(needs_full_tree_sync_);
303 needs_full_tree_sync_ = false;
305 if (hud_layer_.get()) {
306 LayerImpl* hud_impl = LayerTreeHostCommon::FindLayerInSubtree(
307 sync_tree->root_layer(), hud_layer_->id());
308 sync_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(hud_impl));
309 } else {
310 sync_tree->set_hud_layer(NULL);
313 sync_tree->set_background_color(background_color_);
314 sync_tree->set_has_transparent_background(has_transparent_background_);
316 if (page_scale_layer_.get() && inner_viewport_scroll_layer_.get()) {
317 sync_tree->SetViewportLayersFromIds(
318 overscroll_elasticity_layer_.get() ? overscroll_elasticity_layer_->id()
319 : Layer::INVALID_ID,
320 page_scale_layer_->id(), inner_viewport_scroll_layer_->id(),
321 outer_viewport_scroll_layer_.get() ? outer_viewport_scroll_layer_->id()
322 : Layer::INVALID_ID);
323 DCHECK(inner_viewport_scroll_layer_->IsContainerForFixedPositionLayers());
324 } else {
325 sync_tree->ClearViewportLayers();
328 sync_tree->RegisterSelection(selection_);
330 sync_tree->PushPageScaleFromMainThread(
331 page_scale_factor_, min_page_scale_factor_, max_page_scale_factor_);
332 sync_tree->elastic_overscroll()->PushFromMainThread(elastic_overscroll_);
333 if (sync_tree->IsActiveTree())
334 sync_tree->elastic_overscroll()->PushPendingToActive();
336 sync_tree->PassSwapPromises(&swap_promise_list_);
338 sync_tree->set_top_controls_shrink_blink_size(
339 top_controls_shrink_blink_size_);
340 sync_tree->set_top_controls_height(top_controls_height_);
341 sync_tree->PushTopControlsFromMainThread(top_controls_shown_ratio_);
343 host_impl->SetUseGpuRasterization(UseGpuRasterization());
344 host_impl->set_gpu_rasterization_status(GetGpuRasterizationStatus());
345 RecordGpuRasterizationHistogram();
347 host_impl->SetViewportSize(device_viewport_size_);
348 host_impl->SetDeviceScaleFactor(device_scale_factor_);
349 host_impl->SetDebugState(debug_state_);
350 if (pending_page_scale_animation_) {
351 sync_tree->SetPendingPageScaleAnimation(
352 pending_page_scale_animation_.Pass());
355 if (!ui_resource_request_queue_.empty()) {
356 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_);
357 ui_resource_request_queue_.clear();
360 DCHECK(!sync_tree->ViewportSizeInvalid());
362 if (new_impl_tree_has_no_evicted_resources) {
363 if (sync_tree->ContentsTexturesPurged())
364 sync_tree->ResetContentsTexturesPurged();
367 sync_tree->set_has_ever_been_drawn(false);
368 sync_tree->SetPropertyTrees(property_trees_);
371 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
372 TreeSynchronizer::PushProperties(root_layer(), sync_tree->root_layer());
375 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl);
378 void LayerTreeHost::WillCommit() {
379 client_->WillCommit();
382 void LayerTreeHost::UpdateHudLayer() {
383 if (debug_state_.ShowHudInfo()) {
384 if (!hud_layer_.get())
385 hud_layer_ = HeadsUpDisplayLayer::Create();
387 if (root_layer_.get() && !hud_layer_->parent())
388 root_layer_->AddChild(hud_layer_);
389 } else if (hud_layer_.get()) {
390 hud_layer_->RemoveFromParent();
391 hud_layer_ = NULL;
395 void LayerTreeHost::CommitComplete() {
396 source_frame_number_++;
397 client_->DidCommit();
398 if (did_complete_scale_animation_) {
399 client_->DidCompletePageScaleAnimation();
400 did_complete_scale_animation_ = false;
404 void LayerTreeHost::SetOutputSurface(scoped_ptr<OutputSurface> surface) {
405 TRACE_EVENT0("cc", "LayerTreeHost::SetOutputSurface");
406 DCHECK(output_surface_lost_);
407 DCHECK(surface);
409 proxy_->SetOutputSurface(surface.Pass());
412 void LayerTreeHost::RequestNewOutputSurface() {
413 client_->RequestNewOutputSurface();
416 void LayerTreeHost::DidInitializeOutputSurface() {
417 output_surface_lost_ = false;
419 if (!contents_texture_manager_ && !settings_.impl_side_painting) {
420 contents_texture_manager_ =
421 PrioritizedResourceManager::Create(proxy_.get());
422 surface_memory_placeholder_ =
423 contents_texture_manager_->CreateTexture(gfx::Size(), RGBA_8888);
426 if (root_layer()) {
427 LayerTreeHostCommon::CallFunctionForSubtree(
428 root_layer(), [](Layer* layer) { layer->OnOutputSurfaceCreated(); });
431 client_->DidInitializeOutputSurface();
434 void LayerTreeHost::DidFailToInitializeOutputSurface() {
435 DCHECK(output_surface_lost_);
436 client_->DidFailToInitializeOutputSurface();
439 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
440 LayerTreeHostImplClient* client) {
441 DCHECK(proxy_->IsImplThread());
442 scoped_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
443 settings_, client, proxy_.get(), rendering_stats_instrumentation_.get(),
444 shared_bitmap_manager_, gpu_memory_buffer_manager_, task_graph_runner_,
445 id_);
446 host_impl->SetUseGpuRasterization(UseGpuRasterization());
447 shared_bitmap_manager_ = NULL;
448 gpu_memory_buffer_manager_ = NULL;
449 task_graph_runner_ = NULL;
450 top_controls_manager_weak_ptr_ =
451 host_impl->top_controls_manager()->AsWeakPtr();
452 input_handler_weak_ptr_ = host_impl->AsWeakPtr();
453 return host_impl.Pass();
456 void LayerTreeHost::DidLoseOutputSurface() {
457 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface");
458 DCHECK(proxy_->IsMainThread());
460 if (output_surface_lost_)
461 return;
463 output_surface_lost_ = true;
464 SetNeedsCommit();
467 void LayerTreeHost::FinishAllRendering() {
468 proxy_->FinishAllRendering();
471 void LayerTreeHost::SetDeferCommits(bool defer_commits) {
472 proxy_->SetDeferCommits(defer_commits);
475 void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
476 std::stack<Layer*> layer_stack;
477 layer_stack.push(root_layer());
478 while (!layer_stack.empty()) {
479 Layer* current_layer = layer_stack.top();
480 layer_stack.pop();
481 current_layer->SetNeedsDisplay();
482 for (unsigned int i = 0; i < current_layer->children().size(); i++) {
483 layer_stack.push(current_layer->child_at(i));
488 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const {
489 return proxy_->GetRendererCapabilities();
492 void LayerTreeHost::SetNeedsAnimate() {
493 proxy_->SetNeedsAnimate();
494 NotifySwapPromiseMonitorsOfSetNeedsCommit();
497 void LayerTreeHost::SetNeedsUpdateLayers() {
498 proxy_->SetNeedsUpdateLayers();
499 NotifySwapPromiseMonitorsOfSetNeedsCommit();
502 void LayerTreeHost::SetNeedsCommit() {
503 if (!prepaint_callback_.IsCancelled()) {
504 TRACE_EVENT_INSTANT0("cc",
505 "LayerTreeHost::SetNeedsCommit::cancel prepaint",
506 TRACE_EVENT_SCOPE_THREAD);
507 prepaint_callback_.Cancel();
509 proxy_->SetNeedsCommit();
510 NotifySwapPromiseMonitorsOfSetNeedsCommit();
513 void LayerTreeHost::SetNeedsFullTreeSync() {
514 needs_full_tree_sync_ = true;
516 property_trees_.needs_rebuild = true;
517 SetNeedsCommit();
520 void LayerTreeHost::SetNeedsRedraw() {
521 SetNeedsRedrawRect(gfx::Rect(device_viewport_size_));
524 void LayerTreeHost::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
525 proxy_->SetNeedsRedraw(damage_rect);
528 bool LayerTreeHost::CommitRequested() const {
529 return proxy_->CommitRequested();
532 bool LayerTreeHost::BeginMainFrameRequested() const {
533 return proxy_->BeginMainFrameRequested();
537 void LayerTreeHost::SetNextCommitWaitsForActivation() {
538 proxy_->SetNextCommitWaitsForActivation();
541 void LayerTreeHost::SetNextCommitForcesRedraw() {
542 next_commit_forces_redraw_ = true;
545 void LayerTreeHost::SetAnimationEvents(
546 scoped_ptr<AnimationEventsVector> events) {
547 DCHECK(proxy_->IsMainThread());
548 animation_registrar_->SetAnimationEvents(events.Pass());
551 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) {
552 if (root_layer_.get() == root_layer.get())
553 return;
555 if (root_layer_.get())
556 root_layer_->SetLayerTreeHost(NULL);
557 root_layer_ = root_layer;
558 if (root_layer_.get()) {
559 DCHECK(!root_layer_->parent());
560 root_layer_->SetLayerTreeHost(this);
563 if (hud_layer_.get())
564 hud_layer_->RemoveFromParent();
566 // Reset gpu rasterization flag.
567 // This flag is sticky until a new tree comes along.
568 content_is_suitable_for_gpu_rasterization_ = true;
569 gpu_rasterization_histogram_recorded_ = false;
571 SetNeedsFullTreeSync();
574 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) {
575 LayerTreeDebugState new_debug_state =
576 LayerTreeDebugState::Unite(settings_.initial_debug_state, debug_state);
578 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state))
579 return;
581 debug_state_ = new_debug_state;
583 rendering_stats_instrumentation_->set_record_rendering_stats(
584 debug_state_.RecordRenderingStats());
586 SetNeedsCommit();
587 proxy_->SetDebugState(debug_state);
590 bool LayerTreeHost::UseGpuRasterization() const {
591 if (settings_.gpu_rasterization_forced) {
592 return true;
593 } else if (settings_.gpu_rasterization_enabled) {
594 return has_gpu_rasterization_trigger_ &&
595 content_is_suitable_for_gpu_rasterization_;
596 } else {
597 return false;
601 GpuRasterizationStatus LayerTreeHost::GetGpuRasterizationStatus() const {
602 if (settings_.gpu_rasterization_forced) {
603 return GpuRasterizationStatus::ON_FORCED;
604 } else if (settings_.gpu_rasterization_enabled) {
605 if (!has_gpu_rasterization_trigger_) {
606 return GpuRasterizationStatus::OFF_VIEWPORT;
607 } else if (!content_is_suitable_for_gpu_rasterization_) {
608 return GpuRasterizationStatus::OFF_CONTENT;
609 } else {
610 return GpuRasterizationStatus::ON;
613 return GpuRasterizationStatus::OFF_DEVICE;
616 void LayerTreeHost::SetHasGpuRasterizationTrigger(bool has_trigger) {
617 if (has_trigger == has_gpu_rasterization_trigger_)
618 return;
620 has_gpu_rasterization_trigger_ = has_trigger;
621 TRACE_EVENT_INSTANT1("cc",
622 "LayerTreeHost::SetHasGpuRasterizationTrigger",
623 TRACE_EVENT_SCOPE_THREAD,
624 "has_trigger",
625 has_gpu_rasterization_trigger_);
628 void LayerTreeHost::SetViewportSize(const gfx::Size& device_viewport_size) {
629 if (device_viewport_size == device_viewport_size_)
630 return;
632 device_viewport_size_ = device_viewport_size;
634 property_trees_.needs_rebuild = true;
635 SetNeedsCommit();
638 void LayerTreeHost::SetTopControlsHeight(float height, bool shrink) {
639 if (top_controls_height_ == height &&
640 top_controls_shrink_blink_size_ == shrink)
641 return;
643 top_controls_height_ = height;
644 top_controls_shrink_blink_size_ = shrink;
645 SetNeedsCommit();
648 void LayerTreeHost::SetTopControlsShownRatio(float ratio) {
649 if (top_controls_shown_ratio_ == ratio)
650 return;
652 top_controls_shown_ratio_ = ratio;
653 SetNeedsCommit();
656 void LayerTreeHost::ApplyPageScaleDeltaFromImplSide(float page_scale_delta) {
657 DCHECK(CommitRequested());
658 if (page_scale_delta == 1.f)
659 return;
660 page_scale_factor_ *= page_scale_delta;
661 property_trees_.needs_rebuild = true;
664 void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor,
665 float min_page_scale_factor,
666 float max_page_scale_factor) {
667 if (page_scale_factor == page_scale_factor_ &&
668 min_page_scale_factor == min_page_scale_factor_ &&
669 max_page_scale_factor == max_page_scale_factor_)
670 return;
672 page_scale_factor_ = page_scale_factor;
673 min_page_scale_factor_ = min_page_scale_factor;
674 max_page_scale_factor_ = max_page_scale_factor;
675 property_trees_.needs_rebuild = true;
676 SetNeedsCommit();
679 void LayerTreeHost::SetVisible(bool visible) {
680 if (visible_ == visible)
681 return;
682 visible_ = visible;
683 if (!visible)
684 ReduceMemoryUsage();
685 proxy_->SetVisible(visible);
688 void LayerTreeHost::SetThrottleFrameProduction(bool throttle) {
689 proxy_->SetThrottleFrameProduction(throttle);
692 void LayerTreeHost::StartPageScaleAnimation(const gfx::Vector2d& target_offset,
693 bool use_anchor,
694 float scale,
695 base::TimeDelta duration) {
696 pending_page_scale_animation_.reset(
697 new PendingPageScaleAnimation(
698 target_offset,
699 use_anchor,
700 scale,
701 duration));
703 SetNeedsCommit();
706 void LayerTreeHost::NotifyInputThrottledUntilCommit() {
707 proxy_->NotifyInputThrottledUntilCommit();
710 void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) {
711 DCHECK(!proxy_->HasImplThread());
712 // This function is only valid when not using the scheduler.
713 DCHECK(!settings_.single_thread_proxy_scheduler);
714 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get());
716 SetLayerTreeHostClientReady();
717 proxy->CompositeImmediately(frame_begin_time);
720 bool LayerTreeHost::UpdateLayers(ResourceUpdateQueue* queue) {
721 DCHECK(!output_surface_lost_);
723 if (!root_layer())
724 return false;
726 DCHECK(!root_layer()->parent());
728 bool result = UpdateLayers(root_layer(), queue);
730 micro_benchmark_controller_.DidUpdateLayers();
732 return result || next_commit_forces_redraw_;
735 void LayerTreeHost::DidCompletePageScaleAnimation() {
736 did_complete_scale_animation_ = true;
739 static Layer* FindFirstScrollableLayer(Layer* layer) {
740 if (!layer)
741 return NULL;
743 if (layer->scrollable())
744 return layer;
746 for (size_t i = 0; i < layer->children().size(); ++i) {
747 Layer* found = FindFirstScrollableLayer(layer->children()[i].get());
748 if (found)
749 return found;
752 return NULL;
755 void LayerTreeHost::RecordGpuRasterizationHistogram() {
756 // Gpu rasterization is only supported when impl-side painting is enabled.
757 if (gpu_rasterization_histogram_recorded_ || !settings_.impl_side_painting)
758 return;
760 // Record how widely gpu rasterization is enabled.
761 // This number takes device/gpu whitelisting/backlisting into account.
762 // Note that we do not consider the forced gpu rasterization mode, which is
763 // mostly used for debugging purposes.
764 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationEnabled",
765 settings_.gpu_rasterization_enabled);
766 if (settings_.gpu_rasterization_enabled) {
767 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationTriggered",
768 has_gpu_rasterization_trigger_);
769 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationSuitableContent",
770 content_is_suitable_for_gpu_rasterization_);
771 // Record how many pages actually get gpu rasterization when enabled.
772 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed",
773 (has_gpu_rasterization_trigger_ &&
774 content_is_suitable_for_gpu_rasterization_));
777 gpu_rasterization_histogram_recorded_ = true;
780 bool LayerTreeHost::UsingSharedMemoryResources() {
781 return GetRendererCapabilities().using_shared_memory_resources;
784 bool LayerTreeHost::UpdateLayers(Layer* root_layer,
785 ResourceUpdateQueue* queue) {
786 TRACE_EVENT1("cc", "LayerTreeHost::UpdateLayers",
787 "source_frame_number", source_frame_number());
789 RenderSurfaceLayerList update_list;
791 UpdateHudLayer();
793 Layer* root_scroll = FindFirstScrollableLayer(root_layer);
794 Layer* page_scale_layer = page_scale_layer_.get();
795 if (!page_scale_layer && root_scroll)
796 page_scale_layer = root_scroll->parent();
798 if (hud_layer_.get()) {
799 hud_layer_->PrepareForCalculateDrawProperties(
800 device_viewport_size(), device_scale_factor_);
803 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::CalcDrawProps");
804 bool can_render_to_separate_surface = true;
805 // TODO(vmpstr): Passing 0 as the current render surface layer list id means
806 // that we won't be able to detect if a layer is part of |update_list|.
807 // Change this if this information is required.
808 int render_surface_layer_list_id = 0;
809 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(
810 root_layer, device_viewport_size(), gfx::Transform(),
811 device_scale_factor_, page_scale_factor_, page_scale_layer,
812 elastic_overscroll_, overscroll_elasticity_layer_.get(),
813 GetRendererCapabilities().max_texture_size, settings_.can_use_lcd_text,
814 settings_.layers_always_allowed_lcd_text,
815 can_render_to_separate_surface,
816 settings_.layer_transforms_should_scale_layer_contents,
817 settings_.verify_property_trees, &update_list,
818 render_surface_layer_list_id, &property_trees_);
819 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
822 // Reset partial texture update requests.
823 partial_texture_update_requests_ = 0;
825 bool did_paint_content = false;
826 bool need_more_updates = false;
827 PaintLayerContents(
828 update_list, queue, &did_paint_content, &need_more_updates);
829 if (need_more_updates) {
830 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::posting prepaint task");
831 prepaint_callback_.Reset(base::Bind(&LayerTreeHost::TriggerPrepaint,
832 base::Unretained(this)));
833 static base::TimeDelta prepaint_delay =
834 base::TimeDelta::FromMilliseconds(100);
835 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
836 FROM_HERE, prepaint_callback_.callback(), prepaint_delay);
839 return did_paint_content;
842 void LayerTreeHost::TriggerPrepaint() {
843 prepaint_callback_.Cancel();
844 TRACE_EVENT0("cc", "LayerTreeHost::TriggerPrepaint");
845 SetNeedsCommit();
848 void LayerTreeHost::ReduceMemoryUsage() {
849 if (!root_layer())
850 return;
852 LayerTreeHostCommon::CallFunctionForSubtree(
853 root_layer(), [](Layer* layer) { layer->ReduceMemoryUsage(); });
856 void LayerTreeHost::SetPrioritiesForSurfaces(size_t surface_memory_bytes) {
857 DCHECK(surface_memory_placeholder_);
859 // Surfaces have a place holder for their memory since they are managed
860 // independantly but should still be tracked and reduce other memory usage.
861 surface_memory_placeholder_->SetTextureManager(
862 contents_texture_manager_.get());
863 surface_memory_placeholder_->set_request_priority(
864 PriorityCalculator::RenderSurfacePriority());
865 surface_memory_placeholder_->SetToSelfManagedMemoryPlaceholder(
866 surface_memory_bytes);
869 void LayerTreeHost::SetPrioritiesForLayers(
870 const RenderSurfaceLayerList& update_list) {
871 PriorityCalculator calculator;
872 typedef LayerIterator<Layer> LayerIteratorType;
873 LayerIteratorType end = LayerIteratorType::End(&update_list);
874 for (LayerIteratorType it = LayerIteratorType::Begin(&update_list);
875 it != end;
876 ++it) {
877 if (it.represents_itself()) {
878 it->SetTexturePriorities(calculator);
879 } else if (it.represents_target_render_surface()) {
880 if (it->mask_layer())
881 it->mask_layer()->SetTexturePriorities(calculator);
882 if (it->replica_layer() && it->replica_layer()->mask_layer())
883 it->replica_layer()->mask_layer()->SetTexturePriorities(calculator);
888 void LayerTreeHost::PrioritizeTextures(
889 const RenderSurfaceLayerList& render_surface_layer_list) {
890 if (!contents_texture_manager_)
891 return;
893 contents_texture_manager_->ClearPriorities();
895 size_t memory_for_render_surfaces_metric =
896 CalculateMemoryForRenderSurfaces(render_surface_layer_list);
898 SetPrioritiesForLayers(render_surface_layer_list);
899 SetPrioritiesForSurfaces(memory_for_render_surfaces_metric);
901 contents_texture_manager_->PrioritizeTextures();
904 size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
905 const RenderSurfaceLayerList& update_list) {
906 size_t readback_bytes = 0;
907 size_t contents_texture_bytes = 0;
909 // Start iteration at 1 to skip the root surface as it does not have a texture
910 // cost.
911 for (size_t i = 1; i < update_list.size(); ++i) {
912 Layer* render_surface_layer = update_list.at(i);
913 RenderSurface* render_surface = render_surface_layer->render_surface();
915 size_t bytes =
916 Resource::MemorySizeBytes(render_surface->content_rect().size(),
917 RGBA_8888);
918 contents_texture_bytes += bytes;
920 if (render_surface_layer->background_filters().IsEmpty() &&
921 render_surface_layer->uses_default_blend_mode())
922 continue;
924 if (!readback_bytes) {
925 readback_bytes = Resource::MemorySizeBytes(device_viewport_size_,
926 RGBA_8888);
929 return readback_bytes + contents_texture_bytes;
932 void LayerTreeHost::PaintMasksForRenderSurface(Layer* render_surface_layer,
933 ResourceUpdateQueue* queue,
934 bool* did_paint_content,
935 bool* need_more_updates) {
936 // Note: Masks and replicas only exist for layers that own render surfaces. If
937 // we reach this point in code, we already know that at least something will
938 // be drawn into this render surface, so the mask and replica should be
939 // painted.
941 Layer* mask_layer = render_surface_layer->mask_layer();
942 if (mask_layer) {
943 *did_paint_content |= mask_layer->Update(queue, NULL);
944 *need_more_updates |= mask_layer->NeedMoreUpdates();
947 Layer* replica_mask_layer =
948 render_surface_layer->replica_layer() ?
949 render_surface_layer->replica_layer()->mask_layer() : NULL;
950 if (replica_mask_layer) {
951 *did_paint_content |= replica_mask_layer->Update(queue, NULL);
952 *need_more_updates |= replica_mask_layer->NeedMoreUpdates();
956 void LayerTreeHost::PaintLayerContents(
957 const RenderSurfaceLayerList& render_surface_layer_list,
958 ResourceUpdateQueue* queue,
959 bool* did_paint_content,
960 bool* need_more_updates) {
961 OcclusionTracker<Layer> occlusion_tracker(
962 root_layer_->render_surface()->content_rect());
963 occlusion_tracker.set_minimum_tracking_size(
964 settings_.minimum_occlusion_tracking_size);
966 PrioritizeTextures(render_surface_layer_list);
968 in_paint_layer_contents_ = true;
970 // Iterates front-to-back to allow for testing occlusion and performing
971 // culling during the tree walk.
972 typedef LayerIterator<Layer> LayerIteratorType;
973 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list);
974 for (LayerIteratorType it =
975 LayerIteratorType::Begin(&render_surface_layer_list);
976 it != end;
977 ++it) {
978 occlusion_tracker.EnterLayer(it);
980 if (it.represents_target_render_surface()) {
981 PaintMasksForRenderSurface(
982 *it, queue, did_paint_content, need_more_updates);
983 } else if (it.represents_itself()) {
984 DCHECK(!it->paint_properties().bounds.IsEmpty());
985 *did_paint_content |= it->Update(queue, &occlusion_tracker);
986 *need_more_updates |= it->NeedMoreUpdates();
987 // Note the '&&' with previous is-suitable state.
988 // This means that once the layer-tree becomes unsuitable for gpu
989 // rasterization due to some content, it will continue to be unsuitable
990 // even if that content is replaced by gpu-friendly content.
991 // This is to avoid switching back-and-forth between gpu and sw
992 // rasterization which may be both bad for performance and visually
993 // jarring.
994 content_is_suitable_for_gpu_rasterization_ &=
995 it->IsSuitableForGpuRasterization();
998 occlusion_tracker.LeaveLayer(it);
1001 in_paint_layer_contents_ = false;
1004 void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) {
1005 ScopedPtrVector<SwapPromise>::iterator it = info->swap_promises.begin();
1006 for (; it != info->swap_promises.end(); ++it) {
1007 scoped_ptr<SwapPromise> swap_promise(info->swap_promises.take(it));
1008 TRACE_EVENT_FLOW_STEP0("input",
1009 "LatencyInfo.Flow",
1010 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()),
1011 "Main thread scroll update");
1012 QueueSwapPromise(swap_promise.Pass());
1015 gfx::Vector2dF inner_viewport_scroll_delta;
1016 gfx::Vector2dF outer_viewport_scroll_delta;
1018 if (root_layer_.get()) {
1019 for (size_t i = 0; i < info->scrolls.size(); ++i) {
1020 Layer* layer = LayerTreeHostCommon::FindLayerInSubtree(
1021 root_layer_.get(), info->scrolls[i].layer_id);
1022 if (!layer)
1023 continue;
1024 if (layer == outer_viewport_scroll_layer_.get()) {
1025 outer_viewport_scroll_delta += info->scrolls[i].scroll_delta;
1026 } else if (layer == inner_viewport_scroll_layer_.get()) {
1027 inner_viewport_scroll_delta += info->scrolls[i].scroll_delta;
1028 } else {
1029 layer->SetScrollOffsetFromImplSide(
1030 gfx::ScrollOffsetWithDelta(layer->scroll_offset(),
1031 info->scrolls[i].scroll_delta));
1036 if (!inner_viewport_scroll_delta.IsZero() ||
1037 !outer_viewport_scroll_delta.IsZero() || info->page_scale_delta != 1.f ||
1038 !info->elastic_overscroll_delta.IsZero() || info->top_controls_delta) {
1039 // Preemptively apply the scroll offset and scale delta here before sending
1040 // it to the client. If the client comes back and sets it to the same
1041 // value, then the layer can early out without needing a full commit.
1042 if (inner_viewport_scroll_layer_.get()) {
1043 inner_viewport_scroll_layer_->SetScrollOffsetFromImplSide(
1044 gfx::ScrollOffsetWithDelta(
1045 inner_viewport_scroll_layer_->scroll_offset(),
1046 inner_viewport_scroll_delta));
1049 if (outer_viewport_scroll_layer_.get()) {
1050 outer_viewport_scroll_layer_->SetScrollOffsetFromImplSide(
1051 gfx::ScrollOffsetWithDelta(
1052 outer_viewport_scroll_layer_->scroll_offset(),
1053 outer_viewport_scroll_delta));
1056 ApplyPageScaleDeltaFromImplSide(info->page_scale_delta);
1057 elastic_overscroll_ += info->elastic_overscroll_delta;
1058 if (!settings_.use_pinch_virtual_viewport) {
1059 // TODO(miletus): Make sure either this code path is totally gone,
1060 // or revisit the flooring here if the old pinch viewport code path
1061 // is causing problems with fractional scroll offset.
1062 client_->ApplyViewportDeltas(
1063 gfx::ToFlooredVector2d(inner_viewport_scroll_delta +
1064 outer_viewport_scroll_delta),
1065 info->page_scale_delta, info->top_controls_delta);
1066 } else {
1067 // TODO(ccameron): pass the elastic overscroll here so that input events
1068 // may be translated appropriately.
1069 client_->ApplyViewportDeltas(
1070 inner_viewport_scroll_delta, outer_viewport_scroll_delta,
1071 info->elastic_overscroll_delta, info->page_scale_delta,
1072 info->top_controls_delta);
1077 void LayerTreeHost::StartRateLimiter() {
1078 if (inside_begin_main_frame_)
1079 return;
1081 if (!rate_limit_timer_.IsRunning()) {
1082 rate_limit_timer_.Start(FROM_HERE,
1083 base::TimeDelta(),
1084 this,
1085 &LayerTreeHost::RateLimit);
1089 void LayerTreeHost::StopRateLimiter() {
1090 rate_limit_timer_.Stop();
1093 void LayerTreeHost::RateLimit() {
1094 // Force a no-op command on the compositor context, so that any ratelimiting
1095 // commands will wait for the compositing context, and therefore for the
1096 // SwapBuffers.
1097 proxy_->ForceSerializeOnSwapBuffers();
1098 client_->RateLimitSharedMainThreadContext();
1101 bool LayerTreeHost::AlwaysUsePartialTextureUpdates() {
1102 if (!proxy_->GetRendererCapabilities().allow_partial_texture_updates)
1103 return false;
1104 return !proxy_->HasImplThread();
1107 size_t LayerTreeHost::MaxPartialTextureUpdates() const {
1108 size_t max_partial_texture_updates = 0;
1109 if (proxy_->GetRendererCapabilities().allow_partial_texture_updates &&
1110 !settings_.impl_side_painting) {
1111 max_partial_texture_updates =
1112 std::min(settings_.max_partial_texture_updates,
1113 proxy_->MaxPartialTextureUpdates());
1115 return max_partial_texture_updates;
1118 bool LayerTreeHost::RequestPartialTextureUpdate() {
1119 if (partial_texture_update_requests_ >= MaxPartialTextureUpdates())
1120 return false;
1122 partial_texture_update_requests_++;
1123 return true;
1126 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) {
1127 if (device_scale_factor == device_scale_factor_)
1128 return;
1129 device_scale_factor_ = device_scale_factor;
1131 property_trees_.needs_rebuild = true;
1132 SetNeedsCommit();
1135 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
1136 TopControlsState current,
1137 bool animate) {
1138 // Top controls are only used in threaded mode.
1139 proxy_->ImplThreadTaskRunner()->PostTask(
1140 FROM_HERE,
1141 base::Bind(&TopControlsManager::UpdateTopControlsState,
1142 top_controls_manager_weak_ptr_,
1143 constraints,
1144 current,
1145 animate));
1148 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
1149 if (!settings_.accelerated_animation_enabled)
1150 return;
1152 AnimationEventsVector events;
1153 if (animation_registrar_->AnimateLayers(monotonic_time)) {
1154 animation_registrar_->UpdateAnimationState(true, &events);
1155 if (!events.empty())
1156 property_trees_.needs_rebuild = true;
1160 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) {
1161 DCHECK(client);
1163 UIResourceId next_id = next_ui_resource_id_++;
1164 DCHECK(ui_resource_client_map_.find(next_id) ==
1165 ui_resource_client_map_.end());
1167 bool resource_lost = false;
1168 UIResourceRequest request(UIResourceRequest::UI_RESOURCE_CREATE, next_id,
1169 client->GetBitmap(next_id, resource_lost));
1170 ui_resource_request_queue_.push_back(request);
1172 UIResourceClientData data;
1173 data.client = client;
1174 data.size = request.GetBitmap().GetSize();
1176 ui_resource_client_map_[request.GetId()] = data;
1177 return request.GetId();
1180 // Deletes a UI resource. May safely be called more than once.
1181 void LayerTreeHost::DeleteUIResource(UIResourceId uid) {
1182 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
1183 if (iter == ui_resource_client_map_.end())
1184 return;
1186 UIResourceRequest request(UIResourceRequest::UI_RESOURCE_DELETE, uid);
1187 ui_resource_request_queue_.push_back(request);
1188 ui_resource_client_map_.erase(iter);
1191 void LayerTreeHost::RecreateUIResources() {
1192 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin();
1193 iter != ui_resource_client_map_.end();
1194 ++iter) {
1195 UIResourceId uid = iter->first;
1196 const UIResourceClientData& data = iter->second;
1197 bool resource_lost = true;
1198 UIResourceRequest request(UIResourceRequest::UI_RESOURCE_CREATE, uid,
1199 data.client->GetBitmap(uid, resource_lost));
1200 ui_resource_request_queue_.push_back(request);
1204 // Returns the size of a resource given its id.
1205 gfx::Size LayerTreeHost::GetUIResourceSize(UIResourceId uid) const {
1206 UIResourceClientMap::const_iterator iter = ui_resource_client_map_.find(uid);
1207 if (iter == ui_resource_client_map_.end())
1208 return gfx::Size();
1210 const UIResourceClientData& data = iter->second;
1211 return data.size;
1214 void LayerTreeHost::RegisterViewportLayers(
1215 scoped_refptr<Layer> overscroll_elasticity_layer,
1216 scoped_refptr<Layer> page_scale_layer,
1217 scoped_refptr<Layer> inner_viewport_scroll_layer,
1218 scoped_refptr<Layer> outer_viewport_scroll_layer) {
1219 overscroll_elasticity_layer_ = overscroll_elasticity_layer;
1220 page_scale_layer_ = page_scale_layer;
1221 inner_viewport_scroll_layer_ = inner_viewport_scroll_layer;
1222 outer_viewport_scroll_layer_ = outer_viewport_scroll_layer;
1225 void LayerTreeHost::RegisterSelection(const LayerSelection& selection) {
1226 if (selection_ == selection)
1227 return;
1229 selection_ = selection;
1230 SetNeedsCommit();
1233 int LayerTreeHost::ScheduleMicroBenchmark(
1234 const std::string& benchmark_name,
1235 scoped_ptr<base::Value> value,
1236 const MicroBenchmark::DoneCallback& callback) {
1237 return micro_benchmark_controller_.ScheduleRun(
1238 benchmark_name, value.Pass(), callback);
1241 bool LayerTreeHost::SendMessageToMicroBenchmark(int id,
1242 scoped_ptr<base::Value> value) {
1243 return micro_benchmark_controller_.SendMessage(id, value.Pass());
1246 void LayerTreeHost::InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
1247 swap_promise_monitor_.insert(monitor);
1250 void LayerTreeHost::RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
1251 swap_promise_monitor_.erase(monitor);
1254 void LayerTreeHost::NotifySwapPromiseMonitorsOfSetNeedsCommit() {
1255 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
1256 for (; it != swap_promise_monitor_.end(); it++)
1257 (*it)->OnSetNeedsCommitOnMain();
1260 void LayerTreeHost::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
1261 DCHECK(swap_promise);
1262 swap_promise_list_.push_back(swap_promise.Pass());
1265 void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
1266 for (size_t i = 0; i < swap_promise_list_.size(); i++)
1267 swap_promise_list_[i]->DidNotSwap(reason);
1268 swap_promise_list_.clear();
1271 void LayerTreeHost::set_surface_id_namespace(uint32_t id_namespace) {
1272 surface_id_namespace_ = id_namespace;
1275 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() {
1276 return SurfaceSequence(surface_id_namespace_, next_surface_sequence_++);
1279 void LayerTreeHost::SetChildrenNeedBeginFrames(
1280 bool children_need_begin_frames) const {
1281 proxy_->SetChildrenNeedBeginFrames(children_need_begin_frames);
1284 void LayerTreeHost::SendBeginFramesToChildren(
1285 const BeginFrameArgs& args) const {
1286 client_->SendBeginFramesToChildren(args);
1289 void LayerTreeHost::SetAuthoritativeVSyncInterval(
1290 const base::TimeDelta& interval) {
1291 proxy_->SetAuthoritativeVSyncInterval(interval);
1294 } // namespace cc