OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 LayerType* layer) { | 1122 LayerType* layer) { |
1123 if (!layer->render_surface()) { | 1123 if (!layer->render_surface()) { |
1124 layer->CreateRenderSurface(); | 1124 layer->CreateRenderSurface(); |
1125 return layer->render_surface(); | 1125 return layer->render_surface(); |
1126 } | 1126 } |
1127 | 1127 |
1128 layer->render_surface()->ClearLayerLists(); | 1128 layer->render_surface()->ClearLayerLists(); |
1129 return layer->render_surface(); | 1129 return layer->render_surface(); |
1130 } | 1130 } |
1131 | 1131 |
1132 template <typename LayerTypePtr> | |
1133 static inline void MarkLayerWithRenderSurfaceLayerListId( | |
1134 LayerTypePtr layer, | |
1135 int current_render_surface_layer_list_id) { | |
1136 layer->draw_properties().last_valid_render_surface_layer_list_id = | |
1137 current_render_surface_layer_list_id; | |
1138 if (layer->mask_layer()) { | |
1139 layer->mask_layer() | |
1140 ->draw_properties() | |
1141 .last_valid_render_surface_layer_list_id = | |
1142 current_render_surface_layer_list_id; | |
1143 } | |
1144 if (layer->replica_layer()) { | |
1145 layer->replica_layer() | |
1146 ->draw_properties() | |
1147 .last_valid_render_surface_layer_list_id = | |
1148 current_render_surface_layer_list_id; | |
1149 if (layer->replica_layer()->mask_layer()) { | |
1150 layer->replica_layer() | |
1151 ->mask_layer() | |
1152 ->draw_properties() | |
1153 .last_valid_render_surface_layer_list_id = | |
1154 current_render_surface_layer_list_id; | |
1155 } | |
1156 } | |
1157 } | |
1158 | |
1159 template <typename LayerListType> | |
1160 static inline void MarkLayerListWithRenderSurfaceLayerListId( | |
1161 LayerListType* layer_list, | |
1162 int current_render_surface_layer_list_id) { | |
1163 for (typename LayerListType::iterator it = layer_list->begin(); | |
1164 it != layer_list->end(); | |
1165 ++it) { | |
1166 MarkLayerWithRenderSurfaceLayerListId(*it, | |
1167 current_render_surface_layer_list_id); | |
1168 } | |
1169 } | |
1170 | |
1132 template <typename LayerType> | 1171 template <typename LayerType> |
1133 static inline void RemoveSurfaceForEarlyExit( | 1172 static inline void RemoveSurfaceForEarlyExit( |
1134 LayerType* layer_to_remove, | 1173 LayerType* layer_to_remove, |
1135 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { | 1174 typename LayerType::RenderSurfaceListType* render_surface_layer_list) { |
1136 DCHECK(layer_to_remove->render_surface()); | 1175 DCHECK(layer_to_remove->render_surface()); |
1137 // Technically, we know that the layer we want to remove should be | 1176 // 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 | 1177 // at the back of the render_surface_layer_list. However, we have had |
1139 // bugs before that added unnecessary layers here | 1178 // bugs before that added unnecessary layers here |
1140 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes | 1179 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes |
1141 // things to crash. So here we proactively remove any additional | 1180 // things to crash. So here we proactively remove any additional |
1142 // layers from the end of the list. | 1181 // layers from the end of the list. |
1143 while (render_surface_layer_list->back() != layer_to_remove) { | 1182 while (render_surface_layer_list->back() != layer_to_remove) { |
1144 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); | 1183 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); |
1184 MarkLayerListWithRenderSurfaceLayerListId( | |
enne (OOO)
2014/05/06 21:10:27
This doesn't do anything. You're calling this aft
vmpstr
2014/05/06 22:38:53
Fixed.
| |
1185 &render_surface_layer_list->back()->render_surface()->layer_list(), 0); | |
1186 MarkLayerWithRenderSurfaceLayerListId(render_surface_layer_list->back(), 0); | |
enne (OOO)
2014/05/06 21:10:27
Likewise, this.
vmpstr
2014/05/06 22:38:53
This marks the layer itself?
enne (OOO)
2014/05/07 00:12:11
Ok, I guess it's getting the mask and replica from
| |
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 MarkLayerListWithRenderSurfaceLayerListId( | |
enne (OOO)
2014/05/06 21:10:27
We will only get into this function if layer_to_re
vmpstr
2014/05/06 22:38:53
It doesn't have to be empty here, we also call thi
enne (OOO)
2014/05/07 00:12:11
Oh right, I forgot the clip case.
| |
1191 &layer_to_remove->render_surface()->layer_list(), 0); | |
1192 MarkLayerWithRenderSurfaceLayerListId(layer_to_remove, 0); | |
enne (OOO)
2014/05/06 21:10:27
This should already be marked properly. The layer
| |
1148 render_surface_layer_list->pop_back(); | 1193 render_surface_layer_list->pop_back(); |
1149 layer_to_remove->ClearRenderSurfaceLayerList(); | 1194 layer_to_remove->ClearRenderSurfaceLayerList(); |
1150 } | 1195 } |
1151 | 1196 |
1152 struct PreCalculateMetaInformationRecursiveData { | 1197 struct PreCalculateMetaInformationRecursiveData { |
1153 bool layer_or_descendant_has_copy_request; | 1198 bool layer_or_descendant_has_copy_request; |
1154 int num_unclipped_descendants; | 1199 int num_unclipped_descendants; |
1155 | 1200 |
1156 PreCalculateMetaInformationRecursiveData() | 1201 PreCalculateMetaInformationRecursiveData() |
1157 : layer_or_descendant_has_copy_request(false), | 1202 : layer_or_descendant_has_copy_request(false), |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1416 | 1461 |
1417 // Recursively walks the layer tree starting at the given node and computes all | 1462 // Recursively walks the layer tree starting at the given node and computes all |
1418 // the necessary transformations, clip rects, render surfaces, etc. | 1463 // the necessary transformations, clip rects, render surfaces, etc. |
1419 template <typename LayerType> | 1464 template <typename LayerType> |
1420 static void CalculateDrawPropertiesInternal( | 1465 static void CalculateDrawPropertiesInternal( |
1421 LayerType* layer, | 1466 LayerType* layer, |
1422 const SubtreeGlobals<LayerType>& globals, | 1467 const SubtreeGlobals<LayerType>& globals, |
1423 const DataForRecursion<LayerType>& data_from_ancestor, | 1468 const DataForRecursion<LayerType>& data_from_ancestor, |
1424 typename LayerType::RenderSurfaceListType* render_surface_layer_list, | 1469 typename LayerType::RenderSurfaceListType* render_surface_layer_list, |
1425 typename LayerType::LayerListType* layer_list, | 1470 typename LayerType::LayerListType* layer_list, |
1426 std::vector<AccumulatedSurfaceState<LayerType> >* | 1471 std::vector<AccumulatedSurfaceState<LayerType> >* accumulated_surface_state, |
1427 accumulated_surface_state) { | 1472 int current_render_surface_layer_list_id) { |
1428 // This function computes the new matrix transformations recursively for this | 1473 // This function computes the new matrix transformations recursively for this |
1429 // layer and all its descendants. It also computes the appropriate render | 1474 // layer and all its descendants. It also computes the appropriate render |
1430 // surfaces. | 1475 // surfaces. |
1431 // Some important points to remember: | 1476 // Some important points to remember: |
1432 // | 1477 // |
1433 // 0. Here, transforms are notated in Matrix x Vector order, and in words we | 1478 // 0. Here, transforms are notated in Matrix x Vector order, and in words we |
1434 // describe what the transform does from left to right. | 1479 // describe what the transform does from left to right. |
1435 // | 1480 // |
1436 // 1. In our terminology, the "layer origin" refers to the top-left corner of | 1481 // 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 | 1482 // 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()); | 1973 render_surface->SetClipRect(gfx::Rect()); |
1929 clip_rect_of_target_surface_in_target_space = | 1974 clip_rect_of_target_surface_in_target_space = |
1930 data_from_ancestor.clip_rect_of_target_surface_in_target_space; | 1975 data_from_ancestor.clip_rect_of_target_surface_in_target_space; |
1931 } | 1976 } |
1932 | 1977 |
1933 // If the new render surface is drawn translucent or with a non-integral | 1978 // 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 | 1979 // translation then the subtree that gets drawn on this render surface |
1935 // cannot use LCD text. | 1980 // cannot use LCD text. |
1936 data_for_children.subtree_can_use_lcd_text = layer_can_use_lcd_text; | 1981 data_for_children.subtree_can_use_lcd_text = layer_can_use_lcd_text; |
1937 | 1982 |
1983 MarkLayerWithRenderSurfaceLayerListId(layer, | |
danakj
2014/05/06 21:02:36
We were discussing this and enne@ pointed out that
| |
1984 current_render_surface_layer_list_id); | |
1938 render_surface_layer_list->push_back(layer); | 1985 render_surface_layer_list->push_back(layer); |
1939 } else { | 1986 } else { |
1940 DCHECK(layer->parent()); | 1987 DCHECK(layer->parent()); |
1941 | 1988 |
1942 // Note: layer_draw_properties.target_space_transform is computed above, | 1989 // Note: layer_draw_properties.target_space_transform is computed above, |
1943 // before this if-else statement. | 1990 // before this if-else statement. |
1944 layer_draw_properties.target_space_transform_is_animating = | 1991 layer_draw_properties.target_space_transform_is_animating = |
1945 animating_transform_to_target; | 1992 animating_transform_to_target; |
1946 layer_draw_properties.screen_space_transform_is_animating = | 1993 layer_draw_properties.screen_space_transform_is_animating = |
1947 animating_transform_to_screen; | 1994 animating_transform_to_screen; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2004 } | 2051 } |
2005 | 2052 |
2006 typename LayerType::LayerListType& descendants = | 2053 typename LayerType::LayerListType& descendants = |
2007 (layer->render_surface() ? layer->render_surface()->layer_list() | 2054 (layer->render_surface() ? layer->render_surface()->layer_list() |
2008 : *layer_list); | 2055 : *layer_list); |
2009 | 2056 |
2010 // Any layers that are appended after this point are in the layer's subtree | 2057 // Any layers that are appended after this point are in the layer's subtree |
2011 // and should be included in the sorting process. | 2058 // and should be included in the sorting process. |
2012 size_t sorting_start_index = descendants.size(); | 2059 size_t sorting_start_index = descendants.size(); |
2013 | 2060 |
2014 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) | 2061 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) { |
2062 MarkLayerWithRenderSurfaceLayerListId(layer, | |
2063 current_render_surface_layer_list_id); | |
2015 descendants.push_back(layer); | 2064 descendants.push_back(layer); |
2065 } | |
2016 | 2066 |
2017 // Any layers that are appended after this point may need to be sorted if we | 2067 // Any layers that are appended after this point may need to be sorted if we |
2018 // visit the children out of order. | 2068 // visit the children out of order. |
2019 size_t render_surface_layer_list_child_sorting_start_index = | 2069 size_t render_surface_layer_list_child_sorting_start_index = |
2020 render_surface_layer_list->size(); | 2070 render_surface_layer_list->size(); |
2021 size_t layer_list_child_sorting_start_index = descendants.size(); | 2071 size_t layer_list_child_sorting_start_index = descendants.size(); |
2022 | 2072 |
2023 if (!layer->children().empty()) { | 2073 if (!layer->children().empty()) { |
2024 if (layer == globals.page_scale_application_layer) { | 2074 if (layer == globals.page_scale_application_layer) { |
2025 data_for_children.parent_matrix.Scale( | 2075 data_for_children.parent_matrix.Scale( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2065 LayerType* child = | 2115 LayerType* child = |
2066 layer_draw_properties.has_child_with_a_scroll_parent | 2116 layer_draw_properties.has_child_with_a_scroll_parent |
2067 ? sorted_children[i] | 2117 ? sorted_children[i] |
2068 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); | 2118 : LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i); |
2069 | 2119 |
2070 child->draw_properties().index_of_first_descendants_addition = | 2120 child->draw_properties().index_of_first_descendants_addition = |
2071 descendants.size(); | 2121 descendants.size(); |
2072 child->draw_properties().index_of_first_render_surface_layer_list_addition = | 2122 child->draw_properties().index_of_first_render_surface_layer_list_addition = |
2073 render_surface_layer_list->size(); | 2123 render_surface_layer_list->size(); |
2074 | 2124 |
2075 CalculateDrawPropertiesInternal<LayerType>(child, | 2125 CalculateDrawPropertiesInternal<LayerType>( |
2076 globals, | 2126 child, |
2077 data_for_children, | 2127 globals, |
2078 render_surface_layer_list, | 2128 data_for_children, |
2079 &descendants, | 2129 render_surface_layer_list, |
2080 accumulated_surface_state); | 2130 &descendants, |
2131 accumulated_surface_state, | |
2132 current_render_surface_layer_list_id); | |
2081 if (child->render_surface() && | 2133 if (child->render_surface() && |
2082 !child->render_surface()->layer_list().empty() && | 2134 !child->render_surface()->layer_list().empty() && |
2083 !child->render_surface()->content_rect().IsEmpty()) { | 2135 !child->render_surface()->content_rect().IsEmpty()) { |
2136 // We don't need to mark this child with the draw properties id, since it | |
2137 // should've already been marked when it was pushed into the top level | |
2138 // render surface list. | |
2139 DCHECK(std::find(render_surface_layer_list->begin(), | |
2140 render_surface_layer_list->end(), | |
2141 child) != render_surface_layer_list->end()); | |
2084 descendants.push_back(child); | 2142 descendants.push_back(child); |
2085 } | 2143 } |
2086 | 2144 |
2087 child->draw_properties().num_descendants_added = | 2145 child->draw_properties().num_descendants_added = |
2088 descendants.size() - | 2146 descendants.size() - |
2089 child->draw_properties().index_of_first_descendants_addition; | 2147 child->draw_properties().index_of_first_descendants_addition; |
2090 child->draw_properties().num_render_surfaces_added = | 2148 child->draw_properties().num_render_surfaces_added = |
2091 render_surface_layer_list->size() - | 2149 render_surface_layer_list->size() - |
2092 child->draw_properties() | 2150 child->draw_properties() |
2093 .index_of_first_render_surface_layer_list_addition; | 2151 .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( | 2379 void LayerTreeHostCommon::CalculateDrawProperties( |
2322 CalcDrawPropsMainInputs* inputs) { | 2380 CalcDrawPropsMainInputs* inputs) { |
2323 LayerList dummy_layer_list; | 2381 LayerList dummy_layer_list; |
2324 SubtreeGlobals<Layer> globals; | 2382 SubtreeGlobals<Layer> globals; |
2325 DataForRecursion<Layer> data_for_recursion; | 2383 DataForRecursion<Layer> data_for_recursion; |
2326 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2384 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2327 | 2385 |
2328 PreCalculateMetaInformationRecursiveData recursive_data; | 2386 PreCalculateMetaInformationRecursiveData recursive_data; |
2329 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2387 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2330 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; | 2388 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; |
2331 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer, | 2389 CalculateDrawPropertiesInternal<Layer>( |
2332 globals, | 2390 inputs->root_layer, |
2333 data_for_recursion, | 2391 globals, |
2334 inputs->render_surface_layer_list, | 2392 data_for_recursion, |
2335 &dummy_layer_list, | 2393 inputs->render_surface_layer_list, |
2336 &accumulated_surface_state); | 2394 &dummy_layer_list, |
2395 &accumulated_surface_state, | |
2396 inputs->current_render_surface_layer_list_id); | |
2337 | 2397 |
2338 // The dummy layer list should not have been used. | 2398 // The dummy layer list should not have been used. |
2339 DCHECK_EQ(0u, dummy_layer_list.size()); | 2399 DCHECK_EQ(0u, dummy_layer_list.size()); |
2340 // A root layer render_surface should always exist after | 2400 // A root layer render_surface should always exist after |
2341 // CalculateDrawProperties. | 2401 // CalculateDrawProperties. |
2342 DCHECK(inputs->root_layer->render_surface()); | 2402 DCHECK(inputs->root_layer->render_surface()); |
2343 } | 2403 } |
2344 | 2404 |
2345 void LayerTreeHostCommon::CalculateDrawProperties( | 2405 void LayerTreeHostCommon::CalculateDrawProperties( |
2346 CalcDrawPropsImplInputs* inputs) { | 2406 CalcDrawPropsImplInputs* inputs) { |
2347 LayerImplList dummy_layer_list; | 2407 LayerImplList dummy_layer_list; |
2348 SubtreeGlobals<LayerImpl> globals; | 2408 SubtreeGlobals<LayerImpl> globals; |
2349 DataForRecursion<LayerImpl> data_for_recursion; | 2409 DataForRecursion<LayerImpl> data_for_recursion; |
2350 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2410 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2351 | 2411 |
2352 LayerSorter layer_sorter; | 2412 LayerSorter layer_sorter; |
2353 globals.layer_sorter = &layer_sorter; | 2413 globals.layer_sorter = &layer_sorter; |
2354 | 2414 |
2355 PreCalculateMetaInformationRecursiveData recursive_data; | 2415 PreCalculateMetaInformationRecursiveData recursive_data; |
2356 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2416 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2357 std::vector<AccumulatedSurfaceState<LayerImpl> > | 2417 std::vector<AccumulatedSurfaceState<LayerImpl> > |
2358 accumulated_surface_state; | 2418 accumulated_surface_state; |
2359 CalculateDrawPropertiesInternal<LayerImpl>(inputs->root_layer, | 2419 CalculateDrawPropertiesInternal<LayerImpl>( |
2360 globals, | 2420 inputs->root_layer, |
2361 data_for_recursion, | 2421 globals, |
2362 inputs->render_surface_layer_list, | 2422 data_for_recursion, |
2363 &dummy_layer_list, | 2423 inputs->render_surface_layer_list, |
2364 &accumulated_surface_state); | 2424 &dummy_layer_list, |
2425 &accumulated_surface_state, | |
2426 inputs->current_render_surface_layer_list_id); | |
2365 | 2427 |
2366 // The dummy layer list should not have been used. | 2428 // The dummy layer list should not have been used. |
2367 DCHECK_EQ(0u, dummy_layer_list.size()); | 2429 DCHECK_EQ(0u, dummy_layer_list.size()); |
2368 // A root layer render_surface should always exist after | 2430 // A root layer render_surface should always exist after |
2369 // CalculateDrawProperties. | 2431 // CalculateDrawProperties. |
2370 DCHECK(inputs->root_layer->render_surface()); | 2432 DCHECK(inputs->root_layer->render_surface()); |
2371 } | 2433 } |
2372 | 2434 |
2373 static bool PointHitsRect( | 2435 static bool PointHitsRect( |
2374 const gfx::PointF& screen_space_point, | 2436 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 | 2642 // 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 | 2643 // 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 | 2644 // was not clipped in such a way that the hit point actually should not hit |
2583 // the layer. | 2645 // the layer. |
2584 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 2646 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
2585 return false; | 2647 return false; |
2586 | 2648 |
2587 return true; | 2649 return true; |
2588 } | 2650 } |
2589 } // namespace cc | 2651 } // namespace cc |
OLD | NEW |