Enable snappy for IndexedDB.
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.cc
blobaa587b4aa1123dfca221c1d58c7337b2651512cc
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/debug/traced_value.h"
11 #include "cc/layers/heads_up_display_layer_impl.h"
12 #include "cc/layers/layer.h"
13 #include "cc/layers/render_surface_impl.h"
14 #include "cc/layers/scrollbar_layer_impl_base.h"
15 #include "cc/trees/layer_tree_host_common.h"
16 #include "cc/trees/layer_tree_host_impl.h"
17 #include "ui/gfx/size_conversions.h"
18 #include "ui/gfx/vector2d_conversions.h"
20 namespace cc {
22 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
23 : layer_tree_host_impl_(layer_tree_host_impl),
24 source_frame_number_(-1),
25 hud_layer_(0),
26 root_scroll_layer_(NULL),
27 currently_scrolling_layer_(NULL),
28 root_layer_scroll_offset_delegate_(NULL),
29 background_color_(0),
30 has_transparent_background_(false),
31 page_scale_layer_(NULL),
32 inner_viewport_scroll_layer_(NULL),
33 outer_viewport_scroll_layer_(NULL),
34 page_scale_factor_(1),
35 page_scale_delta_(1),
36 sent_page_scale_delta_(1),
37 min_page_scale_factor_(0),
38 max_page_scale_factor_(0),
39 scrolling_layer_id_from_previous_tree_(0),
40 contents_textures_purged_(false),
41 viewport_size_invalid_(false),
42 needs_update_draw_properties_(true),
43 needs_full_tree_sync_(true) {
46 LayerTreeImpl::~LayerTreeImpl() {
47 // Need to explicitly clear the tree prior to destroying this so that
48 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
49 root_layer_.reset();
52 static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) {
53 if (!layer)
54 return NULL;
56 if (layer->scrollable())
57 return layer;
59 for (size_t i = 0; i < layer->children().size(); ++i) {
60 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]);
61 if (found)
62 return found;
65 return NULL;
68 void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
69 if (root_scroll_layer_)
70 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
71 root_layer_ = layer.Pass();
72 currently_scrolling_layer_ = NULL;
73 root_scroll_layer_ = NULL;
75 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
78 void LayerTreeImpl::FindRootScrollLayer() {
79 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get());
81 if (root_scroll_layer_) {
82 UpdateMaxScrollOffset();
83 root_scroll_layer_->SetScrollOffsetDelegate(
84 root_layer_scroll_offset_delegate_);
87 if (scrolling_layer_id_from_previous_tree_) {
88 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
89 root_layer_.get(),
90 scrolling_layer_id_from_previous_tree_);
93 scrolling_layer_id_from_previous_tree_ = 0;
96 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
97 // Clear all data structures that have direct references to the layer tree.
98 scrolling_layer_id_from_previous_tree_ =
99 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
100 if (root_scroll_layer_)
101 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
102 root_scroll_layer_ = NULL;
103 currently_scrolling_layer_ = NULL;
105 render_surface_layer_list_.clear();
106 set_needs_update_draw_properties();
107 return root_layer_.Pass();
110 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
111 // The request queue should have been processed and does not require a push.
112 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
114 target_tree->SetLatencyInfo(latency_info_);
115 latency_info_.Clear();
116 target_tree->SetPageScaleFactorAndLimits(
117 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor());
118 target_tree->SetPageScaleDelta(
119 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
120 target_tree->set_sent_page_scale_delta(1);
122 if (settings().use_pinch_virtual_viewport) {
123 target_tree->SetViewportLayersFromIds(
124 page_scale_layer_->id(),
125 inner_viewport_scroll_layer_->id(),
126 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
127 : Layer::INVALID_ID);
129 // This should match the property synchronization in
130 // LayerTreeHost::finishCommitOnImplThread().
131 target_tree->set_source_frame_number(source_frame_number());
132 target_tree->set_background_color(background_color());
133 target_tree->set_has_transparent_background(has_transparent_background());
135 if (ContentsTexturesPurged())
136 target_tree->SetContentsTexturesPurged();
137 else
138 target_tree->ResetContentsTexturesPurged();
140 if (ViewportSizeInvalid())
141 target_tree->SetViewportSizeInvalid();
142 else
143 target_tree->ResetViewportSizeInvalid();
145 if (hud_layer())
146 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
147 LayerTreeHostCommon::FindLayerInSubtree(
148 target_tree->root_layer(), hud_layer()->id())));
149 else
150 target_tree->set_hud_layer(NULL);
153 LayerImpl* LayerTreeImpl::RootScrollLayer() const {
154 return root_scroll_layer_;
157 LayerImpl* LayerTreeImpl::RootContainerLayer() const {
158 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
161 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
162 DCHECK(IsActiveTree());
163 return currently_scrolling_layer_;
166 void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
167 if (currently_scrolling_layer_ == layer)
168 return;
170 if (currently_scrolling_layer_ &&
171 currently_scrolling_layer_->scrollbar_animation_controller())
172 currently_scrolling_layer_->scrollbar_animation_controller()->
173 DidScrollGestureEnd(CurrentPhysicalTimeTicks());
174 currently_scrolling_layer_ = layer;
175 if (layer && layer->scrollbar_animation_controller())
176 layer->scrollbar_animation_controller()->DidScrollGestureBegin();
179 void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
180 SetCurrentlyScrollingLayer(NULL);
181 scrolling_layer_id_from_previous_tree_ = 0;
184 void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
185 float min_page_scale_factor, float max_page_scale_factor) {
186 if (!page_scale_factor)
187 return;
189 min_page_scale_factor_ = min_page_scale_factor;
190 max_page_scale_factor_ = max_page_scale_factor;
191 page_scale_factor_ = page_scale_factor;
193 if (root_layer_scroll_offset_delegate_) {
194 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor(
195 total_page_scale_factor());
199 void LayerTreeImpl::SetPageScaleDelta(float delta) {
200 // Clamp to the current min/max limits.
201 float total = page_scale_factor_ * delta;
202 if (min_page_scale_factor_ && total < min_page_scale_factor_)
203 delta = min_page_scale_factor_ / page_scale_factor_;
204 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
205 delta = max_page_scale_factor_ / page_scale_factor_;
207 if (delta == page_scale_delta_)
208 return;
210 page_scale_delta_ = delta;
212 if (IsActiveTree()) {
213 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
214 if (pending_tree) {
215 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
216 pending_tree->SetPageScaleDelta(
217 page_scale_delta_ / sent_page_scale_delta_);
221 UpdateMaxScrollOffset();
222 set_needs_update_draw_properties();
224 if (root_layer_scroll_offset_delegate_) {
225 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor(
226 total_page_scale_factor());
230 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
231 return gfx::ScaleSize(layer_tree_host_impl_->UnscaledScrollableViewportSize(),
232 1.0f / total_page_scale_factor());
235 void LayerTreeImpl::UpdateMaxScrollOffset() {
236 LayerImpl* root_scroll = RootScrollLayer();
237 if (!root_scroll || !root_scroll->children().size())
238 return;
240 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
241 gfx::RectF(ScrollableViewportSize()).bottom_right();
243 // The viewport may be larger than the contents in some cases, such as
244 // having a vertical scrollbar but no horizontal overflow.
245 max_scroll.SetToMax(gfx::Vector2dF());
247 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
250 static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
251 layer->ApplySentScrollDeltasFromAbortedCommit();
254 void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
255 DCHECK(IsActiveTree());
257 page_scale_factor_ *= sent_page_scale_delta_;
258 page_scale_delta_ /= sent_page_scale_delta_;
259 sent_page_scale_delta_ = 1.f;
261 if (!root_layer())
262 return;
264 LayerTreeHostCommon::CallFunctionForSubtree(
265 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
268 static void ApplyScrollDeltasSinceBeginFrameTo(LayerImpl* layer) {
269 layer->ApplyScrollDeltasSinceBeginFrame();
272 void LayerTreeImpl::ApplyScrollDeltasSinceBeginFrame() {
273 DCHECK(IsPendingTree());
274 if (!root_layer())
275 return;
277 LayerTreeHostCommon::CallFunctionForSubtree(
278 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginFrameTo));
281 void LayerTreeImpl::SetViewportLayersFromIds(
282 int page_scale_layer_id,
283 int inner_viewport_scroll_layer_id,
284 int outer_viewport_scroll_layer_id) {
285 page_scale_layer_ = LayerById(page_scale_layer_id);
286 DCHECK(page_scale_layer_);
288 inner_viewport_scroll_layer_ =
289 LayerById(inner_viewport_scroll_layer_id);
290 DCHECK(inner_viewport_scroll_layer_);
292 outer_viewport_scroll_layer_ =
293 LayerById(outer_viewport_scroll_layer_id);
294 DCHECK(outer_viewport_scroll_layer_ ||
295 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
298 void LayerTreeImpl::ClearViewportLayers() {
299 page_scale_layer_ = NULL;
300 inner_viewport_scroll_layer_ = NULL;
301 outer_viewport_scroll_layer_ = NULL;
304 // TODO(wjmaclean) This needs to go away, and be replaced with a single core
305 // of login that works for both scrollbar layer types. This is already planned
306 // as part of the larger pinch-zoom re-factoring viewport.
307 void LayerTreeImpl::UpdateSolidColorScrollbars() {
308 DCHECK(settings().solid_color_scrollbars);
310 LayerImpl* root_scroll = RootScrollLayer();
311 DCHECK(root_scroll);
312 DCHECK(IsActiveTree());
314 gfx::RectF scrollable_viewport(
315 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
316 ScrollableViewportSize());
317 float vertical_adjust = 0.0f;
318 if (RootContainerLayer())
319 vertical_adjust =
320 layer_tree_host_impl_->UnscaledScrollableViewportSize().height() -
321 RootContainerLayer()->bounds().height();
322 if (ScrollbarLayerImplBase* horiz =
323 root_scroll->horizontal_scrollbar_layer()) {
324 horiz->SetVerticalAdjust(vertical_adjust);
325 horiz->SetVisibleToTotalLengthRatio(
326 scrollable_viewport.width() / ScrollableSize().width());
328 if (ScrollbarLayerImplBase* vertical =
329 root_scroll->vertical_scrollbar_layer()) {
330 vertical->SetVerticalAdjust(vertical_adjust);
331 vertical->SetVisibleToTotalLengthRatio(
332 scrollable_viewport.height() / ScrollableSize().height());
336 void LayerTreeImpl::UpdateDrawProperties() {
337 if (IsActiveTree() && RootScrollLayer() && RootContainerLayer())
338 UpdateRootScrollLayerSizeDelta();
340 if (settings().solid_color_scrollbars &&
341 IsActiveTree() &&
342 RootScrollLayer()) {
343 UpdateSolidColorScrollbars();
346 needs_update_draw_properties_ = false;
347 render_surface_layer_list_.clear();
349 // For max_texture_size.
350 if (!layer_tree_host_impl_->renderer())
351 return;
353 if (!root_layer())
354 return;
357 TRACE_EVENT2("cc",
358 "LayerTreeImpl::UpdateDrawProperties",
359 "IsActive",
360 IsActiveTree(),
361 "SourceFrameNumber",
362 source_frame_number_);
363 LayerImpl* page_scale_layer =
364 page_scale_layer_ ? page_scale_layer_ : RootContainerLayer();
365 bool can_render_to_separate_surface =
366 !output_surface()->ForcedDrawToSoftwareDevice();
367 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
368 root_layer(),
369 DrawViewportSize(),
370 layer_tree_host_impl_->DrawTransform(),
371 device_scale_factor(),
372 total_page_scale_factor(),
373 page_scale_layer,
374 MaxTextureSize(),
375 settings().can_use_lcd_text,
376 can_render_to_separate_surface,
377 settings().layer_transforms_should_scale_layer_contents,
378 &render_surface_layer_list_);
379 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
382 DCHECK(!needs_update_draw_properties_) <<
383 "CalcDrawProperties should not set_needs_update_draw_properties()";
386 const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
387 // If this assert triggers, then the list is dirty.
388 DCHECK(!needs_update_draw_properties_);
389 return render_surface_layer_list_;
392 gfx::Size LayerTreeImpl::ScrollableSize() const {
393 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
394 return gfx::Size();
395 return root_scroll_layer_->children()[0]->bounds();
398 LayerImpl* LayerTreeImpl::LayerById(int id) {
399 LayerIdMap::iterator iter = layer_id_map_.find(id);
400 return iter != layer_id_map_.end() ? iter->second : NULL;
403 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
404 DCHECK(!LayerById(layer->id()));
405 layer_id_map_[layer->id()] = layer;
408 void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
409 DCHECK(LayerById(layer->id()));
410 layer_id_map_.erase(layer->id());
413 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
414 pending_tree->SetCurrentlyScrollingLayer(
415 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
416 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
417 pending_tree->SetLatencyInfo(latency_info_);
418 latency_info_.Clear();
421 static void DidBecomeActiveRecursive(LayerImpl* layer) {
422 layer->DidBecomeActive();
423 for (size_t i = 0; i < layer->children().size(); ++i)
424 DidBecomeActiveRecursive(layer->children()[i]);
427 void LayerTreeImpl::DidBecomeActive() {
428 if (!root_layer())
429 return;
431 DidBecomeActiveRecursive(root_layer());
432 FindRootScrollLayer();
435 bool LayerTreeImpl::ContentsTexturesPurged() const {
436 return contents_textures_purged_;
439 void LayerTreeImpl::SetContentsTexturesPurged() {
440 if (contents_textures_purged_)
441 return;
442 contents_textures_purged_ = true;
443 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
446 void LayerTreeImpl::ResetContentsTexturesPurged() {
447 if (!contents_textures_purged_)
448 return;
449 contents_textures_purged_ = false;
450 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
453 bool LayerTreeImpl::ViewportSizeInvalid() const {
454 return viewport_size_invalid_;
457 void LayerTreeImpl::SetViewportSizeInvalid() {
458 viewport_size_invalid_ = true;
459 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
462 void LayerTreeImpl::ResetViewportSizeInvalid() {
463 viewport_size_invalid_ = false;
464 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
467 Proxy* LayerTreeImpl::proxy() const {
468 return layer_tree_host_impl_->proxy();
471 const LayerTreeSettings& LayerTreeImpl::settings() const {
472 return layer_tree_host_impl_->settings();
475 const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const {
476 return layer_tree_host_impl_->GetRendererCapabilities();
479 ContextProvider* LayerTreeImpl::context_provider() const {
480 return output_surface()->context_provider();
483 OutputSurface* LayerTreeImpl::output_surface() const {
484 return layer_tree_host_impl_->output_surface();
487 ResourceProvider* LayerTreeImpl::resource_provider() const {
488 return layer_tree_host_impl_->resource_provider();
491 TileManager* LayerTreeImpl::tile_manager() const {
492 return layer_tree_host_impl_->tile_manager();
495 FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
496 return layer_tree_host_impl_->fps_counter();
499 PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
500 return layer_tree_host_impl_->paint_time_counter();
503 MemoryHistory* LayerTreeImpl::memory_history() const {
504 return layer_tree_host_impl_->memory_history();
507 bool LayerTreeImpl::device_viewport_valid_for_tile_management() const {
508 return layer_tree_host_impl_->device_viewport_valid_for_tile_management();
511 bool LayerTreeImpl::IsActiveTree() const {
512 return layer_tree_host_impl_->active_tree() == this;
515 bool LayerTreeImpl::IsPendingTree() const {
516 return layer_tree_host_impl_->pending_tree() == this;
519 bool LayerTreeImpl::IsRecycleTree() const {
520 return layer_tree_host_impl_->recycle_tree() == this;
523 LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
524 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
525 if (!tree)
526 return NULL;
527 return tree->LayerById(id);
530 LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
531 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
532 if (!tree)
533 return NULL;
534 return tree->LayerById(id);
537 int LayerTreeImpl::MaxTextureSize() const {
538 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
541 bool LayerTreeImpl::PinchGestureActive() const {
542 return layer_tree_host_impl_->pinch_gesture_active();
545 base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const {
546 return layer_tree_host_impl_->CurrentFrameTimeTicks();
549 base::Time LayerTreeImpl::CurrentFrameTime() const {
550 return layer_tree_host_impl_->CurrentFrameTime();
553 base::TimeTicks LayerTreeImpl::CurrentPhysicalTimeTicks() const {
554 return layer_tree_host_impl_->CurrentPhysicalTimeTicks();
557 void LayerTreeImpl::SetNeedsCommit() {
558 layer_tree_host_impl_->SetNeedsCommit();
561 gfx::Size LayerTreeImpl::DrawViewportSize() const {
562 return layer_tree_host_impl_->DrawViewportSize();
565 void LayerTreeImpl::StartScrollbarAnimation() {
566 layer_tree_host_impl_->StartScrollbarAnimation();
569 void LayerTreeImpl::SetNeedsRedraw() {
570 layer_tree_host_impl_->SetNeedsRedraw();
573 const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
574 return layer_tree_host_impl_->debug_state();
577 float LayerTreeImpl::device_scale_factor() const {
578 return layer_tree_host_impl_->device_scale_factor();
581 DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
582 return layer_tree_host_impl_->debug_rect_history();
585 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
586 return layer_tree_host_impl_->animation_registrar();
589 scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
590 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
591 TracedValue::MakeDictIntoImplicitSnapshot(
592 state.get(), "cc::LayerTreeImpl", this);
594 state->Set("root_layer", root_layer_->AsValue().release());
596 scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue());
597 typedef LayerIterator<LayerImpl,
598 LayerImplList,
599 RenderSurfaceImpl,
600 LayerIteratorActions::BackToFront> LayerIteratorType;
601 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
602 for (LayerIteratorType it = LayerIteratorType::Begin(
603 &render_surface_layer_list_); it != end; ++it) {
604 if (!it.represents_itself())
605 continue;
606 render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release());
609 state->Set("render_surface_layer_list",
610 render_surface_layer_list.release());
611 return state.PassAs<base::Value>();
614 void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
615 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
616 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
617 return;
619 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
621 if (root_scroll_layer_) {
622 root_scroll_layer_->SetScrollOffsetDelegate(
623 root_layer_scroll_offset_delegate_);
626 if (root_layer_scroll_offset_delegate_) {
627 root_layer_scroll_offset_delegate_->SetScrollableSize(ScrollableSize());
628 root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor(
629 total_page_scale_factor());
633 void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() {
634 LayerImpl* root_scroll = RootScrollLayer();
635 LayerImpl* root_container = RootContainerLayer();
636 DCHECK(root_scroll);
637 DCHECK(root_container);
638 DCHECK(IsActiveTree());
640 gfx::Vector2dF scrollable_viewport_size =
641 gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF();
643 gfx::Vector2dF original_viewport_size =
644 gfx::RectF(root_container->bounds()).bottom_right() -
645 gfx::PointF();
646 original_viewport_size.Scale(1 / page_scale_factor());
648 root_scroll->SetFixedContainerSizeDelta(
649 scrollable_viewport_size - original_viewport_size);
652 void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
653 latency_info_.MergeWith(latency_info);
656 const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() {
657 return latency_info_;
660 void LayerTreeImpl::ClearLatencyInfo() {
661 latency_info_.Clear();
664 void LayerTreeImpl::DidModifyTilePriorities() {
665 layer_tree_host_impl_->DidModifyTilePriorities();
668 void LayerTreeImpl::set_ui_resource_request_queue(
669 const UIResourceRequestQueue& queue) {
670 ui_resource_request_queue_ = queue;
673 ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
674 UIResourceId uid) const {
675 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
678 void LayerTreeImpl::ProcessUIResourceRequestQueue() {
679 while (ui_resource_request_queue_.size() > 0) {
680 UIResourceRequest req = ui_resource_request_queue_.front();
681 ui_resource_request_queue_.pop_front();
683 switch (req.GetType()) {
684 case UIResourceRequest::UIResourceCreate:
685 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
686 break;
687 case UIResourceRequest::UIResourceDelete:
688 layer_tree_host_impl_->DeleteUIResource(req.GetId());
689 break;
690 case UIResourceRequest::UIResourceInvalidRequest:
691 NOTREACHED();
692 break;
696 // If all UI resource evictions were not recreated by processing this queue,
697 // then another commit is required.
698 if (layer_tree_host_impl_->EvictedUIResourcesExist())
699 layer_tree_host_impl_->SetNeedsCommit();
702 void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
703 // Only the active tree needs to know about layers with copy requests, as
704 // they are aborted if not serviced during draw.
705 DCHECK(IsActiveTree());
707 DCHECK(std::find(layers_with_copy_output_request_.begin(),
708 layers_with_copy_output_request_.end(),
709 layer) == layers_with_copy_output_request_.end());
710 layers_with_copy_output_request_.push_back(layer);
713 void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
714 // Only the active tree needs to know about layers with copy requests, as
715 // they are aborted if not serviced during draw.
716 DCHECK(IsActiveTree());
718 std::vector<LayerImpl*>::iterator it = std::find(
719 layers_with_copy_output_request_.begin(),
720 layers_with_copy_output_request_.end(),
721 layer);
722 DCHECK(it != layers_with_copy_output_request_.end());
723 layers_with_copy_output_request_.erase(it);
726 const std::vector<LayerImpl*> LayerTreeImpl::LayersWithCopyOutputRequest()
727 const {
728 // Only the active tree needs to know about layers with copy requests, as
729 // they are aborted if not serviced during draw.
730 DCHECK(IsActiveTree());
732 return layers_with_copy_output_request_;
735 } // namespace cc