[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "cc/layer_tree_impl.h" |
| 6 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 7 | #include "base/debug/trace_event.h" |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 8 | #include "cc/heads_up_display_layer_impl.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 9 | #include "cc/layer_tree_host_common.h" |
| 10 | #include "cc/layer_tree_host_impl.h" |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 11 | #include "cc/scrollbar_layer_impl.h" |
| 12 | #include "ui/gfx/size_conversions.h" |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 13 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 14 | |
| 15 | namespace cc { |
| 16 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 17 | LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 18 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 19 | source_frame_number_(-1), |
| 20 | hud_layer_(0), |
| 21 | root_scroll_layer_(0), |
| 22 | currently_scrolling_layer_(0), |
| 23 | background_color_(0), |
| 24 | has_transparent_background_(false), |
| 25 | page_scale_factor_(1), |
| 26 | page_scale_delta_(1), |
| 27 | sent_page_scale_delta_(1), |
| 28 | min_page_scale_factor_(0), |
| 29 | max_page_scale_factor_(0), |
| 30 | scrolling_layer_id_from_previous_tree_(0), |
| 31 | contents_textures_purged_(false), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 32 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 33 | needs_update_draw_properties_(true), |
| 34 | needs_full_tree_sync_(true) { |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | LayerTreeImpl::~LayerTreeImpl() { |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 38 | // Need to explicitly clear the tree prior to destroying this so that |
| 39 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
| 40 | root_layer_.reset(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static LayerImpl* findRootScrollLayer(LayerImpl* layer) |
| 44 | { |
| 45 | if (!layer) |
| 46 | return 0; |
| 47 | |
| 48 | if (layer->scrollable()) |
| 49 | return layer; |
| 50 | |
| 51 | for (size_t i = 0; i < layer->children().size(); ++i) { |
| 52 | LayerImpl* found = findRootScrollLayer(layer->children()[i]); |
| 53 | if (found) |
| 54 | return found; |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
| 61 | root_layer_ = layer.Pass(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 62 | root_scroll_layer_ = NULL; |
| 63 | currently_scrolling_layer_ = NULL; |
| 64 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 65 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void LayerTreeImpl::FindRootScrollLayer() { |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 69 | root_scroll_layer_ = findRootScrollLayer(root_layer_.get()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 70 | |
| 71 | if (root_layer_ && scrolling_layer_id_from_previous_tree_) { |
| 72 | currently_scrolling_layer_ = LayerTreeHostCommon::findLayerInSubtree( |
| 73 | root_layer_.get(), |
| 74 | scrolling_layer_id_from_previous_tree_); |
| 75 | } |
| 76 | |
| 77 | scrolling_layer_id_from_previous_tree_ = 0; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 81 | // Clear all data structures that have direct references to the layer tree. |
| 82 | scrolling_layer_id_from_previous_tree_ = |
| 83 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 84 | root_scroll_layer_ = NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 85 | currently_scrolling_layer_ = NULL; |
| 86 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 87 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 88 | set_needs_update_draw_properties(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 89 | return root_layer_.Pass(); |
| 90 | } |
| 91 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 92 | void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 93 | target_tree->SetPageScaleFactorAndLimits( |
| 94 | page_scale_factor(), min_page_scale_factor(), max_page_scale_factor()); |
| 95 | target_tree->SetPageScaleDelta( |
| 96 | target_tree->page_scale_delta() / target_tree->sent_page_scale_delta()); |
| 97 | target_tree->set_sent_page_scale_delta(1); |
| 98 | |
| 99 | // This should match the property synchronization in |
| 100 | // LayerTreeHost::finishCommitOnImplThread(). |
| 101 | target_tree->set_source_frame_number(source_frame_number()); |
| 102 | target_tree->set_background_color(background_color()); |
| 103 | target_tree->set_has_transparent_background(has_transparent_background()); |
| 104 | |
| 105 | if (ContentsTexturesPurged()) |
| 106 | target_tree->SetContentsTexturesPurged(); |
| 107 | else |
| 108 | target_tree->ResetContentsTexturesPurged(); |
| 109 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 110 | if (ViewportSizeInvalid()) |
| 111 | target_tree->SetViewportSizeInvalid(); |
| 112 | else |
| 113 | target_tree->ResetViewportSizeInvalid(); |
| 114 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 115 | if (hud_layer()) |
| 116 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
| 117 | LayerTreeHostCommon::findLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 118 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 119 | else |
| 120 | target_tree->set_hud_layer(NULL); |
| 121 | } |
| 122 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 123 | LayerImpl* LayerTreeImpl::RootScrollLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 124 | DCHECK(IsActiveTree()); |
| 125 | return root_scroll_layer_; |
| 126 | } |
| 127 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 128 | LayerImpl* LayerTreeImpl::RootClipLayer() const { |
| 129 | return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; |
| 130 | } |
| 131 | |
| 132 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 133 | DCHECK(IsActiveTree()); |
| 134 | return currently_scrolling_layer_; |
| 135 | } |
| 136 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 137 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
| 138 | currently_scrolling_layer_ = NULL; |
| 139 | scrolling_layer_id_from_previous_tree_ = 0; |
| 140 | } |
| 141 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 142 | void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, |
| 143 | float min_page_scale_factor, float max_page_scale_factor) |
| 144 | { |
| 145 | if (!page_scale_factor) |
| 146 | return; |
| 147 | |
| 148 | min_page_scale_factor_ = min_page_scale_factor; |
| 149 | max_page_scale_factor_ = max_page_scale_factor; |
| 150 | page_scale_factor_ = page_scale_factor; |
| 151 | } |
| 152 | |
| 153 | void LayerTreeImpl::SetPageScaleDelta(float delta) |
| 154 | { |
| 155 | // Clamp to the current min/max limits. |
| 156 | float total = page_scale_factor_ * delta; |
| 157 | if (min_page_scale_factor_ && total < min_page_scale_factor_) |
| 158 | delta = min_page_scale_factor_ / page_scale_factor_; |
| 159 | else if (max_page_scale_factor_ && total > max_page_scale_factor_) |
| 160 | delta = max_page_scale_factor_ / page_scale_factor_; |
| 161 | |
| 162 | if (delta == page_scale_delta_) |
| 163 | return; |
| 164 | |
| 165 | page_scale_delta_ = delta; |
| 166 | |
| 167 | if (IsActiveTree()) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 168 | LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 169 | if (pending_tree) { |
| 170 | DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); |
| 171 | pending_tree->SetPageScaleDelta(page_scale_delta_ / sent_page_scale_delta_); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | UpdateMaxScrollOffset(); |
| 176 | set_needs_update_draw_properties(); |
| 177 | } |
| 178 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 179 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 180 | return gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(), |
| 181 | 1.0f / total_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 182 | } |
| 183 | |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 184 | void LayerTreeImpl::UpdateMaxScrollOffset() { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 185 | if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 186 | return; |
| 187 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 188 | gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 189 | gfx::RectF(ScrollableViewportSize()).bottom_right(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 190 | |
| 191 | // The viewport may be larger than the contents in some cases, such as |
| 192 | // having a vertical scrollbar but no horizontal overflow. |
| 193 | max_scroll.ClampToMin(gfx::Vector2dF()); |
| 194 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 195 | root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 198 | gfx::Transform LayerTreeImpl::ImplTransform() const { |
| 199 | gfx::Transform transform; |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 200 | transform.Scale(total_page_scale_factor(), total_page_scale_factor()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 201 | return transform; |
| 202 | } |
| 203 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 204 | void LayerTreeImpl::UpdateSolidColorScrollbars() { |
| 205 | DCHECK(settings().solidColorScrollbars); |
| 206 | |
| 207 | LayerImpl* root_scroll = RootScrollLayer(); |
| 208 | if (!root_scroll) |
| 209 | return; |
| 210 | |
| 211 | if (!IsActiveTree()) |
| 212 | return; |
| 213 | |
| 214 | gfx::RectF scrollable_viewport( |
| 215 | gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()), |
| 216 | ScrollableViewportSize()); |
| 217 | float vertical_adjust = 0.0f; |
| 218 | if (RootClipLayer()) |
| 219 | vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() - |
| 220 | RootClipLayer()->bounds().height(); |
| 221 | if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) { |
| 222 | horiz->set_vertical_adjust(vertical_adjust); |
| 223 | horiz->SetViewportWithinScrollableArea(scrollable_viewport, |
| 224 | ScrollableSize()); |
| 225 | } |
| 226 | if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) { |
| 227 | vertical->set_vertical_adjust(vertical_adjust); |
| 228 | vertical->SetViewportWithinScrollableArea(scrollable_viewport, |
| 229 | ScrollableSize()); |
| 230 | } |
| 231 | } |
| 232 | |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 233 | struct UpdateTilePrioritiesForLayer { |
| 234 | void operator()(LayerImpl *layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 235 | layer->UpdateTilePriorities(); |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 236 | } |
| 237 | }; |
| 238 | |
| 239 | void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 240 | if (settings().solidColorScrollbars && IsActiveTree()) { |
| 241 | UpdateSolidColorScrollbars(); |
| 242 | |
| 243 | // The top controls manager is incompatible with the WebKit-created cliprect |
| 244 | // because it can bring into view a larger amount of content when it |
| 245 | // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars |
| 246 | // are present. |
| 247 | if (layer_tree_host_impl_->top_controls_manager()) |
| 248 | RootScrollLayer()->parent()->SetMasksToBounds(false); |
| 249 | } |
| 250 | |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 251 | if (!needs_update_draw_properties_) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 252 | if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && root_layer()) |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 253 | LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 254 | root_layer()); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 255 | return; |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 256 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 257 | |
| 258 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 259 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 260 | |
| 261 | // For maxTextureSize. |
| 262 | if (!layer_tree_host_impl_->renderer()) |
| 263 | return; |
| 264 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 265 | if (!root_layer()) |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 266 | return; |
| 267 | |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 268 | if (root_scroll_layer_) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 269 | root_scroll_layer_->SetImplTransform(ImplTransform()); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 270 | // Setting the impl transform re-sets this. |
| 271 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 275 | TRACE_EVENT1("cc", |
| 276 | "LayerTreeImpl::UpdateDrawProperties", |
| 277 | "IsActive", |
| 278 | IsActiveTree()); |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 279 | bool update_tile_priorities = |
| 280 | reason == UPDATE_PENDING_TREE || |
| 281 | reason == UPDATE_ACTIVE_TREE_FOR_DRAW; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 282 | LayerTreeHostCommon::calculateDrawProperties( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 283 | root_layer(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 284 | device_viewport_size(), |
| 285 | device_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 286 | total_page_scale_factor(), |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 287 | MaxTextureSize(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 288 | settings().canUseLCDText, |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 289 | render_surface_layer_list_, |
| 290 | update_tile_priorities); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 291 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 292 | |
| 293 | DCHECK(!needs_update_draw_properties_) << |
| 294 | "calcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) |
| 298 | { |
| 299 | DCHECK(current); |
| 300 | for (size_t i = 0; i < current->children().size(); ++i) |
| 301 | ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 302 | current->ClearRenderSurface(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void LayerTreeImpl::ClearRenderSurfaces() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 306 | ClearRenderSurfacesOnLayerImplRecursive(root_layer()); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 307 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 308 | set_needs_update_draw_properties(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 311 | bool LayerTreeImpl::AreVisibleResourcesReady() const { |
| 312 | TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady"); |
| 313 | |
| 314 | typedef LayerIterator<LayerImpl, |
| 315 | std::vector<LayerImpl*>, |
| 316 | RenderSurfaceImpl, |
| 317 | LayerIteratorActions::BackToFront> LayerIteratorType; |
| 318 | LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); |
| 319 | for (LayerIteratorType it = LayerIteratorType::begin( |
| 320 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 321 | if (it.representsItself() && !(*it)->AreVisibleResourcesReady()) |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 328 | const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const { |
| 329 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 330 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 331 | return render_surface_layer_list_; |
| 332 | } |
| 333 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 334 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 335 | if (!root_scroll_layer_ || root_scroll_layer_->children().empty()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 336 | return gfx::Size(); |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 337 | return root_scroll_layer_->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 338 | } |
| 339 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 340 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 341 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 342 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 343 | } |
| 344 | |
| 345 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 346 | DCHECK(!LayerById(layer->id())); |
| 347 | layer_id_map_[layer->id()] = layer; |
| 348 | } |
| 349 | |
| 350 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 351 | DCHECK(LayerById(layer->id())); |
| 352 | layer_id_map_.erase(layer->id()); |
| 353 | } |
| 354 | |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 355 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) { |
| 356 | int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
| 357 | pendingTree->set_currently_scrolling_layer( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 358 | LayerTreeHostCommon::findLayerInSubtree(pendingTree->root_layer(), id)); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 361 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 362 | layer->DidBecomeActive(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 363 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 364 | DidBecomeActiveRecursive(layer->children()[i]); |
| 365 | } |
| 366 | |
| 367 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 368 | if (root_layer()) |
| 369 | DidBecomeActiveRecursive(root_layer()); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 370 | FindRootScrollLayer(); |
| 371 | UpdateMaxScrollOffset(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 374 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 375 | return contents_textures_purged_; |
| 376 | } |
| 377 | |
| 378 | void LayerTreeImpl::SetContentsTexturesPurged() { |
| 379 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 380 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
| 384 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 385 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 388 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 389 | return viewport_size_invalid_; |
| 390 | } |
| 391 | |
| 392 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 393 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 394 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 398 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 399 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 400 | } |
| 401 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 402 | Proxy* LayerTreeImpl::proxy() const { |
| 403 | return layer_tree_host_impl_->proxy(); |
| 404 | } |
| 405 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 406 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 407 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 410 | const RendererCapabilities& LayerTreeImpl::rendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 411 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 412 | } |
| 413 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 414 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 415 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 419 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 423 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 427 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 430 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 431 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 434 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 435 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 436 | } |
| 437 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 438 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 439 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 443 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 444 | } |
| 445 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 446 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 447 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 450 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 451 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 452 | if (!tree) |
| 453 | return NULL; |
| 454 | return tree->LayerById(id); |
| 455 | } |
| 456 | |
| 457 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 458 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 459 | if (!tree) |
| 460 | return NULL; |
| 461 | return tree->LayerById(id); |
| 462 | } |
| 463 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 464 | int LayerTreeImpl::MaxTextureSize() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 465 | return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 466 | } |
| 467 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 468 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 469 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 470 | } |
| 471 | |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 472 | base::TimeTicks LayerTreeImpl::CurrentFrameTime() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 473 | return layer_tree_host_impl_->CurrentFrameTime(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 474 | } |
| 475 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 476 | void LayerTreeImpl::SetNeedsRedraw() { |
| 477 | layer_tree_host_impl_->setNeedsRedraw(); |
| 478 | } |
| 479 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 480 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 481 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 485 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 486 | } |
| 487 | |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 488 | gfx::Size LayerTreeImpl::device_viewport_size() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 489 | return layer_tree_host_impl_->device_viewport_size(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 490 | } |
| 491 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 492 | gfx::Size LayerTreeImpl::layout_viewport_size() const { |
| 493 | return layer_tree_host_impl_->layout_viewport_size(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | std::string LayerTreeImpl::layer_tree_as_text() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 497 | return layer_tree_host_impl_->LayerTreeAsText(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 501 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 502 | } |
| 503 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 504 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 505 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 506 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 507 | |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 508 | scoped_ptr<base::Value> LayerTreeImpl::AsValue() const { |
| 509 | scoped_ptr<base::ListValue> state(new base::ListValue()); |
| 510 | typedef LayerIterator<LayerImpl, |
| 511 | std::vector<LayerImpl*>, |
| 512 | RenderSurfaceImpl, |
| 513 | LayerIteratorActions::BackToFront> LayerIteratorType; |
| 514 | LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); |
| 515 | for (LayerIteratorType it = LayerIteratorType::begin( |
| 516 | &render_surface_layer_list_); it != end; ++it) { |
| 517 | if (!it.representsItself()) |
| 518 | continue; |
| 519 | state->Append((*it)->AsValue().release()); |
| 520 | } |
| 521 | return state.PassAs<base::Value>(); |
| 522 | } |
| 523 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 524 | } // namespace cc |