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/trees/layer_tree_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); | 114 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
115 inner_viewport_scroll_delegate_proxy_.reset(); | 115 inner_viewport_scroll_delegate_proxy_.reset(); |
116 outer_viewport_scroll_delegate_proxy_.reset(); | 116 outer_viewport_scroll_delegate_proxy_.reset(); |
117 | 117 |
118 root_layer_ = layer.Pass(); | 118 root_layer_ = layer.Pass(); |
119 currently_scrolling_layer_ = NULL; | 119 currently_scrolling_layer_ = NULL; |
120 inner_viewport_scroll_layer_ = NULL; | 120 inner_viewport_scroll_layer_ = NULL; |
121 outer_viewport_scroll_layer_ = NULL; | 121 outer_viewport_scroll_layer_ = NULL; |
122 page_scale_layer_ = NULL; | 122 page_scale_layer_ = NULL; |
123 | 123 |
124 ClearSelection(); | |
aelias_OOO_until_Jul13
2014/06/28 00:02:17
I suggest removing this call. We may eventually w
jdduke (slow)
2014/06/28 00:29:10
Done.
| |
125 | |
124 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); | 126 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
125 } | 127 } |
126 | 128 |
127 LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { | 129 LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { |
128 return inner_viewport_scroll_layer_; | 130 return inner_viewport_scroll_layer_; |
129 } | 131 } |
130 | 132 |
131 LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { | 133 LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { |
132 return outer_viewport_scroll_layer_; | 134 return outer_viewport_scroll_layer_; |
133 } | 135 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); | 175 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
174 if (outer_viewport_scroll_layer_) | 176 if (outer_viewport_scroll_layer_) |
175 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); | 177 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
176 inner_viewport_scroll_delegate_proxy_.reset(); | 178 inner_viewport_scroll_delegate_proxy_.reset(); |
177 outer_viewport_scroll_delegate_proxy_.reset(); | 179 outer_viewport_scroll_delegate_proxy_.reset(); |
178 inner_viewport_scroll_layer_ = NULL; | 180 inner_viewport_scroll_layer_ = NULL; |
179 outer_viewport_scroll_layer_ = NULL; | 181 outer_viewport_scroll_layer_ = NULL; |
180 page_scale_layer_ = NULL; | 182 page_scale_layer_ = NULL; |
181 currently_scrolling_layer_ = NULL; | 183 currently_scrolling_layer_ = NULL; |
182 | 184 |
185 ClearSelection(); | |
aelias_OOO_until_Jul13
2014/06/28 00:02:17
Likewise, please remove this call.
jdduke (slow)
2014/06/28 00:29:10
Done.
| |
186 | |
183 render_surface_layer_list_.clear(); | 187 render_surface_layer_list_.clear(); |
184 set_needs_update_draw_properties(); | 188 set_needs_update_draw_properties(); |
185 return root_layer_.Pass(); | 189 return root_layer_.Pass(); |
186 } | 190 } |
187 | 191 |
188 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { | 192 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
189 // The request queue should have been processed and does not require a push. | 193 // The request queue should have been processed and does not require a push. |
190 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); | 194 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); |
191 | 195 |
192 if (next_activation_forces_redraw_) { | 196 if (next_activation_forces_redraw_) { |
(...skipping 10 matching lines...) Expand all Loading... | |
203 | 207 |
204 if (page_scale_layer_ && inner_viewport_scroll_layer_) { | 208 if (page_scale_layer_ && inner_viewport_scroll_layer_) { |
205 target_tree->SetViewportLayersFromIds( | 209 target_tree->SetViewportLayersFromIds( |
206 page_scale_layer_->id(), | 210 page_scale_layer_->id(), |
207 inner_viewport_scroll_layer_->id(), | 211 inner_viewport_scroll_layer_->id(), |
208 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() | 212 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() |
209 : Layer::INVALID_ID); | 213 : Layer::INVALID_ID); |
210 } else { | 214 } else { |
211 target_tree->ClearViewportLayers(); | 215 target_tree->ClearViewportLayers(); |
212 } | 216 } |
217 | |
218 target_tree->RegisterSelection(selection_anchor_, selection_focus_); | |
219 | |
213 // This should match the property synchronization in | 220 // This should match the property synchronization in |
214 // LayerTreeHost::finishCommitOnImplThread(). | 221 // LayerTreeHost::finishCommitOnImplThread(). |
215 target_tree->set_source_frame_number(source_frame_number()); | 222 target_tree->set_source_frame_number(source_frame_number()); |
216 target_tree->set_background_color(background_color()); | 223 target_tree->set_background_color(background_color()); |
217 target_tree->set_has_transparent_background(has_transparent_background()); | 224 target_tree->set_has_transparent_background(has_transparent_background()); |
218 | 225 |
219 if (ContentsTexturesPurged()) | 226 if (ContentsTexturesPurged()) |
220 target_tree->SetContentsTexturesPurged(); | 227 target_tree->SetContentsTexturesPurged(); |
221 else | 228 else |
222 target_tree->ResetContentsTexturesPurged(); | 229 target_tree->ResetContentsTexturesPurged(); |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1037 DCHECK(current); | 1044 DCHECK(current); |
1038 current->ReleaseResources(); | 1045 current->ReleaseResources(); |
1039 if (current->mask_layer()) | 1046 if (current->mask_layer()) |
1040 ReleaseResourcesRecursive(current->mask_layer()); | 1047 ReleaseResourcesRecursive(current->mask_layer()); |
1041 if (current->replica_layer()) | 1048 if (current->replica_layer()) |
1042 ReleaseResourcesRecursive(current->replica_layer()); | 1049 ReleaseResourcesRecursive(current->replica_layer()); |
1043 for (size_t i = 0; i < current->children().size(); ++i) | 1050 for (size_t i = 0; i < current->children().size(); ++i) |
1044 ReleaseResourcesRecursive(current->children()[i]); | 1051 ReleaseResourcesRecursive(current->children()[i]); |
1045 } | 1052 } |
1046 | 1053 |
1054 void LayerTreeImpl::ClearSelection() { | |
1055 RegisterSelection(LayerSelectionBound(), LayerSelectionBound()); | |
1056 } | |
1057 | |
1047 template <typename LayerType> | 1058 template <typename LayerType> |
1048 static inline bool LayerClipsSubtree(LayerType* layer) { | 1059 static inline bool LayerClipsSubtree(LayerType* layer) { |
1049 return layer->masks_to_bounds() || layer->mask_layer(); | 1060 return layer->masks_to_bounds() || layer->mask_layer(); |
1050 } | 1061 } |
1051 | 1062 |
1052 static bool PointHitsRect( | 1063 static bool PointHitsRect( |
1053 const gfx::PointF& screen_space_point, | 1064 const gfx::PointF& screen_space_point, |
1054 const gfx::Transform& local_space_to_screen_space_transform, | 1065 const gfx::Transform& local_space_to_screen_space_transform, |
1055 const gfx::RectF& local_space_rect, | 1066 const gfx::RectF& local_space_rect, |
1056 float* distance_to_camera) { | 1067 float* distance_to_camera) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1115 | 1126 |
1116 // If ProjectPoint could not project to a valid value, then we assume that | 1127 // If ProjectPoint could not project to a valid value, then we assume that |
1117 // this point doesn't hit this region. | 1128 // this point doesn't hit this region. |
1118 if (clipped) | 1129 if (clipped) |
1119 return false; | 1130 return false; |
1120 | 1131 |
1121 return layer_space_region.Contains( | 1132 return layer_space_region.Contains( |
1122 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); | 1133 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); |
1123 } | 1134 } |
1124 | 1135 |
1125 static LayerImpl* GetNextClippingLayer(LayerImpl* layer) { | 1136 static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) { |
1126 if (layer->scroll_parent()) | 1137 if (layer->scroll_parent()) |
1127 return layer->scroll_parent(); | 1138 return layer->scroll_parent(); |
1128 if (layer->clip_parent()) | 1139 if (layer->clip_parent()) |
1129 return layer->clip_parent(); | 1140 return layer->clip_parent(); |
1130 return layer->parent(); | 1141 return layer->parent(); |
1131 } | 1142 } |
1132 | 1143 |
1133 static bool PointIsClippedBySurfaceOrClipRect( | 1144 static bool PointIsClippedBySurfaceOrClipRect( |
1134 const gfx::PointF& screen_space_point, | 1145 const gfx::PointF& screen_space_point, |
1135 LayerImpl* layer) { | 1146 const LayerImpl* layer) { |
1136 // Walk up the layer tree and hit-test any render_surfaces and any layer | 1147 // Walk up the layer tree and hit-test any render_surfaces and any layer |
1137 // clip rects that are active. | 1148 // clip rects that are active. |
1138 for (; layer; layer = GetNextClippingLayer(layer)) { | 1149 for (; layer; layer = GetNextClippingLayer(layer)) { |
1139 if (layer->render_surface() && | 1150 if (layer->render_surface() && |
1140 !PointHitsRect(screen_space_point, | 1151 !PointHitsRect(screen_space_point, |
1141 layer->render_surface()->screen_space_transform(), | 1152 layer->render_surface()->screen_space_transform(), |
1142 layer->render_surface()->content_rect(), | 1153 layer->render_surface()->content_rect(), |
1143 NULL)) | 1154 NULL)) |
1144 return true; | 1155 return true; |
1145 | 1156 |
1146 if (LayerClipsSubtree(layer) && | 1157 if (LayerClipsSubtree(layer) && |
1147 !PointHitsRect(screen_space_point, | 1158 !PointHitsRect(screen_space_point, |
1148 layer->screen_space_transform(), | 1159 layer->screen_space_transform(), |
1149 gfx::Rect(layer->content_bounds()), | 1160 gfx::Rect(layer->content_bounds()), |
1150 NULL)) | 1161 NULL)) |
1151 return true; | 1162 return true; |
1152 } | 1163 } |
1153 | 1164 |
1154 // If we have finished walking all ancestors without having already exited, | 1165 // If we have finished walking all ancestors without having already exited, |
1155 // then the point is not clipped by any ancestors. | 1166 // then the point is not clipped by any ancestors. |
1156 return false; | 1167 return false; |
1157 } | 1168 } |
1158 | 1169 |
1159 static bool PointHitsLayer(LayerImpl* layer, | 1170 static bool PointHitsLayer(const LayerImpl* layer, |
1160 const gfx::PointF& screen_space_point, | 1171 const gfx::PointF& screen_space_point, |
1161 float* distance_to_intersection) { | 1172 float* distance_to_intersection) { |
1162 gfx::RectF content_rect(layer->content_bounds()); | 1173 gfx::RectF content_rect(layer->content_bounds()); |
1163 if (!PointHitsRect(screen_space_point, | 1174 if (!PointHitsRect(screen_space_point, |
1164 layer->screen_space_transform(), | 1175 layer->screen_space_transform(), |
1165 content_rect, | 1176 content_rect, |
1166 distance_to_intersection)) | 1177 distance_to_intersection)) |
1167 return false; | 1178 return false; |
1168 | 1179 |
1169 // At this point, we think the point does hit the layer, but we need to walk | 1180 // At this point, we think the point does hit the layer, but we need to walk |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1301 return NULL; | 1312 return NULL; |
1302 if (!UpdateDrawProperties()) | 1313 if (!UpdateDrawProperties()) |
1303 return NULL; | 1314 return NULL; |
1304 FindTouchEventLayerFunctor func = {screen_space_point}; | 1315 FindTouchEventLayerFunctor func = {screen_space_point}; |
1305 FindClosestMatchingLayerDataForRecursion data_for_recursion; | 1316 FindClosestMatchingLayerDataForRecursion data_for_recursion; |
1306 FindClosestMatchingLayer( | 1317 FindClosestMatchingLayer( |
1307 screen_space_point, root_layer(), func, &data_for_recursion); | 1318 screen_space_point, root_layer(), func, &data_for_recursion); |
1308 return data_for_recursion.closest_match; | 1319 return data_for_recursion.closest_match; |
1309 } | 1320 } |
1310 | 1321 |
1322 void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& anchor, | |
1323 const LayerSelectionBound& focus) { | |
1324 selection_anchor_ = anchor; | |
1325 selection_focus_ = focus; | |
1326 } | |
1327 | |
1328 static ViewportSelectionBound ComputeViewportSelection( | |
1329 const LayerSelectionBound& bound, | |
1330 LayerImpl* layer, | |
1331 float device_scale_factor) { | |
1332 ViewportSelectionBound result; | |
1333 result.type = bound.type; | |
1334 | |
1335 if (!layer || bound.type == SELECTION_BOUND_EMPTY) | |
1336 return result; | |
1337 | |
1338 gfx::RectF layer_scaled_rect = gfx::ScaleRect( | |
1339 bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y()); | |
1340 gfx::RectF screen_rect = MathUtil::ProjectClippedRect( | |
1341 layer->screen_space_transform(), layer_scaled_rect); | |
1342 | |
1343 // The bottom left of the bound is used for visibility because 1) the bound | |
1344 // edge rect is one-dimensional (no width), and 2) the bottom is the logical | |
1345 // focal point for bound selection handles (this may change in the future). | |
1346 const gfx::PointF visibility_anchor = screen_rect.bottom_left(); | |
1347 | |
1348 // Using a small inclusive slop region for visibility prevents visibility | |
aelias_OOO_until_Jul13
2014/06/28 00:02:17
Won't you still get jitter when the edge of the sl
jdduke (slow)
2014/06/28 00:29:10
Yes, agreed. In fact I changed this just this afte
| |
1349 // "jitter" from floating point scaling error if a handle is on a boundary. | |
1350 const float visibility_slop = device_scale_factor; | |
1351 const gfx::RectF visibility_rect(visibility_anchor.x() - visibility_slop, | |
1352 visibility_anchor.y() - visibility_slop, | |
1353 visibility_slop * 2.f, | |
1354 visibility_slop * 2.f); | |
1355 | |
1356 float intersect_dist = 0.f; | |
1357 result.visible = | |
1358 PointHitsLayer(layer, visibility_rect.origin(), &intersect_dist) || | |
1359 PointHitsLayer(layer, visibility_rect.top_right(), &intersect_dist) || | |
1360 PointHitsLayer(layer, visibility_rect.bottom_left(), &intersect_dist) || | |
1361 PointHitsLayer(layer, visibility_rect.bottom_right(), &intersect_dist); | |
1362 | |
1363 screen_rect.Scale(1.f / device_scale_factor); | |
1364 result.viewport_rect = screen_rect; | |
1365 | |
1366 return result; | |
1367 } | |
1368 | |
1369 void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* anchor, | |
1370 ViewportSelectionBound* focus) { | |
1371 DCHECK(!needs_update_draw_properties_); | |
1372 DCHECK(anchor); | |
1373 DCHECK(focus); | |
1374 | |
1375 *anchor = ComputeViewportSelection( | |
1376 selection_anchor_, | |
1377 selection_anchor_.layer_id ? LayerById(selection_anchor_.layer_id) : NULL, | |
1378 device_scale_factor()); | |
1379 if (anchor->type == SELECTION_BOUND_CENTER || | |
1380 anchor->type == SELECTION_BOUND_EMPTY) { | |
1381 *focus = *anchor; | |
1382 } else { | |
1383 *focus = ComputeViewportSelection( | |
1384 selection_focus_, | |
1385 selection_focus_.layer_id ? LayerById(selection_focus_.layer_id) : NULL, | |
1386 device_scale_factor()); | |
1387 } | |
1388 } | |
1389 | |
1311 void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { | 1390 void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
1312 layer_tree_host_impl_->RegisterPictureLayerImpl(layer); | 1391 layer_tree_host_impl_->RegisterPictureLayerImpl(layer); |
1313 } | 1392 } |
1314 | 1393 |
1315 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 1394 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
1316 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer); | 1395 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer); |
1317 } | 1396 } |
1318 | 1397 |
1319 } // namespace cc | 1398 } // namespace cc |
OLD | NEW |