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 2467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2478 const float tolerance = | 2478 const float tolerance = |
2479 col == 3 && row < 3 ? translation_tolerance : component_tolerance; | 2479 col == 3 && row < 3 ? translation_tolerance : component_tolerance; |
2480 if (delta > tolerance) | 2480 if (delta > tolerance) |
2481 return false; | 2481 return false; |
2482 } | 2482 } |
2483 } | 2483 } |
2484 | 2484 |
2485 return true; | 2485 return true; |
2486 } | 2486 } |
2487 | 2487 |
2488 void LayerTreeHostCommon::CalculateDrawProperties( | 2488 void VerifyPropertyTreeValues( |
2489 CalcDrawPropsMainInputs* inputs) { | 2489 LayerTreeHostCommon::CalcDrawPropsMainInputs* inputs) { |
2490 UpdateRenderSurfaces(inputs->root_layer, | 2490 LayerIterator<Layer> it, end; |
2491 inputs->can_render_to_separate_surface, gfx::Transform(), | 2491 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list), |
2492 false); | 2492 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list); |
2493 LayerList dummy_layer_list; | 2493 it != end; ++it) { |
2494 SubtreeGlobals<Layer> globals; | 2494 Layer* current_layer = *it; |
2495 DataForRecursion<Layer> data_for_recursion; | 2495 if (!it.represents_itself() || !current_layer->DrawsContent()) |
| 2496 continue; |
| 2497 |
| 2498 const bool visible_rects_match = |
| 2499 ApproximatelyEqual(current_layer->visible_content_rect(), |
| 2500 current_layer->visible_rect_from_property_trees()); |
| 2501 CHECK(visible_rects_match) |
| 2502 << "expected: " << current_layer->visible_content_rect().ToString() |
| 2503 << " actual: " |
| 2504 << current_layer->visible_rect_from_property_trees().ToString(); |
| 2505 |
| 2506 const bool draw_transforms_match = ApproximatelyEqual( |
| 2507 current_layer->draw_transform(), |
| 2508 DrawTransformFromPropertyTrees(current_layer, |
| 2509 inputs->property_trees->transform_tree)); |
| 2510 CHECK(draw_transforms_match); |
| 2511 |
| 2512 const bool draw_opacities_match = |
| 2513 current_layer->draw_opacity() == |
| 2514 DrawOpacityFromPropertyTrees(current_layer, |
| 2515 inputs->property_trees->opacity_tree); |
| 2516 CHECK(draw_opacities_match); |
| 2517 } |
| 2518 } |
| 2519 |
| 2520 void VerifyPropertyTreeValues( |
| 2521 LayerTreeHostCommon::CalcDrawPropsImplInputs* inputs) { |
| 2522 // TODO(enne): need to synchronize compositor thread changes |
| 2523 // for animation and scrolling to the property trees before these |
| 2524 // can be correct. |
| 2525 } |
| 2526 |
| 2527 enum PropertyTreeOption { |
| 2528 BUILD_PROPERTY_TREES_IF_NEEDED, |
| 2529 DONT_BUILD_PROPERTY_TREES |
| 2530 }; |
| 2531 |
| 2532 template <typename LayerType, typename RenderSurfaceLayerListType> |
| 2533 void CalculateDrawPropertiesAndVerify(LayerTreeHostCommon::CalcDrawPropsInputs< |
| 2534 LayerType, |
| 2535 RenderSurfaceLayerListType>* inputs, |
| 2536 PropertyTreeOption property_tree_option) { |
| 2537 typename LayerType::LayerListType dummy_layer_list; |
| 2538 SubtreeGlobals<LayerType> globals; |
| 2539 DataForRecursion<LayerType> data_for_recursion; |
| 2540 |
2496 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2541 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2497 | |
2498 PreCalculateMetaInformationRecursiveData recursive_data; | 2542 PreCalculateMetaInformationRecursiveData recursive_data; |
2499 | 2543 |
2500 if (!inputs->verify_property_trees) { | 2544 if (!inputs->verify_property_trees) { |
2501 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2545 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2502 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; | 2546 std::vector<AccumulatedSurfaceState<LayerType>> accumulated_surface_state; |
2503 CalculateDrawPropertiesInternal<Layer>( | 2547 CalculateDrawPropertiesInternal<LayerType>( |
2504 inputs->root_layer, globals, data_for_recursion, | 2548 inputs->root_layer, globals, data_for_recursion, |
2505 inputs->render_surface_layer_list, &dummy_layer_list, | 2549 inputs->render_surface_layer_list, &dummy_layer_list, |
2506 &accumulated_surface_state, | 2550 &accumulated_surface_state, |
2507 inputs->current_render_surface_layer_list_id); | 2551 inputs->current_render_surface_layer_list_id); |
2508 } else { | 2552 } else { |
2509 { | 2553 { |
2510 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 2554 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
2511 "LayerTreeHostCommon::CalculateDrawProperties"); | 2555 "LayerTreeHostCommon::CalculateDrawProperties"); |
2512 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2556 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2513 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; | 2557 std::vector<AccumulatedSurfaceState<LayerType>> accumulated_surface_state; |
2514 CalculateDrawPropertiesInternal<Layer>( | 2558 CalculateDrawPropertiesInternal<LayerType>( |
2515 inputs->root_layer, globals, data_for_recursion, | 2559 inputs->root_layer, globals, data_for_recursion, |
2516 inputs->render_surface_layer_list, &dummy_layer_list, | 2560 inputs->render_surface_layer_list, &dummy_layer_list, |
2517 &accumulated_surface_state, | 2561 &accumulated_surface_state, |
2518 inputs->current_render_surface_layer_list_id); | 2562 inputs->current_render_surface_layer_list_id); |
2519 } | 2563 } |
2520 | 2564 |
2521 // The translation from layer to property trees is an intermediate state. We | 2565 // For testing purposes, sometimes property trees need to be built on the |
2522 // will eventually get these data passed directly to the compositor. | 2566 // compositor thread, so this can't just switch on Layer vs LayerImpl, |
2523 { | 2567 // even though in practice only the main thread builds property trees. |
2524 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 2568 switch (property_tree_option) { |
2525 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees"); | 2569 case BUILD_PROPERTY_TREES_IF_NEEDED: { |
2526 ComputeVisibleRectsUsingPropertyTrees( | 2570 // The translation from layer to property trees is an intermediate |
2527 inputs->root_layer, inputs->page_scale_application_layer, | 2571 // state. We will eventually get these data passed directly to the |
2528 inputs->page_scale_factor, inputs->device_scale_factor, | 2572 // compositor. |
2529 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, | 2573 BuildPropertyTreesAndComputeVisibleRects( |
2530 inputs->property_trees); | 2574 inputs->root_layer, inputs->page_scale_application_layer, |
| 2575 inputs->page_scale_factor, inputs->device_scale_factor, |
| 2576 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, |
| 2577 inputs->property_trees); |
| 2578 break; |
| 2579 } |
| 2580 case DONT_BUILD_PROPERTY_TREES: { |
| 2581 TRACE_EVENT0( |
| 2582 TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 2583 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTreesImpl"); |
| 2584 ComputeVisibleRectsUsingPropertyTrees(inputs->root_layer, |
| 2585 inputs->property_trees); |
| 2586 break; |
| 2587 } |
2531 } | 2588 } |
2532 | 2589 |
2533 LayerIterator<Layer> it, end; | 2590 VerifyPropertyTreeValues(inputs); |
2534 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list), | |
2535 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list); | |
2536 it != end; ++it) { | |
2537 Layer* current_layer = *it; | |
2538 if (!it.represents_itself() || !current_layer->DrawsContent()) | |
2539 continue; | |
2540 | |
2541 const bool visible_rects_match = | |
2542 ApproximatelyEqual(current_layer->visible_content_rect(), | |
2543 current_layer->visible_rect_from_property_trees()); | |
2544 CHECK(visible_rects_match) | |
2545 << "expected: " << current_layer->visible_content_rect().ToString() | |
2546 << " actual: " | |
2547 << current_layer->visible_rect_from_property_trees().ToString(); | |
2548 | |
2549 const bool draw_transforms_match = | |
2550 ApproximatelyEqual(current_layer->draw_transform(), | |
2551 current_layer->draw_transform_from_property_trees( | |
2552 inputs->property_trees->transform_tree)); | |
2553 CHECK(draw_transforms_match); | |
2554 | |
2555 const bool draw_opacities_match = | |
2556 current_layer->draw_opacity() == | |
2557 current_layer->DrawOpacityFromPropertyTrees( | |
2558 inputs->property_trees->opacity_tree); | |
2559 CHECK(draw_opacities_match); | |
2560 } | |
2561 } | 2591 } |
2562 | 2592 |
2563 // The dummy layer list should not have been used. | 2593 // The dummy layer list should not have been used. |
2564 DCHECK_EQ(0u, dummy_layer_list.size()); | 2594 DCHECK_EQ(0u, dummy_layer_list.size()); |
2565 // A root layer render_surface should always exist after | 2595 // A root layer render_surface should always exist after |
2566 // CalculateDrawProperties. | 2596 // CalculateDrawProperties. |
2567 DCHECK(inputs->root_layer->render_surface()); | 2597 DCHECK(inputs->root_layer->render_surface()); |
2568 } | 2598 } |
2569 | 2599 |
2570 void LayerTreeHostCommon::CalculateDrawProperties( | 2600 void LayerTreeHostCommon::CalculateDrawProperties( |
| 2601 CalcDrawPropsMainInputs* inputs) { |
| 2602 UpdateRenderSurfaces(inputs->root_layer, |
| 2603 inputs->can_render_to_separate_surface, gfx::Transform(), |
| 2604 false); |
| 2605 CalculateDrawPropertiesAndVerify(inputs, BUILD_PROPERTY_TREES_IF_NEEDED); |
| 2606 } |
| 2607 |
| 2608 void LayerTreeHostCommon::CalculateDrawProperties( |
2571 CalcDrawPropsImplInputs* inputs) { | 2609 CalcDrawPropsImplInputs* inputs) { |
2572 LayerImplList dummy_layer_list; | 2610 CalculateDrawPropertiesAndVerify(inputs, DONT_BUILD_PROPERTY_TREES); |
2573 SubtreeGlobals<LayerImpl> globals; | 2611 } |
2574 DataForRecursion<LayerImpl> data_for_recursion; | |
2575 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | |
2576 | 2612 |
2577 PreCalculateMetaInformationRecursiveData recursive_data; | 2613 void LayerTreeHostCommon::CalculateDrawProperties( |
2578 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2614 CalcDrawPropsImplInputsForTesting* inputs) { |
2579 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; | 2615 CalculateDrawPropertiesAndVerify(inputs, BUILD_PROPERTY_TREES_IF_NEEDED); |
2580 CalculateDrawPropertiesInternal<LayerImpl>( | |
2581 inputs->root_layer, | |
2582 globals, | |
2583 data_for_recursion, | |
2584 inputs->render_surface_layer_list, | |
2585 &dummy_layer_list, | |
2586 &accumulated_surface_state, | |
2587 inputs->current_render_surface_layer_list_id); | |
2588 | |
2589 // The dummy layer list should not have been used. | |
2590 DCHECK_EQ(0u, dummy_layer_list.size()); | |
2591 // A root layer render_surface should always exist after | |
2592 // CalculateDrawProperties. | |
2593 DCHECK(inputs->root_layer->render_surface()); | |
2594 } | 2616 } |
2595 | 2617 |
2596 } // namespace cc | 2618 } // namespace cc |
OLD | NEW |