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" |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 *combined_maximum_animation_contents_scale = 0.f; | 1105 *combined_maximum_animation_contents_scale = 0.f; |
1106 return; | 1106 return; |
1107 } | 1107 } |
1108 gfx::Vector2dF ancestor_transform_scales = | 1108 gfx::Vector2dF ancestor_transform_scales = |
1109 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); | 1109 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); |
1110 *combined_maximum_animation_contents_scale = | 1110 *combined_maximum_animation_contents_scale = |
1111 layer_maximum_animated_scale * | 1111 layer_maximum_animated_scale * |
1112 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); | 1112 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); |
1113 } | 1113 } |
1114 | 1114 |
1115 static inline RenderSurface* CreateOrReuseRenderSurface(Layer* layer) { | 1115 template <typename LayerType> |
1116 // The render surface should always be new on the main thread, as the | 1116 static inline typename LayerType::RenderSurfaceType* CreateOrReuseRenderSurface( |
1117 // RenderSurfaceLayerList should be a new empty list when given to | 1117 LayerType* layer) { |
1118 // CalculateDrawProperties. | |
1119 DCHECK(!layer->render_surface()); | |
1120 layer->CreateRenderSurface(); | |
1121 return layer->render_surface(); | |
1122 } | |
1123 | |
1124 static inline RenderSurfaceImpl* CreateOrReuseRenderSurface(LayerImpl* layer) { | |
1125 if (!layer->render_surface()) { | 1118 if (!layer->render_surface()) { |
1126 layer->CreateRenderSurface(); | 1119 layer->CreateRenderSurface(); |
1127 return layer->render_surface(); | 1120 return layer->render_surface(); |
1128 } | 1121 } |
1129 | 1122 |
1130 layer->render_surface()->ClearLayerLists(); | 1123 layer->render_surface()->ClearLayerLists(); |
1131 return layer->render_surface(); | 1124 return layer->render_surface(); |
1132 } | 1125 } |
1133 | 1126 |
1134 template <typename LayerType> | 1127 template <typename LayerType> |
1135 static inline void RemoveSurfaceForEarlyExit( | 1128 static inline void RemoveSurfaceForEarlyExit( |
1136 LayerType* layer_to_remove, | 1129 LayerType* layer_to_remove, |
1137 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { | 1130 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { |
1138 DCHECK(layer_to_remove->render_surface()); | 1131 DCHECK(layer_to_remove->render_surface()); |
1139 // Technically, we know that the layer we want to remove should be | 1132 // Technically, we know that the layer we want to remove should be |
1140 // at the back of the render_surface_layer_list. However, we have had | 1133 // at the back of the render_surface_layer_list. However, we have had |
1141 // bugs before that added unnecessary layers here | 1134 // bugs before that added unnecessary layers here |
1142 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes | 1135 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes |
1143 // things to crash. So here we proactively remove any additional | 1136 // things to crash. So here we proactively remove any additional |
1144 // layers from the end of the list. | 1137 // layers from the end of the list. |
1145 while (render_surface_layer_list->back() != layer_to_remove) { | 1138 while (render_surface_layer_list->back() != layer_to_remove) |
1146 render_surface_layer_list->back()->ClearRenderSurface(); | |
1147 render_surface_layer_list->pop_back(); | 1139 render_surface_layer_list->pop_back(); |
1148 } | |
1149 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); | 1140 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); |
1150 render_surface_layer_list->pop_back(); | 1141 render_surface_layer_list->pop_back(); |
1151 layer_to_remove->ClearRenderSurface(); | |
1152 } | 1142 } |
1153 | 1143 |
1154 struct PreCalculateMetaInformationRecursiveData { | 1144 struct PreCalculateMetaInformationRecursiveData { |
1155 bool layer_or_descendant_has_copy_request; | 1145 bool layer_or_descendant_has_copy_request; |
1156 int num_unclipped_descendants; | 1146 int num_unclipped_descendants; |
1157 | 1147 |
1158 PreCalculateMetaInformationRecursiveData() | 1148 PreCalculateMetaInformationRecursiveData() |
1159 : layer_or_descendant_has_copy_request(false), | 1149 : layer_or_descendant_has_copy_request(false), |
1160 num_unclipped_descendants(0) {} | 1150 num_unclipped_descendants(0) {} |
1161 | 1151 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 | 1364 |
1375 template <typename LayerType> | 1365 template <typename LayerType> |
1376 static void GetNewRenderSurfacesStartIndexAndCount(LayerType* layer, | 1366 static void GetNewRenderSurfacesStartIndexAndCount(LayerType* layer, |
1377 size_t* start_index, | 1367 size_t* start_index, |
1378 size_t* count) { | 1368 size_t* count) { |
1379 *start_index = layer->draw_properties() | 1369 *start_index = layer->draw_properties() |
1380 .index_of_first_render_surface_layer_list_addition; | 1370 .index_of_first_render_surface_layer_list_addition; |
1381 *count = layer->draw_properties().num_render_surfaces_added; | 1371 *count = layer->draw_properties().num_render_surfaces_added; |
1382 } | 1372 } |
1383 | 1373 |
1384 template <typename LayerType, | 1374 // We need to extract a list from the the two flavors of RenderSurfaceListType |
1385 typename GetIndexAndCountType> | 1375 // for use in the sorting function below. |
| 1376 static LayerList* GetLayerListForSorting(RenderSurfaceLayerList* rsll) { |
| 1377 return rsll->layer_list(); |
| 1378 } |
| 1379 |
| 1380 static LayerImplList* GetLayerListForSorting(LayerImplList* layer_list) { |
| 1381 return layer_list; |
| 1382 } |
| 1383 |
| 1384 template <typename LayerType, typename GetIndexAndCountType> |
1386 static void SortLayerListContributions( | 1385 static void SortLayerListContributions( |
1387 const LayerType& parent, | 1386 const LayerType& parent, |
1388 typename LayerType::RenderSurfaceListType* unsorted, | 1387 typename LayerType::LayerListType* unsorted, |
1389 size_t start_index_for_all_contributions, | 1388 size_t start_index_for_all_contributions, |
1390 GetIndexAndCountType get_index_and_count) { | 1389 GetIndexAndCountType get_index_and_count) { |
1391 | |
1392 typename LayerType::LayerListType buffer; | 1390 typename LayerType::LayerListType buffer; |
1393 for (size_t i = 0; i < parent.children().size(); ++i) { | 1391 for (size_t i = 0; i < parent.children().size(); ++i) { |
1394 LayerType* child = | 1392 LayerType* child = |
1395 LayerTreeHostCommon::get_child_as_raw_ptr(parent.children(), i); | 1393 LayerTreeHostCommon::get_child_as_raw_ptr(parent.children(), i); |
1396 | 1394 |
1397 size_t start_index = 0; | 1395 size_t start_index = 0; |
1398 size_t count = 0; | 1396 size_t count = 0; |
1399 get_index_and_count(child, &start_index, &count); | 1397 get_index_and_count(child, &start_index, &count); |
1400 for (size_t j = start_index; j < start_index + count; ++j) | 1398 for (size_t j = start_index; j < start_index + count; ++j) |
1401 buffer.push_back(unsorted->at(j)); | 1399 buffer.push_back(unsorted->at(j)); |
1402 } | 1400 } |
1403 | 1401 |
1404 DCHECK_EQ(buffer.size(), | 1402 DCHECK_EQ(buffer.size(), |
1405 unsorted->size() - start_index_for_all_contributions); | 1403 unsorted->size() - start_index_for_all_contributions); |
1406 | 1404 |
1407 for (size_t i = 0; i < buffer.size(); ++i) | 1405 for (size_t i = 0; i < buffer.size(); ++i) |
1408 (*unsorted)[i + start_index_for_all_contributions] = buffer[i]; | 1406 (*unsorted)[i + start_index_for_all_contributions] = buffer[i]; |
1409 } | 1407 } |
1410 | 1408 |
1411 // Recursively walks the layer tree starting at the given node and computes all | 1409 // Recursively walks the layer tree starting at the given node and computes all |
1412 // the necessary transformations, clip rects, render surfaces, etc. | 1410 // the necessary transformations, clip rects, render surfaces, etc. |
1413 template <typename LayerType> | 1411 template <typename LayerType> |
1414 static void CalculateDrawPropertiesInternal( | 1412 static void CalculateDrawPropertiesInternal( |
1415 LayerType* layer, | 1413 LayerType* layer, |
1416 const SubtreeGlobals<LayerType>& globals, | 1414 const SubtreeGlobals<LayerType>& globals, |
1417 const DataForRecursion<LayerType>& data_from_ancestor, | 1415 const DataForRecursion<LayerType>& data_from_ancestor, |
1418 typename LayerType::RenderSurfaceListType* render_surface_layer_list, | 1416 typename LayerType::RenderSurfaceListType* render_surface_layer_list, |
1419 typename LayerType::RenderSurfaceListType* layer_list, | 1417 typename LayerType::LayerListType* layer_list, |
1420 std::vector<AccumulatedSurfaceState<LayerType> >* | 1418 std::vector<AccumulatedSurfaceState<LayerType> >* |
1421 accumulated_surface_state) { | 1419 accumulated_surface_state) { |
1422 // This function computes the new matrix transformations recursively for this | 1420 // This function computes the new matrix transformations recursively for this |
1423 // layer and all its descendants. It also computes the appropriate render | 1421 // layer and all its descendants. It also computes the appropriate render |
1424 // surfaces. | 1422 // surfaces. |
1425 // Some important points to remember: | 1423 // Some important points to remember: |
1426 // | 1424 // |
1427 // 0. Here, transforms are notated in Matrix x Vector order, and in words we | 1425 // 0. Here, transforms are notated in Matrix x Vector order, and in words we |
1428 // describe what the transform does from left to right. | 1426 // describe what the transform does from left to right. |
1429 // | 1427 // |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 // Layers that are marked as hidden will hide themselves and their subtree. | 1549 // Layers that are marked as hidden will hide themselves and their subtree. |
1552 // Exception: Layers with copy requests, whether hidden or not, must be drawn | 1550 // Exception: Layers with copy requests, whether hidden or not, must be drawn |
1553 // anyway. In this case, we will inform their subtree they are visible to get | 1551 // anyway. In this case, we will inform their subtree they are visible to get |
1554 // the right results. | 1552 // the right results. |
1555 const bool layer_is_visible = | 1553 const bool layer_is_visible = |
1556 data_from_ancestor.subtree_is_visible_from_ancestor && | 1554 data_from_ancestor.subtree_is_visible_from_ancestor && |
1557 !layer->hide_layer_and_subtree(); | 1555 !layer->hide_layer_and_subtree(); |
1558 const bool layer_is_drawn = layer_is_visible || layer->HasCopyRequest(); | 1556 const bool layer_is_drawn = layer_is_visible || layer->HasCopyRequest(); |
1559 | 1557 |
1560 // The root layer cannot skip CalcDrawProperties. | 1558 // The root layer cannot skip CalcDrawProperties. |
1561 if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn)) { | 1559 if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn)) |
1562 if (layer->render_surface()) | |
1563 layer->ClearRenderSurface(); | |
1564 return; | 1560 return; |
1565 } | |
1566 | 1561 |
1567 // We need to circumvent the normal recursive flow of information for clip | 1562 // We need to circumvent the normal recursive flow of information for clip |
1568 // children (they don't inherit their direct ancestor's clip information). | 1563 // children (they don't inherit their direct ancestor's clip information). |
1569 // This is unfortunate, and would be unnecessary if we were to formally | 1564 // This is unfortunate, and would be unnecessary if we were to formally |
1570 // separate the clipping hierarchy from the layer hierarchy. | 1565 // separate the clipping hierarchy from the layer hierarchy. |
1571 bool ancestor_clips_subtree = data_from_ancestor.ancestor_clips_subtree; | 1566 bool ancestor_clips_subtree = data_from_ancestor.ancestor_clips_subtree; |
1572 gfx::Rect ancestor_clip_rect_in_target_space = | 1567 gfx::Rect ancestor_clip_rect_in_target_space = |
1573 data_from_ancestor.clip_rect_in_target_space; | 1568 data_from_ancestor.clip_rect_in_target_space; |
1574 | 1569 |
1575 // Update our clipping state. If we have a clip parent we will need to pull | 1570 // Update our clipping state. If we have a clip parent we will need to pull |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 if (globals.can_render_to_separate_surface) { | 1751 if (globals.can_render_to_separate_surface) { |
1757 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( | 1752 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( |
1758 layer, combined_transform.Preserves2dAxisAlignment()); | 1753 layer, combined_transform.Preserves2dAxisAlignment()); |
1759 } else { | 1754 } else { |
1760 render_to_separate_surface = IsRootLayer(layer); | 1755 render_to_separate_surface = IsRootLayer(layer); |
1761 } | 1756 } |
1762 if (render_to_separate_surface) { | 1757 if (render_to_separate_surface) { |
1763 // Check back-face visibility before continuing with this surface and its | 1758 // Check back-face visibility before continuing with this surface and its |
1764 // subtree | 1759 // subtree |
1765 if (!layer->double_sided() && TransformToParentIsKnown(layer) && | 1760 if (!layer->double_sided() && TransformToParentIsKnown(layer) && |
1766 IsSurfaceBackFaceVisible(layer, combined_transform)) { | 1761 IsSurfaceBackFaceVisible(layer, combined_transform)) |
1767 layer->ClearRenderSurface(); | |
1768 return; | 1762 return; |
1769 } | |
1770 | 1763 |
1771 typename LayerType::RenderSurfaceType* render_surface = | 1764 typename LayerType::RenderSurfaceType* render_surface = |
1772 CreateOrReuseRenderSurface(layer); | 1765 CreateOrReuseRenderSurface(layer); |
1773 | 1766 |
1774 if (IsRootLayer(layer)) { | 1767 if (IsRootLayer(layer)) { |
1775 // The root layer's render surface size is predetermined and so the root | 1768 // The root layer's render surface size is predetermined and so the root |
1776 // layer can't directly support non-identity transforms. It should just | 1769 // layer can't directly support non-identity transforms. It should just |
1777 // forward top-level transforms to the rest of the tree. | 1770 // forward top-level transforms to the rest of the tree. |
1778 data_for_children.parent_matrix = combined_transform; | 1771 data_for_children.parent_matrix = combined_transform; |
1779 | 1772 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 // is used in the recursion below, so we must set it beforehand. | 1983 // is used in the recursion below, so we must set it beforehand. |
1991 layer_draw_properties.is_clipped = layer_or_ancestor_clips_descendants; | 1984 layer_draw_properties.is_clipped = layer_or_ancestor_clips_descendants; |
1992 if (layer_or_ancestor_clips_descendants) { | 1985 if (layer_or_ancestor_clips_descendants) { |
1993 layer_draw_properties.clip_rect = clip_rect_in_target_space; | 1986 layer_draw_properties.clip_rect = clip_rect_in_target_space; |
1994 } else { | 1987 } else { |
1995 // Initialize the clip rect to a safe value that will not clip the | 1988 // Initialize the clip rect to a safe value that will not clip the |
1996 // layer, just in case clipping is still accidentally used. | 1989 // layer, just in case clipping is still accidentally used. |
1997 layer_draw_properties.clip_rect = rect_in_target_space; | 1990 layer_draw_properties.clip_rect = rect_in_target_space; |
1998 } | 1991 } |
1999 | 1992 |
2000 typename LayerType::RenderSurfaceListType& descendants = | 1993 typename LayerType::LayerListType& descendants = |
2001 (layer->render_surface() ? layer->render_surface()->layer_list() | 1994 (layer->render_surface() ? layer->render_surface()->layer_list() |
2002 : *layer_list); | 1995 : *layer_list); |
2003 | 1996 |
2004 // Any layers that are appended after this point are in the layer's subtree | 1997 // Any layers that are appended after this point are in the layer's subtree |
2005 // and should be included in the sorting process. | 1998 // and should be included in the sorting process. |
2006 size_t sorting_start_index = descendants.size(); | 1999 size_t sorting_start_index = descendants.size(); |
2007 | 2000 |
2008 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) | 2001 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) |
2009 descendants.push_back(layer); | 2002 descendants.push_back(layer); |
2010 | 2003 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2083 child->draw_properties().num_render_surfaces_added = | 2076 child->draw_properties().num_render_surfaces_added = |
2084 render_surface_layer_list->size() - | 2077 render_surface_layer_list->size() - |
2085 child->draw_properties() | 2078 child->draw_properties() |
2086 .index_of_first_render_surface_layer_list_addition; | 2079 .index_of_first_render_surface_layer_list_addition; |
2087 } | 2080 } |
2088 | 2081 |
2089 // Add the unsorted layer list contributions, if necessary. | 2082 // Add the unsorted layer list contributions, if necessary. |
2090 if (child_order_changed) { | 2083 if (child_order_changed) { |
2091 SortLayerListContributions( | 2084 SortLayerListContributions( |
2092 *layer, | 2085 *layer, |
2093 render_surface_layer_list, | 2086 GetLayerListForSorting(render_surface_layer_list), |
2094 render_surface_layer_list_child_sorting_start_index, | 2087 render_surface_layer_list_child_sorting_start_index, |
2095 &GetNewRenderSurfacesStartIndexAndCount<LayerType>); | 2088 &GetNewRenderSurfacesStartIndexAndCount<LayerType>); |
2096 | 2089 |
2097 SortLayerListContributions( | 2090 SortLayerListContributions( |
2098 *layer, | 2091 *layer, |
2099 &descendants, | 2092 &descendants, |
2100 layer_list_child_sorting_start_index, | 2093 layer_list_child_sorting_start_index, |
2101 &GetNewDescendantsStartIndexAndCount<LayerType>); | 2094 &GetNewDescendantsStartIndexAndCount<LayerType>); |
2102 } | 2095 } |
2103 | 2096 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 data_for_recursion->ancestor_is_animating_scale = false; | 2299 data_for_recursion->ancestor_is_animating_scale = false; |
2307 data_for_recursion->ancestor_clips_subtree = true; | 2300 data_for_recursion->ancestor_clips_subtree = true; |
2308 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; | 2301 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; |
2309 data_for_recursion->in_subtree_of_page_scale_application_layer = false; | 2302 data_for_recursion->in_subtree_of_page_scale_application_layer = false; |
2310 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; | 2303 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; |
2311 data_for_recursion->subtree_is_visible_from_ancestor = true; | 2304 data_for_recursion->subtree_is_visible_from_ancestor = true; |
2312 } | 2305 } |
2313 | 2306 |
2314 void LayerTreeHostCommon::CalculateDrawProperties( | 2307 void LayerTreeHostCommon::CalculateDrawProperties( |
2315 CalcDrawPropsMainInputs* inputs) { | 2308 CalcDrawPropsMainInputs* inputs) { |
2316 RenderSurfaceLayerList dummy_layer_list; | 2309 LayerList dummy_layer_list; |
2317 SubtreeGlobals<Layer> globals; | 2310 SubtreeGlobals<Layer> globals; |
2318 DataForRecursion<Layer> data_for_recursion; | 2311 DataForRecursion<Layer> data_for_recursion; |
2319 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2312 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2320 | 2313 |
2321 PreCalculateMetaInformationRecursiveData recursive_data; | 2314 PreCalculateMetaInformationRecursiveData recursive_data; |
2322 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2315 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2323 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; | 2316 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; |
2324 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer, | 2317 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer, |
2325 globals, | 2318 globals, |
2326 data_for_recursion, | 2319 data_for_recursion, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2575 // At this point, we think the point does hit the touch event handler region | 2568 // At this point, we think the point does hit the touch event handler region |
2576 // on the layer, but we need to walk up the parents to ensure that the layer | 2569 // on the layer, but we need to walk up the parents to ensure that the layer |
2577 // was not clipped in such a way that the hit point actually should not hit | 2570 // was not clipped in such a way that the hit point actually should not hit |
2578 // the layer. | 2571 // the layer. |
2579 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 2572 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
2580 return false; | 2573 return false; |
2581 | 2574 |
2582 return true; | 2575 return true; |
2583 } | 2576 } |
2584 } // namespace cc | 2577 } // namespace cc |
OLD | NEW |