Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 1097583002: cc: Commit property trees to the compositor thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win bool conversion compile fix Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_common.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 << "expected: " << current_layer->draw_transform().ToString()
2512 << " actual: "
2513 << DrawTransformFromPropertyTrees(
2514 current_layer, inputs->property_trees->transform_tree)
2515 .ToString();
2516
2517 const bool draw_opacities_match =
2518 current_layer->draw_opacity() ==
2519 DrawOpacityFromPropertyTrees(current_layer,
2520 inputs->property_trees->opacity_tree);
2521 CHECK(draw_opacities_match)
2522 << "expected: " << current_layer->draw_opacity() << " actual: "
2523 << DrawOpacityFromPropertyTrees(current_layer,
2524 inputs->property_trees->opacity_tree);
2525 }
2526 }
2527
2528 void VerifyPropertyTreeValues(
2529 LayerTreeHostCommon::CalcDrawPropsImplInputs* inputs) {
2530 // TODO(enne): need to synchronize compositor thread changes
2531 // for animation and scrolling to the property trees before these
2532 // can be correct.
2533 }
2534
2535 enum PropertyTreeOption {
2536 BUILD_PROPERTY_TREES_IF_NEEDED,
2537 DONT_BUILD_PROPERTY_TREES
2538 };
2539
2540 template <typename LayerType, typename RenderSurfaceLayerListType>
2541 void CalculateDrawPropertiesAndVerify(LayerTreeHostCommon::CalcDrawPropsInputs<
2542 LayerType,
2543 RenderSurfaceLayerListType>* inputs,
2544 PropertyTreeOption property_tree_option) {
2545 typename LayerType::LayerListType dummy_layer_list;
2546 SubtreeGlobals<LayerType> globals;
2547 DataForRecursion<LayerType> data_for_recursion;
2548
2496 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); 2549 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2497
2498 PreCalculateMetaInformationRecursiveData recursive_data; 2550 PreCalculateMetaInformationRecursiveData recursive_data;
2499 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2551 PreCalculateMetaInformation(inputs->root_layer, &recursive_data);
2500 2552
2501 if (!inputs->verify_property_trees) { 2553 if (!inputs->verify_property_trees) {
2502 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; 2554 std::vector<AccumulatedSurfaceState<LayerType>> accumulated_surface_state;
2503 CalculateDrawPropertiesInternal<Layer>( 2555 CalculateDrawPropertiesInternal<LayerType>(
2504 inputs->root_layer, globals, data_for_recursion, 2556 inputs->root_layer, globals, data_for_recursion,
2505 inputs->render_surface_layer_list, &dummy_layer_list, 2557 inputs->render_surface_layer_list, &dummy_layer_list,
2506 &accumulated_surface_state, 2558 &accumulated_surface_state,
2507 inputs->current_render_surface_layer_list_id); 2559 inputs->current_render_surface_layer_list_id);
2508 } else { 2560 } else {
2509 { 2561 {
2510 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), 2562 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"),
2511 "LayerTreeHostCommon::CalculateDrawProperties"); 2563 "LayerTreeHostCommon::CalculateDrawProperties");
2512 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; 2564 std::vector<AccumulatedSurfaceState<LayerType>> accumulated_surface_state;
2513 CalculateDrawPropertiesInternal<Layer>( 2565 CalculateDrawPropertiesInternal<LayerType>(
2514 inputs->root_layer, globals, data_for_recursion, 2566 inputs->root_layer, globals, data_for_recursion,
2515 inputs->render_surface_layer_list, &dummy_layer_list, 2567 inputs->render_surface_layer_list, &dummy_layer_list,
2516 &accumulated_surface_state, 2568 &accumulated_surface_state,
2517 inputs->current_render_surface_layer_list_id); 2569 inputs->current_render_surface_layer_list_id);
2518 } 2570 }
2519 2571
2520 // The translation from layer to property trees is an intermediate state. We 2572 // For testing purposes, sometimes property trees need to be built on the
2521 // will eventually get these data passed directly to the compositor. 2573 // compositor thread, so this can't just switch on Layer vs LayerImpl,
2522 { 2574 // even though in practice only the main thread builds property trees.
2523 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), 2575 switch (property_tree_option) {
2524 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees"); 2576 case BUILD_PROPERTY_TREES_IF_NEEDED: {
2525 ComputeVisibleRectsUsingPropertyTrees( 2577 // The translation from layer to property trees is an intermediate
2526 inputs->root_layer, inputs->page_scale_application_layer, 2578 // state. We will eventually get these data passed directly to the
2527 inputs->page_scale_factor, inputs->device_scale_factor, 2579 // compositor.
2528 gfx::Rect(inputs->device_viewport_size), inputs->device_transform, 2580 TRACE_EVENT0(
2529 inputs->property_trees); 2581 TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"),
2582 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees");
2583 BuildPropertyTreesAndComputeVisibleRects(
2584 inputs->root_layer, inputs->page_scale_application_layer,
2585 inputs->page_scale_factor, inputs->device_scale_factor,
2586 gfx::Rect(inputs->device_viewport_size), inputs->device_transform,
2587 inputs->property_trees);
2588 break;
2589 }
2590 case DONT_BUILD_PROPERTY_TREES: {
2591 TRACE_EVENT0(
2592 TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"),
2593 "LayerTreeHostCommon::ComputeJustVisibleRectsWithPropertyTrees");
2594 ComputeVisibleRectsUsingPropertyTrees(inputs->root_layer,
2595 inputs->property_trees);
2596 break;
2597 }
2530 } 2598 }
2531 2599
2532 LayerIterator<Layer> it, end; 2600 VerifyPropertyTreeValues(inputs);
2533 for (it = LayerIterator<Layer>::Begin(inputs->render_surface_layer_list),
2534 end = LayerIterator<Layer>::End(inputs->render_surface_layer_list);
2535 it != end; ++it) {
2536 Layer* current_layer = *it;
2537 if (!it.represents_itself() || !current_layer->DrawsContent())
2538 continue;
2539
2540 const bool visible_rects_match =
2541 ApproximatelyEqual(current_layer->visible_content_rect(),
2542 current_layer->visible_rect_from_property_trees());
2543 CHECK(visible_rects_match)
2544 << "expected: " << current_layer->visible_content_rect().ToString()
2545 << " actual: "
2546 << current_layer->visible_rect_from_property_trees().ToString();
2547
2548 const bool draw_transforms_match =
2549 ApproximatelyEqual(current_layer->draw_transform(),
2550 current_layer->draw_transform_from_property_trees(
2551 inputs->property_trees->transform_tree));
2552 CHECK(draw_transforms_match);
2553
2554 const bool draw_opacities_match =
2555 current_layer->draw_opacity() ==
2556 current_layer->DrawOpacityFromPropertyTrees(
2557 inputs->property_trees->opacity_tree);
2558 CHECK(draw_opacities_match)
2559 << "expected: " << current_layer->draw_opacity() << " actual: "
2560 << current_layer->DrawOpacityFromPropertyTrees(
2561 inputs->property_trees->opacity_tree);
2562 }
2563 } 2601 }
2564 2602
2565 // The dummy layer list should not have been used. 2603 // The dummy layer list should not have been used.
2566 DCHECK_EQ(0u, dummy_layer_list.size()); 2604 DCHECK_EQ(0u, dummy_layer_list.size());
2567 // A root layer render_surface should always exist after 2605 // A root layer render_surface should always exist after
2568 // CalculateDrawProperties. 2606 // CalculateDrawProperties.
2569 DCHECK(inputs->root_layer->render_surface()); 2607 DCHECK(inputs->root_layer->render_surface());
2570 } 2608 }
2571 2609
2572 void LayerTreeHostCommon::CalculateDrawProperties( 2610 void LayerTreeHostCommon::CalculateDrawProperties(
2611 CalcDrawPropsMainInputs* inputs) {
2612 UpdateRenderSurfaces(inputs->root_layer,
2613 inputs->can_render_to_separate_surface, gfx::Transform(),
2614 false);
2615 CalculateDrawPropertiesAndVerify(inputs, BUILD_PROPERTY_TREES_IF_NEEDED);
2616 }
2617
2618 void LayerTreeHostCommon::CalculateDrawProperties(
2573 CalcDrawPropsImplInputs* inputs) { 2619 CalcDrawPropsImplInputs* inputs) {
2574 LayerImplList dummy_layer_list; 2620 CalculateDrawPropertiesAndVerify(inputs, DONT_BUILD_PROPERTY_TREES);
2575 SubtreeGlobals<LayerImpl> globals; 2621 }
2576 DataForRecursion<LayerImpl> data_for_recursion;
2577 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2578 2622
2579 PreCalculateMetaInformationRecursiveData recursive_data; 2623 void LayerTreeHostCommon::CalculateDrawProperties(
2580 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2624 CalcDrawPropsImplInputsForTesting* inputs) {
2581 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; 2625 CalculateDrawPropertiesAndVerify(inputs, BUILD_PROPERTY_TREES_IF_NEEDED);
2582 CalculateDrawPropertiesInternal<LayerImpl>(
2583 inputs->root_layer,
2584 globals,
2585 data_for_recursion,
2586 inputs->render_surface_layer_list,
2587 &dummy_layer_list,
2588 &accumulated_surface_state,
2589 inputs->current_render_surface_layer_list_id);
2590
2591 // The dummy layer list should not have been used.
2592 DCHECK_EQ(0u, dummy_layer_list.size());
2593 // A root layer render_surface should always exist after
2594 // CalculateDrawProperties.
2595 DCHECK(inputs->root_layer->render_surface());
2596 } 2626 }
2597 2627
2598 PropertyTrees* GetPropertyTrees(Layer* layer, 2628 PropertyTrees* GetPropertyTrees(Layer* layer,
2599 PropertyTrees* trees_from_inputs) { 2629 PropertyTrees* trees_from_inputs) {
2600 return layer->layer_tree_host()->property_trees(); 2630 return layer->layer_tree_host()->property_trees();
2601 } 2631 }
2602 2632
2603 PropertyTrees* GetPropertyTrees(LayerImpl* layer, 2633 PropertyTrees* GetPropertyTrees(LayerImpl* layer,
2604 PropertyTrees* trees_from_inputs) { 2634 PropertyTrees* trees_from_inputs) {
2605 return trees_from_inputs; 2635 return trees_from_inputs;
2606 } 2636 }
2607 2637
2608 } // namespace cc 2638 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698