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

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

Issue 2334003003: cc : Compute visible rects dynamically (1) (Closed)
Patch Set: comment Created 4 years, 3 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/test/fake_layer_tree_host_impl.cc ('k') | cc/trees/draw_property_utils.h » ('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/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"
(...skipping 10 matching lines...) Expand all
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 float device_scale_factor,
31 bool skip_verify_visible_rect_calculations,
31 LayerImplList* render_surface_layer_list) { 32 LayerImplList* render_surface_layer_list) {
32 // Sanity check: The test itself should create the root layer's render 33 // Sanity check: The test itself should create the root layer's render
33 // surface, so that the surface (and its damage tracker) can 34 // surface, so that the surface (and its damage tracker) can
34 // persist across multiple calls to this function. 35 // persist across multiple calls to this function.
35 ASSERT_FALSE(render_surface_layer_list->size()); 36 ASSERT_FALSE(render_surface_layer_list->size());
36 37
37 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); 38 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root);
38 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 39 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
39 root, root->bounds(), device_scale_factor, render_surface_layer_list); 40 root, root->bounds(), device_scale_factor, render_surface_layer_list);
41 if (skip_verify_visible_rect_calculations)
42 inputs.verify_visible_rect_calculations = false;
40 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 43 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
41 ASSERT_TRUE(root->render_surface()); 44 ASSERT_TRUE(root->render_surface());
42 } 45 }
43 46
44 void ClearDamageForAllSurfaces(LayerImpl* root) { 47 void ClearDamageForAllSurfaces(LayerImpl* root) {
45 for (auto* layer : *root->layer_tree_impl()) { 48 for (auto* layer : *root->layer_tree_impl()) {
46 if (layer->render_surface()) 49 if (layer->render_surface())
47 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); 50 layer->render_surface()->damage_tracker()->DidDrawDamagedArea();
48 } 51 }
49 } 52 }
50 53
51 void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) { 54 void EmulateDrawingOneFrame(
55 LayerImpl* root,
56 float device_scale_factor = 1.f,
57 bool skip_verify_visible_rect_calculations = false) {
52 // This emulates only steps that are relevant to testing the damage tracker: 58 // This emulates only steps that are relevant to testing the damage tracker:
53 // 1. computing the render passes and layerlists 59 // 1. computing the render passes and layerlists
54 // 2. updating all damage trackers in the correct order 60 // 2. updating all damage trackers in the correct order
55 // 3. resetting all update_rects and property_changed flags for all layers 61 // 3. resetting all update_rects and property_changed flags for all layers
56 // and surfaces. 62 // and surfaces.
57 63
58 LayerImplList render_surface_layer_list; 64 LayerImplList render_surface_layer_list;
59 ExecuteCalculateDrawProperties(root, device_scale_factor, 65 ExecuteCalculateDrawProperties(root, device_scale_factor,
66 skip_verify_visible_rect_calculations,
60 &render_surface_layer_list); 67 &render_surface_layer_list);
61 68
62 // Iterate back-to-front, so that damage correctly propagates from descendant 69 // Iterate back-to-front, so that damage correctly propagates from descendant
63 // surfaces to ancestors. 70 // surfaces to ancestors.
64 size_t render_surface_layer_list_size = render_surface_layer_list.size(); 71 size_t render_surface_layer_list_size = render_surface_layer_list.size();
65 for (size_t i = 0; i < render_surface_layer_list_size; ++i) { 72 for (size_t i = 0; i < render_surface_layer_list_size; ++i) {
66 size_t index = render_surface_layer_list_size - 1 - i; 73 size_t index = render_surface_layer_list_size - 1 - i;
67 RenderSurfaceImpl* target_surface = 74 RenderSurfaceImpl* target_surface =
68 render_surface_layer_list[index]->render_surface(); 75 render_surface_layer_list[index]->render_surface();
69 target_surface->damage_tracker()->UpdateDamageTrackingState( 76 target_surface->damage_tracker()->UpdateDamageTrackingState(
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 1670
1664 gfx::Transform transform; 1671 gfx::Transform transform;
1665 transform.Translate(-kBigNumber, -kBigNumber); 1672 transform.Translate(-kBigNumber, -kBigNumber);
1666 1673
1667 // The child layer covers (0, 0, i, i) of the viewport, 1674 // The child layer covers (0, 0, i, i) of the viewport,
1668 // but has a huge negative position. 1675 // but has a huge negative position.
1669 child->SetPosition(gfx::PointF()); 1676 child->SetPosition(gfx::PointF());
1670 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); 1677 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i));
1671 child->test_properties()->transform = transform; 1678 child->test_properties()->transform = transform;
1672 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1679 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1673 EmulateDrawingOneFrame(root); 1680 float device_scale_factor = 1.f;
1681 // Visible rects computed from combining clips in target space and root
1682 // space don't match because of the loss in floating point accuracy. So, we
1683 // skip verify_clip_tree_calculations.
1684 bool skip_verify_visible_rect_calculations = true;
1685 EmulateDrawingOneFrame(root, device_scale_factor,
1686 skip_verify_visible_rect_calculations);
1674 1687
1675 // The expected damage should cover the visible part of the child layer, 1688 // The expected damage should cover the visible part of the child layer,
1676 // which is (0, 0, i, i) in the viewport. 1689 // which is (0, 0, i, i) in the viewport.
1677 gfx::Rect root_damage_rect = 1690 gfx::Rect root_damage_rect =
1678 root->render_surface()->damage_tracker()->current_damage_rect(); 1691 root->render_surface()->damage_tracker()->current_damage_rect();
1679 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1692 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1680 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1693 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1681 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1694 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1682 } 1695 }
1683 } 1696 }
1684 1697
1685 } // namespace 1698 } // namespace
1686 } // namespace cc 1699 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/fake_layer_tree_host_impl.cc ('k') | cc/trees/draw_property_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698