Chromium Code Reviews| 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 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1122 LayerType* layer) { | 1122 LayerType* layer) { |
| 1123 if (!layer->render_surface()) { | 1123 if (!layer->render_surface()) { |
| 1124 layer->CreateRenderSurface(); | 1124 layer->CreateRenderSurface(); |
| 1125 return layer->render_surface(); | 1125 return layer->render_surface(); |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 layer->render_surface()->ClearLayerLists(); | 1128 layer->render_surface()->ClearLayerLists(); |
| 1129 return layer->render_surface(); | 1129 return layer->render_surface(); |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 template <typename LayerTypePtr> | |
| 1133 static inline void MarkLayerWithRenderSurfaceLayerListId( | |
| 1134 LayerTypePtr layer, | |
| 1135 int current_render_surface_layer_list_id) { | |
| 1136 layer->draw_properties().last_drawn_render_surface_layer_list_id = | |
| 1137 current_render_surface_layer_list_id; | |
| 1138 if (layer->mask_layer()) { | |
| 1139 layer->mask_layer() | |
| 1140 ->draw_properties() | |
| 1141 .last_drawn_render_surface_layer_list_id = | |
| 1142 current_render_surface_layer_list_id; | |
| 1143 } | |
| 1144 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { | |
| 1145 layer->replica_layer() | |
| 1146 ->mask_layer() | |
| 1147 ->draw_properties() | |
| 1148 .last_drawn_render_surface_layer_list_id = | |
| 1149 current_render_surface_layer_list_id; | |
| 1150 } | |
| 1151 } | |
| 1152 | |
| 1153 template <typename LayerListType> | |
| 1154 static inline void MarkLayerListWithRenderSurfaceLayerListId( | |
| 1155 LayerListType* layer_list, | |
| 1156 int current_render_surface_layer_list_id) { | |
| 1157 for (typename LayerListType::iterator it = layer_list->begin(); | |
| 1158 it != layer_list->end(); | |
| 1159 ++it) { | |
| 1160 MarkLayerWithRenderSurfaceLayerListId(*it, | |
| 1161 current_render_surface_layer_list_id); | |
| 1162 } | |
| 1163 } | |
| 1164 | |
| 1132 template <typename LayerType> | 1165 template <typename LayerType> |
| 1133 static inline void RemoveSurfaceForEarlyExit( | 1166 static inline void RemoveSurfaceForEarlyExit( |
| 1134 LayerType* layer_to_remove, | 1167 LayerType* layer_to_remove, |
| 1135 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { | 1168 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { |
| 1136 DCHECK(layer_to_remove->render_surface()); | 1169 DCHECK(layer_to_remove->render_surface()); |
| 1137 // Technically, we know that the layer we want to remove should be | 1170 // Technically, we know that the layer we want to remove should be |
| 1138 // at the back of the render_surface_layer_list. However, we have had | 1171 // at the back of the render_surface_layer_list. However, we have had |
| 1139 // bugs before that added unnecessary layers here | 1172 // bugs before that added unnecessary layers here |
| 1140 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes | 1173 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes |
| 1141 // things to crash. So here we proactively remove any additional | 1174 // things to crash. So here we proactively remove any additional |
| 1142 // layers from the end of the list. | 1175 // layers from the end of the list. |
| 1143 while (render_surface_layer_list->back() != layer_to_remove) { | 1176 while (render_surface_layer_list->back() != layer_to_remove) { |
| 1177 MarkLayerListWithRenderSurfaceLayerListId( | |
| 1178 &render_surface_layer_list->back()->render_surface()->layer_list(), 0); | |
| 1179 MarkLayerWithRenderSurfaceLayerListId(render_surface_layer_list->back(), 0); | |
| 1180 | |
| 1144 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); | 1181 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); |
| 1145 render_surface_layer_list->pop_back(); | 1182 render_surface_layer_list->pop_back(); |
| 1146 } | 1183 } |
| 1147 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); | 1184 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); |
| 1185 MarkLayerListWithRenderSurfaceLayerListId( | |
| 1186 &layer_to_remove->render_surface()->layer_list(), 0); | |
| 1187 MarkLayerWithRenderSurfaceLayerListId(layer_to_remove, 0); | |
| 1148 render_surface_layer_list->pop_back(); | 1188 render_surface_layer_list->pop_back(); |
| 1149 layer_to_remove->ClearRenderSurfaceLayerList(); | 1189 layer_to_remove->ClearRenderSurfaceLayerList(); |
| 1150 } | 1190 } |
| 1151 | 1191 |
| 1152 struct PreCalculateMetaInformationRecursiveData { | 1192 struct PreCalculateMetaInformationRecursiveData { |
| 1153 bool layer_or_descendant_has_copy_request; | 1193 bool layer_or_descendant_has_copy_request; |
| 1154 int num_unclipped_descendants; | 1194 int num_unclipped_descendants; |
| 1155 | 1195 |
| 1156 PreCalculateMetaInformationRecursiveData() | 1196 PreCalculateMetaInformationRecursiveData() |
| 1157 : layer_or_descendant_has_copy_request(false), | 1197 : layer_or_descendant_has_copy_request(false), |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1416 | 1456 |
| 1417 // Recursively walks the layer tree starting at the given node and computes all | 1457 // Recursively walks the layer tree starting at the given node and computes all |
| 1418 // the necessary transformations, clip rects, render surfaces, etc. | 1458 // the necessary transformations, clip rects, render surfaces, etc. |
| 1419 template <typename LayerType> | 1459 template <typename LayerType> |
| 1420 static void CalculateDrawPropertiesInternal( | 1460 static void CalculateDrawPropertiesInternal( |
| 1421 LayerType* layer, | 1461 LayerType* layer, |
| 1422 const SubtreeGlobals<LayerType>& globals, | 1462 const SubtreeGlobals<LayerType>& globals, |
| 1423 const DataForRecursion<LayerType>& data_from_ancestor, | 1463 const DataForRecursion<LayerType>& data_from_ancestor, |
| 1424 typename LayerType::RenderSurfaceListType* render_surface_layer_list, | 1464 typename LayerType::RenderSurfaceListType* render_surface_layer_list, |
| 1425 typename LayerType::LayerListType* layer_list, | 1465 typename LayerType::LayerListType* layer_list, |
| 1426 std::vector<AccumulatedSurfaceState<LayerType> >* | 1466 std::vector<AccumulatedSurfaceState<LayerType> >* accumulated_surface_state, |
| 1427 accumulated_surface_state) { | 1467 int current_render_surface_layer_list_id) { |
| 1428 // This function computes the new matrix transformations recursively for this | 1468 // This function computes the new matrix transformations recursively for this |
| 1429 // layer and all its descendants. It also computes the appropriate render | 1469 // layer and all its descendants. It also computes the appropriate render |
| 1430 // surfaces. | 1470 // surfaces. |
| 1431 // Some important points to remember: | 1471 // Some important points to remember: |
| 1432 // | 1472 // |
| 1433 // 0. Here, transforms are notated in Matrix x Vector order, and in words we | 1473 // 0. Here, transforms are notated in Matrix x Vector order, and in words we |
| 1434 // describe what the transform does from left to right. | 1474 // describe what the transform does from left to right. |
| 1435 // | 1475 // |
| 1436 // 1. In our terminology, the "layer origin" refers to the top-left corner of | 1476 // 1. In our terminology, the "layer origin" refers to the top-left corner of |
| 1437 // a layer, and the positive Y-axis points downwards. This interpretation is | 1477 // a layer, and the positive Y-axis points downwards. This interpretation is |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2004 } | 2044 } |
| 2005 | 2045 |
| 2006 typename LayerType::LayerListType& descendants = | 2046 typename LayerType::LayerListType& descendants = |
| 2007 (layer->render_surface() ? layer->render_surface()->layer_list() | 2047 (layer->render_surface() ? layer->render_surface()->layer_list() |
| 2008 : *layer_list); | 2048 : *layer_list); |
| 2009 | 2049 |
| 2010 // Any layers that are appended after this point are in the layer's subtree | 2050 // Any layers that are appended after this point are in the layer's subtree |
| 2011 // and should be included in the sorting process. | 2051 // and should be included in the sorting process. |
| 2012 size_t sorting_start_index = descendants.size(); | 2052 size_t sorting_start_index = descendants.size(); |
| 2013 | 2053 |
| 2014 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) | 2054 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) { |
| 2055 MarkLayerWithRenderSurfaceLayerListId(layer, | |
|
enne (OOO)
2014/05/07 00:12:11
This is a little weird because it also adds the ma
vmpstr
2014/05/07 17:35:58
You mean this could just be marking the layer and
enne (OOO)
2014/05/07 17:41:17
Yeah, the masks get marked twice. It's not a huge
danakj
2014/05/07 17:43:05
Ya there's really no reason to mark the masks here
| |
| 2056 current_render_surface_layer_list_id); | |
| 2015 descendants.push_back(layer); | 2057 descendants.push_back(layer); |
| 2058 } | |
| 2016 | 2059 |
| 2017 // Any layers that are appended after this point may need to be sorted if we | 2060 // Any layers that are appended after this point may need to be sorted if we |
| 2018 // visit the children out of order. | 2061 // visit the children out of order. |
| 2019 size_t render_surface_layer_list_child_sorting_start_index = | 2062 size_t render_surface_layer_list_child_sorting_start_index = |
| 2020 render_surface_layer_list->size(); | 2063 render_surface_layer_list->size(); |
| 2021 size_t layer_list_child_sorting_start_index = descendants.size(); | 2064 size_t layer_list_child_sorting_start_index = descendants.size(); |
| 2022 | 2065 |
| 2023 if (!layer->children().empty()) { | 2066 if (!layer->children().empty()) { |
| 2024 if (layer == globals.page_scale_application_layer) { | 2067 if (layer == globals.page_scale_application_layer) { |
| 2025 data_for_children.parent_matrix.Scale( | 2068 data_for_children.parent_matrix.Scale( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2065 LayerType* child = | 2108 LayerType* child = |
| 2066 layer_draw_properties.has_child_with_a_scroll_parent | 2109 layer_draw_properties.has_child_with_a_scroll_parent |
| 2067 ? sorted_children[i] | 2110 ? sorted_children[i] |
| 2068 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); | 2111 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); |
| 2069 | 2112 |
| 2070 child->draw_properties().index_of_first_descendants_addition = | 2113 child->draw_properties().index_of_first_descendants_addition = |
| 2071 descendants.size(); | 2114 descendants.size(); |
| 2072 child->draw_properties().index_of_first_render_surface_layer_list_addition = | 2115 child->draw_properties().index_of_first_render_surface_layer_list_addition = |
| 2073 render_surface_layer_list->size(); | 2116 render_surface_layer_list->size(); |
| 2074 | 2117 |
| 2075 CalculateDrawPropertiesInternal<LayerType>(child, | 2118 CalculateDrawPropertiesInternal<LayerType>( |
| 2076 globals, | 2119 child, |
| 2077 data_for_children, | 2120 globals, |
| 2078 render_surface_layer_list, | 2121 data_for_children, |
| 2079 &descendants, | 2122 render_surface_layer_list, |
| 2080 accumulated_surface_state); | 2123 &descendants, |
| 2124 accumulated_surface_state, | |
| 2125 current_render_surface_layer_list_id); | |
| 2081 if (child->render_surface() && | 2126 if (child->render_surface() && |
| 2082 !child->render_surface()->layer_list().empty() && | 2127 !child->render_surface()->layer_list().empty() && |
| 2083 !child->render_surface()->content_rect().IsEmpty()) { | 2128 !child->render_surface()->content_rect().IsEmpty()) { |
| 2129 // This child will contribute its render surface, which means | |
| 2130 // we need to mark just the mask layer (and replica mask layer) | |
| 2131 // with the id. | |
| 2132 if (child->mask_layer()) { | |
| 2133 MarkLayerWithRenderSurfaceLayerListId( | |
| 2134 child->mask_layer(), current_render_surface_layer_list_id); | |
| 2135 } | |
| 2136 if (child->replica_layer() && child->replica_layer()->mask_layer()) { | |
| 2137 MarkLayerWithRenderSurfaceLayerListId( | |
| 2138 child->replica_layer()->mask_layer(), | |
| 2139 current_render_surface_layer_list_id); | |
| 2140 } | |
| 2084 descendants.push_back(child); | 2141 descendants.push_back(child); |
| 2085 } | 2142 } |
| 2086 | 2143 |
| 2087 child->draw_properties().num_descendants_added = | 2144 child->draw_properties().num_descendants_added = |
| 2088 descendants.size() - | 2145 descendants.size() - |
| 2089 child->draw_properties().index_of_first_descendants_addition; | 2146 child->draw_properties().index_of_first_descendants_addition; |
| 2090 child->draw_properties().num_render_surfaces_added = | 2147 child->draw_properties().num_render_surfaces_added = |
| 2091 render_surface_layer_list->size() - | 2148 render_surface_layer_list->size() - |
| 2092 child->draw_properties() | 2149 child->draw_properties() |
| 2093 .index_of_first_render_surface_layer_list_addition; | 2150 .index_of_first_render_surface_layer_list_addition; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2321 void LayerTreeHostCommon::CalculateDrawProperties( | 2378 void LayerTreeHostCommon::CalculateDrawProperties( |
| 2322 CalcDrawPropsMainInputs* inputs) { | 2379 CalcDrawPropsMainInputs* inputs) { |
| 2323 LayerList dummy_layer_list; | 2380 LayerList dummy_layer_list; |
| 2324 SubtreeGlobals<Layer> globals; | 2381 SubtreeGlobals<Layer> globals; |
| 2325 DataForRecursion<Layer> data_for_recursion; | 2382 DataForRecursion<Layer> data_for_recursion; |
| 2326 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2383 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
| 2327 | 2384 |
| 2328 PreCalculateMetaInformationRecursiveData recursive_data; | 2385 PreCalculateMetaInformationRecursiveData recursive_data; |
| 2329 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2386 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
| 2330 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; | 2387 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; |
| 2331 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer, | 2388 CalculateDrawPropertiesInternal<Layer>( |
| 2332 globals, | 2389 inputs->root_layer, |
| 2333 data_for_recursion, | 2390 globals, |
| 2334 inputs->render_surface_layer_list, | 2391 data_for_recursion, |
| 2335 &dummy_layer_list, | 2392 inputs->render_surface_layer_list, |
| 2336 &accumulated_surface_state); | 2393 &dummy_layer_list, |
| 2394 &accumulated_surface_state, | |
| 2395 inputs->current_render_surface_layer_list_id); | |
| 2337 | 2396 |
| 2338 // The dummy layer list should not have been used. | 2397 // The dummy layer list should not have been used. |
| 2339 DCHECK_EQ(0u, dummy_layer_list.size()); | 2398 DCHECK_EQ(0u, dummy_layer_list.size()); |
| 2340 // A root layer render_surface should always exist after | 2399 // A root layer render_surface should always exist after |
| 2341 // CalculateDrawProperties. | 2400 // CalculateDrawProperties. |
| 2342 DCHECK(inputs->root_layer->render_surface()); | 2401 DCHECK(inputs->root_layer->render_surface()); |
| 2343 } | 2402 } |
| 2344 | 2403 |
| 2345 void LayerTreeHostCommon::CalculateDrawProperties( | 2404 void LayerTreeHostCommon::CalculateDrawProperties( |
| 2346 CalcDrawPropsImplInputs* inputs) { | 2405 CalcDrawPropsImplInputs* inputs) { |
| 2347 LayerImplList dummy_layer_list; | 2406 LayerImplList dummy_layer_list; |
| 2348 SubtreeGlobals<LayerImpl> globals; | 2407 SubtreeGlobals<LayerImpl> globals; |
| 2349 DataForRecursion<LayerImpl> data_for_recursion; | 2408 DataForRecursion<LayerImpl> data_for_recursion; |
| 2350 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2409 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
| 2351 | 2410 |
| 2352 LayerSorter layer_sorter; | 2411 LayerSorter layer_sorter; |
| 2353 globals.layer_sorter = &layer_sorter; | 2412 globals.layer_sorter = &layer_sorter; |
| 2354 | 2413 |
| 2355 PreCalculateMetaInformationRecursiveData recursive_data; | 2414 PreCalculateMetaInformationRecursiveData recursive_data; |
| 2356 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2415 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
| 2357 std::vector<AccumulatedSurfaceState<LayerImpl> > | 2416 std::vector<AccumulatedSurfaceState<LayerImpl> > |
| 2358 accumulated_surface_state; | 2417 accumulated_surface_state; |
| 2359 CalculateDrawPropertiesInternal<LayerImpl>(inputs->root_layer, | 2418 CalculateDrawPropertiesInternal<LayerImpl>( |
| 2360 globals, | 2419 inputs->root_layer, |
| 2361 data_for_recursion, | 2420 globals, |
| 2362 inputs->render_surface_layer_list, | 2421 data_for_recursion, |
| 2363 &dummy_layer_list, | 2422 inputs->render_surface_layer_list, |
| 2364 &accumulated_surface_state); | 2423 &dummy_layer_list, |
| 2424 &accumulated_surface_state, | |
| 2425 inputs->current_render_surface_layer_list_id); | |
| 2365 | 2426 |
| 2366 // The dummy layer list should not have been used. | 2427 // The dummy layer list should not have been used. |
| 2367 DCHECK_EQ(0u, dummy_layer_list.size()); | 2428 DCHECK_EQ(0u, dummy_layer_list.size()); |
| 2368 // A root layer render_surface should always exist after | 2429 // A root layer render_surface should always exist after |
| 2369 // CalculateDrawProperties. | 2430 // CalculateDrawProperties. |
| 2370 DCHECK(inputs->root_layer->render_surface()); | 2431 DCHECK(inputs->root_layer->render_surface()); |
| 2371 } | 2432 } |
| 2372 | 2433 |
| 2373 static bool PointHitsRect( | 2434 static bool PointHitsRect( |
| 2374 const gfx::PointF& screen_space_point, | 2435 const gfx::PointF& screen_space_point, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2580 // At this point, we think the point does hit the touch event handler region | 2641 // At this point, we think the point does hit the touch event handler region |
| 2581 // on the layer, but we need to walk up the parents to ensure that the layer | 2642 // on the layer, but we need to walk up the parents to ensure that the layer |
| 2582 // was not clipped in such a way that the hit point actually should not hit | 2643 // was not clipped in such a way that the hit point actually should not hit |
| 2583 // the layer. | 2644 // the layer. |
| 2584 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 2645 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
| 2585 return false; | 2646 return false; |
| 2586 | 2647 |
| 2587 return true; | 2648 return true; |
| 2588 } | 2649 } |
| 2589 } // namespace cc | 2650 } // namespace cc |
| OLD | NEW |