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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 if (page_scale_layer_ && inner_viewport_scroll_layer_) { | 204 if (page_scale_layer_ && inner_viewport_scroll_layer_) { |
205 target_tree->SetViewportLayersFromIds( | 205 target_tree->SetViewportLayersFromIds( |
206 page_scale_layer_->id(), | 206 page_scale_layer_->id(), |
207 inner_viewport_scroll_layer_->id(), | 207 inner_viewport_scroll_layer_->id(), |
208 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() | 208 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() |
209 : Layer::INVALID_ID); | 209 : Layer::INVALID_ID); |
210 } else { | 210 } else { |
211 target_tree->ClearViewportLayers(); | 211 target_tree->ClearViewportLayers(); |
212 } | 212 } |
| 213 |
| 214 target_tree->RegisterSelection(selection_anchor_, selection_focus_); |
| 215 |
213 // This should match the property synchronization in | 216 // This should match the property synchronization in |
214 // LayerTreeHost::finishCommitOnImplThread(). | 217 // LayerTreeHost::finishCommitOnImplThread(). |
215 target_tree->set_source_frame_number(source_frame_number()); | 218 target_tree->set_source_frame_number(source_frame_number()); |
216 target_tree->set_background_color(background_color()); | 219 target_tree->set_background_color(background_color()); |
217 target_tree->set_has_transparent_background(has_transparent_background()); | 220 target_tree->set_has_transparent_background(has_transparent_background()); |
218 | 221 |
219 if (ContentsTexturesPurged()) | 222 if (ContentsTexturesPurged()) |
220 target_tree->SetContentsTexturesPurged(); | 223 target_tree->SetContentsTexturesPurged(); |
221 else | 224 else |
222 target_tree->ResetContentsTexturesPurged(); | 225 target_tree->ResetContentsTexturesPurged(); |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 | 1118 |
1116 // If ProjectPoint could not project to a valid value, then we assume that | 1119 // If ProjectPoint could not project to a valid value, then we assume that |
1117 // this point doesn't hit this region. | 1120 // this point doesn't hit this region. |
1118 if (clipped) | 1121 if (clipped) |
1119 return false; | 1122 return false; |
1120 | 1123 |
1121 return layer_space_region.Contains( | 1124 return layer_space_region.Contains( |
1122 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); | 1125 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); |
1123 } | 1126 } |
1124 | 1127 |
1125 static LayerImpl* GetNextClippingLayer(LayerImpl* layer) { | 1128 static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) { |
1126 if (layer->scroll_parent()) | 1129 if (layer->scroll_parent()) |
1127 return layer->scroll_parent(); | 1130 return layer->scroll_parent(); |
1128 if (layer->clip_parent()) | 1131 if (layer->clip_parent()) |
1129 return layer->clip_parent(); | 1132 return layer->clip_parent(); |
1130 return layer->parent(); | 1133 return layer->parent(); |
1131 } | 1134 } |
1132 | 1135 |
1133 static bool PointIsClippedBySurfaceOrClipRect( | 1136 static bool PointIsClippedBySurfaceOrClipRect( |
1134 const gfx::PointF& screen_space_point, | 1137 const gfx::PointF& screen_space_point, |
1135 LayerImpl* layer) { | 1138 const LayerImpl* layer) { |
1136 // Walk up the layer tree and hit-test any render_surfaces and any layer | 1139 // Walk up the layer tree and hit-test any render_surfaces and any layer |
1137 // clip rects that are active. | 1140 // clip rects that are active. |
1138 for (; layer; layer = GetNextClippingLayer(layer)) { | 1141 for (; layer; layer = GetNextClippingLayer(layer)) { |
1139 if (layer->render_surface() && | 1142 if (layer->render_surface() && |
1140 !PointHitsRect(screen_space_point, | 1143 !PointHitsRect(screen_space_point, |
1141 layer->render_surface()->screen_space_transform(), | 1144 layer->render_surface()->screen_space_transform(), |
1142 layer->render_surface()->content_rect(), | 1145 layer->render_surface()->content_rect(), |
1143 NULL)) | 1146 NULL)) |
1144 return true; | 1147 return true; |
1145 | 1148 |
1146 if (LayerClipsSubtree(layer) && | 1149 if (LayerClipsSubtree(layer) && |
1147 !PointHitsRect(screen_space_point, | 1150 !PointHitsRect(screen_space_point, |
1148 layer->screen_space_transform(), | 1151 layer->screen_space_transform(), |
1149 gfx::Rect(layer->content_bounds()), | 1152 gfx::Rect(layer->content_bounds()), |
1150 NULL)) | 1153 NULL)) |
1151 return true; | 1154 return true; |
1152 } | 1155 } |
1153 | 1156 |
1154 // If we have finished walking all ancestors without having already exited, | 1157 // If we have finished walking all ancestors without having already exited, |
1155 // then the point is not clipped by any ancestors. | 1158 // then the point is not clipped by any ancestors. |
1156 return false; | 1159 return false; |
1157 } | 1160 } |
1158 | 1161 |
1159 static bool PointHitsLayer(LayerImpl* layer, | 1162 static bool PointHitsLayer(const LayerImpl* layer, |
1160 const gfx::PointF& screen_space_point, | 1163 const gfx::PointF& screen_space_point, |
1161 float* distance_to_intersection) { | 1164 float* distance_to_intersection) { |
1162 gfx::RectF content_rect(layer->content_bounds()); | 1165 gfx::RectF content_rect(layer->content_bounds()); |
1163 if (!PointHitsRect(screen_space_point, | 1166 if (!PointHitsRect(screen_space_point, |
1164 layer->screen_space_transform(), | 1167 layer->screen_space_transform(), |
1165 content_rect, | 1168 content_rect, |
1166 distance_to_intersection)) | 1169 distance_to_intersection)) |
1167 return false; | 1170 return false; |
1168 | 1171 |
1169 // At this point, we think the point does hit the layer, but we need to walk | 1172 // 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; | 1304 return NULL; |
1302 if (!UpdateDrawProperties()) | 1305 if (!UpdateDrawProperties()) |
1303 return NULL; | 1306 return NULL; |
1304 FindTouchEventLayerFunctor func = {screen_space_point}; | 1307 FindTouchEventLayerFunctor func = {screen_space_point}; |
1305 FindClosestMatchingLayerDataForRecursion data_for_recursion; | 1308 FindClosestMatchingLayerDataForRecursion data_for_recursion; |
1306 FindClosestMatchingLayer( | 1309 FindClosestMatchingLayer( |
1307 screen_space_point, root_layer(), func, &data_for_recursion); | 1310 screen_space_point, root_layer(), func, &data_for_recursion); |
1308 return data_for_recursion.closest_match; | 1311 return data_for_recursion.closest_match; |
1309 } | 1312 } |
1310 | 1313 |
| 1314 void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& anchor, |
| 1315 const LayerSelectionBound& focus) { |
| 1316 selection_anchor_ = anchor; |
| 1317 selection_focus_ = focus; |
| 1318 } |
| 1319 |
| 1320 static ViewportSelectionBound ComputeViewportSelection( |
| 1321 const LayerSelectionBound& bound, |
| 1322 LayerImpl* layer, |
| 1323 float device_scale_factor) { |
| 1324 ViewportSelectionBound result; |
| 1325 result.type = bound.type; |
| 1326 |
| 1327 if (!layer || bound.type == SELECTION_BOUND_EMPTY) |
| 1328 return result; |
| 1329 |
| 1330 gfx::RectF layer_scaled_rect = gfx::ScaleRect( |
| 1331 bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y()); |
| 1332 gfx::RectF screen_rect = MathUtil::ProjectClippedRect( |
| 1333 layer->screen_space_transform(), layer_scaled_rect); |
| 1334 |
| 1335 // The bottom left of the bound is used for visibility because 1) the bound |
| 1336 // edge rect is one-dimensional (no width), and 2) the bottom is the logical |
| 1337 // focal point for bound selection handles (this may change in the future). |
| 1338 const gfx::PointF& visibility_point = screen_rect.bottom_left(); |
| 1339 float intersect_distance = 0.f; |
| 1340 result.visible = PointHitsLayer(layer, visibility_point, &intersect_distance); |
| 1341 |
| 1342 screen_rect.Scale(1.f / device_scale_factor); |
| 1343 result.viewport_rect = screen_rect; |
| 1344 |
| 1345 return result; |
| 1346 } |
| 1347 |
| 1348 void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* anchor, |
| 1349 ViewportSelectionBound* focus) { |
| 1350 DCHECK(anchor); |
| 1351 DCHECK(focus); |
| 1352 |
| 1353 *anchor = ComputeViewportSelection( |
| 1354 selection_anchor_, |
| 1355 selection_anchor_.layer_id ? LayerById(selection_anchor_.layer_id) : NULL, |
| 1356 device_scale_factor()); |
| 1357 if (anchor->type == SELECTION_BOUND_CENTER || |
| 1358 anchor->type == SELECTION_BOUND_EMPTY) { |
| 1359 *focus = *anchor; |
| 1360 } else { |
| 1361 *focus = ComputeViewportSelection( |
| 1362 selection_focus_, |
| 1363 selection_focus_.layer_id ? LayerById(selection_focus_.layer_id) : NULL, |
| 1364 device_scale_factor()); |
| 1365 } |
| 1366 } |
| 1367 |
1311 void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { | 1368 void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
1312 layer_tree_host_impl_->RegisterPictureLayerImpl(layer); | 1369 layer_tree_host_impl_->RegisterPictureLayerImpl(layer); |
1313 } | 1370 } |
1314 | 1371 |
1315 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 1372 void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
1316 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer); | 1373 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer); |
1317 } | 1374 } |
1318 | 1375 |
1319 } // namespace cc | 1376 } // namespace cc |
OLD | NEW |