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/damage_tracker.h" | 5 #include "cc/trees/damage_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
| 11 #include "cc/output/filter_operation.h" | 11 #include "cc/output/filter_operation.h" |
| 12 #include "cc/output/filter_operations.h" | 12 #include "cc/output/filter_operations.h" |
| 13 #include "cc/test/fake_impl_task_runner_provider.h" | 13 #include "cc/test/fake_impl_task_runner_provider.h" |
| 14 #include "cc/test/fake_layer_tree_host_impl.h" | 14 #include "cc/test/fake_layer_tree_host_impl.h" |
| 15 #include "cc/test/geometry_test_utils.h" | 15 #include "cc/test/geometry_test_utils.h" |
| 16 #include "cc/test/test_shared_bitmap_manager.h" | 16 #include "cc/test/test_shared_bitmap_manager.h" |
| 17 #include "cc/test/test_task_graph_runner.h" | 17 #include "cc/test/test_task_graph_runner.h" |
| 18 #include "cc/trees/layer_tree_host_common.h" | 18 #include "cc/trees/layer_tree_host_common.h" |
| 19 #include "cc/trees/layer_tree_impl.h" | 19 #include "cc/trees/layer_tree_impl.h" |
| 20 #include "cc/trees/single_thread_proxy.h" | 20 #include "cc/trees/single_thread_proxy.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 22 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 23 #include "ui/gfx/geometry/quad_f.h" | 23 #include "ui/gfx/geometry/quad_f.h" |
| 24 #include "ui/gfx/geometry/rect_conversions.h" | 24 #include "ui/gfx/geometry/rect_conversions.h" |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void ExecuteCalculateDrawProperties(LayerImpl* root, | 29 void ExecuteCalculateDrawProperties(LayerImpl* root, |
| 30 float device_scale_factor, | |
| 30 LayerImplList* render_surface_layer_list) { | 31 LayerImplList* render_surface_layer_list) { |
| 31 // Sanity check: The test itself should create the root layer's render | 32 // Sanity check: The test itself should create the root layer's render |
| 32 // surface, so that the surface (and its damage tracker) can | 33 // surface, so that the surface (and its damage tracker) can |
| 33 // persist across multiple calls to this function. | 34 // persist across multiple calls to this function. |
| 34 ASSERT_FALSE(render_surface_layer_list->size()); | 35 ASSERT_FALSE(render_surface_layer_list->size()); |
| 35 | 36 |
| 36 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); | 37 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); |
| 37 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 38 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 38 root, root->bounds(), render_surface_layer_list); | 39 root, root->bounds(), device_scale_factor, render_surface_layer_list); |
| 39 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 40 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 40 ASSERT_TRUE(root->render_surface()); | 41 ASSERT_TRUE(root->render_surface()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void ClearDamageForAllSurfaces(LayerImpl* root) { | 44 void ClearDamageForAllSurfaces(LayerImpl* root) { |
| 44 for (auto* layer : *root->layer_tree_impl()) { | 45 for (auto* layer : *root->layer_tree_impl()) { |
| 45 if (layer->render_surface()) | 46 if (layer->render_surface()) |
| 46 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 47 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 void EmulateDrawingOneFrame(LayerImpl* root) { | 51 void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) { |
| 51 // This emulates only steps that are relevant to testing the damage tracker: | 52 // This emulates only steps that are relevant to testing the damage tracker: |
| 52 // 1. computing the render passes and layerlists | 53 // 1. computing the render passes and layerlists |
| 53 // 2. updating all damage trackers in the correct order | 54 // 2. updating all damage trackers in the correct order |
| 54 // 3. resetting all update_rects and property_changed flags for all layers | 55 // 3. resetting all update_rects and property_changed flags for all layers |
| 55 // and surfaces. | 56 // and surfaces. |
| 56 | 57 |
| 57 LayerImplList render_surface_layer_list; | 58 LayerImplList render_surface_layer_list; |
| 58 ExecuteCalculateDrawProperties(root, &render_surface_layer_list); | 59 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 60 &render_surface_layer_list); | |
| 59 | 61 |
| 60 // Iterate back-to-front, so that damage correctly propagates from descendant | 62 // Iterate back-to-front, so that damage correctly propagates from descendant |
| 61 // surfaces to ancestors. | 63 // surfaces to ancestors. |
| 62 size_t render_surface_layer_list_size = render_surface_layer_list.size(); | 64 size_t render_surface_layer_list_size = render_surface_layer_list.size(); |
| 63 for (size_t i = 0; i < render_surface_layer_list_size; ++i) { | 65 for (size_t i = 0; i < render_surface_layer_list_size; ++i) { |
| 64 size_t index = render_surface_layer_list_size - 1 - i; | 66 size_t index = render_surface_layer_list_size - 1 - i; |
| 65 RenderSurfaceImpl* target_surface = | 67 RenderSurfaceImpl* target_surface = |
| 66 render_surface_layer_list[index]->render_surface(); | 68 render_surface_layer_list[index]->render_surface(); |
| 67 target_surface->damage_tracker()->UpdateDamageTrackingState( | 69 target_surface->damage_tracker()->UpdateDamageTrackingState( |
| 68 target_surface->layer_list(), target_surface, | 70 target_surface->layer_list(), target_surface, |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 | 660 |
| 659 int expect_width = 30 + 2 * blur_outset; | 661 int expect_width = 30 + 2 * blur_outset; |
| 660 int expect_height = 30 + 2 * blur_outset; | 662 int expect_height = 30 + 2 * blur_outset; |
| 661 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, | 663 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, |
| 662 expect_width / 2, expect_height), | 664 expect_width / 2, expect_height), |
| 663 root_damage_rect); | 665 root_damage_rect); |
| 664 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), | 666 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), |
| 665 child_damage_rect); | 667 child_damage_rect); |
| 666 } | 668 } |
| 667 | 669 |
| 670 TEST_F(DamageTrackerTest, VerifyDamageForHighDPIImageFilter) { | |
| 671 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | |
| 672 LayerImpl* child = root->test_properties()->children[0]; | |
| 673 gfx::Rect root_damage_rect, child_damage_rect; | |
| 674 | |
| 675 // Allow us to set damage on child too. | |
| 676 child->SetDrawsContent(true); | |
| 677 | |
| 678 FilterOperations filters; | |
| 679 filters.Append(FilterOperation::CreateBlurFilter(3.f)); | |
| 680 | |
| 681 // Setting the filter will damage the whole surface. | |
| 682 ClearDamageForAllSurfaces(root); | |
| 683 child->test_properties()->force_render_surface = true; | |
| 684 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | |
| 685 int device_scale_factor = 2; | |
| 686 EmulateDrawingOneFrame(root, device_scale_factor); | |
| 687 child->OnFilterAnimated(filters); | |
| 688 EmulateDrawingOneFrame(root, device_scale_factor); | |
| 689 root_damage_rect = | |
| 690 root->render_surface()->damage_tracker()->current_damage_rect(); | |
| 691 child_damage_rect = | |
| 692 child->render_surface()->damage_tracker()->current_damage_rect(); | |
| 693 | |
| 694 // Blur outset is 9px for a 3px blur, scaled up by DSF. | |
| 695 int blur_outset = 9 * device_scale_factor; | |
| 696 gfx::Rect original_rect(100, 100, 100, 100); | |
| 697 gfx::Rect expected_child_damage_rect(60, 60); | |
| 698 expected_child_damage_rect.Inset(-blur_outset, -blur_outset); | |
| 699 gfx::Rect expected_root_damage_rect(child_damage_rect); | |
| 700 expected_root_damage_rect.Offset(200, 200); | |
| 701 gfx::Rect expected_total_damage_rect = expected_root_damage_rect; | |
| 702 expected_total_damage_rect.Union(original_rect); | |
| 703 EXPECT_EQ(expected_total_damage_rect, root_damage_rect); | |
| 704 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); | |
| 705 | |
| 706 // Setting the update rect should damage the whole surface (for now) | |
|
enne (OOO)
2016/08/12 17:34:33
I don't think this comment is true? It looks like
| |
| 707 ClearDamageForAllSurfaces(root); | |
| 708 child->SetUpdateRect(gfx::Rect(30, 30)); | |
| 709 EmulateDrawingOneFrame(root, device_scale_factor); | |
| 710 | |
| 711 root_damage_rect = | |
| 712 root->render_surface()->damage_tracker()->current_damage_rect(); | |
| 713 child_damage_rect = | |
| 714 child->render_surface()->damage_tracker()->current_damage_rect(); | |
| 715 | |
| 716 EXPECT_EQ(expected_root_damage_rect, root_damage_rect); | |
| 717 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); | |
| 718 } | |
| 719 | |
| 668 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { | 720 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { |
| 669 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 721 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 670 LayerImpl* child1 = root->test_properties()->children[0]; | 722 LayerImpl* child1 = root->test_properties()->children[0]; |
| 671 LayerImpl* child2 = root->test_properties()->children[1]; | 723 LayerImpl* child2 = root->test_properties()->children[1]; |
| 672 | 724 |
| 673 // Allow us to set damage on child1 too. | 725 // Allow us to set damage on child1 too. |
| 674 child1->SetDrawsContent(true); | 726 child1->SetDrawsContent(true); |
| 675 | 727 |
| 676 FilterOperations filters; | 728 FilterOperations filters; |
| 677 filters.Append(FilterOperation::CreateBlurFilter(2.f)); | 729 filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1615 gfx::Rect root_damage_rect = | 1667 gfx::Rect root_damage_rect = |
| 1616 root->render_surface()->damage_tracker()->current_damage_rect(); | 1668 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1617 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1669 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
| 1618 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1670 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
| 1619 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1671 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1620 } | 1672 } |
| 1621 } | 1673 } |
| 1622 | 1674 |
| 1623 } // namespace | 1675 } // namespace |
| 1624 } // namespace cc | 1676 } // namespace cc |
| OLD | NEW |