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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // CalculateDrawPropertiesInternal. If we, say, create a render surface, these | 195 // CalculateDrawPropertiesInternal. If we, say, create a render surface, these |
196 // clip rects will want to be in its target space, not ours. | 196 // clip rects will want to be in its target space, not ours. |
197 if (clip_parent == layer->clip_parent()) { | 197 if (clip_parent == layer->clip_parent()) { |
198 *clip_rect_in_parent_target_space = TranslateRectToTargetSpace<LayerType>( | 198 *clip_rect_in_parent_target_space = TranslateRectToTargetSpace<LayerType>( |
199 *clip_parent, | 199 *clip_parent, |
200 *layer->parent(), | 200 *layer->parent(), |
201 *clip_rect_in_parent_target_space, | 201 *clip_rect_in_parent_target_space, |
202 TranslateRectDirectionToDescendant); | 202 TranslateRectDirectionToDescendant); |
203 } else { | 203 } else { |
204 // If we're being clipped by our scroll parent, we must translate through | 204 // If we're being clipped by our scroll parent, we must translate through |
205 // our common ancestor. | 205 // our common ancestor. This happens to be our parent, so it is sufficent to |
206 const LayerType* lca = | 206 // translate from our clip parent's space to the space of its ancestor (our |
207 HighestScrollParentAncestorNotOnChildAncestorChain( | 207 // parent). |
208 layer->draw_properties().sequence_number, layer, clip_parent) | |
209 ->parent(); | |
210 | |
211 *clip_rect_in_parent_target_space = | 208 *clip_rect_in_parent_target_space = |
212 TranslateRectToTargetSpace<LayerType>(*lca, | 209 TranslateRectToTargetSpace<LayerType>(*layer->parent(), |
213 *clip_parent, | 210 *clip_parent, |
214 *clip_rect_in_parent_target_space, | 211 *clip_rect_in_parent_target_space, |
215 TranslateRectDirectionToAncestor); | 212 TranslateRectDirectionToAncestor); |
216 | |
217 // The lowest common ancestor is usually, but not always, our parent. We | |
218 // must check if we need to transform from the lca's space to our parent's. | |
219 if (lca != layer->parent()) { | |
220 *clip_rect_in_parent_target_space = TranslateRectToTargetSpace<LayerType>( | |
221 *lca, | |
222 *layer->parent(), | |
223 *clip_rect_in_parent_target_space, | |
224 TranslateRectDirectionToDescendant); | |
225 } | |
226 } | 213 } |
227 } | 214 } |
228 | 215 |
229 // We collect an accumulated drawable content rect per render surface. | 216 // We collect an accumulated drawable content rect per render surface. |
230 // Typically, a layer will contribute to only one surface, the surface | 217 // Typically, a layer will contribute to only one surface, the surface |
231 // associated with its render target. Clip children, however, may affect | 218 // associated with its render target. Clip children, however, may affect |
232 // several surfaces since there may be several surfaces between the clip child | 219 // several surfaces since there may be several surfaces between the clip child |
233 // and its parent. | 220 // and its parent. |
234 // | 221 // |
235 // NB: we accumulate the layer's *clipped* drawable content rect. | 222 // NB: we accumulate the layer's *clipped* drawable content rect. |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 it != layer_list->end(); | 1148 it != layer_list->end(); |
1162 ++it) { | 1149 ++it) { |
1163 MarkLayerWithRenderSurfaceLayerListId(*it, | 1150 MarkLayerWithRenderSurfaceLayerListId(*it, |
1164 current_render_surface_layer_list_id); | 1151 current_render_surface_layer_list_id); |
1165 MarkMasksWithRenderSurfaceLayerListId(*it, | 1152 MarkMasksWithRenderSurfaceLayerListId(*it, |
1166 current_render_surface_layer_list_id); | 1153 current_render_surface_layer_list_id); |
1167 } | 1154 } |
1168 } | 1155 } |
1169 | 1156 |
1170 template <typename LayerType> | 1157 template <typename LayerType> |
1171 static inline bool HaveVisited(LayerType* layer, int sequence_number) { | |
1172 return layer->draw_properties().sequence_number == sequence_number; | |
1173 } | |
1174 | |
1175 template <typename LayerType> | |
1176 static inline bool HaveAssignedSortWeight(LayerType* layer, | |
1177 int sequence_number) { | |
1178 return layer->draw_properties().sort_weight_sequence_number == | |
1179 sequence_number; | |
1180 } | |
1181 | |
1182 template <typename LayerType> | |
1183 static inline void RemoveSurfaceForEarlyExit( | 1158 static inline void RemoveSurfaceForEarlyExit( |
1184 LayerType* layer_to_remove, | 1159 LayerType* layer_to_remove, |
1185 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { | 1160 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { |
1186 DCHECK(layer_to_remove->render_surface()); | 1161 DCHECK(layer_to_remove->render_surface()); |
1187 // Technically, we know that the layer we want to remove should be | 1162 // Technically, we know that the layer we want to remove should be |
1188 // at the back of the render_surface_layer_list. However, we have had | 1163 // at the back of the render_surface_layer_list. However, we have had |
1189 // bugs before that added unnecessary layers here | 1164 // bugs before that added unnecessary layers here |
1190 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes | 1165 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes |
1191 // things to crash. So here we proactively remove any additional | 1166 // things to crash. So here we proactively remove any additional |
1192 // layers from the end of the list. | 1167 // layers from the end of the list. |
1193 while (render_surface_layer_list->back() != layer_to_remove) { | 1168 while (render_surface_layer_list->back() != layer_to_remove) { |
1194 MarkLayerListWithRenderSurfaceLayerListId( | 1169 MarkLayerListWithRenderSurfaceLayerListId( |
1195 &render_surface_layer_list->back()->render_surface()->layer_list(), 0); | 1170 &render_surface_layer_list->back()->render_surface()->layer_list(), 0); |
1196 MarkLayerWithRenderSurfaceLayerListId(render_surface_layer_list->back(), 0); | 1171 MarkLayerWithRenderSurfaceLayerListId(render_surface_layer_list->back(), 0); |
1197 | 1172 |
1198 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); | 1173 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); |
1199 render_surface_layer_list->pop_back(); | 1174 render_surface_layer_list->pop_back(); |
1200 } | 1175 } |
1201 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); | 1176 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); |
1202 MarkLayerListWithRenderSurfaceLayerListId( | 1177 MarkLayerListWithRenderSurfaceLayerListId( |
1203 &layer_to_remove->render_surface()->layer_list(), 0); | 1178 &layer_to_remove->render_surface()->layer_list(), 0); |
1204 MarkLayerWithRenderSurfaceLayerListId(layer_to_remove, 0); | 1179 MarkLayerWithRenderSurfaceLayerListId(layer_to_remove, 0); |
1205 render_surface_layer_list->pop_back(); | 1180 render_surface_layer_list->pop_back(); |
1206 layer_to_remove->ClearRenderSurfaceLayerList(); | 1181 layer_to_remove->ClearRenderSurfaceLayerList(); |
1207 } | 1182 } |
1208 | 1183 |
1209 template <typename LayerType> | |
1210 static inline LayerType* HighestScrollParentAncestorNotOnChildAncestorChain( | |
1211 int sequence_number, | |
1212 LayerType* scroll_child, | |
1213 LayerType* scroll_parent) { | |
1214 // Say we have the following tree. | |
1215 // | |
1216 // a | |
1217 // +-b | |
1218 // | +-c | |
1219 // | +-scroll_child | |
1220 // +-d | |
1221 // +-e | |
1222 // +-scroll_parent | |
1223 // | |
1224 // This function aims to find find the highest ancestor of |scroll_parent| | |
1225 // that's not on |scroll_child|'s ancestor chain. d, in this case. | |
1226 // | |
1227 // Fortunately, we have some hints that make finding the lowest common | |
1228 // ancestor a bit easier than usual. We know if we've visited a layer, and for | |
1229 // those layers that we've visited, we know their depth in the tree. | |
1230 if (!HaveVisited(scroll_parent, sequence_number)) { | |
1231 DCHECK(scroll_parent->parent()); | |
1232 // This case is easy. Since we walk the tree in DFS order, if we haven't | |
1233 // visited the scroll parent, we just have to walk up to the first visited | |
1234 // layer, which will be the LCA. | |
1235 while (!HaveVisited(scroll_parent->parent(), sequence_number)) | |
1236 scroll_parent = scroll_parent->parent(); | |
1237 // This would mean that |scroll_parent| is a descendant of |scroll_child|, | |
1238 // which is an error. | |
1239 DCHECK_NE(scroll_child, scroll_parent->parent()); | |
1240 } else { | |
1241 // In this case, we've visited both the scroll_parent and scroll_child, so | |
1242 // it's not as easy as walking to the first visited ancestor of the scroll | |
1243 // parent. But since we've visited the layers, we know their depths, and we | |
1244 // can efficiently find the LCA by walking up nodes at the same height. | |
1245 | |
1246 // First, walk up from the deeper layer until we reach two layers at the | |
1247 // same depth in the tree. | |
1248 while (scroll_child->draw_properties().depth != | |
1249 scroll_parent->draw_properties().depth) { | |
1250 int child_is_deeper = scroll_child->draw_properties().depth > | |
1251 scroll_parent->draw_properties().depth; | |
1252 if (child_is_deeper) | |
1253 scroll_child = scroll_child->parent(); | |
1254 else | |
1255 scroll_parent = scroll_parent->parent(); | |
1256 } | |
1257 | |
1258 // This would only happen if |scroll_child| and |scroll_parent| were on the | |
1259 // same ancestor chain, which is an error. We only ever set up scroll parent | |
1260 // scroll child relationships if scroll child is not a descendant of the | |
1261 // scroll parent and will therefore not scroll with it naturally and needs | |
1262 // special treatment by the compositor. | |
1263 DCHECK_NE(scroll_child, scroll_parent); | |
1264 | |
1265 // Now that scroll_child and scroll_parent are at the same depth, we can | |
1266 // walk up in tandem to find the LCA. | |
1267 while (scroll_child->parent() != scroll_parent->parent()) { | |
1268 scroll_child = scroll_child->parent(); | |
1269 scroll_parent = scroll_parent->parent(); | |
1270 } | |
1271 } | |
1272 | |
1273 return scroll_parent; | |
1274 } | |
1275 | |
1276 struct PreCalculateMetaInformationRecursiveData { | 1184 struct PreCalculateMetaInformationRecursiveData { |
1277 bool layer_or_descendant_has_copy_request; | 1185 bool layer_or_descendant_has_copy_request; |
1278 bool layer_or_descendant_has_input_handler; | 1186 bool layer_or_descendant_has_input_handler; |
1279 int num_unclipped_descendants; | 1187 int num_unclipped_descendants; |
1280 | 1188 |
1281 PreCalculateMetaInformationRecursiveData() | 1189 PreCalculateMetaInformationRecursiveData() |
1282 : layer_or_descendant_has_copy_request(false), | 1190 : layer_or_descendant_has_copy_request(false), |
1283 layer_or_descendant_has_input_handler(false), | 1191 layer_or_descendant_has_input_handler(false), |
1284 num_unclipped_descendants(0) {} | 1192 num_unclipped_descendants(0) {} |
1285 | 1193 |
1286 void Merge(const PreCalculateMetaInformationRecursiveData& data) { | 1194 void Merge(const PreCalculateMetaInformationRecursiveData& data) { |
1287 layer_or_descendant_has_copy_request |= | 1195 layer_or_descendant_has_copy_request |= |
1288 data.layer_or_descendant_has_copy_request; | 1196 data.layer_or_descendant_has_copy_request; |
1289 layer_or_descendant_has_input_handler |= | 1197 layer_or_descendant_has_input_handler |= |
1290 data.layer_or_descendant_has_input_handler; | 1198 data.layer_or_descendant_has_input_handler; |
1291 num_unclipped_descendants += | 1199 num_unclipped_descendants += |
1292 data.num_unclipped_descendants; | 1200 data.num_unclipped_descendants; |
1293 } | 1201 } |
1294 }; | 1202 }; |
1295 | 1203 |
1296 static int next_sort_weight(int* last_sort_weight) { | |
1297 return ++(*last_sort_weight); | |
1298 } | |
1299 | |
1300 template <typename LayerType> | |
1301 static inline void AssignSortWeights(LayerType* layer, | |
1302 int sequence_number, | |
1303 int* last_sort_weight) { | |
1304 // Give |layer| the highest sort weight in the tree so far. | |
1305 if (!HaveAssignedSortWeight(layer, sequence_number)) { | |
1306 layer->draw_properties().sort_weight = next_sort_weight(last_sort_weight); | |
1307 layer->draw_properties().sort_weight_sequence_number = sequence_number; | |
1308 } | |
1309 | |
1310 if (LayerType* scroll_parent = layer->scroll_parent()) { | |
1311 // It's important to note where we need to take care of ordering so that | |
1312 // scroll parents are visited before scroll children; it's at their lowest | |
1313 // common ancestor. | |
1314 // | |
1315 // LCA | |
1316 // +-scroll_parent_ancestor | |
1317 // | +- ... | |
1318 // | + scroll_parent | |
1319 // | | |
1320 // +-scroll_child_ancestor | |
1321 // +- .. | |
1322 // + scroll_child | |
1323 // | |
1324 // So given the above tree, we need to guarentee that scroll_parent_ancestor | |
1325 // is processed before scroll_child. We ensure that by assigning it the | |
1326 // lowest sort weight in the tree. We also want to flag LCA if we need to do | |
1327 // any funny business with sort weights so that it knows to do special | |
1328 // sorting of its descendants. | |
1329 LayerType* scroll_parent_ancestor = | |
1330 HighestScrollParentAncestorNotOnChildAncestorChain( | |
1331 sequence_number, layer, scroll_parent); | |
1332 | |
1333 // We know we need to reorder if we haven't yet assigned | |
1334 // |scroll_parent_ancestor| a sort weight. Sort weights are monotonically | |
1335 // increasing, so unless we intervene, it will be given a higher sort weight | |
1336 // than |layer|. | |
1337 bool need_to_reorder = | |
1338 !HaveAssignedSortWeight(scroll_parent_ancestor, sequence_number); | |
1339 | |
1340 LayerType* lca = scroll_parent_ancestor->parent(); | |
1341 | |
1342 // We also might need to reorder if scroll_parent_ancestor has been visited | |
1343 // and has an unacceptable sort weight. | |
1344 if (!need_to_reorder) { | |
1345 LayerType* scroll_child_ancestor = layer; | |
1346 while (scroll_child_ancestor->parent() && | |
1347 scroll_child_ancestor->parent() != lca) { | |
1348 scroll_child_ancestor = scroll_child_ancestor->parent(); | |
1349 } | |
1350 // We must have assigned a sort weight to this layer since its on our | |
1351 // ancestor chain. | |
1352 DCHECK(HaveAssignedSortWeight(scroll_child_ancestor, sequence_number)); | |
1353 if (scroll_child_ancestor->draw_properties().sort_weight < | |
1354 scroll_parent_ancestor->draw_properties().sort_weight) | |
1355 need_to_reorder = true; | |
1356 } | |
1357 | |
1358 if (need_to_reorder) { | |
1359 // Give |scroll_parent_ancestor| the lowest weight in the tree so far. | |
1360 scroll_parent_ancestor->draw_properties().sort_weight = | |
1361 -next_sort_weight(last_sort_weight); | |
1362 scroll_parent_ancestor->draw_properties().sort_weight_sequence_number = | |
1363 sequence_number; | |
1364 | |
1365 // Mark the LCA as needing to sort. | |
1366 lca->draw_properties().children_need_sorting = true; | |
1367 } | |
1368 } | |
1369 } | |
1370 | |
1371 // Recursively walks the layer tree to compute any information that is needed | 1204 // Recursively walks the layer tree to compute any information that is needed |
1372 // before doing the main recursion. | 1205 // before doing the main recursion. |
1373 template <typename LayerType> | 1206 template <typename LayerType> |
1374 static void PreCalculateMetaInformation( | 1207 static void PreCalculateMetaInformation( |
1375 LayerType* layer, | 1208 LayerType* layer, |
1376 PreCalculateMetaInformationRecursiveData* recursive_data, | 1209 PreCalculateMetaInformationRecursiveData* recursive_data) { |
1377 int depth, | 1210 |
1378 int sequence_number, | 1211 layer->draw_properties().sorted_for_recursion = false; |
1379 int* last_sort_weight) { | 1212 layer->draw_properties().has_child_with_a_scroll_parent = false; |
1380 layer->draw_properties().children_need_sorting = false; | |
1381 layer->draw_properties().depth = depth; | |
1382 layer->draw_properties().sequence_number = sequence_number; | |
1383 | 1213 |
1384 if (!HasInvertibleOrAnimatedTransform(layer)) { | 1214 if (!HasInvertibleOrAnimatedTransform(layer)) { |
1385 // Layers with singular transforms should not be drawn, the whole subtree | 1215 // Layers with singular transforms should not be drawn, the whole subtree |
1386 // can be skipped. | 1216 // can be skipped. |
1387 return; | 1217 return; |
1388 } | 1218 } |
1389 | 1219 |
1390 if (layer->clip_parent()) | 1220 if (layer->clip_parent()) |
1391 recursive_data->num_unclipped_descendants++; | 1221 recursive_data->num_unclipped_descendants++; |
1392 | 1222 |
1393 AssignSortWeights(layer, sequence_number, last_sort_weight); | |
1394 | |
1395 for (size_t i = 0; i < layer->children().size(); ++i) { | 1223 for (size_t i = 0; i < layer->children().size(); ++i) { |
1396 LayerType* child_layer = | 1224 LayerType* child_layer = |
1397 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); | 1225 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); |
| 1226 |
1398 PreCalculateMetaInformationRecursiveData data_for_child; | 1227 PreCalculateMetaInformationRecursiveData data_for_child; |
1399 PreCalculateMetaInformation(child_layer, | 1228 PreCalculateMetaInformation(child_layer, &data_for_child); |
1400 &data_for_child, | 1229 |
1401 depth + 1, | 1230 if (child_layer->scroll_parent()) |
1402 sequence_number, | 1231 layer->draw_properties().has_child_with_a_scroll_parent = true; |
1403 last_sort_weight); | |
1404 recursive_data->Merge(data_for_child); | 1232 recursive_data->Merge(data_for_child); |
1405 } | 1233 } |
1406 | 1234 |
1407 if (layer->clip_children()) { | 1235 if (layer->clip_children()) { |
1408 int num_clip_children = layer->clip_children()->size(); | 1236 int num_clip_children = layer->clip_children()->size(); |
1409 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); | 1237 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); |
1410 recursive_data->num_unclipped_descendants -= num_clip_children; | 1238 recursive_data->num_unclipped_descendants -= num_clip_children; |
1411 } | 1239 } |
1412 | 1240 |
1413 if (layer->HasCopyRequest()) | 1241 if (layer->HasCopyRequest()) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 bool ancestor_is_animating_scale; | 1308 bool ancestor_is_animating_scale; |
1481 bool ancestor_clips_subtree; | 1309 bool ancestor_clips_subtree; |
1482 typename LayerType::RenderSurfaceType* | 1310 typename LayerType::RenderSurfaceType* |
1483 nearest_occlusion_immune_ancestor_surface; | 1311 nearest_occlusion_immune_ancestor_surface; |
1484 bool in_subtree_of_page_scale_application_layer; | 1312 bool in_subtree_of_page_scale_application_layer; |
1485 bool subtree_can_use_lcd_text; | 1313 bool subtree_can_use_lcd_text; |
1486 bool subtree_is_visible_from_ancestor; | 1314 bool subtree_is_visible_from_ancestor; |
1487 }; | 1315 }; |
1488 | 1316 |
1489 template <typename LayerType> | 1317 template <typename LayerType> |
1490 struct AscendingScrollWeightComparator { | 1318 static LayerType* GetChildContainingLayer(const LayerType& parent, |
1491 bool operator()(LayerType* lhs, LayerType* rhs) { | 1319 LayerType* layer) { |
1492 return lhs->draw_properties().sort_weight < | 1320 for (LayerType* ancestor = layer; ancestor; ancestor = ancestor->parent()) { |
1493 rhs->draw_properties().sort_weight; | 1321 if (ancestor->parent() == &parent) |
| 1322 return ancestor; |
1494 } | 1323 } |
1495 }; | 1324 NOTREACHED(); |
1496 | 1325 return 0; |
1497 template <typename LayerType> | |
1498 static void SortChildrenForRecursion(std::vector<LayerType*>* out, | |
1499 const LayerType& parent) { | |
1500 out->resize(parent.children().size()); | |
1501 for (size_t i = 0; i < parent.children().size(); ++i) | |
1502 (*out)[i] = LayerTreeHostCommon::get_layer_as_raw_ptr(parent.children(), i); | |
1503 | |
1504 // Ensures the children are sorted in ascending sort weight. | |
1505 std::sort( | |
1506 out->begin(), out->end(), AscendingScrollWeightComparator<LayerType>()); | |
1507 } | 1326 } |
1508 | 1327 |
1509 template <typename LayerType> | 1328 template <typename LayerType> |
| 1329 static void AddScrollParentChain(std::vector<LayerType*>* out, |
| 1330 const LayerType& parent, |
| 1331 LayerType* layer) { |
| 1332 // At a high level, this function walks up the chain of scroll parents |
| 1333 // recursively, and once we reach the end of the chain, we add the child |
| 1334 // of |parent| containing each scroll ancestor as we unwind. The result is |
| 1335 // an ordering of parent's children that ensures that scroll parents are |
| 1336 // visited before their descendants. |
| 1337 // Take for example this layer tree: |
| 1338 // |
| 1339 // + stacking_context |
| 1340 // + scroll_child (1) |
| 1341 // + scroll_parent_graphics_layer (*) |
| 1342 // | + scroll_parent_scrolling_layer |
| 1343 // | + scroll_parent_scrolling_content_layer (2) |
| 1344 // + scroll_grandparent_graphics_layer (**) |
| 1345 // + scroll_grandparent_scrolling_layer |
| 1346 // + scroll_grandparent_scrolling_content_layer (3) |
| 1347 // |
| 1348 // The scroll child is (1), its scroll parent is (2) and its scroll |
| 1349 // grandparent is (3). Note, this doesn't mean that (2)'s scroll parent is |
| 1350 // (3), it means that (*)'s scroll parent is (3). We don't want our list to |
| 1351 // look like [ (3), (2), (1) ], even though that does have the ancestor chain |
| 1352 // in the right order. Instead, we want [ (**), (*), (1) ]. That is, only want |
| 1353 // (1)'s siblings in the list, but we want them to appear in such an order |
| 1354 // that the scroll ancestors get visited in the correct order. |
| 1355 // |
| 1356 // So our first task at this step of the recursion is to determine the layer |
| 1357 // that we will potentionally add to the list. That is, the child of parent |
| 1358 // containing |layer|. |
| 1359 LayerType* child = GetChildContainingLayer(parent, layer); |
| 1360 if (child->draw_properties().sorted_for_recursion) |
| 1361 return; |
| 1362 |
| 1363 if (LayerType* scroll_parent = child->scroll_parent()) |
| 1364 AddScrollParentChain(out, parent, scroll_parent); |
| 1365 |
| 1366 out->push_back(child); |
| 1367 child->draw_properties().sorted_for_recursion = true; |
| 1368 } |
| 1369 |
| 1370 template <typename LayerType> |
| 1371 static bool SortChildrenForRecursion(std::vector<LayerType*>* out, |
| 1372 const LayerType& parent) { |
| 1373 out->reserve(parent.children().size()); |
| 1374 bool order_changed = false; |
| 1375 for (size_t i = 0; i < parent.children().size(); ++i) { |
| 1376 LayerType* current = |
| 1377 LayerTreeHostCommon::get_layer_as_raw_ptr(parent.children(), i); |
| 1378 |
| 1379 if (current->draw_properties().sorted_for_recursion) { |
| 1380 order_changed = true; |
| 1381 continue; |
| 1382 } |
| 1383 |
| 1384 AddScrollParentChain(out, parent, current); |
| 1385 } |
| 1386 |
| 1387 DCHECK_EQ(parent.children().size(), out->size()); |
| 1388 return order_changed; |
| 1389 } |
| 1390 |
| 1391 template <typename LayerType> |
1510 static void GetNewDescendantsStartIndexAndCount(LayerType* layer, | 1392 static void GetNewDescendantsStartIndexAndCount(LayerType* layer, |
1511 size_t* start_index, | 1393 size_t* start_index, |
1512 size_t* count) { | 1394 size_t* count) { |
1513 *start_index = layer->draw_properties().index_of_first_descendants_addition; | 1395 *start_index = layer->draw_properties().index_of_first_descendants_addition; |
1514 *count = layer->draw_properties().num_descendants_added; | 1396 *count = layer->draw_properties().num_descendants_added; |
1515 } | 1397 } |
1516 | 1398 |
1517 template <typename LayerType> | 1399 template <typename LayerType> |
1518 static void GetNewRenderSurfacesStartIndexAndCount(LayerType* layer, | 1400 static void GetNewRenderSurfacesStartIndexAndCount(LayerType* layer, |
1519 size_t* start_index, | 1401 size_t* start_index, |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2222 data_for_children.clip_rect_of_target_surface_in_target_space = | 2104 data_for_children.clip_rect_of_target_surface_in_target_space = |
2223 clip_rect_of_target_surface_in_target_space; | 2105 clip_rect_of_target_surface_in_target_space; |
2224 data_for_children.ancestor_clips_subtree = | 2106 data_for_children.ancestor_clips_subtree = |
2225 layer_or_ancestor_clips_descendants; | 2107 layer_or_ancestor_clips_descendants; |
2226 data_for_children.nearest_occlusion_immune_ancestor_surface = | 2108 data_for_children.nearest_occlusion_immune_ancestor_surface = |
2227 nearest_occlusion_immune_ancestor_surface; | 2109 nearest_occlusion_immune_ancestor_surface; |
2228 data_for_children.subtree_is_visible_from_ancestor = layer_is_drawn; | 2110 data_for_children.subtree_is_visible_from_ancestor = layer_is_drawn; |
2229 } | 2111 } |
2230 | 2112 |
2231 std::vector<LayerType*> sorted_children; | 2113 std::vector<LayerType*> sorted_children; |
2232 if (layer_draw_properties.children_need_sorting) | 2114 bool child_order_changed = false; |
2233 SortChildrenForRecursion(&sorted_children, *layer); | 2115 if (layer_draw_properties.has_child_with_a_scroll_parent) |
| 2116 child_order_changed = SortChildrenForRecursion(&sorted_children, *layer); |
2234 | 2117 |
2235 for (size_t i = 0; i < layer->children().size(); ++i) { | 2118 for (size_t i = 0; i < layer->children().size(); ++i) { |
2236 // If one of layer's children has a scroll parent, then we may have to | 2119 // If one of layer's children has a scroll parent, then we may have to |
2237 // visit the children out of order. The new order is stored in | 2120 // visit the children out of order. The new order is stored in |
2238 // sorted_children. Otherwise, we'll grab the child directly from the | 2121 // sorted_children. Otherwise, we'll grab the child directly from the |
2239 // layer's list of children. | 2122 // layer's list of children. |
2240 LayerType* child = | 2123 LayerType* child = |
2241 layer_draw_properties.children_need_sorting | 2124 layer_draw_properties.has_child_with_a_scroll_parent |
2242 ? sorted_children[i] | 2125 ? sorted_children[i] |
2243 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); | 2126 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); |
2244 | 2127 |
2245 child->draw_properties().index_of_first_descendants_addition = | 2128 child->draw_properties().index_of_first_descendants_addition = |
2246 descendants.size(); | 2129 descendants.size(); |
2247 child->draw_properties().index_of_first_render_surface_layer_list_addition = | 2130 child->draw_properties().index_of_first_render_surface_layer_list_addition = |
2248 render_surface_layer_list->size(); | 2131 render_surface_layer_list->size(); |
2249 | 2132 |
2250 CalculateDrawPropertiesInternal<LayerType>( | 2133 CalculateDrawPropertiesInternal<LayerType>( |
2251 child, | 2134 child, |
(...skipping 17 matching lines...) Expand all Loading... |
2269 child->draw_properties().num_descendants_added = | 2152 child->draw_properties().num_descendants_added = |
2270 descendants.size() - | 2153 descendants.size() - |
2271 child->draw_properties().index_of_first_descendants_addition; | 2154 child->draw_properties().index_of_first_descendants_addition; |
2272 child->draw_properties().num_render_surfaces_added = | 2155 child->draw_properties().num_render_surfaces_added = |
2273 render_surface_layer_list->size() - | 2156 render_surface_layer_list->size() - |
2274 child->draw_properties() | 2157 child->draw_properties() |
2275 .index_of_first_render_surface_layer_list_addition; | 2158 .index_of_first_render_surface_layer_list_addition; |
2276 } | 2159 } |
2277 | 2160 |
2278 // Add the unsorted layer list contributions, if necessary. | 2161 // Add the unsorted layer list contributions, if necessary. |
2279 if (layer_draw_properties.children_need_sorting) { | 2162 if (child_order_changed) { |
2280 SortLayerListContributions( | 2163 SortLayerListContributions( |
2281 *layer, | 2164 *layer, |
2282 GetLayerListForSorting(render_surface_layer_list), | 2165 GetLayerListForSorting(render_surface_layer_list), |
2283 render_surface_layer_list_child_sorting_start_index, | 2166 render_surface_layer_list_child_sorting_start_index, |
2284 &GetNewRenderSurfacesStartIndexAndCount<LayerType>); | 2167 &GetNewRenderSurfacesStartIndexAndCount<LayerType>); |
2285 | 2168 |
2286 SortLayerListContributions( | 2169 SortLayerListContributions( |
2287 *layer, | 2170 *layer, |
2288 &descendants, | 2171 &descendants, |
2289 layer_list_child_sorting_start_index, | 2172 layer_list_child_sorting_start_index, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2500 data_for_recursion->subtree_is_visible_from_ancestor = true; | 2383 data_for_recursion->subtree_is_visible_from_ancestor = true; |
2501 } | 2384 } |
2502 | 2385 |
2503 void LayerTreeHostCommon::CalculateDrawProperties( | 2386 void LayerTreeHostCommon::CalculateDrawProperties( |
2504 CalcDrawPropsMainInputs* inputs) { | 2387 CalcDrawPropsMainInputs* inputs) { |
2505 LayerList dummy_layer_list; | 2388 LayerList dummy_layer_list; |
2506 SubtreeGlobals<Layer> globals; | 2389 SubtreeGlobals<Layer> globals; |
2507 DataForRecursion<Layer> data_for_recursion; | 2390 DataForRecursion<Layer> data_for_recursion; |
2508 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2391 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2509 | 2392 |
2510 // This is used as a global throughout the precalculate recursion. | |
2511 int last_sort_weight = 0; | |
2512 PreCalculateMetaInformationRecursiveData recursive_data; | 2393 PreCalculateMetaInformationRecursiveData recursive_data; |
2513 PreCalculateMetaInformation(inputs->root_layer, | 2394 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2514 &recursive_data, | |
2515 0, | |
2516 inputs->current_render_surface_layer_list_id, | |
2517 &last_sort_weight); | |
2518 | |
2519 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; | 2395 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; |
2520 CalculateDrawPropertiesInternal<Layer>( | 2396 CalculateDrawPropertiesInternal<Layer>( |
2521 inputs->root_layer, | 2397 inputs->root_layer, |
2522 globals, | 2398 globals, |
2523 data_for_recursion, | 2399 data_for_recursion, |
2524 inputs->render_surface_layer_list, | 2400 inputs->render_surface_layer_list, |
2525 &dummy_layer_list, | 2401 &dummy_layer_list, |
2526 &accumulated_surface_state, | 2402 &accumulated_surface_state, |
2527 inputs->current_render_surface_layer_list_id); | 2403 inputs->current_render_surface_layer_list_id); |
2528 | 2404 |
2529 // The dummy layer list should not have been used. | 2405 // The dummy layer list should not have been used. |
2530 DCHECK_EQ(0u, dummy_layer_list.size()); | 2406 DCHECK_EQ(0u, dummy_layer_list.size()); |
2531 // A root layer render_surface should always exist after | 2407 // A root layer render_surface should always exist after |
2532 // CalculateDrawProperties. | 2408 // CalculateDrawProperties. |
2533 DCHECK(inputs->root_layer->render_surface()); | 2409 DCHECK(inputs->root_layer->render_surface()); |
2534 } | 2410 } |
2535 | 2411 |
2536 void LayerTreeHostCommon::CalculateDrawProperties( | 2412 void LayerTreeHostCommon::CalculateDrawProperties( |
2537 CalcDrawPropsImplInputs* inputs) { | 2413 CalcDrawPropsImplInputs* inputs) { |
2538 LayerImplList dummy_layer_list; | 2414 LayerImplList dummy_layer_list; |
2539 SubtreeGlobals<LayerImpl> globals; | 2415 SubtreeGlobals<LayerImpl> globals; |
2540 DataForRecursion<LayerImpl> data_for_recursion; | 2416 DataForRecursion<LayerImpl> data_for_recursion; |
2541 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2417 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2542 | 2418 |
2543 LayerSorter layer_sorter; | 2419 LayerSorter layer_sorter; |
2544 globals.layer_sorter = &layer_sorter; | 2420 globals.layer_sorter = &layer_sorter; |
2545 | 2421 |
2546 // This is used as a global throughout the precalculate recursion. | |
2547 int last_sort_weight = 0; | |
2548 PreCalculateMetaInformationRecursiveData recursive_data; | 2422 PreCalculateMetaInformationRecursiveData recursive_data; |
2549 PreCalculateMetaInformation(inputs->root_layer, | 2423 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2550 &recursive_data, | |
2551 0, | |
2552 inputs->current_render_surface_layer_list_id, | |
2553 &last_sort_weight); | |
2554 | |
2555 std::vector<AccumulatedSurfaceState<LayerImpl> > | 2424 std::vector<AccumulatedSurfaceState<LayerImpl> > |
2556 accumulated_surface_state; | 2425 accumulated_surface_state; |
2557 CalculateDrawPropertiesInternal<LayerImpl>( | 2426 CalculateDrawPropertiesInternal<LayerImpl>( |
2558 inputs->root_layer, | 2427 inputs->root_layer, |
2559 globals, | 2428 globals, |
2560 data_for_recursion, | 2429 data_for_recursion, |
2561 inputs->render_surface_layer_list, | 2430 inputs->render_surface_layer_list, |
2562 &dummy_layer_list, | 2431 &dummy_layer_list, |
2563 &accumulated_surface_state, | 2432 &accumulated_surface_state, |
2564 inputs->current_render_surface_layer_list_id); | 2433 inputs->current_render_surface_layer_list_id); |
2565 | 2434 |
2566 // The dummy layer list should not have been used. | 2435 // The dummy layer list should not have been used. |
2567 DCHECK_EQ(0u, dummy_layer_list.size()); | 2436 DCHECK_EQ(0u, dummy_layer_list.size()); |
2568 // A root layer render_surface should always exist after | 2437 // A root layer render_surface should always exist after |
2569 // CalculateDrawProperties. | 2438 // CalculateDrawProperties. |
2570 DCHECK(inputs->root_layer->render_surface()); | 2439 DCHECK(inputs->root_layer->render_surface()); |
2571 } | 2440 } |
2572 | 2441 |
2573 } // namespace cc | 2442 } // namespace cc |
OLD | NEW |