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