Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a seriou...
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.cc
blob2d83af093989089e1fc5ccfb4e3ea20db6e51cb3
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_impl.h"
7 #include "base/debug/trace_event.h"
8 #include "cc/animation/keyframed_animation_curve.h"
9 #include "cc/animation/scrollbar_animation_controller.h"
10 #include "cc/base/math_util.h"
11 #include "cc/base/util.h"
12 #include "cc/debug/traced_value.h"
13 #include "cc/layers/heads_up_display_layer_impl.h"
14 #include "cc/layers/layer.h"
15 #include "cc/layers/render_surface_impl.h"
16 #include "cc/layers/scrollbar_layer_impl_base.h"
17 #include "cc/resources/ui_resource_request.h"
18 #include "cc/trees/layer_tree_host_common.h"
19 #include "cc/trees/layer_tree_host_impl.h"
20 #include "ui/gfx/size_conversions.h"
21 #include "ui/gfx/vector2d_conversions.h"
23 namespace cc {
25 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
26 : layer_tree_host_impl_(layer_tree_host_impl),
27 source_frame_number_(-1),
28 hud_layer_(0),
29 root_scroll_layer_(NULL),
30 currently_scrolling_layer_(NULL),
31 root_layer_scroll_offset_delegate_(NULL),
32 background_color_(0),
33 has_transparent_background_(false),
34 page_scale_layer_(NULL),
35 inner_viewport_scroll_layer_(NULL),
36 outer_viewport_scroll_layer_(NULL),
37 page_scale_factor_(1),
38 page_scale_delta_(1),
39 sent_page_scale_delta_(1),
40 min_page_scale_factor_(0),
41 max_page_scale_factor_(0),
42 scrolling_layer_id_from_previous_tree_(0),
43 contents_textures_purged_(false),
44 viewport_size_invalid_(false),
45 needs_update_draw_properties_(true),
46 needs_full_tree_sync_(true),
47 next_activation_forces_redraw_(false) {
50 LayerTreeImpl::~LayerTreeImpl() {
51 // Need to explicitly clear the tree prior to destroying this so that
52 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
53 root_layer_.reset();
56 static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) {
57 if (!layer)
58 return NULL;
60 if (layer->scrollable())
61 return layer;
63 for (size_t i = 0; i < layer->children().size(); ++i) {
64 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]);
65 if (found)
66 return found;
69 return NULL;
72 void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
73 if (root_scroll_layer_)
74 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
75 root_layer_ = layer.Pass();
76 currently_scrolling_layer_ = NULL;
77 root_scroll_layer_ = NULL;
79 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
82 void LayerTreeImpl::FindRootScrollLayer() {
83 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get());
85 if (root_scroll_layer_) {
86 UpdateMaxScrollOffset();
87 root_scroll_layer_->SetScrollOffsetDelegate(
88 root_layer_scroll_offset_delegate_);
91 if (scrolling_layer_id_from_previous_tree_) {
92 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
93 root_layer_.get(),
94 scrolling_layer_id_from_previous_tree_);
97 scrolling_layer_id_from_previous_tree_ = 0;
100 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
101 // Clear all data structures that have direct references to the layer tree.
102 scrolling_layer_id_from_previous_tree_ =
103 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
104 if (root_scroll_layer_)
105 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
106 root_scroll_layer_ = NULL;
107 currently_scrolling_layer_ = NULL;
109 render_surface_layer_list_.clear();
110 set_needs_update_draw_properties();
111 return root_layer_.Pass();
114 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
115 // The request queue should have been processed and does not require a push.
116 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
118 if (next_activation_forces_redraw_) {
119 layer_tree_host_impl_->SetFullRootLayerDamage();
120 next_activation_forces_redraw_ = false;
123 target_tree->PassSwapPromises(&swap_promise_list_);
125 target_tree->SetPageScaleFactorAndLimits(
126 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor());
127 target_tree->SetPageScaleDelta(
128 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
129 target_tree->set_sent_page_scale_delta(1);
131 if (settings().use_pinch_virtual_viewport) {
132 target_tree->SetViewportLayersFromIds(
133 page_scale_layer_->id(),
134 inner_viewport_scroll_layer_->id(),
135 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
136 : Layer::INVALID_ID);
138 // This should match the property synchronization in
139 // LayerTreeHost::finishCommitOnImplThread().
140 target_tree->set_source_frame_number(source_frame_number());
141 target_tree->set_background_color(background_color());
142 target_tree->set_has_transparent_background(has_transparent_background());
144 if (ContentsTexturesPurged())
145 target_tree->SetContentsTexturesPurged();
146 else
147 target_tree->ResetContentsTexturesPurged();
149 if (ViewportSizeInvalid())
150 target_tree->SetViewportSizeInvalid();
151 else
152 target_tree->ResetViewportSizeInvalid();
154 if (hud_layer())
155 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
156 LayerTreeHostCommon::FindLayerInSubtree(
157 target_tree->root_layer(), hud_layer()->id())));
158 else
159 target_tree->set_hud_layer(NULL);
162 LayerImpl* LayerTreeImpl::RootScrollLayer() const {
163 return root_scroll_layer_;
166 LayerImpl* LayerTreeImpl::RootContainerLayer() const {
167 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
170 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
171 DCHECK(IsActiveTree());
172 return currently_scrolling_layer_;
175 void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
176 if (currently_scrolling_layer_ == layer)
177 return;
179 if (currently_scrolling_layer_ &&
180 currently_scrolling_layer_->scrollbar_animation_controller())
181 currently_scrolling_layer_->scrollbar_animation_controller()->
182 DidScrollGestureEnd(CurrentPhysicalTimeTicks());
183 currently_scrolling_layer_ = layer;
184 if (layer && layer->scrollbar_animation_controller())
185 layer->scrollbar_animation_controller()->DidScrollGestureBegin();
188 void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
189 SetCurrentlyScrollingLayer(NULL);
190 scrolling_layer_id_from_previous_tree_ = 0;
193 void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
194 float min_page_scale_factor, float max_page_scale_factor) {
195 if (!page_scale_factor)
196 return;
198 min_page_scale_factor_ = min_page_scale_factor;
199 max_page_scale_factor_ = max_page_scale_factor;
200 page_scale_factor_ = page_scale_factor;
202 if (root_layer_scroll_offset_delegate_) {
203 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor(
204 total_page_scale_factor());
208 void LayerTreeImpl::SetPageScaleDelta(float delta) {
209 // Clamp to the current min/max limits.
210 float total = page_scale_factor_ * delta;
211 if (min_page_scale_factor_ && total < min_page_scale_factor_)
212 delta = min_page_scale_factor_ / page_scale_factor_;
213 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
214 delta = max_page_scale_factor_ / page_scale_factor_;
216 if (delta == page_scale_delta_)
217 return;
219 page_scale_delta_ = delta;
221 if (IsActiveTree()) {
222 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
223 if (pending_tree) {
224 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
225 pending_tree->SetPageScaleDelta(
226 page_scale_delta_ / sent_page_scale_delta_);
230 UpdateMaxScrollOffset();
231 set_needs_update_draw_properties();
233 if (root_layer_scroll_offset_delegate_) {
234 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor(
235 total_page_scale_factor());
239 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
240 return gfx::ScaleSize(layer_tree_host_impl_->UnscaledScrollableViewportSize(),
241 1.0f / total_page_scale_factor());
244 gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
245 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
246 return gfx::Rect();
247 LayerImpl* layer = root_scroll_layer_->children()[0];
248 return MathUtil::MapClippedRect(
249 layer->screen_space_transform(),
250 gfx::Rect(layer->content_bounds()));
253 void LayerTreeImpl::UpdateMaxScrollOffset() {
254 LayerImpl* root_scroll = RootScrollLayer();
255 if (!root_scroll || !root_scroll->children().size())
256 return;
258 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
259 gfx::RectF(ScrollableViewportSize()).bottom_right();
261 // The viewport may be larger than the contents in some cases, such as
262 // having a vertical scrollbar but no horizontal overflow.
263 max_scroll.SetToMax(gfx::Vector2dF());
265 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
268 static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
269 layer->ApplySentScrollDeltasFromAbortedCommit();
272 void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
273 DCHECK(IsActiveTree());
275 page_scale_factor_ *= sent_page_scale_delta_;
276 page_scale_delta_ /= sent_page_scale_delta_;
277 sent_page_scale_delta_ = 1.f;
279 if (!root_layer())
280 return;
282 LayerTreeHostCommon::CallFunctionForSubtree(
283 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
286 static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) {
287 layer->ApplyScrollDeltasSinceBeginMainFrame();
290 void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() {
291 DCHECK(IsPendingTree());
292 if (!root_layer())
293 return;
295 LayerTreeHostCommon::CallFunctionForSubtree(
296 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo));
299 void LayerTreeImpl::SetViewportLayersFromIds(
300 int page_scale_layer_id,
301 int inner_viewport_scroll_layer_id,
302 int outer_viewport_scroll_layer_id) {
303 page_scale_layer_ = LayerById(page_scale_layer_id);
304 DCHECK(page_scale_layer_);
306 inner_viewport_scroll_layer_ =
307 LayerById(inner_viewport_scroll_layer_id);
308 DCHECK(inner_viewport_scroll_layer_);
310 outer_viewport_scroll_layer_ =
311 LayerById(outer_viewport_scroll_layer_id);
312 DCHECK(outer_viewport_scroll_layer_ ||
313 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
316 void LayerTreeImpl::ClearViewportLayers() {
317 page_scale_layer_ = NULL;
318 inner_viewport_scroll_layer_ = NULL;
319 outer_viewport_scroll_layer_ = NULL;
322 // TODO(wjmaclean) This needs to go away, and be replaced with a single core
323 // of login that works for both scrollbar layer types. This is already planned
324 // as part of the larger pinch-zoom re-factoring viewport.
325 void LayerTreeImpl::UpdateSolidColorScrollbars() {
326 LayerImpl* root_scroll = RootScrollLayer();
327 DCHECK(root_scroll);
328 DCHECK(IsActiveTree());
330 gfx::RectF scrollable_viewport(
331 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
332 ScrollableViewportSize());
333 float vertical_adjust = 0.0f;
334 if (RootContainerLayer())
335 vertical_adjust =
336 layer_tree_host_impl_->UnscaledScrollableViewportSize().height() -
337 RootContainerLayer()->bounds().height();
338 if (ScrollbarLayerImplBase* horiz =
339 root_scroll->horizontal_scrollbar_layer()) {
340 horiz->SetVerticalAdjust(vertical_adjust);
341 horiz->SetVisibleToTotalLengthRatio(
342 scrollable_viewport.width() / ScrollableSize().width());
344 if (ScrollbarLayerImplBase* vertical =
345 root_scroll->vertical_scrollbar_layer()) {
346 vertical->SetVerticalAdjust(vertical_adjust);
347 vertical->SetVisibleToTotalLengthRatio(
348 scrollable_viewport.height() / ScrollableSize().height());
352 void LayerTreeImpl::UpdateDrawProperties() {
353 if (IsActiveTree() && RootScrollLayer() && RootContainerLayer())
354 UpdateRootScrollLayerSizeDelta();
356 if (IsActiveTree() && RootContainerLayer())
357 UpdateSolidColorScrollbars();
359 needs_update_draw_properties_ = false;
360 render_surface_layer_list_.clear();
362 // For max_texture_size.
363 if (!layer_tree_host_impl_->renderer())
364 return;
366 if (!root_layer())
367 return;
370 TRACE_EVENT2("cc",
371 "LayerTreeImpl::UpdateDrawProperties",
372 "IsActive",
373 IsActiveTree(),
374 "SourceFrameNumber",
375 source_frame_number_);
376 LayerImpl* page_scale_layer =
377 page_scale_layer_ ? page_scale_layer_ : RootContainerLayer();
378 bool can_render_to_separate_surface =
379 !output_surface()->ForcedDrawToSoftwareDevice();
380 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
381 root_layer(),
382 DrawViewportSize(),
383 layer_tree_host_impl_->DrawTransform(),
384 device_scale_factor(),
385 total_page_scale_factor(),
386 page_scale_layer,
387 MaxTextureSize(),
388 settings().can_use_lcd_text,
389 can_render_to_separate_surface,
390 settings().layer_transforms_should_scale_layer_contents,
391 &render_surface_layer_list_);
392 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
396 TRACE_EVENT2("cc",
397 "LayerTreeImpl::UpdateTilePriorities",
398 "IsActive",
399 IsActiveTree(),
400 "SourceFrameNumber",
401 source_frame_number_);
402 // LayerIterator is used here instead of CallFunctionForSubtree to only
403 // UpdateTilePriorities on layers that will be visible (and thus have valid
404 // draw properties) and not because any ordering is required.
405 typedef LayerIterator<LayerImpl,
406 LayerImplList,
407 RenderSurfaceImpl,
408 LayerIteratorActions::FrontToBack> LayerIteratorType;
409 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
410 for (LayerIteratorType it =
411 LayerIteratorType::Begin(&render_surface_layer_list_);
412 it != end;
413 ++it) {
414 if (!it.represents_itself())
415 continue;
416 LayerImpl* layer = *it;
418 layer->UpdateTilePriorities();
419 if (layer->mask_layer())
420 layer->mask_layer()->UpdateTilePriorities();
421 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
422 layer->replica_layer()->mask_layer()->UpdateTilePriorities();
426 DCHECK(!needs_update_draw_properties_) <<
427 "CalcDrawProperties should not set_needs_update_draw_properties()";
430 const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
431 // If this assert triggers, then the list is dirty.
432 DCHECK(!needs_update_draw_properties_);
433 return render_surface_layer_list_;
436 gfx::Size LayerTreeImpl::ScrollableSize() const {
437 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
438 return gfx::Size();
439 return root_scroll_layer_->children()[0]->bounds();
442 LayerImpl* LayerTreeImpl::LayerById(int id) {
443 LayerIdMap::iterator iter = layer_id_map_.find(id);
444 return iter != layer_id_map_.end() ? iter->second : NULL;
447 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
448 DCHECK(!LayerById(layer->id()));
449 layer_id_map_[layer->id()] = layer;
452 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
453 DCHECK(LayerById(layer->id()));
454 layer_id_map_.erase(layer->id());
457 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
458 pending_tree->SetCurrentlyScrollingLayer(
459 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
460 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
463 static void DidBecomeActiveRecursive(LayerImpl* layer) {
464 layer->DidBecomeActive();
465 for (size_t i = 0; i < layer->children().size(); ++i)
466 DidBecomeActiveRecursive(layer->children()[i]);
469 void LayerTreeImpl::DidBecomeActive() {
470 if (!root_layer())
471 return;
473 DidBecomeActiveRecursive(root_layer());
474 FindRootScrollLayer();
477 bool LayerTreeImpl::ContentsTexturesPurged() const {
478 return contents_textures_purged_;
481 void LayerTreeImpl::SetContentsTexturesPurged() {
482 if (contents_textures_purged_)
483 return;
484 contents_textures_purged_ = true;
485 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
488 void LayerTreeImpl::ResetContentsTexturesPurged() {
489 if (!contents_textures_purged_)
490 return;
491 contents_textures_purged_ = false;
492 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
495 bool LayerTreeImpl::ViewportSizeInvalid() const {
496 return viewport_size_invalid_;
499 void LayerTreeImpl::SetViewportSizeInvalid() {
500 viewport_size_invalid_ = true;
501 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
504 void LayerTreeImpl::ResetViewportSizeInvalid() {
505 viewport_size_invalid_ = false;
506 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
509 Proxy* LayerTreeImpl::proxy() const {
510 return layer_tree_host_impl_->proxy();
513 const LayerTreeSettings& LayerTreeImpl::settings() const {
514 return layer_tree_host_impl_->settings();
517 const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const {
518 return layer_tree_host_impl_->GetRendererCapabilities();
521 ContextProvider* LayerTreeImpl::context_provider() const {
522 return output_surface()->context_provider();
525 OutputSurface* LayerTreeImpl::output_surface() const {
526 return layer_tree_host_impl_->output_surface();
529 ResourceProvider* LayerTreeImpl::resource_provider() const {
530 return layer_tree_host_impl_->resource_provider();
533 TileManager* LayerTreeImpl::tile_manager() const {
534 return layer_tree_host_impl_->tile_manager();
537 FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
538 return layer_tree_host_impl_->fps_counter();
541 PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
542 return layer_tree_host_impl_->paint_time_counter();
545 MemoryHistory* LayerTreeImpl::memory_history() const {
546 return layer_tree_host_impl_->memory_history();
549 bool LayerTreeImpl::device_viewport_valid_for_tile_management() const {
550 return layer_tree_host_impl_->device_viewport_valid_for_tile_management();
553 bool LayerTreeImpl::IsActiveTree() const {
554 return layer_tree_host_impl_->active_tree() == this;
557 bool LayerTreeImpl::IsPendingTree() const {
558 return layer_tree_host_impl_->pending_tree() == this;
561 bool LayerTreeImpl::IsRecycleTree() const {
562 return layer_tree_host_impl_->recycle_tree() == this;
565 LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
566 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
567 if (!tree)
568 return NULL;
569 return tree->LayerById(id);
572 LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
573 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
574 if (!tree)
575 return NULL;
576 return tree->LayerById(id);
579 int LayerTreeImpl::MaxTextureSize() const {
580 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
583 bool LayerTreeImpl::PinchGestureActive() const {
584 return layer_tree_host_impl_->pinch_gesture_active();
587 base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const {
588 return layer_tree_host_impl_->CurrentFrameTimeTicks();
591 base::Time LayerTreeImpl::CurrentFrameTime() const {
592 return layer_tree_host_impl_->CurrentFrameTime();
595 base::TimeTicks LayerTreeImpl::CurrentPhysicalTimeTicks() const {
596 return layer_tree_host_impl_->CurrentPhysicalTimeTicks();
599 void LayerTreeImpl::SetNeedsCommit() {
600 layer_tree_host_impl_->SetNeedsCommit();
603 gfx::Size LayerTreeImpl::DrawViewportSize() const {
604 return layer_tree_host_impl_->DrawViewportSize();
607 void LayerTreeImpl::StartScrollbarAnimation() {
608 layer_tree_host_impl_->StartScrollbarAnimation();
611 void LayerTreeImpl::DidAnimateScrollOffset() {
612 layer_tree_host_impl_->DidAnimateScrollOffset();
615 void LayerTreeImpl::SetNeedsRedraw() {
616 layer_tree_host_impl_->SetNeedsRedraw();
619 const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
620 return layer_tree_host_impl_->debug_state();
623 float LayerTreeImpl::device_scale_factor() const {
624 return layer_tree_host_impl_->device_scale_factor();
627 DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
628 return layer_tree_host_impl_->debug_rect_history();
631 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
632 return layer_tree_host_impl_->animation_registrar();
635 scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
636 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
637 TracedValue::MakeDictIntoImplicitSnapshot(
638 state.get(), "cc::LayerTreeImpl", this);
640 state->Set("root_layer", root_layer_->AsValue().release());
642 scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue());
643 typedef LayerIterator<LayerImpl,
644 LayerImplList,
645 RenderSurfaceImpl,
646 LayerIteratorActions::FrontToBack> LayerIteratorType;
647 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
648 for (LayerIteratorType it = LayerIteratorType::Begin(
649 &render_surface_layer_list_); it != end; ++it) {
650 if (!it.represents_itself())
651 continue;
652 render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release());
655 state->Set("render_surface_layer_list",
656 render_surface_layer_list.release());
657 return state.PassAs<base::Value>();
660 void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
661 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
662 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
663 return;
665 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
667 if (root_scroll_layer_) {
668 root_scroll_layer_->SetScrollOffsetDelegate(
669 root_layer_scroll_offset_delegate_);
672 if (root_layer_scroll_offset_delegate_) {
673 root_layer_scroll_offset_delegate_->SetScrollableSize(ScrollableSize());
674 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor(
675 total_page_scale_factor());
679 void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() {
680 LayerImpl* root_scroll = RootScrollLayer();
681 LayerImpl* root_container = RootContainerLayer();
682 DCHECK(root_scroll);
683 DCHECK(root_container);
684 DCHECK(IsActiveTree());
686 gfx::Vector2dF scrollable_viewport_size =
687 gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF();
689 gfx::Vector2dF original_viewport_size =
690 gfx::RectF(root_container->bounds()).bottom_right() -
691 gfx::PointF();
692 original_viewport_size.Scale(1 / page_scale_factor());
694 root_scroll->SetFixedContainerSizeDelta(
695 scrollable_viewport_size - original_viewport_size);
698 void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
699 DCHECK(swap_promise);
700 if (swap_promise_list_.size() > kMaxQueuedSwapPromiseNumber)
701 BreakSwapPromises(SwapPromise::SWAP_PROMISE_LIST_OVERFLOW);
702 swap_promise_list_.push_back(swap_promise.Pass());
705 void LayerTreeImpl::PassSwapPromises(
706 ScopedPtrVector<SwapPromise>* new_swap_promise) {
707 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
708 *new_swap_promise);
709 new_swap_promise->clear();
712 void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
713 for (size_t i = 0; i < swap_promise_list_.size(); i++)
714 swap_promise_list_[i]->DidSwap(metadata);
715 swap_promise_list_.clear();
718 void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
719 for (size_t i = 0; i < swap_promise_list_.size(); i++)
720 swap_promise_list_[i]->DidNotSwap(reason);
721 swap_promise_list_.clear();
724 void LayerTreeImpl::DidModifyTilePriorities() {
725 layer_tree_host_impl_->DidModifyTilePriorities();
728 void LayerTreeImpl::set_ui_resource_request_queue(
729 const UIResourceRequestQueue& queue) {
730 ui_resource_request_queue_ = queue;
733 ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
734 UIResourceId uid) const {
735 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
738 bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
739 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
742 void LayerTreeImpl::ProcessUIResourceRequestQueue() {
743 while (ui_resource_request_queue_.size() > 0) {
744 UIResourceRequest req = ui_resource_request_queue_.front();
745 ui_resource_request_queue_.pop_front();
747 switch (req.GetType()) {
748 case UIResourceRequest::UIResourceCreate:
749 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
750 break;
751 case UIResourceRequest::UIResourceDelete:
752 layer_tree_host_impl_->DeleteUIResource(req.GetId());
753 break;
754 case UIResourceRequest::UIResourceInvalidRequest:
755 NOTREACHED();
756 break;
760 // If all UI resource evictions were not recreated by processing this queue,
761 // then another commit is required.
762 if (layer_tree_host_impl_->EvictedUIResourcesExist())
763 layer_tree_host_impl_->SetNeedsCommit();
766 void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
767 // Only the active tree needs to know about layers with copy requests, as
768 // they are aborted if not serviced during draw.
769 DCHECK(IsActiveTree());
771 DCHECK(std::find(layers_with_copy_output_request_.begin(),
772 layers_with_copy_output_request_.end(),
773 layer) == layers_with_copy_output_request_.end());
774 layers_with_copy_output_request_.push_back(layer);
777 void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
778 // Only the active tree needs to know about layers with copy requests, as
779 // they are aborted if not serviced during draw.
780 DCHECK(IsActiveTree());
782 std::vector<LayerImpl*>::iterator it = std::find(
783 layers_with_copy_output_request_.begin(),
784 layers_with_copy_output_request_.end(),
785 layer);
786 DCHECK(it != layers_with_copy_output_request_.end());
787 layers_with_copy_output_request_.erase(it);
790 const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
791 const {
792 // Only the active tree needs to know about layers with copy requests, as
793 // they are aborted if not serviced during draw.
794 DCHECK(IsActiveTree());
796 return layers_with_copy_output_request_;
799 } // namespace cc