Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 548963002: Generalize scroll parent work in CalculateDrawProperties Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // 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 }
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
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 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 get the layers to the same depth.
danakj 2014/09/11 19:22:05 nit: I think this comment was clearer before. Now
Ian Vollick 2014/09/11 19:58:08 Yeah, I've switched it up for something that's hop
1247 while (scroll_child->draw_properties().depth !=
1248 scroll_parent->draw_properties().depth) {
1249 int child_is_deeper = scroll_child->draw_properties().depth >
1250 scroll_parent->draw_properties().depth;
1251 if (child_is_deeper)
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. We set up scroll parent scroll
1259 // child relationships in blink precisely because the scroll child is not a
danakj 2014/09/11 19:22:05 oh thanks for this comment, that's helpful. but ca
Ian Vollick 2014/09/11 19:58:08 Done.
1260 // descendant of the scroll parent and will therefore not scroll with it
1261 // naturally and needs special treatment by the compositor.
1262 DCHECK_NE(scroll_child, scroll_parent);
1263
1264 // Now that scroll_child and scroll_parent are at the same depth, we can
1265 // walk up in tandem to find the LCA.
1266 while (scroll_child->parent() != scroll_parent->parent()) {
1267 scroll_child = scroll_child->parent();
1268 scroll_parent = scroll_parent->parent();
1269 }
1270 }
1271
1272 return scroll_parent;
1273 }
1274
1184 struct PreCalculateMetaInformationRecursiveData { 1275 struct PreCalculateMetaInformationRecursiveData {
1185 bool layer_or_descendant_has_copy_request; 1276 bool layer_or_descendant_has_copy_request;
1186 bool layer_or_descendant_has_input_handler; 1277 bool layer_or_descendant_has_input_handler;
1187 int num_unclipped_descendants; 1278 int num_unclipped_descendants;
1188 1279
1189 PreCalculateMetaInformationRecursiveData() 1280 PreCalculateMetaInformationRecursiveData()
1190 : layer_or_descendant_has_copy_request(false), 1281 : layer_or_descendant_has_copy_request(false),
1191 layer_or_descendant_has_input_handler(false), 1282 layer_or_descendant_has_input_handler(false),
1192 num_unclipped_descendants(0) {} 1283 num_unclipped_descendants(0) {}
1193 1284
1194 void Merge(const PreCalculateMetaInformationRecursiveData& data) { 1285 void Merge(const PreCalculateMetaInformationRecursiveData& data) {
1195 layer_or_descendant_has_copy_request |= 1286 layer_or_descendant_has_copy_request |=
1196 data.layer_or_descendant_has_copy_request; 1287 data.layer_or_descendant_has_copy_request;
1197 layer_or_descendant_has_input_handler |= 1288 layer_or_descendant_has_input_handler |=
1198 data.layer_or_descendant_has_input_handler; 1289 data.layer_or_descendant_has_input_handler;
1199 num_unclipped_descendants += 1290 num_unclipped_descendants +=
1200 data.num_unclipped_descendants; 1291 data.num_unclipped_descendants;
1201 } 1292 }
1202 }; 1293 };
1203 1294
1295 static int next_sort_weight(int* last_sort_weight) {
1296 return ++(*last_sort_weight);
1297 }
1298
1299 template <typename LayerType>
1300 static inline void AssignSortWeights(LayerType* layer,
1301 size_t sequence_number,
1302 int* last_sort_weight) {
1303 // Give |layer| the highest sort weight in the tree so far.
1304 if (!HaveAssignedSortWeight(layer, sequence_number)) {
1305 layer->draw_properties().sort_weight = next_sort_weight(last_sort_weight);
1306 layer->draw_properties().sort_weight_sequence_number = sequence_number;
1307 }
1308
1309 if (LayerType* scroll_parent = layer->scroll_parent()) {
1310 // It's important to note where we need to take care of ordering so that
1311 // scroll parents are visited before scroll children; it's at their lowest
1312 // common ancestor.
1313 //
1314 // LCA
1315 // +-scroll_parent_ancestor
1316 // | +- ...
1317 // | + scroll_parent
1318 // |
1319 // +-scroll_child_ancestor
1320 // +- ..
1321 // + scroll_child
1322 //
1323 // So given the above tree, we need to guarentee that scroll_parent_ancestor
1324 // is processed before scroll_child. We ensure that by assigning it the
1325 // lowest sort weight in the tree. We also want to flag LCA if we need to do
1326 // any funny business with sort weights so that it knows to do special
1327 // sorting of its descendants.
1328 LayerType* scroll_parent_ancestor =
1329 HighestScrollParentAncestorNotOnChildAncestorChain(
1330 sequence_number, layer, scroll_parent);
1331
1332 // We know we need to reorder if we haven't yet assigned
1333 // |scroll_parent_ancestor| a sort weight. Sort weights are monotonically
1334 // increasing, so unless we intervene, it will be given a higher sort weight
1335 // than |layer|.
1336 bool need_to_reorder =
1337 !HaveAssignedSortWeight(scroll_parent_ancestor, sequence_number);
1338
1339 LayerType* lca = scroll_parent_ancestor->parent();
1340
1341 // We also might need to reorder if scroll_parent_ancestor has been visited
1342 // and has an unacceptable sort weight.
1343 if (!need_to_reorder) {
1344 LayerType* scroll_child_ancestor = layer;
1345 while (scroll_child_ancestor->parent() &&
1346 scroll_child_ancestor->parent() != lca) {
1347 scroll_child_ancestor = scroll_child_ancestor->parent();
1348 }
1349 // We must have assigned a sort weight to this layer since its on our
1350 // ancestor chain.
1351 DCHECK(HaveAssignedSortWeight(scroll_child_ancestor, sequence_number));
1352 if (scroll_child_ancestor->draw_properties().sort_weight <
1353 scroll_parent_ancestor->draw_properties().sort_weight)
1354 need_to_reorder = true;
1355 }
1356
1357 if (need_to_reorder) {
1358 // Give |scroll_parent_ancestor| the lowest weight in the tree so far.
1359 scroll_parent_ancestor->draw_properties().sort_weight =
1360 -next_sort_weight(last_sort_weight);
1361 scroll_parent_ancestor->draw_properties().sort_weight_sequence_number =
1362 sequence_number;
1363
1364 // Mark the LCA as needing to sort.
1365 lca->draw_properties().children_need_sorting = true;
1366 }
1367 }
1368 }
1369
1204 // Recursively walks the layer tree to compute any information that is needed 1370 // Recursively walks the layer tree to compute any information that is needed
1205 // before doing the main recursion. 1371 // before doing the main recursion.
1206 template <typename LayerType> 1372 template <typename LayerType>
1207 static void PreCalculateMetaInformation( 1373 static void PreCalculateMetaInformation(
1208 LayerType* layer, 1374 LayerType* layer,
1209 PreCalculateMetaInformationRecursiveData* recursive_data) { 1375 PreCalculateMetaInformationRecursiveData* recursive_data,
1210 1376 int depth,
1211 layer->draw_properties().sorted_for_recursion = false; 1377 size_t sequence_number,
1212 layer->draw_properties().has_child_with_a_scroll_parent = false; 1378 int* last_sort_weight) {
1379 layer->draw_properties().children_need_sorting = false;
1380 layer->draw_properties().depth = depth;
1381 layer->draw_properties().sequence_number = sequence_number;
1213 1382
1214 if (!HasInvertibleOrAnimatedTransform(layer)) { 1383 if (!HasInvertibleOrAnimatedTransform(layer)) {
1215 // Layers with singular transforms should not be drawn, the whole subtree 1384 // Layers with singular transforms should not be drawn, the whole subtree
1216 // can be skipped. 1385 // can be skipped.
1217 return; 1386 return;
1218 } 1387 }
1219 1388
1220 if (layer->clip_parent()) 1389 if (layer->clip_parent())
1221 recursive_data->num_unclipped_descendants++; 1390 recursive_data->num_unclipped_descendants++;
1222 1391
1392 AssignSortWeights(layer, sequence_number, last_sort_weight);
1393
1223 for (size_t i = 0; i < layer->children().size(); ++i) { 1394 for (size_t i = 0; i < layer->children().size(); ++i) {
1224 LayerType* child_layer = 1395 LayerType* child_layer =
1225 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); 1396 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i);
1226 1397
1227 PreCalculateMetaInformationRecursiveData data_for_child; 1398 PreCalculateMetaInformationRecursiveData data_for_child;
1228 PreCalculateMetaInformation(child_layer, &data_for_child); 1399 PreCalculateMetaInformation(child_layer,
1229 1400 &data_for_child,
1230 if (child_layer->scroll_parent()) 1401 depth + 1,
1231 layer->draw_properties().has_child_with_a_scroll_parent = true; 1402 sequence_number,
1403 last_sort_weight);
1232 recursive_data->Merge(data_for_child); 1404 recursive_data->Merge(data_for_child);
1233 } 1405 }
1234 1406
1235 if (layer->clip_children()) { 1407 if (layer->clip_children()) {
1236 int num_clip_children = layer->clip_children()->size(); 1408 int num_clip_children = layer->clip_children()->size();
1237 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); 1409 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children);
1238 recursive_data->num_unclipped_descendants -= num_clip_children; 1410 recursive_data->num_unclipped_descendants -= num_clip_children;
1239 } 1411 }
1240 1412
1241 if (layer->HasCopyRequest()) 1413 if (layer->HasCopyRequest())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 bool ancestor_is_animating_scale; 1480 bool ancestor_is_animating_scale;
1309 bool ancestor_clips_subtree; 1481 bool ancestor_clips_subtree;
1310 typename LayerType::RenderSurfaceType* 1482 typename LayerType::RenderSurfaceType*
1311 nearest_occlusion_immune_ancestor_surface; 1483 nearest_occlusion_immune_ancestor_surface;
1312 bool in_subtree_of_page_scale_application_layer; 1484 bool in_subtree_of_page_scale_application_layer;
1313 bool subtree_can_use_lcd_text; 1485 bool subtree_can_use_lcd_text;
1314 bool subtree_is_visible_from_ancestor; 1486 bool subtree_is_visible_from_ancestor;
1315 }; 1487 };
1316 1488
1317 template <typename LayerType> 1489 template <typename LayerType>
1318 static LayerType* GetChildContainingLayer(const LayerType& parent, 1490 struct AscendingScrollWeightComparator {
1319 LayerType* layer) { 1491 bool operator()(LayerType* lhs, LayerType* rhs) {
1320 for (LayerType* ancestor = layer; ancestor; ancestor = ancestor->parent()) { 1492 return lhs->draw_properties().sort_weight <
1321 if (ancestor->parent() == &parent) 1493 rhs->draw_properties().sort_weight;
1322 return ancestor;
1323 } 1494 }
1324 NOTREACHED(); 1495 };
1325 return 0; 1496
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>());
1326 } 1507 }
1327 1508
1328 template <typename LayerType> 1509 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, 1510 static void GetNewDescendantsStartIndexAndCount(LayerType* layer,
1393 size_t* start_index, 1511 size_t* start_index,
1394 size_t* count) { 1512 size_t* count) {
1395 *start_index = layer->draw_properties().index_of_first_descendants_addition; 1513 *start_index = layer->draw_properties().index_of_first_descendants_addition;
1396 *count = layer->draw_properties().num_descendants_added; 1514 *count = layer->draw_properties().num_descendants_added;
1397 } 1515 }
1398 1516
1399 template <typename LayerType> 1517 template <typename LayerType>
1400 static void GetNewRenderSurfacesStartIndexAndCount(LayerType* layer, 1518 static void GetNewRenderSurfacesStartIndexAndCount(LayerType* layer,
1401 size_t* start_index, 1519 size_t* start_index,
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 // 3.0, then 1 physical pixel is only 1/3 of a CSS pixel. 1799 // 3.0, then 1 physical pixel is only 1/3 of a CSS pixel.
1682 gfx::Vector2dF parent_scales = MathUtil::ComputeTransform2dScaleComponents( 1800 gfx::Vector2dF parent_scales = MathUtil::ComputeTransform2dScaleComponents(
1683 data_from_ancestor.parent_matrix, 1.f); 1801 data_from_ancestor.parent_matrix, 1.f);
1684 effective_scroll_delta -= 1802 effective_scroll_delta -=
1685 gfx::ScaleVector2d(current_translation - previous_translation, 1803 gfx::ScaleVector2d(current_translation - previous_translation,
1686 1.f / parent_scales.x(), 1804 1.f / parent_scales.x(),
1687 1.f / parent_scales.y()); 1805 1.f / parent_scales.y());
1688 } 1806 }
1689 1807
1690 // Apply adjustment from position constraints. 1808 // Apply adjustment from position constraints.
1691 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container, 1809 ApplyPositionAdjustment(layer,
1692 data_from_ancestor.scroll_compensation_matrix, &combined_transform); 1810 data_from_ancestor.fixed_container,
1811 data_from_ancestor.scroll_compensation_matrix,
1812 &combined_transform);
1693 1813
1694 bool combined_is_animating_scale = false; 1814 bool combined_is_animating_scale = false;
1695 float combined_maximum_animation_contents_scale = 0.f; 1815 float combined_maximum_animation_contents_scale = 0.f;
1696 if (globals.can_adjust_raster_scales) { 1816 if (globals.can_adjust_raster_scales) {
1697 CalculateAnimationContentsScale( 1817 CalculateAnimationContentsScale(
1698 layer, 1818 layer,
1699 data_from_ancestor.ancestor_is_animating_scale, 1819 data_from_ancestor.ancestor_is_animating_scale,
1700 data_from_ancestor.maximum_animation_contents_scale, 1820 data_from_ancestor.maximum_animation_contents_scale,
1701 data_from_ancestor.parent_matrix, 1821 data_from_ancestor.parent_matrix,
1702 combined_transform, 1822 combined_transform,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 layer_draw_properties.screen_space_transform.FlattenTo2d(); 1903 layer_draw_properties.screen_space_transform.FlattenTo2d();
1784 layer_draw_properties.screen_space_transform.PreconcatTransform 1904 layer_draw_properties.screen_space_transform.PreconcatTransform
1785 (layer_draw_properties.target_space_transform); 1905 (layer_draw_properties.target_space_transform);
1786 1906
1787 // Adjusting text AA method during animation may cause repaints, which in-turn 1907 // Adjusting text AA method during animation may cause repaints, which in-turn
1788 // causes jank. 1908 // causes jank.
1789 bool adjust_text_aa = 1909 bool adjust_text_aa =
1790 !animating_opacity_to_screen && !animating_transform_to_screen; 1910 !animating_opacity_to_screen && !animating_transform_to_screen;
1791 // To avoid color fringing, LCD text should only be used on opaque layers with 1911 // To avoid color fringing, LCD text should only be used on opaque layers with
1792 // just integral translation. 1912 // just integral translation.
1793 bool layer_can_use_lcd_text = 1913 bool layer_can_use_lcd_text = data_from_ancestor.subtree_can_use_lcd_text &&
1794 data_from_ancestor.subtree_can_use_lcd_text && 1914 accumulated_draw_opacity == 1.f &&
1795 accumulated_draw_opacity == 1.f && 1915 layer_draw_properties.target_space_transform
1796 layer_draw_properties.target_space_transform. 1916 .IsIdentityOrIntegerTranslation();
1797 IsIdentityOrIntegerTranslation();
1798 1917
1799 gfx::Rect content_rect(layer->content_bounds()); 1918 gfx::Rect content_rect(layer->content_bounds());
1800 1919
1801 // full_hierarchy_matrix is the matrix that transforms objects between screen 1920 // full_hierarchy_matrix is the matrix that transforms objects between screen
1802 // space (except projection matrix) and the most recent RenderSurfaceImpl's 1921 // space (except projection matrix) and the most recent RenderSurfaceImpl's
1803 // space. next_hierarchy_matrix will only change if this layer uses a new 1922 // space. next_hierarchy_matrix will only change if this layer uses a new
1804 // RenderSurfaceImpl, otherwise remains the same. 1923 // RenderSurfaceImpl, otherwise remains the same.
1805 data_for_children.full_hierarchy_matrix = 1924 data_for_children.full_hierarchy_matrix =
1806 data_from_ancestor.full_hierarchy_matrix; 1925 data_from_ancestor.full_hierarchy_matrix;
1807 1926
1808 // If the subtree will scale layer contents by the transform hierarchy, then 1927 // If the subtree will scale layer contents by the transform hierarchy, then
1809 // we should scale things into the render surface by the transform hierarchy 1928 // we should scale things into the render surface by the transform hierarchy
1810 // to take advantage of that. 1929 // to take advantage of that.
1811 gfx::Vector2dF render_surface_sublayer_scale = 1930 gfx::Vector2dF render_surface_sublayer_scale =
1812 globals.can_adjust_raster_scales 1931 globals.can_adjust_raster_scales
1813 ? combined_transform_scales 1932 ? combined_transform_scales
1814 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); 1933 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors);
1815 1934
1816 bool render_to_separate_surface; 1935 bool render_to_separate_surface;
1817 if (globals.can_render_to_separate_surface) { 1936 if (globals.can_render_to_separate_surface) {
1818 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( 1937 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface(
1819 layer, combined_transform.Preserves2dAxisAlignment()); 1938 layer, combined_transform.Preserves2dAxisAlignment());
danakj 2014/09/11 19:22:05 these unrelated format changes may make future mer
Ian Vollick 2014/09/11 19:58:08 I put 'em back. (This was the work of git cl forma
1820 } else { 1939 } else {
1821 render_to_separate_surface = IsRootLayer(layer); 1940 render_to_separate_surface = IsRootLayer(layer);
1822 } 1941 }
1823 if (render_to_separate_surface) { 1942 if (render_to_separate_surface) {
1824 // Check back-face visibility before continuing with this surface and its 1943 // Check back-face visibility before continuing with this surface and its
1825 // subtree 1944 // subtree
1826 if (!layer->double_sided() && TransformToParentIsKnown(layer) && 1945 if (!layer->double_sided() && TransformToParentIsKnown(layer) &&
1827 IsSurfaceBackFaceVisible(layer, combined_transform)) { 1946 IsSurfaceBackFaceVisible(layer, combined_transform)) {
1828 layer->ClearRenderSurfaceLayerList(); 1947 layer->ClearRenderSurfaceLayerList();
1829 return; 1948 return;
(...skipping 29 matching lines...) Expand all
1859 render_surface_sublayer_scale.y() / layer->contents_scale_y()); 1978 render_surface_sublayer_scale.y() / layer->contents_scale_y());
1860 1979
1861 // Inside the surface's subtree, we scale everything to the owning layer's 1980 // Inside the surface's subtree, we scale everything to the owning layer's
1862 // scale. The sublayer matrix transforms layer rects into target surface 1981 // scale. The sublayer matrix transforms layer rects into target surface
1863 // content space. Conceptually, all layers in the subtree inherit the 1982 // content space. Conceptually, all layers in the subtree inherit the
1864 // scale at the point of the render surface in the transform hierarchy, 1983 // scale at the point of the render surface in the transform hierarchy,
1865 // but we apply it explicitly to the owning layer and the remainder of the 1984 // but we apply it explicitly to the owning layer and the remainder of the
1866 // subtree independently. 1985 // subtree independently.
1867 DCHECK(data_for_children.parent_matrix.IsIdentity()); 1986 DCHECK(data_for_children.parent_matrix.IsIdentity());
1868 data_for_children.parent_matrix.Scale(render_surface_sublayer_scale.x(), 1987 data_for_children.parent_matrix.Scale(render_surface_sublayer_scale.x(),
1869 render_surface_sublayer_scale.y()); 1988 render_surface_sublayer_scale.y());
1870 1989
1871 // Even if the |layer_is_drawn|, it only contributes to a drawn surface 1990 // Even if the |layer_is_drawn|, it only contributes to a drawn surface
1872 // when the |layer_is_visible|. 1991 // when the |layer_is_visible|.
1873 layer->render_surface()->set_contributes_to_drawn_surface( 1992 layer->render_surface()->set_contributes_to_drawn_surface(
1874 layer_is_visible); 1993 layer_is_visible);
1875 } 1994 }
1876 1995
1877 // The opacity value is moved from the layer to its surface, so that the 1996 // The opacity value is moved from the layer to its surface, so that the
1878 // entire subtree properly inherits opacity. 1997 // entire subtree properly inherits opacity.
1879 render_surface->SetDrawOpacity(accumulated_draw_opacity); 1998 render_surface->SetDrawOpacity(accumulated_draw_opacity);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 if (layer->should_flatten_transform()) 2209 if (layer->should_flatten_transform())
2091 data_for_children.parent_matrix.FlattenTo2d(); 2210 data_for_children.parent_matrix.FlattenTo2d();
2092 2211
2093 data_for_children.scroll_compensation_matrix = 2212 data_for_children.scroll_compensation_matrix =
2094 ComputeScrollCompensationMatrixForChildren( 2213 ComputeScrollCompensationMatrixForChildren(
2095 layer, 2214 layer,
2096 data_from_ancestor.parent_matrix, 2215 data_from_ancestor.parent_matrix,
2097 data_from_ancestor.scroll_compensation_matrix, 2216 data_from_ancestor.scroll_compensation_matrix,
2098 effective_scroll_delta); 2217 effective_scroll_delta);
2099 data_for_children.fixed_container = 2218 data_for_children.fixed_container =
2100 layer->IsContainerForFixedPositionLayers() ? 2219 layer->IsContainerForFixedPositionLayers()
2101 layer : data_from_ancestor.fixed_container; 2220 ? layer
2221 : data_from_ancestor.fixed_container;
2102 2222
2103 data_for_children.clip_rect_in_target_space = clip_rect_in_target_space; 2223 data_for_children.clip_rect_in_target_space = clip_rect_in_target_space;
2104 data_for_children.clip_rect_of_target_surface_in_target_space = 2224 data_for_children.clip_rect_of_target_surface_in_target_space =
2105 clip_rect_of_target_surface_in_target_space; 2225 clip_rect_of_target_surface_in_target_space;
2106 data_for_children.ancestor_clips_subtree = 2226 data_for_children.ancestor_clips_subtree =
2107 layer_or_ancestor_clips_descendants; 2227 layer_or_ancestor_clips_descendants;
2108 data_for_children.nearest_occlusion_immune_ancestor_surface = 2228 data_for_children.nearest_occlusion_immune_ancestor_surface =
2109 nearest_occlusion_immune_ancestor_surface; 2229 nearest_occlusion_immune_ancestor_surface;
2110 data_for_children.subtree_is_visible_from_ancestor = layer_is_drawn; 2230 data_for_children.subtree_is_visible_from_ancestor = layer_is_drawn;
2111 } 2231 }
2112 2232
2113 std::vector<LayerType*> sorted_children; 2233 std::vector<LayerType*> sorted_children;
2114 bool child_order_changed = false; 2234 if (layer_draw_properties.children_need_sorting)
2115 if (layer_draw_properties.has_child_with_a_scroll_parent) 2235 SortChildrenForRecursion(&sorted_children, *layer);
2116 child_order_changed = SortChildrenForRecursion(&sorted_children, *layer);
2117 2236
2118 for (size_t i = 0; i < layer->children().size(); ++i) { 2237 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 2238 // 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 2239 // visit the children out of order. The new order is stored in
2121 // sorted_children. Otherwise, we'll grab the child directly from the 2240 // sorted_children. Otherwise, we'll grab the child directly from the
2122 // layer's list of children. 2241 // layer's list of children.
2123 LayerType* child = 2242 LayerType* child =
2124 layer_draw_properties.has_child_with_a_scroll_parent 2243 layer_draw_properties.children_need_sorting
2125 ? sorted_children[i] 2244 ? sorted_children[i]
2126 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); 2245 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i);
2127 2246
2128 child->draw_properties().index_of_first_descendants_addition = 2247 child->draw_properties().index_of_first_descendants_addition =
2129 descendants.size(); 2248 descendants.size();
2130 child->draw_properties().index_of_first_render_surface_layer_list_addition = 2249 child->draw_properties().index_of_first_render_surface_layer_list_addition =
2131 render_surface_layer_list->size(); 2250 render_surface_layer_list->size();
2132 2251
2133 CalculateDrawPropertiesInternal<LayerType>( 2252 CalculateDrawPropertiesInternal<LayerType>(
2134 child, 2253 child,
(...skipping 17 matching lines...) Expand all
2152 child->draw_properties().num_descendants_added = 2271 child->draw_properties().num_descendants_added =
2153 descendants.size() - 2272 descendants.size() -
2154 child->draw_properties().index_of_first_descendants_addition; 2273 child->draw_properties().index_of_first_descendants_addition;
2155 child->draw_properties().num_render_surfaces_added = 2274 child->draw_properties().num_render_surfaces_added =
2156 render_surface_layer_list->size() - 2275 render_surface_layer_list->size() -
2157 child->draw_properties() 2276 child->draw_properties()
2158 .index_of_first_render_surface_layer_list_addition; 2277 .index_of_first_render_surface_layer_list_addition;
2159 } 2278 }
2160 2279
2161 // Add the unsorted layer list contributions, if necessary. 2280 // Add the unsorted layer list contributions, if necessary.
2162 if (child_order_changed) { 2281 if (layer_draw_properties.children_need_sorting) {
2163 SortLayerListContributions( 2282 SortLayerListContributions(
2164 *layer, 2283 *layer,
2165 GetLayerListForSorting(render_surface_layer_list), 2284 GetLayerListForSorting(render_surface_layer_list),
2166 render_surface_layer_list_child_sorting_start_index, 2285 render_surface_layer_list_child_sorting_start_index,
2167 &GetNewRenderSurfacesStartIndexAndCount<LayerType>); 2286 &GetNewRenderSurfacesStartIndexAndCount<LayerType>);
2168 2287
2169 SortLayerListContributions( 2288 SortLayerListContributions(
2170 *layer, 2289 *layer,
2171 &descendants, 2290 &descendants,
2172 layer_list_child_sorting_start_index, 2291 layer_list_child_sorting_start_index,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 data_for_recursion->subtree_is_visible_from_ancestor = true; 2502 data_for_recursion->subtree_is_visible_from_ancestor = true;
2384 } 2503 }
2385 2504
2386 void LayerTreeHostCommon::CalculateDrawProperties( 2505 void LayerTreeHostCommon::CalculateDrawProperties(
2387 CalcDrawPropsMainInputs* inputs) { 2506 CalcDrawPropsMainInputs* inputs) {
2388 LayerList dummy_layer_list; 2507 LayerList dummy_layer_list;
2389 SubtreeGlobals<Layer> globals; 2508 SubtreeGlobals<Layer> globals;
2390 DataForRecursion<Layer> data_for_recursion; 2509 DataForRecursion<Layer> data_for_recursion;
2391 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); 2510 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2392 2511
2512 // This is used as a global throughout the precalculate recursion.
2513 int last_sort_weight = 0;
2393 PreCalculateMetaInformationRecursiveData recursive_data; 2514 PreCalculateMetaInformationRecursiveData recursive_data;
2394 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2515 PreCalculateMetaInformation(inputs->root_layer,
2516 &recursive_data,
2517 0,
2518 inputs->current_render_surface_layer_list_id + 1,
danakj 2014/09/11 19:22:05 why +1?
Ian Vollick 2014/09/11 19:58:08 0 doesn't work as a sequence number. Although no r
2519 &last_sort_weight);
2520
2395 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; 2521 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state;
2396 CalculateDrawPropertiesInternal<Layer>( 2522 CalculateDrawPropertiesInternal<Layer>(
2397 inputs->root_layer, 2523 inputs->root_layer,
2398 globals, 2524 globals,
2399 data_for_recursion, 2525 data_for_recursion,
2400 inputs->render_surface_layer_list, 2526 inputs->render_surface_layer_list,
2401 &dummy_layer_list, 2527 &dummy_layer_list,
2402 &accumulated_surface_state, 2528 &accumulated_surface_state,
2403 inputs->current_render_surface_layer_list_id); 2529 inputs->current_render_surface_layer_list_id);
2404 2530
2405 // The dummy layer list should not have been used. 2531 // The dummy layer list should not have been used.
2406 DCHECK_EQ(0u, dummy_layer_list.size()); 2532 DCHECK_EQ(0u, dummy_layer_list.size());
2407 // A root layer render_surface should always exist after 2533 // A root layer render_surface should always exist after
2408 // CalculateDrawProperties. 2534 // CalculateDrawProperties.
2409 DCHECK(inputs->root_layer->render_surface()); 2535 DCHECK(inputs->root_layer->render_surface());
2410 } 2536 }
2411 2537
2412 void LayerTreeHostCommon::CalculateDrawProperties( 2538 void LayerTreeHostCommon::CalculateDrawProperties(
2413 CalcDrawPropsImplInputs* inputs) { 2539 CalcDrawPropsImplInputs* inputs) {
2414 LayerImplList dummy_layer_list; 2540 LayerImplList dummy_layer_list;
2415 SubtreeGlobals<LayerImpl> globals; 2541 SubtreeGlobals<LayerImpl> globals;
2416 DataForRecursion<LayerImpl> data_for_recursion; 2542 DataForRecursion<LayerImpl> data_for_recursion;
2417 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); 2543 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2418 2544
2419 LayerSorter layer_sorter; 2545 LayerSorter layer_sorter;
2420 globals.layer_sorter = &layer_sorter; 2546 globals.layer_sorter = &layer_sorter;
2421 2547
2548 // This is used as a global throughout the precalculate recursion.
2549 int last_sort_weight = 0;
2422 PreCalculateMetaInformationRecursiveData recursive_data; 2550 PreCalculateMetaInformationRecursiveData recursive_data;
2423 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2551 PreCalculateMetaInformation(inputs->root_layer,
2552 &recursive_data,
2553 0,
2554 inputs->current_render_surface_layer_list_id + 1,
danakj 2014/09/11 19:22:05 why +1?
Ian Vollick 2014/09/11 19:58:08 Zero doesn't work here. In practice, no real calle
2555 &last_sort_weight);
2556
2424 std::vector<AccumulatedSurfaceState<LayerImpl> > 2557 std::vector<AccumulatedSurfaceState<LayerImpl> >
2425 accumulated_surface_state; 2558 accumulated_surface_state;
2426 CalculateDrawPropertiesInternal<LayerImpl>( 2559 CalculateDrawPropertiesInternal<LayerImpl>(
2427 inputs->root_layer, 2560 inputs->root_layer,
2428 globals, 2561 globals,
2429 data_for_recursion, 2562 data_for_recursion,
2430 inputs->render_surface_layer_list, 2563 inputs->render_surface_layer_list,
2431 &dummy_layer_list, 2564 &dummy_layer_list,
2432 &accumulated_surface_state, 2565 &accumulated_surface_state,
2433 inputs->current_render_surface_layer_list_id); 2566 inputs->current_render_surface_layer_list_id);
2434 2567
2435 // The dummy layer list should not have been used. 2568 // The dummy layer list should not have been used.
2436 DCHECK_EQ(0u, dummy_layer_list.size()); 2569 DCHECK_EQ(0u, dummy_layer_list.size());
2437 // A root layer render_surface should always exist after 2570 // A root layer render_surface should always exist after
2438 // CalculateDrawProperties. 2571 // CalculateDrawProperties.
2439 DCHECK(inputs->root_layer->render_surface()); 2572 DCHECK(inputs->root_layer->render_surface());
2440 } 2573 }
2441 2574
2442 } // namespace cc 2575 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698