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" |
11 #include "cc/layers/heads_up_display_layer_impl.h" | 11 #include "cc/layers/heads_up_display_layer_impl.h" |
12 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
13 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
14 #include "cc/layers/layer_iterator.h" | 14 #include "cc/layers/layer_iterator.h" |
15 #include "cc/layers/render_surface.h" | 15 #include "cc/layers/render_surface.h" |
16 #include "cc/layers/render_surface_impl.h" | 16 #include "cc/layers/render_surface_impl.h" |
17 #include "cc/trees/draw_property_utils.h" | 17 #include "cc/trees/draw_property_utils.h" |
18 #include "cc/trees/layer_sorter.h" | 18 #include "cc/trees/layer_sorter.h" |
19 #include "cc/trees/layer_tree_host.h" | 19 #include "cc/trees/layer_tree_host.h" |
20 #include "cc/trees/layer_tree_impl.h" | 20 #include "cc/trees/layer_tree_impl.h" |
21 #include "ui/gfx/geometry/rect_conversions.h" | 21 #include "ui/gfx/geometry/rect_conversions.h" |
22 #include "ui/gfx/geometry/vector2d_conversions.h" | 22 #include "ui/gfx/geometry/vector2d_conversions.h" |
23 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
| 24 #include "ui/gfx/transform_util.h" |
24 | 25 |
25 namespace cc { | 26 namespace cc { |
26 | 27 |
27 ScrollAndScaleSet::ScrollAndScaleSet() | 28 ScrollAndScaleSet::ScrollAndScaleSet() |
28 : page_scale_delta(1.f), top_controls_delta(0.f) { | 29 : page_scale_delta(1.f), top_controls_delta(0.f) { |
29 } | 30 } |
30 | 31 |
31 ScrollAndScaleSet::~ScrollAndScaleSet() {} | 32 ScrollAndScaleSet::~ScrollAndScaleSet() {} |
32 | 33 |
33 static void SortLayers(LayerList::iterator forst, | 34 static void SortLayers(LayerList::iterator forst, |
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 void Merge(const PreCalculateMetaInformationRecursiveData& data) { | 1196 void Merge(const PreCalculateMetaInformationRecursiveData& data) { |
1196 layer_or_descendant_has_copy_request |= | 1197 layer_or_descendant_has_copy_request |= |
1197 data.layer_or_descendant_has_copy_request; | 1198 data.layer_or_descendant_has_copy_request; |
1198 layer_or_descendant_has_input_handler |= | 1199 layer_or_descendant_has_input_handler |= |
1199 data.layer_or_descendant_has_input_handler; | 1200 data.layer_or_descendant_has_input_handler; |
1200 num_unclipped_descendants += | 1201 num_unclipped_descendants += |
1201 data.num_unclipped_descendants; | 1202 data.num_unclipped_descendants; |
1202 } | 1203 } |
1203 }; | 1204 }; |
1204 | 1205 |
1205 static bool ValidateRenderSurface(LayerImpl* layer) { | |
1206 // There are a few cases in which it is incorrect to not have a | |
1207 // render_surface. | |
1208 if (layer->render_surface()) | |
1209 return true; | |
1210 | |
1211 return layer->filters().IsEmpty() && layer->background_filters().IsEmpty() && | |
1212 !layer->mask_layer() && !layer->replica_layer() && | |
1213 !IsRootLayer(layer) && !layer->is_root_for_isolated_group() && | |
1214 !layer->HasCopyRequest(); | |
1215 } | |
1216 | |
1217 static bool ValidateRenderSurface(Layer* layer) { | |
1218 return true; | |
1219 } | |
1220 | |
1221 // Recursively walks the layer tree to compute any information that is needed | 1206 // Recursively walks the layer tree to compute any information that is needed |
1222 // before doing the main recursion. | 1207 // before doing the main recursion. |
1223 template <typename LayerType> | 1208 template <typename LayerType> |
1224 static void PreCalculateMetaInformation( | 1209 static void PreCalculateMetaInformation( |
1225 LayerType* layer, | 1210 LayerType* layer, |
1226 PreCalculateMetaInformationRecursiveData* recursive_data) { | 1211 PreCalculateMetaInformationRecursiveData* recursive_data) { |
1227 DCHECK(ValidateRenderSurface(layer)); | |
1228 | |
1229 layer->draw_properties().sorted_for_recursion = false; | 1212 layer->draw_properties().sorted_for_recursion = false; |
1230 layer->draw_properties().has_child_with_a_scroll_parent = false; | 1213 layer->draw_properties().has_child_with_a_scroll_parent = false; |
1231 | 1214 |
1232 if (!HasInvertibleOrAnimatedTransform(layer)) { | 1215 if (!HasInvertibleOrAnimatedTransform(layer)) { |
1233 // Layers with singular transforms should not be drawn, the whole subtree | 1216 // Layers with singular transforms should not be drawn, the whole subtree |
1234 // can be skipped. | 1217 // can be skipped. |
1235 return; | 1218 return; |
1236 } | 1219 } |
1237 | 1220 |
1238 if (layer->clip_parent()) | 1221 if (layer->clip_parent()) |
(...skipping 25 matching lines...) Expand all Loading... |
1264 recursive_data->layer_or_descendant_has_input_handler = true; | 1247 recursive_data->layer_or_descendant_has_input_handler = true; |
1265 | 1248 |
1266 layer->draw_properties().num_unclipped_descendants = | 1249 layer->draw_properties().num_unclipped_descendants = |
1267 recursive_data->num_unclipped_descendants; | 1250 recursive_data->num_unclipped_descendants; |
1268 layer->draw_properties().layer_or_descendant_has_copy_request = | 1251 layer->draw_properties().layer_or_descendant_has_copy_request = |
1269 recursive_data->layer_or_descendant_has_copy_request; | 1252 recursive_data->layer_or_descendant_has_copy_request; |
1270 layer->draw_properties().layer_or_descendant_has_input_handler = | 1253 layer->draw_properties().layer_or_descendant_has_input_handler = |
1271 recursive_data->layer_or_descendant_has_input_handler; | 1254 recursive_data->layer_or_descendant_has_input_handler; |
1272 } | 1255 } |
1273 | 1256 |
1274 static void RoundTranslationComponents(gfx::Transform* transform) { | |
1275 transform->matrix().set(0, 3, MathUtil::Round(transform->matrix().get(0, 3))); | |
1276 transform->matrix().set(1, 3, MathUtil::Round(transform->matrix().get(1, 3))); | |
1277 } | |
1278 | |
1279 template <typename LayerType> | 1257 template <typename LayerType> |
1280 struct SubtreeGlobals { | 1258 struct SubtreeGlobals { |
1281 LayerSorter* layer_sorter; | 1259 LayerSorter* layer_sorter; |
1282 int max_texture_size; | 1260 int max_texture_size; |
1283 float device_scale_factor; | 1261 float device_scale_factor; |
1284 float page_scale_factor; | 1262 float page_scale_factor; |
1285 const LayerType* page_scale_application_layer; | 1263 const LayerType* page_scale_application_layer; |
1286 gfx::Vector2dF elastic_overscroll; | 1264 gfx::Vector2dF elastic_overscroll; |
1287 const LayerType* elastic_overscroll_application_layer; | 1265 const LayerType* elastic_overscroll_application_layer; |
1288 bool can_adjust_raster_scales; | 1266 bool can_adjust_raster_scales; |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 combined_transform.Translate(position.x(), position.y()); | 1672 combined_transform.Translate(position.x(), position.y()); |
1695 } | 1673 } |
1696 | 1674 |
1697 gfx::Vector2dF effective_scroll_delta = GetEffectiveScrollDelta(layer); | 1675 gfx::Vector2dF effective_scroll_delta = GetEffectiveScrollDelta(layer); |
1698 if (!animating_transform_to_target && layer->scrollable() && | 1676 if (!animating_transform_to_target && layer->scrollable() && |
1699 combined_transform.IsScaleOrTranslation()) { | 1677 combined_transform.IsScaleOrTranslation()) { |
1700 // Align the scrollable layer's position to screen space pixels to avoid | 1678 // Align the scrollable layer's position to screen space pixels to avoid |
1701 // blurriness. To avoid side-effects, do this only if the transform is | 1679 // blurriness. To avoid side-effects, do this only if the transform is |
1702 // simple. | 1680 // simple. |
1703 gfx::Vector2dF previous_translation = combined_transform.To2dTranslation(); | 1681 gfx::Vector2dF previous_translation = combined_transform.To2dTranslation(); |
1704 RoundTranslationComponents(&combined_transform); | 1682 combined_transform.RoundTranslationComponents(); |
1705 gfx::Vector2dF current_translation = combined_transform.To2dTranslation(); | 1683 gfx::Vector2dF current_translation = combined_transform.To2dTranslation(); |
1706 | 1684 |
1707 // This rounding changes the scroll delta, and so must be included | 1685 // This rounding changes the scroll delta, and so must be included |
1708 // in the scroll compensation matrix. The scaling converts from physical | 1686 // in the scroll compensation matrix. The scaling converts from physical |
1709 // coordinates to the scroll delta's CSS coordinates (using the parent | 1687 // coordinates to the scroll delta's CSS coordinates (using the parent |
1710 // matrix instead of combined transform since scrolling is applied before | 1688 // matrix instead of combined transform since scrolling is applied before |
1711 // the layer's transform). For example, if we have a total scale factor of | 1689 // the layer's transform). For example, if we have a total scale factor of |
1712 // 3.0, then 1 physical pixel is only 1/3 of a CSS pixel. | 1690 // 3.0, then 1 physical pixel is only 1/3 of a CSS pixel. |
1713 gfx::Vector2dF parent_scales = MathUtil::ComputeTransform2dScaleComponents( | 1691 gfx::Vector2dF parent_scales = MathUtil::ComputeTransform2dScaleComponents( |
1714 data_from_ancestor.parent_matrix, 1.f); | 1692 data_from_ancestor.parent_matrix, 1.f); |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2484 } | 2462 } |
2485 | 2463 |
2486 static bool ApproximatelyEqual(const gfx::Rect& r1, const gfx::Rect& r2) { | 2464 static bool ApproximatelyEqual(const gfx::Rect& r1, const gfx::Rect& r2) { |
2487 static const int tolerance = 1; | 2465 static const int tolerance = 1; |
2488 return std::abs(r1.x() - r2.x()) <= tolerance && | 2466 return std::abs(r1.x() - r2.x()) <= tolerance && |
2489 std::abs(r1.y() - r2.y()) <= tolerance && | 2467 std::abs(r1.y() - r2.y()) <= tolerance && |
2490 std::abs(r1.width() - r2.width()) <= tolerance && | 2468 std::abs(r1.width() - r2.width()) <= tolerance && |
2491 std::abs(r1.height() - r2.height()) <= tolerance; | 2469 std::abs(r1.height() - r2.height()) <= tolerance; |
2492 } | 2470 } |
2493 | 2471 |
| 2472 static bool ApproximatelyEqual(const gfx::Transform& a, |
| 2473 const gfx::Transform& b) { |
| 2474 static const float tolerance = 0.01f; |
| 2475 return gfx::MatrixDistance(a, b) < tolerance; |
| 2476 } |
| 2477 |
2494 void LayerTreeHostCommon::CalculateDrawProperties( | 2478 void LayerTreeHostCommon::CalculateDrawProperties( |
2495 CalcDrawPropsMainInputs* inputs) { | 2479 CalcDrawPropsMainInputs* inputs) { |
2496 UpdateRenderSurfaces(inputs->root_layer, | 2480 UpdateRenderSurfaces(inputs->root_layer, |
2497 inputs->can_render_to_separate_surface, gfx::Transform(), | 2481 inputs->can_render_to_separate_surface, gfx::Transform(), |
2498 false); | 2482 false); |
2499 LayerList dummy_layer_list; | 2483 LayerList dummy_layer_list; |
2500 SubtreeGlobals<Layer> globals; | 2484 SubtreeGlobals<Layer> globals; |
2501 DataForRecursion<Layer> data_for_recursion; | 2485 DataForRecursion<Layer> data_for_recursion; |
2502 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2486 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2503 | 2487 |
2504 PreCalculateMetaInformationRecursiveData recursive_data; | 2488 PreCalculateMetaInformationRecursiveData recursive_data; |
2505 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2489 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2506 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; | 2490 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; |
2507 CalculateDrawPropertiesInternal<Layer>( | 2491 CalculateDrawPropertiesInternal<Layer>( |
2508 inputs->root_layer, | 2492 inputs->root_layer, |
2509 globals, | 2493 globals, |
2510 data_for_recursion, | 2494 data_for_recursion, |
2511 inputs->render_surface_layer_list, | 2495 inputs->render_surface_layer_list, |
2512 &dummy_layer_list, | 2496 &dummy_layer_list, |
2513 &accumulated_surface_state, | 2497 &accumulated_surface_state, |
2514 inputs->current_render_surface_layer_list_id); | 2498 inputs->current_render_surface_layer_list_id); |
2515 | 2499 |
2516 // The dummy layer list should not have been used. | 2500 // The dummy layer list should not have been used. |
2517 DCHECK_EQ(0u, dummy_layer_list.size()); | 2501 DCHECK_EQ(0u, dummy_layer_list.size()); |
2518 // A root layer render_surface should always exist after | 2502 // A root layer render_surface should always exist after |
2519 // CalculateDrawProperties. | 2503 // CalculateDrawProperties. |
2520 DCHECK(inputs->root_layer->render_surface()); | 2504 DCHECK(inputs->root_layer->render_surface()); |
2521 | 2505 |
2522 if (inputs->verify_property_trees) { | 2506 if (inputs->verify_property_trees) { |
2523 // TODO(ajuma): Can we efficiently cache some of this rather than | 2507 // The translation from layer to property trees is an intermediate state. We |
2524 // starting from scratch every frame? | 2508 // will eventually get these data passed directly to the compositor. |
2525 TransformTree transform_tree; | 2509 TransformTree transform_tree; |
2526 ClipTree clip_tree; | 2510 ClipTree clip_tree; |
2527 ComputeVisibleRectsUsingPropertyTrees( | 2511 ComputeVisibleRectsUsingPropertyTrees( |
2528 inputs->root_layer, inputs->page_scale_application_layer, | 2512 inputs->root_layer, inputs->page_scale_application_layer, |
2529 inputs->page_scale_factor, inputs->device_scale_factor, | 2513 inputs->page_scale_factor, inputs->device_scale_factor, |
2530 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, | 2514 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, |
2531 &transform_tree, &clip_tree); | 2515 &transform_tree, &clip_tree); |
2532 | 2516 |
2533 bool failed = false; | |
2534 LayerIterator<Layer> it, end; | 2517 LayerIterator<Layer> it, end; |
2535 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list), | 2518 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list), |
2536 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list); | 2519 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list); |
2537 it != end; ++it) { | 2520 it != end; ++it) { |
2538 Layer* current_layer = *it; | 2521 Layer* current_layer = *it; |
2539 if (it.represents_itself()) { | 2522 if (!it.represents_itself() || !current_layer->DrawsContent()) |
2540 if (!failed && current_layer->DrawsContent() && | 2523 continue; |
2541 !ApproximatelyEqual( | 2524 |
2542 current_layer->visible_content_rect(), | 2525 const bool visible_rects_match = |
2543 current_layer->visible_rect_from_property_trees())) { | 2526 ApproximatelyEqual(current_layer->visible_content_rect(), |
2544 failed = true; | 2527 current_layer->visible_rect_from_property_trees()); |
2545 } | 2528 CHECK(visible_rects_match); |
2546 } | 2529 |
| 2530 const bool draw_transforms_match = ApproximatelyEqual( |
| 2531 current_layer->draw_transform(), |
| 2532 current_layer->draw_transform_from_property_trees(transform_tree)); |
| 2533 CHECK(draw_transforms_match); |
2547 } | 2534 } |
2548 | |
2549 CHECK(!failed); | |
2550 } | 2535 } |
2551 } | 2536 } |
2552 | 2537 |
2553 void LayerTreeHostCommon::CalculateDrawProperties( | 2538 void LayerTreeHostCommon::CalculateDrawProperties( |
2554 CalcDrawPropsImplInputs* inputs) { | 2539 CalcDrawPropsImplInputs* inputs) { |
2555 LayerImplList dummy_layer_list; | 2540 LayerImplList dummy_layer_list; |
2556 SubtreeGlobals<LayerImpl> globals; | 2541 SubtreeGlobals<LayerImpl> globals; |
2557 DataForRecursion<LayerImpl> data_for_recursion; | 2542 DataForRecursion<LayerImpl> data_for_recursion; |
2558 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2543 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2559 | 2544 |
(...skipping 13 matching lines...) Expand all Loading... |
2573 inputs->current_render_surface_layer_list_id); | 2558 inputs->current_render_surface_layer_list_id); |
2574 | 2559 |
2575 // The dummy layer list should not have been used. | 2560 // The dummy layer list should not have been used. |
2576 DCHECK_EQ(0u, dummy_layer_list.size()); | 2561 DCHECK_EQ(0u, dummy_layer_list.size()); |
2577 // A root layer render_surface should always exist after | 2562 // A root layer render_surface should always exist after |
2578 // CalculateDrawProperties. | 2563 // CalculateDrawProperties. |
2579 DCHECK(inputs->root_layer->render_surface()); | 2564 DCHECK(inputs->root_layer->render_surface()); |
2580 } | 2565 } |
2581 | 2566 |
2582 } // namespace cc | 2567 } // namespace cc |
OLD | NEW |