| 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_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| 11 #include "cc/layers/heads_up_display_layer_impl.h" | 11 #include "cc/layers/heads_up_display_layer_impl.h" |
| 12 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
| 13 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
| 14 #include "cc/layers/layer_iterator.h" | 14 #include "cc/layers/layer_iterator.h" |
| 15 #include "cc/layers/render_surface.h" | 15 #include "cc/layers/render_surface.h" |
| 16 #include "cc/layers/render_surface_impl.h" | 16 #include "cc/layers/render_surface_impl.h" |
| 17 #include "cc/trees/layer_sorter.h" | 17 #include "cc/trees/layer_sorter.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "ui/gfx/point_conversions.h" | 19 #include "ui/gfx/point_conversions.h" |
| 20 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
| 21 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 22 | 22 |
| 23 namespace cc { | 23 namespace cc { |
| 24 | 24 |
| 25 ScrollAndScaleSet::ScrollAndScaleSet() {} | 25 ScrollAndScaleSet::ScrollAndScaleSet() {} |
| 26 | 26 |
| 27 ScrollAndScaleSet::~ScrollAndScaleSet() {} | 27 ScrollAndScaleSet::~ScrollAndScaleSet() {} |
| 28 | 28 |
| 29 static void SortLayers(std::vector<scoped_refptr<Layer> >::iterator forst, | 29 static void SortLayers(LayerList::iterator forst, |
| 30 std::vector<scoped_refptr<Layer> >::iterator end, | 30 LayerList::iterator end, |
| 31 void* layer_sorter) { | 31 void* layer_sorter) { |
| 32 NOTREACHED(); | 32 NOTREACHED(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 static void SortLayers(std::vector<LayerImpl*>::iterator first, | 35 static void SortLayers(LayerImplList::iterator first, |
| 36 std::vector<LayerImpl*>::iterator end, | 36 LayerImplList::iterator end, |
| 37 LayerSorter* layer_sorter) { | 37 LayerSorter* layer_sorter) { |
| 38 DCHECK(layer_sorter); | 38 DCHECK(layer_sorter); |
| 39 TRACE_EVENT0("cc", "LayerTreeHostCommon::SortLayers"); | 39 TRACE_EVENT0("cc", "LayerTreeHostCommon::SortLayers"); |
| 40 layer_sorter->Sort(first, end); | 40 layer_sorter->Sort(first, end); |
| 41 } | 41 } |
| 42 | 42 |
| 43 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( | 43 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( |
| 44 gfx::Rect target_surface_rect, | 44 gfx::Rect target_surface_rect, |
| 45 gfx::Rect layer_bound_rect, | 45 gfx::Rect layer_bound_rect, |
| 46 gfx::Rect layer_rect_in_target_space, | 46 gfx::Rect layer_rect_in_target_space, |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 } | 1287 } |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 void LayerTreeHostCommon::CalculateDrawProperties( | 1290 void LayerTreeHostCommon::CalculateDrawProperties( |
| 1291 Layer* root_layer, | 1291 Layer* root_layer, |
| 1292 gfx::Size device_viewport_size, | 1292 gfx::Size device_viewport_size, |
| 1293 float device_scale_factor, | 1293 float device_scale_factor, |
| 1294 float page_scale_factor, | 1294 float page_scale_factor, |
| 1295 int max_texture_size, | 1295 int max_texture_size, |
| 1296 bool can_use_lcd_text, | 1296 bool can_use_lcd_text, |
| 1297 std::vector<scoped_refptr<Layer> >* render_surface_layer_list) { | 1297 LayerList* render_surface_layer_list) { |
| 1298 gfx::Rect total_drawable_content_rect; | 1298 gfx::Rect total_drawable_content_rect; |
| 1299 gfx::Transform identity_matrix; | 1299 gfx::Transform identity_matrix; |
| 1300 gfx::Transform device_scale_transform; | 1300 gfx::Transform device_scale_transform; |
| 1301 device_scale_transform.Scale(device_scale_factor, device_scale_factor); | 1301 device_scale_transform.Scale(device_scale_factor, device_scale_factor); |
| 1302 std::vector<scoped_refptr<Layer> > dummy_layer_list; | 1302 LayerList dummy_layer_list; |
| 1303 | 1303 |
| 1304 // The root layer's render_surface should receive the device viewport as the | 1304 // The root layer's render_surface should receive the device viewport as the |
| 1305 // initial clip rect. | 1305 // initial clip rect. |
| 1306 bool subtree_should_be_clipped = true; | 1306 bool subtree_should_be_clipped = true; |
| 1307 gfx::Rect device_viewport_rect(device_viewport_size); | 1307 gfx::Rect device_viewport_rect(device_viewport_size); |
| 1308 bool update_tile_priorities = false; | 1308 bool update_tile_priorities = false; |
| 1309 | 1309 |
| 1310 // This function should have received a root layer. | 1310 // This function should have received a root layer. |
| 1311 DCHECK(IsRootLayer(root_layer)); | 1311 DCHECK(IsRootLayer(root_layer)); |
| 1312 | 1312 |
| 1313 PreCalculateMetaInformation<Layer>(root_layer); | 1313 PreCalculateMetaInformation<Layer>(root_layer); |
| 1314 CalculateDrawPropertiesInternal<Layer, | 1314 CalculateDrawPropertiesInternal<Layer, |
| 1315 std::vector<scoped_refptr<Layer> >, | 1315 LayerList, |
| 1316 RenderSurface>(root_layer, | 1316 RenderSurface>(root_layer, |
| 1317 device_scale_transform, | 1317 device_scale_transform, |
| 1318 identity_matrix, | 1318 identity_matrix, |
| 1319 identity_matrix, | 1319 identity_matrix, |
| 1320 device_viewport_rect, | 1320 device_viewport_rect, |
| 1321 device_viewport_rect, | 1321 device_viewport_rect, |
| 1322 subtree_should_be_clipped, | 1322 subtree_should_be_clipped, |
| 1323 NULL, | 1323 NULL, |
| 1324 render_surface_layer_list, | 1324 render_surface_layer_list, |
| 1325 &dummy_layer_list, | 1325 &dummy_layer_list, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1338 DCHECK(root_layer->render_surface()); | 1338 DCHECK(root_layer->render_surface()); |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 void LayerTreeHostCommon::CalculateDrawProperties( | 1341 void LayerTreeHostCommon::CalculateDrawProperties( |
| 1342 LayerImpl* root_layer, | 1342 LayerImpl* root_layer, |
| 1343 gfx::Size device_viewport_size, | 1343 gfx::Size device_viewport_size, |
| 1344 float device_scale_factor, | 1344 float device_scale_factor, |
| 1345 float page_scale_factor, | 1345 float page_scale_factor, |
| 1346 int max_texture_size, | 1346 int max_texture_size, |
| 1347 bool can_use_lcd_text, | 1347 bool can_use_lcd_text, |
| 1348 std::vector<LayerImpl*>* render_surface_layer_list, | 1348 LayerImplList* render_surface_layer_list, |
| 1349 bool update_tile_priorities) { | 1349 bool update_tile_priorities) { |
| 1350 gfx::Rect total_drawable_content_rect; | 1350 gfx::Rect total_drawable_content_rect; |
| 1351 gfx::Transform identity_matrix; | 1351 gfx::Transform identity_matrix; |
| 1352 gfx::Transform device_scale_transform; | 1352 gfx::Transform device_scale_transform; |
| 1353 device_scale_transform.Scale(device_scale_factor, device_scale_factor); | 1353 device_scale_transform.Scale(device_scale_factor, device_scale_factor); |
| 1354 std::vector<LayerImpl*> dummy_layer_list; | 1354 LayerImplList dummy_layer_list; |
| 1355 LayerSorter layer_sorter; | 1355 LayerSorter layer_sorter; |
| 1356 | 1356 |
| 1357 // The root layer's render_surface should receive the device viewport as the | 1357 // The root layer's render_surface should receive the device viewport as the |
| 1358 // initial clip rect. | 1358 // initial clip rect. |
| 1359 bool subtree_should_be_clipped = true; | 1359 bool subtree_should_be_clipped = true; |
| 1360 gfx::Rect device_viewport_rect(device_viewport_size); | 1360 gfx::Rect device_viewport_rect(device_viewport_size); |
| 1361 | 1361 |
| 1362 // This function should have received a root layer. | 1362 // This function should have received a root layer. |
| 1363 DCHECK(IsRootLayer(root_layer)); | 1363 DCHECK(IsRootLayer(root_layer)); |
| 1364 | 1364 |
| 1365 PreCalculateMetaInformation<LayerImpl>(root_layer); | 1365 PreCalculateMetaInformation<LayerImpl>(root_layer); |
| 1366 CalculateDrawPropertiesInternal<LayerImpl, | 1366 CalculateDrawPropertiesInternal<LayerImpl, |
| 1367 std::vector<LayerImpl*>, | 1367 LayerImplList, |
| 1368 RenderSurfaceImpl>( | 1368 RenderSurfaceImpl>( |
| 1369 root_layer, | 1369 root_layer, |
| 1370 device_scale_transform, | 1370 device_scale_transform, |
| 1371 identity_matrix, | 1371 identity_matrix, |
| 1372 identity_matrix, | 1372 identity_matrix, |
| 1373 device_viewport_rect, | 1373 device_viewport_rect, |
| 1374 device_viewport_rect, | 1374 device_viewport_rect, |
| 1375 subtree_should_be_clipped, | 1375 subtree_should_be_clipped, |
| 1376 NULL, | 1376 NULL, |
| 1377 render_surface_layer_list, | 1377 render_surface_layer_list, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 current_layer = current_layer->parent(); | 1476 current_layer = current_layer->parent(); |
| 1477 } | 1477 } |
| 1478 | 1478 |
| 1479 // If we have finished walking all ancestors without having already exited, | 1479 // If we have finished walking all ancestors without having already exited, |
| 1480 // then the point is not clipped by any ancestors. | 1480 // then the point is not clipped by any ancestors. |
| 1481 return false; | 1481 return false; |
| 1482 } | 1482 } |
| 1483 | 1483 |
| 1484 LayerImpl* LayerTreeHostCommon::FindLayerThatIsHitByPoint( | 1484 LayerImpl* LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 1485 gfx::PointF screen_space_point, | 1485 gfx::PointF screen_space_point, |
| 1486 const std::vector<LayerImpl*>& render_surface_layer_list) { | 1486 const LayerImplList& render_surface_layer_list) { |
| 1487 LayerImpl* found_layer = NULL; | 1487 LayerImpl* found_layer = NULL; |
| 1488 | 1488 |
| 1489 typedef LayerIterator<LayerImpl, | 1489 typedef LayerIterator<LayerImpl, |
| 1490 std::vector<LayerImpl*>, | 1490 LayerImplList, |
| 1491 RenderSurfaceImpl, | 1491 RenderSurfaceImpl, |
| 1492 LayerIteratorActions::FrontToBack> LayerIteratorType; | 1492 LayerIteratorActions::FrontToBack> LayerIteratorType; |
| 1493 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list); | 1493 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list); |
| 1494 | 1494 |
| 1495 for (LayerIteratorType | 1495 for (LayerIteratorType |
| 1496 it = LayerIteratorType::Begin(&render_surface_layer_list); | 1496 it = LayerIteratorType::Begin(&render_surface_layer_list); |
| 1497 it != end; | 1497 it != end; |
| 1498 ++it) { | 1498 ++it) { |
| 1499 // We don't want to consider render_surfaces for hit testing. | 1499 // We don't want to consider render_surfaces for hit testing. |
| 1500 if (!it.represents_itself()) | 1500 if (!it.represents_itself()) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1522 break; | 1522 break; |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 // This can potentially return NULL, which means the screen_space_point did | 1525 // This can potentially return NULL, which means the screen_space_point did |
| 1526 // not successfully hit test any layers, not even the root layer. | 1526 // not successfully hit test any layers, not even the root layer. |
| 1527 return found_layer; | 1527 return found_layer; |
| 1528 } | 1528 } |
| 1529 | 1529 |
| 1530 LayerImpl* LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( | 1530 LayerImpl* LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1531 gfx::PointF screen_space_point, | 1531 gfx::PointF screen_space_point, |
| 1532 const std::vector<LayerImpl*>& render_surface_layer_list) { | 1532 const LayerImplList& render_surface_layer_list) { |
| 1533 LayerImpl* found_layer = NULL; | 1533 LayerImpl* found_layer = NULL; |
| 1534 | 1534 |
| 1535 typedef LayerIterator<LayerImpl, | 1535 typedef LayerIterator<LayerImpl, |
| 1536 std::vector<LayerImpl*>, | 1536 LayerImplList, |
| 1537 RenderSurfaceImpl, | 1537 RenderSurfaceImpl, |
| 1538 LayerIteratorActions::FrontToBack> LayerIteratorType; | 1538 LayerIteratorActions::FrontToBack> LayerIteratorType; |
| 1539 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list); | 1539 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list); |
| 1540 | 1540 |
| 1541 for (LayerIteratorType | 1541 for (LayerIteratorType |
| 1542 it = LayerIteratorType::Begin(&render_surface_layer_list); | 1542 it = LayerIteratorType::Begin(&render_surface_layer_list); |
| 1543 it != end; | 1543 it != end; |
| 1544 ++it) { | 1544 ++it) { |
| 1545 // We don't want to consider render_surfaces for hit testing. | 1545 // We don't want to consider render_surfaces for hit testing. |
| 1546 if (!it.represents_itself()) | 1546 if (!it.represents_itself()) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1576 // At this point, we think the point does hit the touch event handler region | 1576 // At this point, we think the point does hit the touch event handler region |
| 1577 // on the layer, but we need to walk up the parents to ensure that the layer | 1577 // on the layer, but we need to walk up the parents to ensure that the layer |
| 1578 // was not clipped in such a way that the hit point actually should not hit | 1578 // was not clipped in such a way that the hit point actually should not hit |
| 1579 // the layer. | 1579 // the layer. |
| 1580 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 1580 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
| 1581 return false; | 1581 return false; |
| 1582 | 1582 |
| 1583 return true; | 1583 return true; |
| 1584 } | 1584 } |
| 1585 } // namespace cc | 1585 } // namespace cc |
| OLD | NEW |