| 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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/gfx/transform_util.h" | 24 #include "ui/gfx/transform_util.h" |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 | 27 |
| 28 ScrollAndScaleSet::ScrollAndScaleSet() | 28 ScrollAndScaleSet::ScrollAndScaleSet() |
| 29 : page_scale_delta(1.f), top_controls_delta(0.f) { | 29 : page_scale_delta(1.f), top_controls_delta(0.f) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 ScrollAndScaleSet::~ScrollAndScaleSet() {} | 32 ScrollAndScaleSet::~ScrollAndScaleSet() {} |
| 33 | 33 |
| 34 static void SortLayers(LayerList::iterator forst, | 34 static void SortLayers(LayerList::iterator first, |
| 35 LayerList::iterator end, | 35 LayerList::iterator end, |
| 36 void* layer_sorter) { | 36 void* layer_sorter) { |
| 37 NOTREACHED(); | 37 NOTREACHED(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 static void SortLayers(LayerImplList::iterator first, | 40 static void SortLayers(LayerImplList::iterator first, |
| 41 LayerImplList::iterator end, | 41 LayerImplList::iterator end, |
| 42 LayerSorter* layer_sorter) { | 42 LayerSorter* layer_sorter) { |
| 43 DCHECK(layer_sorter); | 43 DCHECK(layer_sorter); |
| 44 TRACE_EVENT0("cc", "LayerTreeHostCommon::SortLayers"); | 44 TRACE_EVENT0("cc", "LayerTreeHostCommon::SortLayers"); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 DCHECK(found_render_target); | 330 DCHECK(found_render_target); |
| 331 } | 331 } |
| 332 | 332 |
| 333 template <typename LayerType> static inline bool IsRootLayer(LayerType* layer) { | 333 template <typename LayerType> static inline bool IsRootLayer(LayerType* layer) { |
| 334 return !layer->parent(); | 334 return !layer->parent(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 template <typename LayerType> | 337 template <typename LayerType> |
| 338 static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) { | 338 static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) { |
| 339 return layer->Is3dSorted() && layer->parent() && | 339 return layer->Is3dSorted() && layer->parent() && |
| 340 layer->parent()->Is3dSorted(); | 340 layer->parent()->Is3dSorted() && |
| 341 (layer->parent()->sorting_context_id() == layer->sorting_context_id()); |
| 341 } | 342 } |
| 342 | 343 |
| 343 template <typename LayerType> | 344 template <typename LayerType> |
| 344 static bool IsRootLayerOfNewRenderingContext(LayerType* layer) { | 345 static bool IsRootLayerOfNewRenderingContext(LayerType* layer) { |
| 345 if (layer->parent()) | 346 if (layer->parent()) |
| 346 return !layer->parent()->Is3dSorted() && layer->Is3dSorted(); | 347 return !layer->parent()->Is3dSorted() && layer->Is3dSorted(); |
| 347 | 348 |
| 348 return layer->Is3dSorted(); | 349 return layer->Is3dSorted(); |
| 349 } | 350 } |
| 350 | 351 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 DCHECK(!is_root); | 584 DCHECK(!is_root); |
| 584 return true; | 585 return true; |
| 585 } | 586 } |
| 586 | 587 |
| 587 // If the layer uses a CSS filter. | 588 // If the layer uses a CSS filter. |
| 588 if (!layer->filters().IsEmpty() || !layer->background_filters().IsEmpty()) { | 589 if (!layer->filters().IsEmpty() || !layer->background_filters().IsEmpty()) { |
| 589 DCHECK(!is_root); | 590 DCHECK(!is_root); |
| 590 return true; | 591 return true; |
| 591 } | 592 } |
| 592 | 593 |
| 594 // If the layer will use a CSS filter. In this case, the animation |
| 595 // will start and add a filter to this layer, so it needs a surface. |
| 596 if (layer->FilterIsAnimating()) { |
| 597 DCHECK(!is_root); |
| 598 return true; |
| 599 } |
| 600 |
| 593 int num_descendants_that_draw_content = | 601 int num_descendants_that_draw_content = |
| 594 layer->NumDescendantsThatDrawContent(); | 602 layer->NumDescendantsThatDrawContent(); |
| 595 | 603 |
| 596 // If the layer flattens its subtree, but it is treated as a 3D object by its | 604 // If the layer flattens its subtree, but it is treated as a 3D object by its |
| 597 // parent (i.e. parent participates in a 3D rendering context). | 605 // parent (i.e. parent participates in a 3D rendering context). |
| 598 if (LayerIsInExisting3DRenderingContext(layer) && | 606 if (LayerIsInExisting3DRenderingContext(layer) && |
| 599 layer->should_flatten_transform() && | 607 layer->should_flatten_transform() && |
| 600 num_descendants_that_draw_content > 0) { | 608 num_descendants_that_draw_content > 0) { |
| 601 TRACE_EVENT_INSTANT0( | 609 TRACE_EVENT_INSTANT0( |
| 602 "cc", | 610 "cc", |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 void Merge(const PreCalculateMetaInformationRecursiveData& data) { | 1198 void Merge(const PreCalculateMetaInformationRecursiveData& data) { |
| 1191 layer_or_descendant_has_copy_request |= | 1199 layer_or_descendant_has_copy_request |= |
| 1192 data.layer_or_descendant_has_copy_request; | 1200 data.layer_or_descendant_has_copy_request; |
| 1193 layer_or_descendant_has_input_handler |= | 1201 layer_or_descendant_has_input_handler |= |
| 1194 data.layer_or_descendant_has_input_handler; | 1202 data.layer_or_descendant_has_input_handler; |
| 1195 num_unclipped_descendants += | 1203 num_unclipped_descendants += |
| 1196 data.num_unclipped_descendants; | 1204 data.num_unclipped_descendants; |
| 1197 } | 1205 } |
| 1198 }; | 1206 }; |
| 1199 | 1207 |
| 1200 static bool ValidateRenderSurface(LayerImpl* layer) { | 1208 static void ValidateRenderSurface(LayerImpl* layer) { |
| 1201 // This test verifies that there are no cases where a LayerImpl needs | 1209 // This test verifies that there are no cases where a LayerImpl needs |
| 1202 // a render surface, but doesn't have one. | 1210 // a render surface, but doesn't have one. |
| 1203 if (layer->render_surface()) | 1211 if (layer->render_surface()) |
| 1204 return true; | 1212 return; |
| 1205 | 1213 |
| 1206 return layer->filters().IsEmpty() && layer->background_filters().IsEmpty() && | 1214 DCHECK(layer->filters().IsEmpty()) << "layer: " << layer->id(); |
| 1207 !layer->mask_layer() && !layer->replica_layer() && | 1215 DCHECK(layer->background_filters().IsEmpty()) << "layer: " << layer->id(); |
| 1208 !IsRootLayer(layer) && !layer->is_root_for_isolated_group() && | 1216 DCHECK(!layer->mask_layer()) << "layer: " << layer->id(); |
| 1209 !layer->HasCopyRequest(); | 1217 DCHECK(!layer->replica_layer()) << "layer: " << layer->id(); |
| 1218 DCHECK(!IsRootLayer(layer)) << "layer: " << layer->id(); |
| 1219 DCHECK(!layer->is_root_for_isolated_group()) << "layer: " << layer->id(); |
| 1220 DCHECK(!layer->HasCopyRequest()) << "layer: " << layer->id(); |
| 1210 } | 1221 } |
| 1211 | 1222 |
| 1212 static bool ValidateRenderSurface(Layer* layer) { | 1223 static void ValidateRenderSurface(Layer* layer) { |
| 1213 return true; | |
| 1214 } | 1224 } |
| 1215 | 1225 |
| 1216 // Recursively walks the layer tree to compute any information that is needed | 1226 // Recursively walks the layer tree to compute any information that is needed |
| 1217 // before doing the main recursion. | 1227 // before doing the main recursion. |
| 1218 template <typename LayerType> | 1228 template <typename LayerType> |
| 1219 static void PreCalculateMetaInformation( | 1229 static void PreCalculateMetaInformation( |
| 1220 LayerType* layer, | 1230 LayerType* layer, |
| 1221 PreCalculateMetaInformationRecursiveData* recursive_data) { | 1231 PreCalculateMetaInformationRecursiveData* recursive_data) { |
| 1222 DCHECK(ValidateRenderSurface(layer)); | 1232 ValidateRenderSurface(layer); |
| 1223 | 1233 |
| 1224 layer->draw_properties().sorted_for_recursion = false; | 1234 layer->draw_properties().sorted_for_recursion = false; |
| 1225 layer->draw_properties().has_child_with_a_scroll_parent = false; | 1235 layer->draw_properties().has_child_with_a_scroll_parent = false; |
| 1236 layer->draw_properties().visited = false; |
| 1226 | 1237 |
| 1227 if (!HasInvertibleOrAnimatedTransform(layer)) { | 1238 if (!HasInvertibleOrAnimatedTransform(layer)) { |
| 1228 // Layers with singular transforms should not be drawn, the whole subtree | 1239 // Layers with singular transforms should not be drawn, the whole subtree |
| 1229 // can be skipped. | 1240 // can be skipped. |
| 1230 return; | 1241 return; |
| 1231 } | 1242 } |
| 1232 | 1243 |
| 1233 if (layer->clip_parent()) | 1244 if (layer->clip_parent()) |
| 1234 recursive_data->num_unclipped_descendants++; | 1245 recursive_data->num_unclipped_descendants++; |
| 1235 | 1246 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 // The replica draw transform to the root (screen space) origin is: | 1594 // The replica draw transform to the root (screen space) origin is: |
| 1584 // M[replica2root] = M[surface2root] * Tr[replica->position()] * | 1595 // M[replica2root] = M[surface2root] * Tr[replica->position()] * |
| 1585 // Tr[replica] * Tr[origin2anchor].inverse() | 1596 // Tr[replica] * Tr[origin2anchor].inverse() |
| 1586 // | 1597 // |
| 1587 | 1598 |
| 1588 // It makes no sense to have a non-unit page_scale_factor without specifying | 1599 // It makes no sense to have a non-unit page_scale_factor without specifying |
| 1589 // which layer roots the subtree the scale is applied to. | 1600 // which layer roots the subtree the scale is applied to. |
| 1590 DCHECK(globals.page_scale_application_layer || | 1601 DCHECK(globals.page_scale_application_layer || |
| 1591 (globals.page_scale_factor == 1.f)); | 1602 (globals.page_scale_factor == 1.f)); |
| 1592 | 1603 |
| 1604 CHECK(!layer->draw_properties().visited); |
| 1605 layer->draw_properties().visited = true; |
| 1606 |
| 1593 DataForRecursion<LayerType> data_for_children; | 1607 DataForRecursion<LayerType> data_for_children; |
| 1594 typename LayerType::RenderSurfaceType* | 1608 typename LayerType::RenderSurfaceType* |
| 1595 nearest_occlusion_immune_ancestor_surface = | 1609 nearest_occlusion_immune_ancestor_surface = |
| 1596 data_from_ancestor.nearest_occlusion_immune_ancestor_surface; | 1610 data_from_ancestor.nearest_occlusion_immune_ancestor_surface; |
| 1597 data_for_children.in_subtree_of_page_scale_application_layer = | 1611 data_for_children.in_subtree_of_page_scale_application_layer = |
| 1598 data_from_ancestor.in_subtree_of_page_scale_application_layer; | 1612 data_from_ancestor.in_subtree_of_page_scale_application_layer; |
| 1599 data_for_children.subtree_can_use_lcd_text = | 1613 data_for_children.subtree_can_use_lcd_text = |
| 1600 data_from_ancestor.subtree_can_use_lcd_text; | 1614 data_from_ancestor.subtree_can_use_lcd_text; |
| 1601 | 1615 |
| 1602 // Layers that are marked as hidden will hide themselves and their subtree. | 1616 // Layers that are marked as hidden will hide themselves and their subtree. |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 false); | 2508 false); |
| 2495 LayerList dummy_layer_list; | 2509 LayerList dummy_layer_list; |
| 2496 SubtreeGlobals<Layer> globals; | 2510 SubtreeGlobals<Layer> globals; |
| 2497 DataForRecursion<Layer> data_for_recursion; | 2511 DataForRecursion<Layer> data_for_recursion; |
| 2498 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2512 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
| 2499 | 2513 |
| 2500 PreCalculateMetaInformationRecursiveData recursive_data; | 2514 PreCalculateMetaInformationRecursiveData recursive_data; |
| 2501 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2515 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
| 2502 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; | 2516 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; |
| 2503 CalculateDrawPropertiesInternal<Layer>( | 2517 CalculateDrawPropertiesInternal<Layer>( |
| 2504 inputs->root_layer, | 2518 inputs->root_layer, globals, data_for_recursion, |
| 2505 globals, | 2519 inputs->render_surface_layer_list, &dummy_layer_list, |
| 2506 data_for_recursion, | 2520 &accumulated_surface_state, inputs->current_render_surface_layer_list_id); |
| 2507 inputs->render_surface_layer_list, | |
| 2508 &dummy_layer_list, | |
| 2509 &accumulated_surface_state, | |
| 2510 inputs->current_render_surface_layer_list_id); | |
| 2511 | 2521 |
| 2512 // The dummy layer list should not have been used. | 2522 // The dummy layer list should not have been used. |
| 2513 DCHECK_EQ(0u, dummy_layer_list.size()); | 2523 DCHECK_EQ(0u, dummy_layer_list.size()); |
| 2514 // A root layer render_surface should always exist after | 2524 // A root layer render_surface should always exist after |
| 2515 // CalculateDrawProperties. | 2525 // CalculateDrawProperties. |
| 2516 DCHECK(inputs->root_layer->render_surface()); | 2526 DCHECK(inputs->root_layer->render_surface()); |
| 2517 | 2527 |
| 2518 if (inputs->verify_property_trees) { | 2528 if (inputs->verify_property_trees) { |
| 2519 // The translation from layer to property trees is an intermediate state. We | 2529 // The translation from layer to property trees is an intermediate state. We |
| 2520 // will eventually get these data passed directly to the compositor. | 2530 // will eventually get these data passed directly to the compositor. |
| 2521 TransformTree transform_tree; | 2531 TransformTree transform_tree; |
| 2522 ClipTree clip_tree; | 2532 ClipTree clip_tree; |
| 2533 OpacityTree opacity_tree; |
| 2523 ComputeVisibleRectsUsingPropertyTrees( | 2534 ComputeVisibleRectsUsingPropertyTrees( |
| 2524 inputs->root_layer, inputs->page_scale_application_layer, | 2535 inputs->root_layer, inputs->page_scale_application_layer, |
| 2525 inputs->page_scale_factor, inputs->device_scale_factor, | 2536 inputs->page_scale_factor, inputs->device_scale_factor, |
| 2526 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, | 2537 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, |
| 2527 &transform_tree, &clip_tree); | 2538 &transform_tree, &clip_tree, &opacity_tree); |
| 2528 | 2539 |
| 2529 LayerIterator<Layer> it, end; | 2540 LayerIterator<Layer> it, end; |
| 2530 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list), | 2541 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list), |
| 2531 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list); | 2542 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list); |
| 2532 it != end; ++it) { | 2543 it != end; ++it) { |
| 2533 Layer* current_layer = *it; | 2544 Layer* current_layer = *it; |
| 2534 if (!it.represents_itself() || !current_layer->DrawsContent()) | 2545 if (!it.represents_itself() || !current_layer->DrawsContent()) |
| 2535 continue; | 2546 continue; |
| 2536 | 2547 |
| 2537 const bool visible_rects_match = | 2548 const bool visible_rects_match = |
| 2538 ApproximatelyEqual(current_layer->visible_content_rect(), | 2549 ApproximatelyEqual(current_layer->visible_content_rect(), |
| 2539 current_layer->visible_rect_from_property_trees()); | 2550 current_layer->visible_rect_from_property_trees()); |
| 2540 CHECK(visible_rects_match); | 2551 CHECK(visible_rects_match); |
| 2541 | 2552 |
| 2542 const bool draw_transforms_match = ApproximatelyEqual( | 2553 const bool draw_transforms_match = ApproximatelyEqual( |
| 2543 current_layer->draw_transform(), | 2554 current_layer->draw_transform(), |
| 2544 current_layer->draw_transform_from_property_trees(transform_tree)); | 2555 current_layer->draw_transform_from_property_trees(transform_tree)); |
| 2545 CHECK(draw_transforms_match); | 2556 CHECK(draw_transforms_match); |
| 2557 |
| 2558 const bool draw_opacities_match = |
| 2559 current_layer->draw_opacity() == |
| 2560 current_layer->DrawOpacityFromPropertyTrees(opacity_tree); |
| 2561 CHECK(draw_opacities_match); |
| 2546 } | 2562 } |
| 2547 } | 2563 } |
| 2548 } | 2564 } |
| 2549 | 2565 |
| 2550 void LayerTreeHostCommon::CalculateDrawProperties( | 2566 void LayerTreeHostCommon::CalculateDrawProperties( |
| 2551 CalcDrawPropsImplInputs* inputs) { | 2567 CalcDrawPropsImplInputs* inputs) { |
| 2552 LayerImplList dummy_layer_list; | 2568 LayerImplList dummy_layer_list; |
| 2553 SubtreeGlobals<LayerImpl> globals; | 2569 SubtreeGlobals<LayerImpl> globals; |
| 2554 DataForRecursion<LayerImpl> data_for_recursion; | 2570 DataForRecursion<LayerImpl> data_for_recursion; |
| 2555 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2571 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2570 inputs->current_render_surface_layer_list_id); | 2586 inputs->current_render_surface_layer_list_id); |
| 2571 | 2587 |
| 2572 // The dummy layer list should not have been used. | 2588 // The dummy layer list should not have been used. |
| 2573 DCHECK_EQ(0u, dummy_layer_list.size()); | 2589 DCHECK_EQ(0u, dummy_layer_list.size()); |
| 2574 // A root layer render_surface should always exist after | 2590 // A root layer render_surface should always exist after |
| 2575 // CalculateDrawProperties. | 2591 // CalculateDrawProperties. |
| 2576 DCHECK(inputs->root_layer->render_surface()); | 2592 DCHECK(inputs->root_layer->render_surface()); |
| 2577 } | 2593 } |
| 2578 | 2594 |
| 2579 } // namespace cc | 2595 } // namespace cc |
| OLD | NEW |