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