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 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1123 if (!layer->render_surface()) { | 1123 if (!layer->render_surface()) { |
| 1124 layer->CreateRenderSurface(); | 1124 layer->CreateRenderSurface(); |
| 1125 return layer->render_surface(); | 1125 return layer->render_surface(); |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 layer->render_surface()->ClearLayerLists(); | 1128 layer->render_surface()->ClearLayerLists(); |
| 1129 return layer->render_surface(); | 1129 return layer->render_surface(); |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 template <typename LayerType> | 1132 template <typename LayerType> |
| 1133 static inline void MarkLayerWithFrameNumber( | |
|
danakj
2014/05/05 19:25:41
"FrameNumber" seems like a misnomer here
vmpstr
2014/05/05 20:50:34
Done.
| |
| 1134 LayerType* layer, | |
| 1135 int current_calculate_draw_properties_count) { | |
| 1136 layer->draw_properties().last_valid_render_surface_list_count = | |
| 1137 current_calculate_draw_properties_count; | |
| 1138 if (layer->mask_layer()) { | |
| 1139 layer->mask_layer() | |
| 1140 ->draw_properties() | |
| 1141 .last_valid_render_surface_list_count = | |
| 1142 current_calculate_draw_properties_count; | |
| 1143 } | |
| 1144 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { | |
|
danakj
2014/05/05 19:25:41
can you mark the replica layer too (it doesn't hav
vmpstr
2014/05/05 20:50:34
Done.
| |
| 1145 layer->replica_layer() | |
| 1146 ->mask_layer() | |
| 1147 ->draw_properties() | |
| 1148 .last_valid_render_surface_list_count = | |
| 1149 current_calculate_draw_properties_count; | |
| 1150 } | |
| 1151 } | |
| 1152 | |
| 1153 template <typename LayerType> | |
| 1154 static inline void MarkLayerWithFrameNumber( | |
| 1155 scoped_refptr<LayerType> layer, | |
|
danakj
2014/05/05 19:25:41
Does the templated method above not handle this ca
vmpstr
2014/05/05 20:50:34
No, the signature is LayerType*, and scoped_refptr
| |
| 1156 int current_calculate_draw_properties_count) { | |
| 1157 MarkLayerWithFrameNumber(layer.get(), | |
| 1158 current_calculate_draw_properties_count); | |
| 1159 } | |
| 1160 | |
| 1161 template <typename LayerListType> | |
| 1162 static inline void MarkLayerListWithFrameNumber( | |
| 1163 LayerListType* layer_list, | |
| 1164 int current_calculate_draw_properties_count) { | |
| 1165 for (typename LayerListType::iterator it = layer_list->begin(); | |
| 1166 it != layer_list->end(); | |
| 1167 ++it) { | |
| 1168 MarkLayerWithFrameNumber(*it, current_calculate_draw_properties_count); | |
| 1169 } | |
| 1170 } | |
| 1171 | |
| 1172 template <typename LayerType> | |
| 1133 static inline void RemoveSurfaceForEarlyExit( | 1173 static inline void RemoveSurfaceForEarlyExit( |
| 1134 LayerType* layer_to_remove, | 1174 LayerType* layer_to_remove, |
| 1135 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { | 1175 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { |
| 1136 DCHECK(layer_to_remove->render_surface()); | 1176 DCHECK(layer_to_remove->render_surface()); |
| 1137 // Technically, we know that the layer we want to remove should be | 1177 // Technically, we know that the layer we want to remove should be |
| 1138 // at the back of the render_surface_layer_list. However, we have had | 1178 // at the back of the render_surface_layer_list. However, we have had |
| 1139 // bugs before that added unnecessary layers here | 1179 // bugs before that added unnecessary layers here |
| 1140 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes | 1180 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes |
| 1141 // things to crash. So here we proactively remove any additional | 1181 // things to crash. So here we proactively remove any additional |
| 1142 // layers from the end of the list. | 1182 // layers from the end of the list. |
| 1143 while (render_surface_layer_list->back() != layer_to_remove) { | 1183 while (render_surface_layer_list->back() != layer_to_remove) { |
| 1144 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); | 1184 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); |
| 1185 MarkLayerListWithFrameNumber( | |
| 1186 &render_surface_layer_list->back()->render_surface()->layer_list(), 0); | |
| 1145 render_surface_layer_list->pop_back(); | 1187 render_surface_layer_list->pop_back(); |
| 1146 } | 1188 } |
| 1147 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); | 1189 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); |
| 1190 | |
|
danakj
2014/05/05 19:25:41
nit: drop extra whitespace?
vmpstr
2014/05/05 20:50:34
Done.
| |
| 1191 MarkLayerListWithFrameNumber(&layer_to_remove->render_surface()->layer_list(), | |
| 1192 0); | |
| 1193 | |
| 1148 render_surface_layer_list->pop_back(); | 1194 render_surface_layer_list->pop_back(); |
| 1149 layer_to_remove->ClearRenderSurfaceLayerList(); | 1195 layer_to_remove->ClearRenderSurfaceLayerList(); |
| 1150 } | 1196 } |
| 1151 | 1197 |
| 1152 struct PreCalculateMetaInformationRecursiveData { | 1198 struct PreCalculateMetaInformationRecursiveData { |
| 1153 bool layer_or_descendant_has_copy_request; | 1199 bool layer_or_descendant_has_copy_request; |
| 1154 int num_unclipped_descendants; | 1200 int num_unclipped_descendants; |
| 1155 | 1201 |
| 1156 PreCalculateMetaInformationRecursiveData() | 1202 PreCalculateMetaInformationRecursiveData() |
| 1157 : layer_or_descendant_has_copy_request(false), | 1203 : layer_or_descendant_has_copy_request(false), |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1416 | 1462 |
| 1417 // Recursively walks the layer tree starting at the given node and computes all | 1463 // Recursively walks the layer tree starting at the given node and computes all |
| 1418 // the necessary transformations, clip rects, render surfaces, etc. | 1464 // the necessary transformations, clip rects, render surfaces, etc. |
| 1419 template <typename LayerType> | 1465 template <typename LayerType> |
| 1420 static void CalculateDrawPropertiesInternal( | 1466 static void CalculateDrawPropertiesInternal( |
| 1421 LayerType* layer, | 1467 LayerType* layer, |
| 1422 const SubtreeGlobals<LayerType>& globals, | 1468 const SubtreeGlobals<LayerType>& globals, |
| 1423 const DataForRecursion<LayerType>& data_from_ancestor, | 1469 const DataForRecursion<LayerType>& data_from_ancestor, |
| 1424 typename LayerType::RenderSurfaceListType* render_surface_layer_list, | 1470 typename LayerType::RenderSurfaceListType* render_surface_layer_list, |
| 1425 typename LayerType::LayerListType* layer_list, | 1471 typename LayerType::LayerListType* layer_list, |
| 1426 std::vector<AccumulatedSurfaceState<LayerType> >* | 1472 std::vector<AccumulatedSurfaceState<LayerType> >* accumulated_surface_state, |
| 1427 accumulated_surface_state) { | 1473 int current_calculate_draw_properties_count) { |
| 1428 // This function computes the new matrix transformations recursively for this | 1474 // This function computes the new matrix transformations recursively for this |
| 1429 // layer and all its descendants. It also computes the appropriate render | 1475 // layer and all its descendants. It also computes the appropriate render |
| 1430 // surfaces. | 1476 // surfaces. |
| 1431 // Some important points to remember: | 1477 // Some important points to remember: |
| 1432 // | 1478 // |
| 1433 // 0. Here, transforms are notated in Matrix x Vector order, and in words we | 1479 // 0. Here, transforms are notated in Matrix x Vector order, and in words we |
| 1434 // describe what the transform does from left to right. | 1480 // describe what the transform does from left to right. |
| 1435 // | 1481 // |
| 1436 // 1. In our terminology, the "layer origin" refers to the top-left corner of | 1482 // 1. In our terminology, the "layer origin" refers to the top-left corner of |
| 1437 // a layer, and the positive Y-axis points downwards. This interpretation is | 1483 // a layer, and the positive Y-axis points downwards. This interpretation is |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1928 render_surface->SetClipRect(gfx::Rect()); | 1974 render_surface->SetClipRect(gfx::Rect()); |
| 1929 clip_rect_of_target_surface_in_target_space = | 1975 clip_rect_of_target_surface_in_target_space = |
| 1930 data_from_ancestor.clip_rect_of_target_surface_in_target_space; | 1976 data_from_ancestor.clip_rect_of_target_surface_in_target_space; |
| 1931 } | 1977 } |
| 1932 | 1978 |
| 1933 // If the new render surface is drawn translucent or with a non-integral | 1979 // If the new render surface is drawn translucent or with a non-integral |
| 1934 // translation then the subtree that gets drawn on this render surface | 1980 // translation then the subtree that gets drawn on this render surface |
| 1935 // cannot use LCD text. | 1981 // cannot use LCD text. |
| 1936 data_for_children.subtree_can_use_lcd_text = layer_can_use_lcd_text; | 1982 data_for_children.subtree_can_use_lcd_text = layer_can_use_lcd_text; |
| 1937 | 1983 |
| 1938 render_surface_layer_list->push_back(layer); | 1984 render_surface_layer_list->push_back(layer); |
|
danakj
2014/05/05 19:25:41
Mark the layer with the number here also, if you w
vmpstr
2014/05/05 20:50:34
In this case, would the layer still be visited by
danakj
2014/05/05 21:25:22
It would be visited by the iterator with the state
| |
| 1939 } else { | 1985 } else { |
| 1940 DCHECK(layer->parent()); | 1986 DCHECK(layer->parent()); |
| 1941 | 1987 |
| 1942 // Note: layer_draw_properties.target_space_transform is computed above, | 1988 // Note: layer_draw_properties.target_space_transform is computed above, |
| 1943 // before this if-else statement. | 1989 // before this if-else statement. |
| 1944 layer_draw_properties.target_space_transform_is_animating = | 1990 layer_draw_properties.target_space_transform_is_animating = |
| 1945 animating_transform_to_target; | 1991 animating_transform_to_target; |
| 1946 layer_draw_properties.screen_space_transform_is_animating = | 1992 layer_draw_properties.screen_space_transform_is_animating = |
| 1947 animating_transform_to_screen; | 1993 animating_transform_to_screen; |
| 1948 layer_draw_properties.opacity = accumulated_draw_opacity; | 1994 layer_draw_properties.opacity = accumulated_draw_opacity; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2004 } | 2050 } |
| 2005 | 2051 |
| 2006 typename LayerType::LayerListType& descendants = | 2052 typename LayerType::LayerListType& descendants = |
| 2007 (layer->render_surface() ? layer->render_surface()->layer_list() | 2053 (layer->render_surface() ? layer->render_surface()->layer_list() |
| 2008 : *layer_list); | 2054 : *layer_list); |
| 2009 | 2055 |
| 2010 // Any layers that are appended after this point are in the layer's subtree | 2056 // Any layers that are appended after this point are in the layer's subtree |
| 2011 // and should be included in the sorting process. | 2057 // and should be included in the sorting process. |
| 2012 size_t sorting_start_index = descendants.size(); | 2058 size_t sorting_start_index = descendants.size(); |
| 2013 | 2059 |
| 2014 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) | 2060 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) { |
| 2061 MarkLayerWithFrameNumber(layer, current_calculate_draw_properties_count); | |
| 2015 descendants.push_back(layer); | 2062 descendants.push_back(layer); |
| 2063 } | |
| 2016 | 2064 |
| 2017 // Any layers that are appended after this point may need to be sorted if we | 2065 // Any layers that are appended after this point may need to be sorted if we |
| 2018 // visit the children out of order. | 2066 // visit the children out of order. |
| 2019 size_t render_surface_layer_list_child_sorting_start_index = | 2067 size_t render_surface_layer_list_child_sorting_start_index = |
| 2020 render_surface_layer_list->size(); | 2068 render_surface_layer_list->size(); |
| 2021 size_t layer_list_child_sorting_start_index = descendants.size(); | 2069 size_t layer_list_child_sorting_start_index = descendants.size(); |
| 2022 | 2070 |
| 2023 if (!layer->children().empty()) { | 2071 if (!layer->children().empty()) { |
| 2024 if (layer == globals.page_scale_application_layer) { | 2072 if (layer == globals.page_scale_application_layer) { |
| 2025 data_for_children.parent_matrix.Scale( | 2073 data_for_children.parent_matrix.Scale( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2065 LayerType* child = | 2113 LayerType* child = |
| 2066 layer_draw_properties.has_child_with_a_scroll_parent | 2114 layer_draw_properties.has_child_with_a_scroll_parent |
| 2067 ? sorted_children[i] | 2115 ? sorted_children[i] |
| 2068 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); | 2116 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); |
| 2069 | 2117 |
| 2070 child->draw_properties().index_of_first_descendants_addition = | 2118 child->draw_properties().index_of_first_descendants_addition = |
| 2071 descendants.size(); | 2119 descendants.size(); |
| 2072 child->draw_properties().index_of_first_render_surface_layer_list_addition = | 2120 child->draw_properties().index_of_first_render_surface_layer_list_addition = |
| 2073 render_surface_layer_list->size(); | 2121 render_surface_layer_list->size(); |
| 2074 | 2122 |
| 2075 CalculateDrawPropertiesInternal<LayerType>(child, | 2123 CalculateDrawPropertiesInternal<LayerType>( |
| 2076 globals, | 2124 child, |
| 2077 data_for_children, | 2125 globals, |
| 2078 render_surface_layer_list, | 2126 data_for_children, |
| 2079 &descendants, | 2127 render_surface_layer_list, |
| 2080 accumulated_surface_state); | 2128 &descendants, |
| 2129 accumulated_surface_state, | |
| 2130 current_calculate_draw_properties_count); | |
| 2081 if (child->render_surface() && | 2131 if (child->render_surface() && |
| 2082 !child->render_surface()->layer_list().empty() && | 2132 !child->render_surface()->layer_list().empty() && |
| 2083 !child->render_surface()->content_rect().IsEmpty()) { | 2133 !child->render_surface()->content_rect().IsEmpty()) { |
| 2134 MarkLayerWithFrameNumber(child, current_calculate_draw_properties_count); | |
|
danakj
2014/05/05 19:25:41
then this one won't be needed any more
vmpstr
2014/05/05 20:50:34
I don't follow... The above would only mark the pa
danakj
2014/05/05 21:25:22
This pushes a child that has a render surface. But
| |
| 2084 descendants.push_back(child); | 2135 descendants.push_back(child); |
| 2085 } | 2136 } |
| 2086 | 2137 |
| 2087 child->draw_properties().num_descendants_added = | 2138 child->draw_properties().num_descendants_added = |
| 2088 descendants.size() - | 2139 descendants.size() - |
| 2089 child->draw_properties().index_of_first_descendants_addition; | 2140 child->draw_properties().index_of_first_descendants_addition; |
| 2090 child->draw_properties().num_render_surfaces_added = | 2141 child->draw_properties().num_render_surfaces_added = |
| 2091 render_surface_layer_list->size() - | 2142 render_surface_layer_list->size() - |
| 2092 child->draw_properties() | 2143 child->draw_properties() |
| 2093 .index_of_first_render_surface_layer_list_addition; | 2144 .index_of_first_render_surface_layer_list_addition; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2321 void LayerTreeHostCommon::CalculateDrawProperties( | 2372 void LayerTreeHostCommon::CalculateDrawProperties( |
| 2322 CalcDrawPropsMainInputs* inputs) { | 2373 CalcDrawPropsMainInputs* inputs) { |
| 2323 LayerList dummy_layer_list; | 2374 LayerList dummy_layer_list; |
| 2324 SubtreeGlobals<Layer> globals; | 2375 SubtreeGlobals<Layer> globals; |
| 2325 DataForRecursion<Layer> data_for_recursion; | 2376 DataForRecursion<Layer> data_for_recursion; |
| 2326 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2377 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
| 2327 | 2378 |
| 2328 PreCalculateMetaInformationRecursiveData recursive_data; | 2379 PreCalculateMetaInformationRecursiveData recursive_data; |
| 2329 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2380 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
| 2330 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; | 2381 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; |
| 2331 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer, | 2382 CalculateDrawPropertiesInternal<Layer>( |
| 2332 globals, | 2383 inputs->root_layer, |
| 2333 data_for_recursion, | 2384 globals, |
| 2334 inputs->render_surface_layer_list, | 2385 data_for_recursion, |
| 2335 &dummy_layer_list, | 2386 inputs->render_surface_layer_list, |
| 2336 &accumulated_surface_state); | 2387 &dummy_layer_list, |
| 2388 &accumulated_surface_state, | |
| 2389 inputs->current_calculate_draw_properties_count); | |
| 2337 | 2390 |
| 2338 // The dummy layer list should not have been used. | 2391 // The dummy layer list should not have been used. |
| 2339 DCHECK_EQ(0u, dummy_layer_list.size()); | 2392 DCHECK_EQ(0u, dummy_layer_list.size()); |
| 2340 // A root layer render_surface should always exist after | 2393 // A root layer render_surface should always exist after |
| 2341 // CalculateDrawProperties. | 2394 // CalculateDrawProperties. |
| 2342 DCHECK(inputs->root_layer->render_surface()); | 2395 DCHECK(inputs->root_layer->render_surface()); |
| 2343 } | 2396 } |
| 2344 | 2397 |
| 2345 void LayerTreeHostCommon::CalculateDrawProperties( | 2398 void LayerTreeHostCommon::CalculateDrawProperties( |
| 2346 CalcDrawPropsImplInputs* inputs) { | 2399 CalcDrawPropsImplInputs* inputs) { |
| 2347 LayerImplList dummy_layer_list; | 2400 LayerImplList dummy_layer_list; |
| 2348 SubtreeGlobals<LayerImpl> globals; | 2401 SubtreeGlobals<LayerImpl> globals; |
| 2349 DataForRecursion<LayerImpl> data_for_recursion; | 2402 DataForRecursion<LayerImpl> data_for_recursion; |
| 2350 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2403 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
| 2351 | 2404 |
| 2352 LayerSorter layer_sorter; | 2405 LayerSorter layer_sorter; |
| 2353 globals.layer_sorter = &layer_sorter; | 2406 globals.layer_sorter = &layer_sorter; |
| 2354 | 2407 |
| 2355 PreCalculateMetaInformationRecursiveData recursive_data; | 2408 PreCalculateMetaInformationRecursiveData recursive_data; |
| 2356 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2409 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
| 2357 std::vector<AccumulatedSurfaceState<LayerImpl> > | 2410 std::vector<AccumulatedSurfaceState<LayerImpl> > |
| 2358 accumulated_surface_state; | 2411 accumulated_surface_state; |
| 2359 CalculateDrawPropertiesInternal<LayerImpl>(inputs->root_layer, | 2412 CalculateDrawPropertiesInternal<LayerImpl>( |
| 2360 globals, | 2413 inputs->root_layer, |
| 2361 data_for_recursion, | 2414 globals, |
| 2362 inputs->render_surface_layer_list, | 2415 data_for_recursion, |
| 2363 &dummy_layer_list, | 2416 inputs->render_surface_layer_list, |
| 2364 &accumulated_surface_state); | 2417 &dummy_layer_list, |
| 2418 &accumulated_surface_state, | |
| 2419 inputs->current_calculate_draw_properties_count); | |
| 2365 | 2420 |
| 2366 // The dummy layer list should not have been used. | 2421 // The dummy layer list should not have been used. |
| 2367 DCHECK_EQ(0u, dummy_layer_list.size()); | 2422 DCHECK_EQ(0u, dummy_layer_list.size()); |
| 2368 // A root layer render_surface should always exist after | 2423 // A root layer render_surface should always exist after |
| 2369 // CalculateDrawProperties. | 2424 // CalculateDrawProperties. |
| 2370 DCHECK(inputs->root_layer->render_surface()); | 2425 DCHECK(inputs->root_layer->render_surface()); |
| 2371 } | 2426 } |
| 2372 | 2427 |
| 2373 static bool PointHitsRect( | 2428 static bool PointHitsRect( |
| 2374 const gfx::PointF& screen_space_point, | 2429 const gfx::PointF& screen_space_point, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2580 // At this point, we think the point does hit the touch event handler region | 2635 // At this point, we think the point does hit the touch event handler region |
| 2581 // on the layer, but we need to walk up the parents to ensure that the layer | 2636 // on the layer, but we need to walk up the parents to ensure that the layer |
| 2582 // was not clipped in such a way that the hit point actually should not hit | 2637 // was not clipped in such a way that the hit point actually should not hit |
| 2583 // the layer. | 2638 // the layer. |
| 2584 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 2639 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
| 2585 return false; | 2640 return false; |
| 2586 | 2641 |
| 2587 return true; | 2642 return true; |
| 2588 } | 2643 } |
| 2589 } // namespace cc | 2644 } // namespace cc |
| OLD | NEW |