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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 } | 1238 } |
1239 | 1239 |
1240 template <typename LayerType> | 1240 template <typename LayerType> |
1241 static inline bool LayerClipsSubtree(LayerType* layer) { | 1241 static inline bool LayerClipsSubtree(LayerType* layer) { |
1242 return layer->masks_to_bounds() || layer->mask_layer(); | 1242 return layer->masks_to_bounds() || layer->mask_layer(); |
1243 } | 1243 } |
1244 | 1244 |
1245 static bool PointHitsRect( | 1245 static bool PointHitsRect( |
1246 const gfx::PointF& screen_space_point, | 1246 const gfx::PointF& screen_space_point, |
1247 const gfx::Transform& local_space_to_screen_space_transform, | 1247 const gfx::Transform& local_space_to_screen_space_transform, |
1248 const gfx::RectF& local_space_rect, | 1248 const gfx::Rect& local_space_rect, |
1249 float* distance_to_camera) { | 1249 float* distance_to_camera) { |
1250 // If the transform is not invertible, then assume that this point doesn't hit | 1250 // If the transform is not invertible, then assume that this point doesn't hit |
1251 // this rect. | 1251 // this rect. |
1252 gfx::Transform inverse_local_space_to_screen_space( | 1252 gfx::Transform inverse_local_space_to_screen_space( |
1253 gfx::Transform::kSkipInitialization); | 1253 gfx::Transform::kSkipInitialization); |
1254 if (!local_space_to_screen_space_transform.GetInverse( | 1254 if (!local_space_to_screen_space_transform.GetInverse( |
1255 &inverse_local_space_to_screen_space)) | 1255 &inverse_local_space_to_screen_space)) |
1256 return false; | 1256 return false; |
1257 | 1257 |
1258 // Transform the hit test point from screen space to the local space of the | 1258 // Transform the hit test point from screen space to the local space of the |
1259 // given rect. | 1259 // given rect. |
1260 bool clipped = false; | 1260 bool clipped = false; |
1261 gfx::Point3F planar_point = MathUtil::ProjectPoint3D( | 1261 gfx::Point3F planar_point = MathUtil::ProjectPoint3D( |
1262 inverse_local_space_to_screen_space, screen_space_point, &clipped); | 1262 inverse_local_space_to_screen_space, screen_space_point, &clipped); |
1263 gfx::PointF hit_test_point_in_local_space = | 1263 gfx::PointF hit_test_point_in_local_space = |
1264 gfx::PointF(planar_point.x(), planar_point.y()); | 1264 gfx::PointF(planar_point.x(), planar_point.y()); |
1265 | 1265 |
1266 // If ProjectPoint could not project to a valid value, then we assume that | 1266 // If ProjectPoint could not project to a valid value, then we assume that |
1267 // this point doesn't hit this rect. | 1267 // this point doesn't hit this rect. |
1268 if (clipped) | 1268 if (clipped) |
1269 return false; | 1269 return false; |
1270 | 1270 |
1271 if (!local_space_rect.Contains(hit_test_point_in_local_space)) | 1271 if (!gfx::RectF(local_space_rect).Contains(hit_test_point_in_local_space)) |
1272 return false; | 1272 return false; |
1273 | 1273 |
1274 if (distance_to_camera) { | 1274 if (distance_to_camera) { |
1275 // To compute the distance to the camera, we have to take the planar point | 1275 // To compute the distance to the camera, we have to take the planar point |
1276 // and pull it back to world space and compute the displacement along the | 1276 // and pull it back to world space and compute the displacement along the |
1277 // z-axis. | 1277 // z-axis. |
1278 gfx::Point3F planar_point_in_screen_space(planar_point); | 1278 gfx::Point3F planar_point_in_screen_space(planar_point); |
1279 local_space_to_screen_space_transform.TransformPoint( | 1279 local_space_to_screen_space_transform.TransformPoint( |
1280 &planar_point_in_screen_space); | 1280 &planar_point_in_screen_space); |
1281 *distance_to_camera = planar_point_in_screen_space.z(); | 1281 *distance_to_camera = planar_point_in_screen_space.z(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 } | 1337 } |
1338 | 1338 |
1339 // If we have finished walking all ancestors without having already exited, | 1339 // If we have finished walking all ancestors without having already exited, |
1340 // then the point is not clipped by any ancestors. | 1340 // then the point is not clipped by any ancestors. |
1341 return false; | 1341 return false; |
1342 } | 1342 } |
1343 | 1343 |
1344 static bool PointHitsLayer(const LayerImpl* layer, | 1344 static bool PointHitsLayer(const LayerImpl* layer, |
1345 const gfx::PointF& screen_space_point, | 1345 const gfx::PointF& screen_space_point, |
1346 float* distance_to_intersection) { | 1346 float* distance_to_intersection) { |
1347 gfx::RectF content_rect(layer->bounds()); | 1347 gfx::Rect content_rect(layer->bounds()); |
1348 if (!PointHitsRect(screen_space_point, | 1348 if (!PointHitsRect(screen_space_point, |
1349 layer->screen_space_transform(), | 1349 layer->screen_space_transform(), |
1350 content_rect, | 1350 content_rect, |
1351 distance_to_intersection)) | 1351 distance_to_intersection)) |
1352 return false; | 1352 return false; |
1353 | 1353 |
1354 // At this point, we think the point does hit the layer, but we need to walk | 1354 // At this point, we think the point does hit the layer, but we need to walk |
1355 // up the parents to ensure that the layer was not clipped in such a way | 1355 // up the parents to ensure that the layer was not clipped in such a way |
1356 // that the hit point actually should not hit the layer. | 1356 // that the hit point actually should not hit the layer. |
1357 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer)) | 1357 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer)) |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 const gfx::BoxF& box, | 1768 const gfx::BoxF& box, |
1769 gfx::BoxF* bounds) const { | 1769 gfx::BoxF* bounds) const { |
1770 *bounds = gfx::BoxF(); | 1770 *bounds = gfx::BoxF(); |
1771 return layer_tree_host_impl_->animation_host() | 1771 return layer_tree_host_impl_->animation_host() |
1772 ? layer_tree_host_impl_->animation_host() | 1772 ? layer_tree_host_impl_->animation_host() |
1773 ->TransformAnimationBoundsForBox(layer->id(), box, bounds) | 1773 ->TransformAnimationBoundsForBox(layer->id(), box, bounds) |
1774 : true; | 1774 : true; |
1775 } | 1775 } |
1776 | 1776 |
1777 } // namespace cc | 1777 } // namespace cc |
OLD | NEW |