Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layer_tree_impl.h" | 5 #include "cc/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "cc/layer_tree_host_common.h" | 8 #include "cc/layer_tree_host_common.h" |
| 9 #include "cc/layer_tree_host_impl.h" | 9 #include "cc/layer_tree_host_impl.h" |
| 10 #include "ui/gfx/vector2d_conversions.h" | 10 #include "ui/gfx/vector2d_conversions.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 scrolling_layer_id_from_previous_tree_); | 63 scrolling_layer_id_from_previous_tree_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 scrolling_layer_id_from_previous_tree_ = 0; | 66 scrolling_layer_id_from_previous_tree_ = 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { | 69 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 70 // Clear all data structures that have direct references to the layer tree. | 70 // Clear all data structures that have direct references to the layer tree. |
| 71 scrolling_layer_id_from_previous_tree_ = | 71 scrolling_layer_id_from_previous_tree_ = |
| 72 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; | 72 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
| 73 root_scroll_layer_ = NULL; | |
| 73 currently_scrolling_layer_ = NULL; | 74 currently_scrolling_layer_ = NULL; |
| 74 | 75 |
| 75 render_surface_layer_list_.clear(); | 76 render_surface_layer_list_.clear(); |
| 76 SetNeedsUpdateDrawProperties(); | 77 SetNeedsUpdateDrawProperties(); |
| 77 return root_layer_.Pass(); | 78 return root_layer_.Pass(); |
| 78 } | 79 } |
| 79 | 80 |
| 81 LayerImpl* LayerTreeImpl::RootScrollLayer() { | |
| 82 DCHECK(IsActiveTree()); | |
| 83 return root_scroll_layer_; | |
| 84 } | |
| 85 | |
| 86 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { | |
| 87 DCHECK(IsActiveTree()); | |
| 88 return currently_scrolling_layer_; | |
| 89 } | |
| 90 | |
| 80 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { | 91 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
| 81 currently_scrolling_layer_ = NULL; | 92 currently_scrolling_layer_ = NULL; |
| 82 scrolling_layer_id_from_previous_tree_ = 0; | 93 scrolling_layer_id_from_previous_tree_ = 0; |
| 83 } | 94 } |
| 84 | 95 |
| 85 void LayerTreeImpl::UpdateMaxScrollOffset() { | 96 void LayerTreeImpl::UpdateMaxScrollOffset() { |
| 86 if (!root_scroll_layer() || !root_scroll_layer()->children().size()) | 97 if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) |
| 87 return; | 98 return; |
| 88 | 99 |
| 89 gfx::SizeF view_bounds = device_viewport_size(); | 100 gfx::SizeF view_bounds = device_viewport_size(); |
| 90 if (LayerImpl* clip_layer = root_scroll_layer()->parent()) { | 101 if (LayerImpl* clip_layer = root_scroll_layer_->parent()) { |
| 91 // Compensate for non-overlay scrollbars. | 102 // Compensate for non-overlay scrollbars. |
| 92 if (clip_layer->masksToBounds()) | 103 if (clip_layer->masksToBounds()) |
| 93 view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor()); | 104 view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor()); |
| 94 } | 105 } |
| 95 | 106 |
| 96 gfx::Size content_bounds = ContentSize(); | 107 gfx::Size content_bounds = ContentSize(); |
| 97 if (settings().pageScalePinchZoomEnabled) { | 108 if (settings().pageScalePinchZoomEnabled) { |
| 98 // Pinch with pageScale scrolls entirely in layout space. ContentSize | 109 // Pinch with pageScale scrolls entirely in layout space. ContentSize |
| 99 // returns the bounds including the page scale factor, so calculate the | 110 // returns the bounds including the page scale factor, so calculate the |
| 100 // pre page-scale layout size here. | 111 // pre page-scale layout size here. |
| 101 float page_scale_factor = pinch_zoom_viewport().page_scale_factor(); | 112 float page_scale_factor = pinch_zoom_viewport().page_scale_factor(); |
| 102 content_bounds.set_width(content_bounds.width() / page_scale_factor); | 113 content_bounds.set_width(content_bounds.width() / page_scale_factor); |
| 103 content_bounds.set_height(content_bounds.height() / page_scale_factor); | 114 content_bounds.set_height(content_bounds.height() / page_scale_factor); |
| 104 } else { | 115 } else { |
| 105 view_bounds.Scale(1 / pinch_zoom_viewport().page_scale_delta()); | 116 view_bounds.Scale(1 / pinch_zoom_viewport().page_scale_delta()); |
| 106 } | 117 } |
| 107 | 118 |
| 108 gfx::Vector2dF max_scroll = gfx::Rect(content_bounds).bottom_right() - | 119 gfx::Vector2dF max_scroll = gfx::Rect(content_bounds).bottom_right() - |
| 109 gfx::RectF(view_bounds).bottom_right(); | 120 gfx::RectF(view_bounds).bottom_right(); |
| 110 max_scroll.Scale(1 / device_scale_factor()); | 121 max_scroll.Scale(1 / device_scale_factor()); |
| 111 | 122 |
| 112 // The viewport may be larger than the contents in some cases, such as | 123 // The viewport may be larger than the contents in some cases, such as |
| 113 // having a vertical scrollbar but no horizontal overflow. | 124 // having a vertical scrollbar but no horizontal overflow. |
| 114 max_scroll.ClampToMin(gfx::Vector2dF()); | 125 max_scroll.ClampToMin(gfx::Vector2dF()); |
| 115 | 126 |
| 116 root_scroll_layer()->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); | 127 root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); |
| 117 } | 128 } |
| 118 | 129 |
| 119 void LayerTreeImpl::UpdateDrawProperties() { | 130 void LayerTreeImpl::UpdateDrawProperties() { |
| 120 render_surface_layer_list_.clear(); | 131 render_surface_layer_list_.clear(); |
| 121 if (!RootLayer()) | 132 if (!RootLayer()) |
| 122 return; | 133 return; |
| 123 | 134 |
| 124 if (root_scroll_layer()) { | 135 if (root_scroll_layer_) { |
| 125 root_scroll_layer()->setImplTransform( | 136 root_scroll_layer_->setImplTransform( |
| 126 layer_tree_host_impl_->implTransform()); | 137 layer_tree_host_impl_->implTransform()); |
| 127 } | 138 } |
| 128 | 139 |
| 129 { | 140 { |
| 130 TRACE_EVENT0("cc", "LayerTreeImpl::UpdateDrawProperties"); | 141 TRACE_EVENT0("cc", "LayerTreeImpl::UpdateDrawProperties"); |
| 131 LayerTreeHostCommon::calculateDrawProperties( | 142 LayerTreeHostCommon::calculateDrawProperties( |
| 132 RootLayer(), | 143 RootLayer(), |
| 133 device_viewport_size(), | 144 device_viewport_size(), |
| 134 device_scale_factor(), | 145 device_scale_factor(), |
| 135 pinch_zoom_viewport().page_scale_factor(), | 146 pinch_zoom_viewport().page_scale_factor(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 return true; | 181 return true; |
| 171 } | 182 } |
| 172 | 183 |
| 173 const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const { | 184 const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const { |
| 174 // If this assert triggers, then the list is dirty. | 185 // If this assert triggers, then the list is dirty. |
| 175 DCHECK(!layer_tree_host_impl_->needsUpdateDrawProperties()); | 186 DCHECK(!layer_tree_host_impl_->needsUpdateDrawProperties()); |
| 176 return render_surface_layer_list_; | 187 return render_surface_layer_list_; |
| 177 } | 188 } |
| 178 | 189 |
| 179 gfx::Size LayerTreeImpl::ContentSize() const { | 190 gfx::Size LayerTreeImpl::ContentSize() const { |
| 180 // TODO(aelias): Hardcoding the first child here is weird. Think of | 191 if (!root_scroll_layer_) |
| 181 // a cleaner way to get the contentBounds on the Impl side. | |
| 182 if (!root_scroll_layer() || root_scroll_layer()->children().empty()) | |
| 183 return gfx::Size(); | 192 return gfx::Size(); |
| 184 return root_scroll_layer()->children()[0]->contentBounds(); | 193 return root_scroll_layer_->bounds(); |
|
aelias_OOO_until_Jul13
2013/01/21 01:12:14
FYI, looks like this broke scrolling. I can rever
| |
| 185 } | 194 } |
| 186 | 195 |
| 187 LayerImpl* LayerTreeImpl::LayerById(int id) { | 196 LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 188 LayerIdMap::iterator iter = layer_id_map_.find(id); | 197 LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 189 return iter != layer_id_map_.end() ? iter->second : NULL; | 198 return iter != layer_id_map_.end() ? iter->second : NULL; |
| 190 } | 199 } |
| 191 | 200 |
| 192 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { | 201 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 193 DCHECK(!LayerById(layer->id())); | 202 DCHECK(!LayerById(layer->id())); |
| 194 layer_id_map_[layer->id()] = layer; | 203 layer_id_map_[layer->id()] = layer; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 207 | 216 |
| 208 static void DidBecomeActiveRecursive(LayerImpl* layer) { | 217 static void DidBecomeActiveRecursive(LayerImpl* layer) { |
| 209 layer->didBecomeActive(); | 218 layer->didBecomeActive(); |
| 210 for (size_t i = 0; i < layer->children().size(); ++i) | 219 for (size_t i = 0; i < layer->children().size(); ++i) |
| 211 DidBecomeActiveRecursive(layer->children()[i]); | 220 DidBecomeActiveRecursive(layer->children()[i]); |
| 212 } | 221 } |
| 213 | 222 |
| 214 void LayerTreeImpl::DidBecomeActive() { | 223 void LayerTreeImpl::DidBecomeActive() { |
| 215 if (RootLayer()) | 224 if (RootLayer()) |
| 216 DidBecomeActiveRecursive(RootLayer()); | 225 DidBecomeActiveRecursive(RootLayer()); |
| 226 FindRootScrollLayer(); | |
| 227 UpdateMaxScrollOffset(); | |
| 217 } | 228 } |
| 218 | 229 |
| 219 bool LayerTreeImpl::ContentsTexturesPurged() const { | 230 bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 220 return contents_textures_purged_; | 231 return contents_textures_purged_; |
| 221 } | 232 } |
| 222 | 233 |
| 223 void LayerTreeImpl::SetContentsTexturesPurged() { | 234 void LayerTreeImpl::SetContentsTexturesPurged() { |
| 224 contents_textures_purged_ = true; | 235 contents_textures_purged_ = true; |
| 225 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); | 236 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); |
| 226 } | 237 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 329 |
| 319 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { | 330 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
| 320 return layer_tree_host_impl_->animationRegistrar(); | 331 return layer_tree_host_impl_->animationRegistrar(); |
| 321 } | 332 } |
| 322 | 333 |
| 323 const PinchZoomViewport& LayerTreeImpl::pinch_zoom_viewport() const { | 334 const PinchZoomViewport& LayerTreeImpl::pinch_zoom_viewport() const { |
| 324 return layer_tree_host_impl_->pinchZoomViewport(); | 335 return layer_tree_host_impl_->pinchZoomViewport(); |
| 325 } | 336 } |
| 326 | 337 |
| 327 } // namespace cc | 338 } // namespace cc |
| OLD | NEW |