blob: 4c1034a7293ea49a59430043d8aa0fcf18c609cf [file] [log] [blame]
[email protected]3b31c6ac2012-12-06 21:27:291// 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.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_impl.h"
[email protected]3b31c6ac2012-12-06 21:27:296
[email protected]76ffd9e2012-12-20 19:12:477#include "base/debug/trace_event.h"
[email protected]95e4e1a02013-03-18 07:09:098#include "cc/animation/keyframed_animation_curve.h"
9#include "cc/animation/scrollbar_animation_controller.h"
[email protected]f6742f52013-05-08 23:52:2210#include "cc/debug/traced_value.h"
[email protected]cc3cfaa2013-03-18 09:05:5211#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]57ac9482013-09-17 21:13:3912#include "cc/layers/layer.h"
[email protected]50761e92013-03-29 20:51:2813#include "cc/layers/render_surface_impl.h"
[email protected]80413d72013-08-30 20:25:3314#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]556fd292013-03-18 08:03:0415#include "cc/trees/layer_tree_host_common.h"
16#include "cc/trees/layer_tree_host_impl.h"
[email protected]ffb2720f2013-03-15 19:18:3717#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1618#include "ui/gfx/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2919
20namespace cc {
21
[email protected]8bef40572012-12-11 21:38:0822LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0423 : layer_tree_host_impl_(layer_tree_host_impl),
24 source_frame_number_(-1),
25 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4726 root_scroll_layer_(NULL),
27 currently_scrolling_layer_(NULL),
28 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0429 background_color_(0),
30 has_transparent_background_(false),
[email protected]57ac9482013-09-17 21:13:3931 page_scale_layer_(NULL),
32 inner_viewport_scroll_layer_(NULL),
33 outer_viewport_scroll_layer_(NULL),
[email protected]db8259f2013-02-01 05:25:0434 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),
[email protected]318822852013-02-14 00:54:2741 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0442 needs_update_draw_properties_(true),
43 needs_full_tree_sync_(true) {
[email protected]3b31c6ac2012-12-06 21:27:2944}
45
46LayerTreeImpl::~LayerTreeImpl() {
[email protected]361bc00d2012-12-14 07:03:2447 // 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();
[email protected]3b31c6ac2012-12-06 21:27:2950}
51
[email protected]3c0a3252013-03-18 04:24:3652static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) {
53 if (!layer)
54 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2955
[email protected]3c0a3252013-03-18 04:24:3656 if (layer->scrollable())
57 return layer;
[email protected]3b31c6ac2012-12-06 21:27:2958
[email protected]3c0a3252013-03-18 04:24:3659 for (size_t i = 0; i < layer->children().size(); ++i) {
60 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]);
61 if (found)
62 return found;
63 }
[email protected]3b31c6ac2012-12-06 21:27:2964
[email protected]3c0a3252013-03-18 04:24:3665 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2966}
67
68void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]1960a712013-04-30 17:06:4769 if (root_scroll_layer_)
70 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
[email protected]3b31c6ac2012-12-06 21:27:2971 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:5372 currently_scrolling_layer_ = NULL;
[email protected]1960a712013-04-30 17:06:4773 root_scroll_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:5374
[email protected]c1bb5af2013-03-13 19:06:2775 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:5376}
77
78void LayerTreeImpl::FindRootScrollLayer() {
[email protected]3c0a3252013-03-18 04:24:3679 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get());
[email protected]3b31c6ac2012-12-06 21:27:2980
[email protected]1960a712013-04-30 17:06:4781 if (root_scroll_layer_) {
[email protected]d30700f12013-07-31 08:21:0182 UpdateMaxScrollOffset();
[email protected]1960a712013-04-30 17:06:4783 root_scroll_layer_->SetScrollOffsetDelegate(
84 root_layer_scroll_offset_delegate_);
85 }
86
[email protected]a90fac72013-06-06 18:56:1387 if (scrolling_layer_id_from_previous_tree_) {
[email protected]6ba914122013-03-22 16:26:3988 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]3b31c6ac2012-12-06 21:27:2989 root_layer_.get(),
90 scrolling_layer_id_from_previous_tree_);
91 }
92
93 scrolling_layer_id_from_previous_tree_ = 0;
[email protected]3b31c6ac2012-12-06 21:27:2994}
95
96scoped_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;
[email protected]1960a712013-04-30 17:06:47100 if (root_scroll_layer_)
101 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
[email protected]69b50ec2013-01-19 04:58:01102 root_scroll_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29103 currently_scrolling_layer_ = NULL;
104
[email protected]76ffd9e2012-12-20 19:12:47105 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16106 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29107 return root_layer_.Pass();
108}
109
[email protected]7aba6662013-03-12 10:17:34110void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c9280762013-08-01 06:28:57111 // The request queue should have been processed and does not require a push.
112 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
113
[email protected]e4c3c87a2013-04-22 02:28:40114 target_tree->SetLatencyInfo(latency_info_);
115 latency_info_.Clear();
[email protected]c60279472013-01-30 12:10:51116 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);
121
[email protected]57ac9482013-09-17 21:13:39122 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);
128 }
[email protected]c60279472013-01-30 12:10:51129 // 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());
134
135 if (ContentsTexturesPurged())
136 target_tree->SetContentsTexturesPurged();
137 else
138 target_tree->ResetContentsTexturesPurged();
139
[email protected]318822852013-02-14 00:54:27140 if (ViewportSizeInvalid())
141 target_tree->SetViewportSizeInvalid();
142 else
143 target_tree->ResetViewportSizeInvalid();
144
[email protected]c60279472013-01-30 12:10:51145 if (hud_layer())
146 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39147 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27148 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51149 else
150 target_tree->set_hud_layer(NULL);
151}
152
[email protected]ffb2720f2013-03-15 19:18:37153LayerImpl* LayerTreeImpl::RootScrollLayer() const {
[email protected]69b50ec2013-01-19 04:58:01154 return root_scroll_layer_;
155}
156
[email protected]02635222013-07-15 18:28:07157LayerImpl* LayerTreeImpl::RootContainerLayer() const {
[email protected]ffb2720f2013-03-15 19:18:37158 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
159}
160
161LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01162 DCHECK(IsActiveTree());
163 return currently_scrolling_layer_;
164}
165
[email protected]0fc818e2013-03-18 06:45:20166void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
167 if (currently_scrolling_layer_ == layer)
168 return;
169
170 if (currently_scrolling_layer_ &&
171 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]6bc09e82013-03-19 03:48:35172 currently_scrolling_layer_->scrollbar_animation_controller()->
[email protected]21c9dee72013-06-15 01:20:05173 DidScrollGestureEnd(CurrentPhysicalTimeTicks());
[email protected]0fc818e2013-03-18 06:45:20174 currently_scrolling_layer_ = layer;
175 if (layer && layer->scrollbar_animation_controller())
[email protected]6bc09e82013-03-19 03:48:35176 layer->scrollbar_animation_controller()->DidScrollGestureBegin();
[email protected]0fc818e2013-03-18 06:45:20177}
178
[email protected]3b31c6ac2012-12-06 21:27:29179void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20180 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29181 scrolling_layer_id_from_previous_tree_ = 0;
182}
183
[email protected]c60279472013-01-30 12:10:51184void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36185 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]c60279472013-01-30 12:10:51186 if (!page_scale_factor)
187 return;
188
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;
192}
193
[email protected]3c0a3252013-03-18 04:24:36194void LayerTreeImpl::SetPageScaleDelta(float delta) {
[email protected]c60279472013-01-30 12:10:51195 // Clamp to the current min/max limits.
196 float total = page_scale_factor_ * delta;
197 if (min_page_scale_factor_ && total < min_page_scale_factor_)
198 delta = min_page_scale_factor_ / page_scale_factor_;
199 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
200 delta = max_page_scale_factor_ / page_scale_factor_;
201
202 if (delta == page_scale_delta_)
203 return;
204
205 page_scale_delta_ = delta;
206
207 if (IsActiveTree()) {
[email protected]c1bb5af2013-03-13 19:06:27208 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
[email protected]c60279472013-01-30 12:10:51209 if (pending_tree) {
210 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
[email protected]ca2902e92013-03-28 01:45:35211 pending_tree->SetPageScaleDelta(
212 page_scale_delta_ / sent_page_scale_delta_);
[email protected]c60279472013-01-30 12:10:51213 }
214 }
215
216 UpdateMaxScrollOffset();
217 set_needs_update_draw_properties();
218}
219
[email protected]257abfa82013-01-29 23:47:24220gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]54af03522013-09-05 00:43:28221 return gfx::ScaleSize(layer_tree_host_impl_->UnscaledScrollableViewportSize(),
[email protected]ffb2720f2013-03-15 19:18:37222 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24223}
224
[email protected]caa567d2012-12-20 07:56:16225void LayerTreeImpl::UpdateMaxScrollOffset() {
[email protected]4babb952013-07-13 00:04:32226 LayerImpl* root_scroll = RootScrollLayer();
227 if (!root_scroll || !root_scroll->children().size())
[email protected]caa567d2012-12-20 07:56:16228 return;
229
[email protected]42ccdbef2013-01-21 07:54:54230 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
[email protected]257abfa82013-01-29 23:47:24231 gfx::RectF(ScrollableViewportSize()).bottom_right();
[email protected]caa567d2012-12-20 07:56:16232
233 // The viewport may be larger than the contents in some cases, such as
234 // having a vertical scrollbar but no horizontal overflow.
[email protected]a4a08d02013-05-30 00:18:00235 max_scroll.SetToMax(gfx::Vector2dF());
[email protected]caa567d2012-12-20 07:56:16236
[email protected]7aba6662013-03-12 10:17:34237 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
[email protected]caa567d2012-12-20 07:56:16238}
239
[email protected]58241dc2013-08-20 01:39:25240static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
241 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50242}
243
[email protected]58241dc2013-08-20 01:39:25244void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50245 DCHECK(IsActiveTree());
246
247 page_scale_factor_ *= sent_page_scale_delta_;
248 page_scale_delta_ /= sent_page_scale_delta_;
249 sent_page_scale_delta_ = 1.f;
250
251 if (!root_layer())
252 return;
253
254 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25255 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
256}
257
258static void ApplyScrollDeltasSinceBeginFrameTo(LayerImpl* layer) {
259 layer->ApplyScrollDeltasSinceBeginFrame();
260}
261
262void LayerTreeImpl::ApplyScrollDeltasSinceBeginFrame() {
263 DCHECK(IsPendingTree());
264 if (!root_layer())
265 return;
266
267 LayerTreeHostCommon::CallFunctionForSubtree(
268 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginFrameTo));
[email protected]3519b872013-07-30 07:17:50269}
270
[email protected]57ac9482013-09-17 21:13:39271void LayerTreeImpl::SetViewportLayersFromIds(
272 int page_scale_layer_id,
273 int inner_viewport_scroll_layer_id,
274 int outer_viewport_scroll_layer_id) {
275 page_scale_layer_ = LayerById(page_scale_layer_id);
276 DCHECK(page_scale_layer_);
277
278 inner_viewport_scroll_layer_ =
279 LayerById(inner_viewport_scroll_layer_id);
280 DCHECK(inner_viewport_scroll_layer_);
281
282 outer_viewport_scroll_layer_ =
283 LayerById(outer_viewport_scroll_layer_id);
284 DCHECK(outer_viewport_scroll_layer_ ||
285 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
286}
287
288void LayerTreeImpl::ClearViewportLayers() {
289 page_scale_layer_ = NULL;
290 inner_viewport_scroll_layer_ = NULL;
291 outer_viewport_scroll_layer_ = NULL;
292}
293
[email protected]80413d72013-08-30 20:25:33294// TODO(wjmaclean) This needs to go away, and be replaced with a single core
295// of login that works for both scrollbar layer types. This is already planned
296// as part of the larger pinch-zoom re-factoring viewport.
[email protected]ffb2720f2013-03-15 19:18:37297void LayerTreeImpl::UpdateSolidColorScrollbars() {
[email protected]8e0176d2013-03-21 03:14:52298 DCHECK(settings().solid_color_scrollbars);
[email protected]ffb2720f2013-03-15 19:18:37299
300 LayerImpl* root_scroll = RootScrollLayer();
[email protected]ab5f4a92013-03-19 20:08:24301 DCHECK(root_scroll);
302 DCHECK(IsActiveTree());
[email protected]ffb2720f2013-03-15 19:18:37303
304 gfx::RectF scrollable_viewport(
305 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
306 ScrollableViewportSize());
307 float vertical_adjust = 0.0f;
[email protected]02635222013-07-15 18:28:07308 if (RootContainerLayer())
[email protected]54af03522013-09-05 00:43:28309 vertical_adjust =
310 layer_tree_host_impl_->UnscaledScrollableViewportSize().height() -
311 RootContainerLayer()->bounds().height();
[email protected]80413d72013-08-30 20:25:33312 if (ScrollbarLayerImplBase* horiz =
[email protected]3a83478b2013-08-22 20:55:17313 root_scroll->horizontal_scrollbar_layer()) {
[email protected]5493fc42013-08-15 01:46:22314 horiz->SetVerticalAdjust(vertical_adjust);
315 horiz->SetVisibleToTotalLengthRatio(
[email protected]c28df4c12013-05-22 17:36:49316 scrollable_viewport.width() / ScrollableSize().width());
[email protected]ffb2720f2013-03-15 19:18:37317 }
[email protected]80413d72013-08-30 20:25:33318 if (ScrollbarLayerImplBase* vertical =
[email protected]3a83478b2013-08-22 20:55:17319 root_scroll->vertical_scrollbar_layer()) {
[email protected]5493fc42013-08-15 01:46:22320 vertical->SetVerticalAdjust(vertical_adjust);
321 vertical->SetVisibleToTotalLengthRatio(
[email protected]c28df4c12013-05-22 17:36:49322 scrollable_viewport.height() / ScrollableSize().height());
[email protected]ffb2720f2013-03-15 19:18:37323 }
324}
325
[email protected]7d19dc342013-05-02 22:02:04326void LayerTreeImpl::UpdateDrawProperties() {
[email protected]02635222013-07-15 18:28:07327 if (IsActiveTree() && RootScrollLayer() && RootContainerLayer())
[email protected]fe956c9c42013-04-09 04:26:33328 UpdateRootScrollLayerSizeDelta();
329
[email protected]ca2902e92013-03-28 01:45:35330 if (settings().solid_color_scrollbars &&
331 IsActiveTree() &&
332 RootScrollLayer()) {
[email protected]ffb2720f2013-03-15 19:18:37333 UpdateSolidColorScrollbars();
[email protected]ffb2720f2013-03-15 19:18:37334 }
335
[email protected]615c78a2013-01-24 23:44:16336 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47337 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16338
[email protected]ed511b8d2013-03-25 03:29:29339 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16340 if (!layer_tree_host_impl_->renderer())
[email protected]c9280762013-08-01 06:28:57341 return;
[email protected]615c78a2013-01-24 23:44:16342
[email protected]c1bb5af2013-03-13 19:06:27343 if (!root_layer())
[email protected]76ffd9e2012-12-20 19:12:47344 return;
345
[email protected]76ffd9e2012-12-20 19:12:47346 {
[email protected]7a52f43e2013-07-10 01:58:47347 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27348 "LayerTreeImpl::UpdateDrawProperties",
349 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47350 IsActiveTree(),
351 "SourceFrameNumber",
352 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39353 LayerImpl* page_scale_layer =
354 page_scale_layer_ ? page_scale_layer_ : RootContainerLayer();
[email protected]7aad55f2013-07-26 11:25:53355 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
[email protected]c1bb5af2013-03-13 19:06:27356 root_layer(),
[email protected]54af03522013-09-05 00:43:28357 DrawViewportSize(),
358 layer_tree_host_impl_->DrawTransform(),
[email protected]76ffd9e2012-12-20 19:12:47359 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51360 total_page_scale_factor(),
[email protected]57ac9482013-09-17 21:13:39361 page_scale_layer,
[email protected]f6776532012-12-21 20:24:33362 MaxTextureSize(),
[email protected]8e0176d2013-03-21 03:14:52363 settings().can_use_lcd_text,
[email protected]35a99a12013-05-09 23:52:29364 settings().layer_transforms_should_scale_layer_contents,
[email protected]7d19dc342013-05-02 22:02:04365 &render_surface_layer_list_);
[email protected]7aad55f2013-07-26 11:25:53366 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47367 }
[email protected]615c78a2013-01-24 23:44:16368
369 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04370 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]76ffd9e2012-12-20 19:12:47371}
372
[email protected]50761e92013-03-29 20:51:28373const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47374 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16375 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47376 return render_surface_layer_list_;
377}
378
[email protected]42ccdbef2013-01-21 07:54:54379gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]c4d467a2013-01-21 03:21:01380 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
[email protected]caa567d2012-12-20 07:56:16381 return gfx::Size();
[email protected]c4d467a2013-01-21 03:21:01382 return root_scroll_layer_->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16383}
384
[email protected]361bc00d2012-12-14 07:03:24385LayerImpl* LayerTreeImpl::LayerById(int id) {
386 LayerIdMap::iterator iter = layer_id_map_.find(id);
387 return iter != layer_id_map_.end() ? iter->second : NULL;
388}
389
390void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
391 DCHECK(!LayerById(layer->id()));
392 layer_id_map_[layer->id()] = layer;
393}
394
395void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
396 DCHECK(LayerById(layer->id()));
397 layer_id_map_.erase(layer->id());
398}
399
[email protected]ed511b8d2013-03-25 03:29:29400void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13401 pending_tree->SetCurrentlyScrollingLayer(
402 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
403 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]b76329d2013-06-11 04:15:08404 pending_tree->SetLatencyInfo(latency_info_);
405 latency_info_.Clear();
[email protected]1e0f8d62013-01-09 07:41:35406}
407
[email protected]ff1211d2013-06-07 01:58:35408static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34409 layer->DidBecomeActive();
[email protected]ff1211d2013-06-07 01:58:35410 for (size_t i = 0; i < layer->children().size(); ++i)
411 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22412}
413
414void LayerTreeImpl::DidBecomeActive() {
[email protected]d30700f12013-07-31 08:21:01415 if (!root_layer())
416 return;
417
418 DidBecomeActiveRecursive(root_layer());
[email protected]69b50ec2013-01-19 04:58:01419 FindRootScrollLayer();
[email protected]37386f052013-01-13 00:42:22420}
421
[email protected]6f90b9e2013-01-17 23:42:00422bool LayerTreeImpl::ContentsTexturesPurged() const {
423 return contents_textures_purged_;
424}
425
426void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04427 if (contents_textures_purged_)
428 return;
[email protected]6f90b9e2013-01-17 23:42:00429 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27430 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00431}
432
433void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04434 if (!contents_textures_purged_)
435 return;
[email protected]6f90b9e2013-01-17 23:42:00436 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27437 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00438}
439
[email protected]318822852013-02-14 00:54:27440bool LayerTreeImpl::ViewportSizeInvalid() const {
441 return viewport_size_invalid_;
442}
443
444void LayerTreeImpl::SetViewportSizeInvalid() {
445 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27446 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27447}
448
449void LayerTreeImpl::ResetViewportSizeInvalid() {
450 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27451 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27452}
453
[email protected]48871fc2013-01-23 07:36:51454Proxy* LayerTreeImpl::proxy() const {
455 return layer_tree_host_impl_->proxy();
456}
457
[email protected]ff762fb2012-12-12 19:18:37458const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27459 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37460}
461
[email protected]ed511b8d2013-03-25 03:29:29462const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27463 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52464}
465
[email protected]0634cdd42013-08-16 00:46:09466ContextProvider* LayerTreeImpl::context_provider() const {
467 return output_surface()->context_provider();
468}
469
[email protected]ff762fb2012-12-12 19:18:37470OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27471 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37472}
473
474ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27475 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37476}
477
478TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27479 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37480}
481
482FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27483 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37484}
485
[email protected]71691c22013-01-18 03:14:22486PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27487 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22488}
489
[email protected]1191d9d2013-02-02 06:00:33490MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27491 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33492}
493
[email protected]54af03522013-09-05 00:43:28494bool LayerTreeImpl::device_viewport_valid_for_tile_management() const {
495 return layer_tree_host_impl_->device_viewport_valid_for_tile_management();
496}
497
[email protected]f117a4c2012-12-16 04:53:10498bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27499 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10500}
501
502bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27503 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10504}
505
[email protected]48871fc2013-01-23 07:36:51506bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27507 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51508}
509
[email protected]f117a4c2012-12-16 04:53:10510LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27511 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10512 if (!tree)
513 return NULL;
514 return tree->LayerById(id);
515}
516
517LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27518 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10519 if (!tree)
520 return NULL;
521 return tree->LayerById(id);
522}
523
[email protected]f6776532012-12-21 20:24:33524int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27525 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33526}
527
[email protected]166db5c82013-01-09 23:54:31528bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27529 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31530}
531
[email protected]fb7425a2013-04-22 16:28:55532base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const {
533 return layer_tree_host_impl_->CurrentFrameTimeTicks();
534}
535
536base::Time LayerTreeImpl::CurrentFrameTime() const {
[email protected]c1bb5af2013-03-13 19:06:27537 return layer_tree_host_impl_->CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10538}
539
[email protected]21c9dee72013-06-15 01:20:05540base::TimeTicks LayerTreeImpl::CurrentPhysicalTimeTicks() const {
541 return layer_tree_host_impl_->CurrentPhysicalTimeTicks();
542}
543
[email protected]d7eb8c72013-03-23 22:57:13544void LayerTreeImpl::SetNeedsCommit() {
545 layer_tree_host_impl_->SetNeedsCommit();
546}
547
[email protected]54af03522013-09-05 00:43:28548gfx::Size LayerTreeImpl::DrawViewportSize() const {
549 return layer_tree_host_impl_->DrawViewportSize();
550}
551
[email protected]2ea5aba2013-09-11 14:26:56552void LayerTreeImpl::StartScrollbarAnimation() {
553 layer_tree_host_impl_->StartScrollbarAnimation();
554}
555
[email protected]ff762fb2012-12-12 19:18:37556void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44557 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37558}
559
[email protected]ff762fb2012-12-12 19:18:37560const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27561 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37562}
563
564float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27565 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37566}
567
[email protected]ff762fb2012-12-12 19:18:37568DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27569 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37570}
571
[email protected]de4afb5e2012-12-20 00:11:34572AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27573 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34574}
[email protected]ff762fb2012-12-12 19:18:37575
[email protected]8c5690222013-02-15 17:36:43576scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
[email protected]f6742f52013-05-08 23:52:22577 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
578 TracedValue::MakeDictIntoImplicitSnapshot(
579 state.get(), "cc::LayerTreeImpl", this);
580
581 state->Set("root_layer", root_layer_->AsValue().release());
582
583 scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue());
[email protected]8c5690222013-02-15 17:36:43584 typedef LayerIterator<LayerImpl,
[email protected]50761e92013-03-29 20:51:28585 LayerImplList,
[email protected]8c5690222013-02-15 17:36:43586 RenderSurfaceImpl,
587 LayerIteratorActions::BackToFront> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09588 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
589 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43590 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09591 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43592 continue;
[email protected]f6742f52013-05-08 23:52:22593 render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release());
[email protected]8c5690222013-02-15 17:36:43594 }
[email protected]f6742f52013-05-08 23:52:22595
596 state->Set("render_surface_layer_list",
597 render_surface_layer_list.release());
[email protected]8c5690222013-02-15 17:36:43598 return state.PassAs<base::Value>();
599}
600
[email protected]1960a712013-04-30 17:06:47601void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57602 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]1960a712013-04-30 17:06:47603 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
604 if (root_scroll_layer_) {
605 root_scroll_layer_->SetScrollOffsetDelegate(
606 root_layer_scroll_offset_delegate_);
607 }
608}
609
[email protected]fe956c9c42013-04-09 04:26:33610void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() {
611 LayerImpl* root_scroll = RootScrollLayer();
[email protected]02635222013-07-15 18:28:07612 LayerImpl* root_container = RootContainerLayer();
[email protected]fe956c9c42013-04-09 04:26:33613 DCHECK(root_scroll);
[email protected]02635222013-07-15 18:28:07614 DCHECK(root_container);
[email protected]fe956c9c42013-04-09 04:26:33615 DCHECK(IsActiveTree());
616
617 gfx::Vector2dF scrollable_viewport_size =
618 gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF();
619
620 gfx::Vector2dF original_viewport_size =
[email protected]02635222013-07-15 18:28:07621 gfx::RectF(root_container->bounds()).bottom_right() -
[email protected]fe956c9c42013-04-09 04:26:33622 gfx::PointF();
623 original_viewport_size.Scale(1 / page_scale_factor());
624
625 root_scroll->SetFixedContainerSizeDelta(
626 scrollable_viewport_size - original_viewport_size);
627}
628
[email protected]4b157662013-05-29 04:05:05629void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) {
[email protected]e4c3c87a2013-04-22 02:28:40630 latency_info_.MergeWith(latency_info);
631}
632
[email protected]4b157662013-05-29 04:05:05633const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() {
[email protected]e4c3c87a2013-04-22 02:28:40634 return latency_info_;
635}
636
637void LayerTreeImpl::ClearLatencyInfo() {
638 latency_info_.Clear();
639}
640
[email protected]c48536a52013-09-14 00:02:08641void LayerTreeImpl::DidModifyTilePriorities() {
642 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:36643}
644
[email protected]c9280762013-08-01 06:28:57645void LayerTreeImpl::set_ui_resource_request_queue(
646 const UIResourceRequestQueue& queue) {
647 ui_resource_request_queue_ = queue;
648}
649
650ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
651 UIResourceId uid) const {
652 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
653}
654
655void LayerTreeImpl::ProcessUIResourceRequestQueue() {
656 while (ui_resource_request_queue_.size() > 0) {
657 UIResourceRequest req = ui_resource_request_queue_.front();
658 ui_resource_request_queue_.pop_front();
659
[email protected]20c8fc3542013-09-13 23:58:04660 switch (req.type) {
[email protected]c9280762013-08-01 06:28:57661 case UIResourceRequest::UIResourceCreate:
[email protected]20c8fc3542013-09-13 23:58:04662 layer_tree_host_impl_->CreateUIResource(req.id, req.bitmap);
[email protected]c9280762013-08-01 06:28:57663 break;
664 case UIResourceRequest::UIResourceDelete:
[email protected]20c8fc3542013-09-13 23:58:04665 layer_tree_host_impl_->DeleteUIResource(req.id);
[email protected]c9280762013-08-01 06:28:57666 break;
[email protected]f28d64d2013-08-27 04:17:45667 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:57668 NOTREACHED();
669 break;
670 }
671 }
[email protected]127bdc1a2013-09-11 01:44:48672
673 // If all UI resource evictions were not recreated by processing this queue,
674 // then another commit is required.
675 if (layer_tree_host_impl_->EvictedUIResourcesExist())
676 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:57677}
678
[email protected]30fe19ff2013-07-04 00:54:45679void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
680 // Only the active tree needs to know about layers with copy requests, as
681 // they are aborted if not serviced during draw.
682 DCHECK(IsActiveTree());
683
[email protected]f5de9e5b2013-07-30 22:26:57684 DCHECK(std::find(layers_with_copy_output_request_.begin(),
685 layers_with_copy_output_request_.end(),
686 layer) == layers_with_copy_output_request_.end());
[email protected]30fe19ff2013-07-04 00:54:45687 layers_with_copy_output_request_.push_back(layer);
688}
689
690void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
691 // Only the active tree needs to know about layers with copy requests, as
692 // they are aborted if not serviced during draw.
693 DCHECK(IsActiveTree());
694
695 std::vector<LayerImpl*>::iterator it = std::find(
696 layers_with_copy_output_request_.begin(),
697 layers_with_copy_output_request_.end(),
698 layer);
699 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:57700 layers_with_copy_output_request_.erase(it);
[email protected]30fe19ff2013-07-04 00:54:45701}
702
703const std::vector<LayerImpl*> LayerTreeImpl::LayersWithCopyOutputRequest()
704 const {
705 // Only the active tree needs to know about layers with copy requests, as
706 // they are aborted if not serviced during draw.
707 DCHECK(IsActiveTree());
708
709 return layers_with_copy_output_request_;
710}
711
[email protected]ca2902e92013-03-28 01:45:35712} // namespace cc