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" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) | 14 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
15 : layer_tree_host_impl_(layer_tree_host_impl) | 15 : layer_tree_host_impl_(layer_tree_host_impl) |
16 , source_frame_number_(-1) | 16 , source_frame_number_(-1) |
17 , hud_layer_(0) | 17 , hud_layer_(0) |
18 , root_scroll_layer_(0) | 18 , root_scroll_layer_(0) |
19 , currently_scrolling_layer_(0) | 19 , currently_scrolling_layer_(0) |
20 , background_color_(0) | 20 , background_color_(0) |
21 , has_transparent_background_(false) | 21 , has_transparent_background_(false) |
22 , page_scale_factor_(1) | |
23 , page_scale_delta_(1) | |
24 , sent_page_scale_delta_(1) | |
25 , min_page_scale_factor_(0) | |
26 , max_page_scale_factor_(0) | |
22 , scrolling_layer_id_from_previous_tree_(0) | 27 , scrolling_layer_id_from_previous_tree_(0) |
23 , contents_textures_purged_(false) | 28 , contents_textures_purged_(false) |
24 , needs_update_draw_properties_(true) { | 29 , needs_update_draw_properties_(true) { |
25 } | 30 } |
26 | 31 |
27 LayerTreeImpl::~LayerTreeImpl() { | 32 LayerTreeImpl::~LayerTreeImpl() { |
28 // Need to explicitly clear the tree prior to destroying this so that | 33 // Need to explicitly clear the tree prior to destroying this so that |
29 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. | 34 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
30 root_layer_.reset(); | 35 root_layer_.reset(); |
31 } | 36 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { | 92 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { |
88 DCHECK(IsActiveTree()); | 93 DCHECK(IsActiveTree()); |
89 return currently_scrolling_layer_; | 94 return currently_scrolling_layer_; |
90 } | 95 } |
91 | 96 |
92 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { | 97 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
93 currently_scrolling_layer_ = NULL; | 98 currently_scrolling_layer_ = NULL; |
94 scrolling_layer_id_from_previous_tree_ = 0; | 99 scrolling_layer_id_from_previous_tree_ = 0; |
95 } | 100 } |
96 | 101 |
102 void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, | |
103 float min_page_scale_factor, float max_page_scale_factor) | |
104 { | |
105 if (!page_scale_factor) | |
106 return; | |
107 | |
108 min_page_scale_factor_ = min_page_scale_factor; | |
109 max_page_scale_factor_ = max_page_scale_factor; | |
110 page_scale_factor_ = page_scale_factor; | |
111 } | |
112 | |
113 void LayerTreeImpl::SetPageScaleDelta(float delta) | |
114 { | |
115 // Clamp to the current min/max limits. | |
116 float total = page_scale_factor_ * delta; | |
117 if (min_page_scale_factor_ && total < min_page_scale_factor_) | |
118 delta = min_page_scale_factor_ / page_scale_factor_; | |
119 else if (max_page_scale_factor_ && total > max_page_scale_factor_) | |
120 delta = max_page_scale_factor_ / page_scale_factor_; | |
121 | |
122 if (delta == page_scale_delta_) | |
123 return; | |
124 | |
125 page_scale_delta_ = delta; | |
126 | |
127 if (IsActiveTree()) | |
128 { | |
danakj
2013/01/28 20:29:03
nit: { on previous line
aelias_OOO_until_Jul13
2013/01/29 06:05:14
Done.
| |
129 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pendingTree(); | |
danakj
2013/01/28 20:29:03
2 space indents and 80 col
aelias_OOO_until_Jul13
2013/01/29 06:05:14
Done.
| |
130 if (pending_tree) { | |
131 DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); | |
132 pending_tree->SetPageScaleDelta(page_scale_delta_ / sent_page_scale_de lta_); | |
133 } | |
134 } | |
135 | |
136 #if 0 | |
137 if (layerTreeImpl()->IsActiveTree()) | |
138 { | |
139 LayerImpl* pending_twin = layerTreeImpl()->FindPendingTreeLayerById(id() ); | |
140 if (pending_twin) { | |
141 // The pending twin can't mirror the scroll delta of the active | |
142 // layer. Although the delta - sent scroll delta difference is | |
143 // identical for both twins, the sent scroll delta for the pending | |
144 // layer is zero, as anything that has been sent has been baked | |
145 // into the layer's position/scroll offset as a part of commit. | |
146 DCHECK(pending_twin->sentScrollDelta().IsZero()); | |
147 pending_twin->setScrollDelta(scrollDelta - sentScrollDelta()); | |
148 } | |
149 } | |
150 #endif | |
151 | |
152 UpdateMaxScrollOffset(); | |
153 set_needs_update_draw_properties(); | |
154 } | |
155 | |
97 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { | 156 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
98 gfx::SizeF view_bounds; | 157 gfx::SizeF view_bounds; |
99 // The clip layer should be used for scrolling bounds if available since it | 158 // The clip layer should be used for scrolling bounds if available since it |
100 // adjusts for non-overlay scrollbars. Otherwise, fall back to our knowledge | 159 // adjusts for non-overlay scrollbars. Otherwise, fall back to our knowledge |
101 // of the physical viewport size. | 160 // of the physical viewport size. |
102 LayerImpl* clip_layer = NULL; | 161 LayerImpl* clip_layer = NULL; |
103 if (root_scroll_layer_) | 162 if (root_scroll_layer_) |
104 clip_layer = root_scroll_layer_->parent(); | 163 clip_layer = root_scroll_layer_->parent(); |
105 if (clip_layer && clip_layer->masksToBounds()) { | 164 if (clip_layer && clip_layer->masksToBounds()) { |
106 view_bounds = clip_layer->bounds(); | 165 view_bounds = clip_layer->bounds(); |
107 } else { | 166 } else { |
108 view_bounds = gfx::ScaleSize(device_viewport_size(), | 167 view_bounds = gfx::ScaleSize(device_viewport_size(), |
109 1 / device_scale_factor()); | 168 1 / device_scale_factor()); |
110 } | 169 } |
111 view_bounds.Scale(1 / pinch_zoom_viewport().total_page_scale_factor()); | 170 view_bounds.Scale(1 / total_page_scale_factor()); |
112 | 171 |
113 return view_bounds; | 172 return view_bounds; |
114 } | 173 } |
115 | 174 |
116 void LayerTreeImpl::UpdateMaxScrollOffset() { | 175 void LayerTreeImpl::UpdateMaxScrollOffset() { |
117 if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) | 176 if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) |
118 return; | 177 return; |
119 | 178 |
120 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - | 179 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - |
121 gfx::RectF(ScrollableViewportSize()).bottom_right(); | 180 gfx::RectF(ScrollableViewportSize()).bottom_right(); |
122 | 181 |
123 // The viewport may be larger than the contents in some cases, such as | 182 // The viewport may be larger than the contents in some cases, such as |
124 // having a vertical scrollbar but no horizontal overflow. | 183 // having a vertical scrollbar but no horizontal overflow. |
125 max_scroll.ClampToMin(gfx::Vector2dF()); | 184 max_scroll.ClampToMin(gfx::Vector2dF()); |
126 | 185 |
127 root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); | 186 root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); |
128 } | 187 } |
129 | 188 |
189 gfx::Transform LayerTreeImpl::ImplTransform() const { | |
190 gfx::Transform transform; | |
191 transform.Scale(page_scale_delta_, page_scale_delta_); | |
192 if (settings().pageScalePinchZoomEnabled) | |
193 transform.Scale(page_scale_factor_, page_scale_factor_); | |
194 return transform; | |
195 } | |
196 | |
130 struct UpdateTilePrioritiesForLayer { | 197 struct UpdateTilePrioritiesForLayer { |
131 void operator()(LayerImpl *layer) { | 198 void operator()(LayerImpl *layer) { |
132 layer->updateTilePriorities(); | 199 layer->updateTilePriorities(); |
133 } | 200 } |
134 }; | 201 }; |
135 | 202 |
136 void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) { | 203 void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) { |
137 if (!needs_update_draw_properties_) { | 204 if (!needs_update_draw_properties_) { |
138 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && RootLayer()) | 205 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && RootLayer()) |
139 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>( | 206 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>( |
140 RootLayer()); | 207 RootLayer()); |
141 return; | 208 return; |
142 } | 209 } |
143 | 210 |
144 needs_update_draw_properties_ = false; | 211 needs_update_draw_properties_ = false; |
145 render_surface_layer_list_.clear(); | 212 render_surface_layer_list_.clear(); |
146 | 213 |
147 // For maxTextureSize. | 214 // For maxTextureSize. |
148 if (!layer_tree_host_impl_->renderer()) | 215 if (!layer_tree_host_impl_->renderer()) |
149 return; | 216 return; |
150 | 217 |
151 if (!RootLayer()) | 218 if (!RootLayer()) |
152 return; | 219 return; |
153 | 220 |
154 if (root_scroll_layer_) { | 221 if (root_scroll_layer_) { |
155 root_scroll_layer_->setImplTransform( | 222 root_scroll_layer_->setImplTransform(ImplTransform()); |
156 layer_tree_host_impl_->implTransform()); | |
157 // Setting the impl transform re-sets this. | 223 // Setting the impl transform re-sets this. |
158 needs_update_draw_properties_ = false; | 224 needs_update_draw_properties_ = false; |
159 } | 225 } |
160 | 226 |
161 { | 227 { |
162 TRACE_EVENT1("cc", "LayerTreeImpl::UpdateDrawProperties", "IsActive", IsActi veTree()); | 228 TRACE_EVENT1("cc", "LayerTreeImpl::UpdateDrawProperties", "IsActive", IsActi veTree()); |
163 bool update_tile_priorities = | 229 bool update_tile_priorities = |
164 reason == UPDATE_PENDING_TREE || | 230 reason == UPDATE_PENDING_TREE || |
165 reason == UPDATE_ACTIVE_TREE_FOR_DRAW; | 231 reason == UPDATE_ACTIVE_TREE_FOR_DRAW; |
166 LayerTreeHostCommon::calculateDrawProperties( | 232 LayerTreeHostCommon::calculateDrawProperties( |
167 RootLayer(), | 233 RootLayer(), |
168 device_viewport_size(), | 234 device_viewport_size(), |
169 device_scale_factor(), | 235 device_scale_factor(), |
170 pinch_zoom_viewport().total_page_scale_factor(), | 236 total_page_scale_factor(), |
171 MaxTextureSize(), | 237 MaxTextureSize(), |
172 settings().canUseLCDText, | 238 settings().canUseLCDText, |
173 render_surface_layer_list_, | 239 render_surface_layer_list_, |
174 update_tile_priorities); | 240 update_tile_priorities); |
175 } | 241 } |
176 | 242 |
177 DCHECK(!needs_update_draw_properties_) << | 243 DCHECK(!needs_update_draw_properties_) << |
178 "calcDrawProperties should not set_needs_update_draw_properties()"; | 244 "calcDrawProperties should not set_needs_update_draw_properties()"; |
179 } | 245 } |
180 | 246 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 } | 422 } |
357 | 423 |
358 DebugRectHistory* LayerTreeImpl::debug_rect_history() const { | 424 DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
359 return layer_tree_host_impl_->debugRectHistory(); | 425 return layer_tree_host_impl_->debugRectHistory(); |
360 } | 426 } |
361 | 427 |
362 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { | 428 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
363 return layer_tree_host_impl_->animationRegistrar(); | 429 return layer_tree_host_impl_->animationRegistrar(); |
364 } | 430 } |
365 | 431 |
366 const PinchZoomViewport& LayerTreeImpl::pinch_zoom_viewport() const { | |
367 return layer_tree_host_impl_->pinchZoomViewport(); | |
368 } | |
369 | |
370 } // namespace cc | 432 } // namespace cc |
OLD | NEW |