blob: 687951794fab25964b62474a87af6379bdf3bedd [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/damage_tracker.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
[email protected]681ccff2013-03-18 06:13:529#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5210#include "cc/layers/layer_impl.h"
[email protected]ae6b1a72013-06-25 18:49:2911#include "cc/output/filter_operation.h"
12#include "cc/output/filter_operations.h"
khushalsagarb64b360d2015-10-21 19:25:1613#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]586d51ed2012-12-07 20:31:4514#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0315#include "cc/test/geometry_test_utils.h"
[email protected]4e2eb352014-03-20 17:25:4516#include "cc/test/test_shared_bitmap_manager.h"
reveman34b7a1522015-03-23 20:27:4717#include "cc/test/test_task_graph_runner.h"
[email protected]556fd292013-03-18 08:03:0418#include "cc/trees/layer_tree_host_common.h"
miletus5032027d2015-06-10 01:27:4719#include "cc/trees/layer_tree_impl.h"
[email protected]556fd292013-03-18 08:03:0420#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1821#include "testing/gtest/include/gtest/gtest.h"
[email protected]4000abf2012-10-23 04:45:4522#include "third_party/skia/include/effects/SkBlurImageFilter.h"
[email protected]b4ead7b2014-04-07 18:12:1823#include "ui/gfx/geometry/quad_f.h"
24#include "ui/gfx/geometry/rect_conversions.h"
[email protected]94f206c12012-08-25 00:09:1425
[email protected]ba565742012-11-10 09:29:4826namespace cc {
[email protected]94f206c12012-08-25 00:09:1427namespace {
28
[email protected]7aad55f2013-07-26 11:25:5329void ExecuteCalculateDrawProperties(LayerImpl* root,
[email protected]a2566412014-06-05 03:14:2030 LayerImplList* render_surface_layer_list) {
[email protected]035441d92013-03-22 23:21:3931 // Sanity check: The test itself should create the root layer's render
32 // surface, so that the surface (and its damage tracker) can
33 // persist across multiple calls to this function.
[email protected]a2566412014-06-05 03:14:2034 ASSERT_FALSE(render_surface_layer_list->size());
[email protected]94f206c12012-08-25 00:09:1435
[email protected]ad63b2f2014-08-11 17:39:5436 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root);
[email protected]7aad55f2013-07-26 11:25:5337 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:3838 root, root->bounds(), render_surface_layer_list);
sunxdb365de02016-04-28 20:32:5739 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc154ce22015-12-09 03:39:2640 ASSERT_TRUE(root->render_surface());
[email protected]94f206c12012-08-25 00:09:1441}
42
sunxdb2e13c92016-04-23 01:00:0543void ClearDamageForAllSurfaces(LayerImpl* root) {
44 for (auto* layer : *root->layer_tree_impl()) {
45 if (layer->render_surface())
46 layer->render_surface()->damage_tracker()->DidDrawDamagedArea();
47 }
[email protected]94f206c12012-08-25 00:09:1448}
49
[email protected]035441d92013-03-22 23:21:3950void EmulateDrawingOneFrame(LayerImpl* root) {
[email protected]035441d92013-03-22 23:21:3951 // This emulates only steps that are relevant to testing the damage tracker:
52 // 1. computing the render passes and layerlists
53 // 2. updating all damage trackers in the correct order
[email protected]ed511b8d2013-03-25 03:29:2954 // 3. resetting all update_rects and property_changed flags for all layers
[email protected]035441d92013-03-22 23:21:3955 // and surfaces.
[email protected]94f206c12012-08-25 00:09:1456
[email protected]50761e92013-03-29 20:51:2857 LayerImplList render_surface_layer_list;
[email protected]a2566412014-06-05 03:14:2058 ExecuteCalculateDrawProperties(root, &render_surface_layer_list);
[email protected]94f206c12012-08-25 00:09:1459
[email protected]035441d92013-03-22 23:21:3960 // Iterate back-to-front, so that damage correctly propagates from descendant
61 // surfaces to ancestors.
vmpstr45816062015-06-10 23:00:0062 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) {
64 size_t index = render_surface_layer_list_size - 1 - i;
[email protected]035441d92013-03-22 23:21:3965 RenderSurfaceImpl* target_surface =
vmpstr45816062015-06-10 23:00:0066 render_surface_layer_list[index]->render_surface();
[email protected]035441d92013-03-22 23:21:3967 target_surface->damage_tracker()->UpdateDamageTrackingState(
weiliangc4012ef72016-04-11 22:04:0668 target_surface->layer_list(), target_surface,
[email protected]035441d92013-03-22 23:21:3969 target_surface->SurfacePropertyChangedOnlyFromDescendant(),
70 target_surface->content_rect(),
vmpstr45816062015-06-10 23:00:0071 render_surface_layer_list[index]->mask_layer(),
72 render_surface_layer_list[index]->filters());
[email protected]035441d92013-03-22 23:21:3973 }
[email protected]94f206c12012-08-25 00:09:1474
jaydasikad6f778b2016-05-19 22:51:2675 root->layer_tree_impl()->ResetAllChangeTracking();
[email protected]94f206c12012-08-25 00:09:1476}
77
[email protected]96baf3e2012-10-22 23:09:5578class DamageTrackerTest : public testing::Test {
[email protected]035441d92013-03-22 23:21:3979 public:
reveman34b7a1522015-03-23 20:27:4780 DamageTrackerTest()
khushalsagarb64b360d2015-10-21 19:25:1681 : host_impl_(&task_runner_provider_,
82 &shared_bitmap_manager_,
83 &task_graph_runner_) {}
[email protected]586d51ed2012-12-07 20:31:4584
jaydasikaef64f9e42016-03-12 01:08:1885 LayerImpl* CreateTestTreeWithOneSurface() {
rockot2176f922016-06-08 19:18:3286 host_impl_.active_tree()->DetachLayers();
danakj60bc3bc2016-04-09 00:24:4887 std::unique_ptr<LayerImpl> root =
88 LayerImpl::Create(host_impl_.active_tree(), 1);
89 std::unique_ptr<LayerImpl> child =
90 LayerImpl::Create(host_impl_.active_tree(), 2);
[email protected]586d51ed2012-12-07 20:31:4591
[email protected]035441d92013-03-22 23:21:3992 root->SetPosition(gfx::PointF());
[email protected]035441d92013-03-22 23:21:3993 root->SetBounds(gfx::Size(500, 500));
[email protected]035441d92013-03-22 23:21:3994 root->SetDrawsContent(true);
jaydasika6b5a32bf2016-04-22 21:56:3695 root->test_properties()->force_render_surface = true;
[email protected]586d51ed2012-12-07 20:31:4596
[email protected]035441d92013-03-22 23:21:3997 child->SetPosition(gfx::PointF(100.f, 100.f));
[email protected]035441d92013-03-22 23:21:3998 child->SetBounds(gfx::Size(30, 30));
[email protected]035441d92013-03-22 23:21:3999 child->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:10100 root->AddChild(std::move(child));
jaydasikaef64f9e42016-03-12 01:08:18101 host_impl_.active_tree()->SetRootLayer(std::move(root));
[email protected]586d51ed2012-12-07 20:31:45102
jaydasikaef64f9e42016-03-12 01:08:18103 return host_impl_.active_tree()->root_layer();
[email protected]035441d92013-03-22 23:21:39104 }
[email protected]586d51ed2012-12-07 20:31:45105
jaydasikaef64f9e42016-03-12 01:08:18106 LayerImpl* CreateTestTreeWithTwoSurfaces() {
[email protected]035441d92013-03-22 23:21:39107 // This test tree has two render surfaces: one for the root, and one for
108 // child1. Additionally, the root has a second child layer, and child1 has
109 // two children of its own.
[email protected]586d51ed2012-12-07 20:31:45110
rockot2176f922016-06-08 19:18:32111 host_impl_.active_tree()->DetachLayers();
danakj60bc3bc2016-04-09 00:24:48112 std::unique_ptr<LayerImpl> root =
113 LayerImpl::Create(host_impl_.active_tree(), 1);
114 std::unique_ptr<LayerImpl> child1 =
115 LayerImpl::Create(host_impl_.active_tree(), 2);
116 std::unique_ptr<LayerImpl> child2 =
117 LayerImpl::Create(host_impl_.active_tree(), 3);
118 std::unique_ptr<LayerImpl> grand_child1 =
119 LayerImpl::Create(host_impl_.active_tree(), 4);
120 std::unique_ptr<LayerImpl> grand_child2 =
121 LayerImpl::Create(host_impl_.active_tree(), 5);
[email protected]586d51ed2012-12-07 20:31:45122
[email protected]035441d92013-03-22 23:21:39123 root->SetPosition(gfx::PointF());
[email protected]035441d92013-03-22 23:21:39124 root->SetBounds(gfx::Size(500, 500));
[email protected]035441d92013-03-22 23:21:39125 root->SetDrawsContent(true);
jaydasika6b5a32bf2016-04-22 21:56:36126 root->test_properties()->force_render_surface = true;
[email protected]586d51ed2012-12-07 20:31:45127
[email protected]035441d92013-03-22 23:21:39128 child1->SetPosition(gfx::PointF(100.f, 100.f));
[email protected]035441d92013-03-22 23:21:39129 child1->SetBounds(gfx::Size(30, 30));
[email protected]ed511b8d2013-03-25 03:29:29130 // With a child that draws_content, opacity will cause the layer to create
131 // its own RenderSurface. This layer does not draw, but is intended to
awoloszyne83f28c2014-12-22 15:40:00132 // create its own RenderSurface.
[email protected]035441d92013-03-22 23:21:39133 child1->SetDrawsContent(false);
jaydasika6b5a32bf2016-04-22 21:56:36134 child1->test_properties()->force_render_surface = true;
[email protected]586d51ed2012-12-07 20:31:45135
[email protected]035441d92013-03-22 23:21:39136 child2->SetPosition(gfx::PointF(11.f, 11.f));
[email protected]035441d92013-03-22 23:21:39137 child2->SetBounds(gfx::Size(18, 18));
[email protected]035441d92013-03-22 23:21:39138 child2->SetDrawsContent(true);
[email protected]586d51ed2012-12-07 20:31:45139
[email protected]035441d92013-03-22 23:21:39140 grand_child1->SetPosition(gfx::PointF(200.f, 200.f));
[email protected]035441d92013-03-22 23:21:39141 grand_child1->SetBounds(gfx::Size(6, 8));
[email protected]035441d92013-03-22 23:21:39142 grand_child1->SetDrawsContent(true);
[email protected]586d51ed2012-12-07 20:31:45143
[email protected]035441d92013-03-22 23:21:39144 grand_child2->SetPosition(gfx::PointF(190.f, 190.f));
[email protected]035441d92013-03-22 23:21:39145 grand_child2->SetBounds(gfx::Size(6, 8));
[email protected]035441d92013-03-22 23:21:39146 grand_child2->SetDrawsContent(true);
[email protected]586d51ed2012-12-07 20:31:45147
danakja04855a2015-11-18 20:39:10148 child1->AddChild(std::move(grand_child1));
149 child1->AddChild(std::move(grand_child2));
150 root->AddChild(std::move(child1));
151 root->AddChild(std::move(child2));
jaydasikaef64f9e42016-03-12 01:08:18152 host_impl_.active_tree()->SetRootLayer(std::move(root));
[email protected]586d51ed2012-12-07 20:31:45153
jaydasikaef64f9e42016-03-12 01:08:18154 return host_impl_.active_tree()->root_layer();
[email protected]035441d92013-03-22 23:21:39155 }
[email protected]586d51ed2012-12-07 20:31:45156
jaydasikaef64f9e42016-03-12 01:08:18157 LayerImpl* CreateAndSetUpTestTreeWithOneSurface() {
158 LayerImpl* root = CreateTestTreeWithOneSurface();
[email protected]586d51ed2012-12-07 20:31:45159
[email protected]035441d92013-03-22 23:21:39160 // Setup includes going past the first frame which always damages
161 // everything, so that we can actually perform specific tests.
jaydasika16515f52016-03-01 00:28:35162 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18163 EmulateDrawingOneFrame(root);
[email protected]586d51ed2012-12-07 20:31:45164
danakja04855a2015-11-18 20:39:10165 return root;
[email protected]035441d92013-03-22 23:21:39166 }
[email protected]586d51ed2012-12-07 20:31:45167
jaydasikaef64f9e42016-03-12 01:08:18168 LayerImpl* CreateAndSetUpTestTreeWithTwoSurfaces() {
169 LayerImpl* root = CreateTestTreeWithTwoSurfaces();
[email protected]586d51ed2012-12-07 20:31:45170
[email protected]035441d92013-03-22 23:21:39171 // Setup includes going past the first frame which always damages
172 // everything, so that we can actually perform specific tests.
jaydasika16515f52016-03-01 00:28:35173 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18174 EmulateDrawingOneFrame(root);
[email protected]586d51ed2012-12-07 20:31:45175
danakja04855a2015-11-18 20:39:10176 return root;
[email protected]035441d92013-03-22 23:21:39177 }
[email protected]586d51ed2012-12-07 20:31:45178
[email protected]b50e06d2013-03-26 09:16:55179 protected:
khushalsagarb64b360d2015-10-21 19:25:16180 FakeImplTaskRunnerProvider task_runner_provider_;
[email protected]4e2eb352014-03-20 17:25:45181 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:47182 TestTaskGraphRunner task_graph_runner_;
[email protected]035441d92013-03-22 23:21:39183 FakeLayerTreeHostImpl host_impl_;
[email protected]94f206c12012-08-25 00:09:14184};
185
[email protected]035441d92013-03-22 23:21:39186TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) {
187 // Sanity check that the simple test tree will actually produce the expected
188 // render surfaces and layer lists.
[email protected]94f206c12012-08-25 00:09:14189
jaydasikaef64f9e42016-03-12 01:08:18190 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
[email protected]94f206c12012-08-25 00:09:14191
[email protected]035441d92013-03-22 23:21:39192 EXPECT_EQ(2u, root->render_surface()->layer_list().size());
193 EXPECT_EQ(1, root->render_surface()->layer_list()[0]->id());
194 EXPECT_EQ(2, root->render_surface()->layer_list()[1]->id());
[email protected]94f206c12012-08-25 00:09:14195
[email protected]b4ead7b2014-04-07 18:12:18196 gfx::Rect root_damage_rect =
197 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]035441d92013-03-22 23:21:39198
[email protected]b4ead7b2014-04-07 18:12:18199 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14200}
201
[email protected]035441d92013-03-22 23:21:39202TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) {
203 // Sanity check that the complex test tree will actually produce the expected
204 // render surfaces and layer lists.
[email protected]94f206c12012-08-25 00:09:14205
jaydasikaef64f9e42016-03-12 01:08:18206 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
[email protected]94f206c12012-08-25 00:09:14207
vollick83fbfc82016-03-22 18:33:27208 LayerImpl* child1 = root->children()[0];
209 LayerImpl* child2 = root->children()[1];
[email protected]b4ead7b2014-04-07 18:12:18210 gfx::Rect child_damage_rect =
211 child1->render_surface()->damage_tracker()->current_damage_rect();
212 gfx::Rect root_damage_rect =
213 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:14214
[email protected]035441d92013-03-22 23:21:39215 ASSERT_TRUE(child1->render_surface());
216 EXPECT_FALSE(child2->render_surface());
217 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
218 EXPECT_EQ(2u, child1->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:14219
[email protected]ed511b8d2013-03-25 03:29:29220 // The render surface for child1 only has a content_rect that encloses
[email protected]035441d92013-03-22 23:21:39221 // grand_child1 and grand_child2, because child1 does not draw content.
[email protected]b4ead7b2014-04-07 18:12:18222 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
223 child_damage_rect.ToString());
224 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14225}
226
[email protected]035441d92013-03-22 23:21:39227TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) {
jaydasikaef64f9e42016-03-12 01:08:18228 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27229 LayerImpl* child = root->children()[0];
[email protected]94f206c12012-08-25 00:09:14230
[email protected]035441d92013-03-22 23:21:39231 // CASE 1: Setting the update rect should cause the corresponding damage to
232 // the surface.
jaydasikaef64f9e42016-03-12 01:08:18233 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42234 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
jaydasika16515f52016-03-01 00:28:35235 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18236 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14237
[email protected]035441d92013-03-22 23:21:39238 // Damage position on the surface should be: position of update_rect (10, 11)
239 // relative to the child (100, 100).
[email protected]b4ead7b2014-04-07 18:12:18240 gfx::Rect root_damage_rect =
241 root->render_surface()->damage_tracker()->current_damage_rect();
242 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(),
243 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14244
[email protected]035441d92013-03-22 23:21:39245 // CASE 2: The same update rect twice in a row still produces the same
246 // damage.
jaydasikaef64f9e42016-03-12 01:08:18247 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42248 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
jaydasika16515f52016-03-01 00:28:35249 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18250 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39251 root_damage_rect =
252 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:18253 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(),
254 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14255
[email protected]035441d92013-03-22 23:21:39256 // CASE 3: Setting a different update rect should cause damage on the new
257 // update region, but no additional exposed old region.
jaydasikaef64f9e42016-03-12 01:08:18258 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42259 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2));
jaydasika16515f52016-03-01 00:28:35260 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18261 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14262
[email protected]035441d92013-03-22 23:21:39263 // Damage position on the surface should be: position of update_rect (20, 25)
264 // relative to the child (100, 100).
265 root_damage_rect =
266 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:18267 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14268}
269
[email protected]cfa7fd922014-04-29 11:50:03270TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
jaydasikaef64f9e42016-03-12 01:08:18271 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27272 LayerImpl* child = root->children()[0];
[email protected]cfa7fd922014-04-29 11:50:03273
274 // CASE 1: Adding the layer damage rect should cause the corresponding damage
275 // to the surface.
jaydasikaef64f9e42016-03-12 01:08:18276 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51277 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
jaydasika16515f52016-03-01 00:28:35278 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18279 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03280
281 // Damage position on the surface should be: position of layer damage_rect
282 // (10, 11) relative to the child (100, 100).
283 gfx::Rect root_damage_rect =
284 root->render_surface()->damage_tracker()->current_damage_rect();
285 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13)));
286
287 // CASE 2: The same layer damage rect twice in a row still produces the same
288 // damage.
jaydasikaef64f9e42016-03-12 01:08:18289 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51290 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
jaydasika16515f52016-03-01 00:28:35291 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18292 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03293 root_damage_rect =
294 root->render_surface()->damage_tracker()->current_damage_rect();
295 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13)));
296
297 // CASE 3: Adding a different layer damage rect should cause damage on the
298 // new damaged region, but no additional exposed old region.
jaydasikaef64f9e42016-03-12 01:08:18299 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51300 child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
jaydasika16515f52016-03-01 00:28:35301 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18302 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03303
304 // Damage position on the surface should be: position of layer damage_rect
305 // (20, 25) relative to the child (100, 100).
306 root_damage_rect =
307 root->render_surface()->damage_tracker()->current_damage_rect();
308 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
309
310 // CASE 4: Adding multiple layer damage rects should cause a unified
311 // damage on root damage rect.
jaydasikaef64f9e42016-03-12 01:08:18312 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51313 child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
314 child->AddDamageRect(gfx::Rect(10, 15, 3, 4));
jaydasika16515f52016-03-01 00:28:35315 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18316 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03317
318 // Damage position on the surface should be: position of layer damage_rect
319 // (20, 25) relative to the child (100, 100).
320 root_damage_rect =
321 root->render_surface()->damage_tracker()->current_damage_rect();
322 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
323 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4)));
324}
325
326TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
jaydasikaef64f9e42016-03-12 01:08:18327 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27328 LayerImpl* child = root->children()[0];
[email protected]cfa7fd922014-04-29 11:50:03329
330 // CASE 1: Adding the layer damage rect and update rect should cause the
331 // corresponding damage to the surface.
jaydasikaef64f9e42016-03-12 01:08:18332 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51333 child->AddDamageRect(gfx::Rect(5, 6, 12, 13));
danakj19f0c9e2014-10-11 03:24:42334 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10));
jaydasika16515f52016-03-01 00:28:35335 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18336 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03337
338 // Damage position on the surface should be: position of unified layer
339 // damage_rect and update rect (5, 6)
340 // relative to the child (100, 100).
341 gfx::Rect root_damage_rect =
342 root->render_surface()->damage_tracker()->current_damage_rect();
343 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20)));
344
345 // CASE 2: The same layer damage rect and update rect twice in a row still
346 // produces the same damage.
jaydasikaef64f9e42016-03-12 01:08:18347 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51348 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
danakj19f0c9e2014-10-11 03:24:42349 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15));
jaydasika16515f52016-03-01 00:28:35350 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18351 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03352 root_damage_rect =
353 root->render_surface()->damage_tracker()->current_damage_rect();
354 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15)));
355
356 // CASE 3: Adding a different layer damage rect and update rect should cause
357 // damage on the new damaged region, but no additional exposed old region.
jaydasikaef64f9e42016-03-12 01:08:18358 ClearDamageForAllSurfaces(root);
danakjd344ab92015-08-28 19:25:51359 child->AddDamageRect(gfx::Rect(20, 25, 2, 3));
danakj19f0c9e2014-10-11 03:24:42360 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8));
jaydasika16515f52016-03-01 00:28:35361 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18362 EmulateDrawingOneFrame(root);
[email protected]cfa7fd922014-04-29 11:50:03363
364 // Damage position on the surface should be: position of unified layer damage
365 // rect and update rect (5, 10) relative to the child (100, 100).
366 root_damage_rect =
367 root->render_surface()->damage_tracker()->current_damage_rect();
368 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18)));
369}
370
[email protected]035441d92013-03-22 23:21:39371TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) {
jaydasikaef64f9e42016-03-12 01:08:18372 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27373 LayerImpl* child = root->children()[0];
[email protected]94f206c12012-08-25 00:09:14374
[email protected]035441d92013-03-22 23:21:39375 // CASE 1: The layer's property changed flag takes priority over update rect.
376 //
jaydasika6b5a32bf2016-04-22 21:56:36377 child->test_properties()->force_render_surface = true;
jaydasika16515f52016-03-01 00:28:35378 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18379 EmulateDrawingOneFrame(root);
380 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42381 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
jaydasika16515f52016-03-01 00:28:35382 child->OnOpacityAnimated(0.5f);
jaydasikaef64f9e42016-03-12 01:08:18383 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14384
[email protected]035441d92013-03-22 23:21:39385 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:14386
[email protected]035441d92013-03-22 23:21:39387 // Damage should be the entire child layer in target_surface space.
[email protected]b4ead7b2014-04-07 18:12:18388 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30);
389 gfx::Rect root_damage_rect =
390 root->render_surface()->damage_tracker()->current_damage_rect();
391 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14392
[email protected]035441d92013-03-22 23:21:39393 // CASE 2: If a layer moves due to property change, it damages both the new
394 // location and the old (exposed) location. The old location is the
395 // entire old layer, not just the update_rect.
[email protected]94f206c12012-08-25 00:09:14396
[email protected]035441d92013-03-22 23:21:39397 // Cycle one frame of no change, just to sanity check that the next rect is
398 // not because of the old damage state.
jaydasikaef64f9e42016-03-12 01:08:18399 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:35400 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18401 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39402 root_damage_rect =
403 root->render_surface()->damage_tracker()->current_damage_rect();
404 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:14405
[email protected]035441d92013-03-22 23:21:39406 // Then, test the actual layer movement.
jaydasikaef64f9e42016-03-12 01:08:18407 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:39408 child->SetPosition(gfx::PointF(200.f, 230.f));
jaydasikaadfec8e2016-02-17 02:46:11409 child->NoteLayerPropertyChanged();
jaydasika16515f52016-03-01 00:28:35410 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18411 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14412
[email protected]035441d92013-03-22 23:21:39413 // Expect damage to be the combination of the previous one and the new one.
[email protected]b4ead7b2014-04-07 18:12:18414 expected_rect.Union(gfx::Rect(200, 230, 30, 30));
[email protected]035441d92013-03-22 23:21:39415 root_damage_rect =
416 root->render_surface()->damage_tracker()->current_damage_rect();
417 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
[email protected]94f206c12012-08-25 00:09:14418}
419
jaydasikacf223762016-05-16 23:02:09420TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) {
421 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
422 LayerImpl* surface = root->children()[0];
423 LayerImpl* child = surface->children()[0];
424 child->SetDrawsContent(true);
425 EmulateDrawingOneFrame(root);
426 ClearDamageForAllSurfaces(root);
427
428 surface->test_properties()->force_render_surface = false;
429 child->SetDrawsContent(false);
430 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
431 EmulateDrawingOneFrame(root);
432 gfx::Rect root_damage_rect =
433 root->render_surface()->damage_tracker()->current_damage_rect();
434 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
435 root_damage_rect.ToString());
436}
437
[email protected]035441d92013-03-22 23:21:39438TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) {
439 // If a layer is transformed, the damage rect should still enclose the entire
440 // transformed layer.
[email protected]94f206c12012-08-25 00:09:14441
jaydasikaef64f9e42016-03-12 01:08:18442 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27443 LayerImpl* child = root->children()[0];
jaydasika6b5a32bf2016-04-22 21:56:36444 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:14445
[email protected]035441d92013-03-22 23:21:39446 gfx::Transform rotation;
447 rotation.Rotate(45.0);
[email protected]94f206c12012-08-25 00:09:14448
jaydasikaef64f9e42016-03-12 01:08:18449 ClearDamageForAllSurfaces(root);
jaydasika38be7a822016-04-21 16:07:06450 child->test_properties()->transform_origin = gfx::Point3F(
451 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f);
[email protected]035441d92013-03-22 23:21:39452 child->SetPosition(gfx::PointF(85.f, 85.f));
jaydasikaadfec8e2016-02-17 02:46:11453 child->NoteLayerPropertyChanged();
jaydasika16515f52016-03-01 00:28:35454 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18455 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14456
[email protected]035441d92013-03-22 23:21:39457 // Sanity check that the layer actually moved to (85, 85), damaging its old
458 // location and new location.
[email protected]b4ead7b2014-04-07 18:12:18459 gfx::Rect root_damage_rect =
460 root->render_surface()->damage_tracker()->current_damage_rect();
461 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14462
[email protected]035441d92013-03-22 23:21:39463 // With the anchor on the layer's center, now we can test the rotation more
464 // intuitively, since it applies about the layer's anchor.
jaydasikaef64f9e42016-03-12 01:08:18465 ClearDamageForAllSurfaces(root);
jaydasika503f6172016-03-01 18:04:33466 child->OnTransformAnimated(rotation);
jaydasikaef64f9e42016-03-12 01:08:18467 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14468
[email protected]035441d92013-03-22 23:21:39469 // Since the child layer is square, rotation by 45 degrees about the center
470 // should increase the size of the expected rect by sqrt(2), centered around
471 // (100, 100). The old exposed region should be fully contained in the new
472 // region.
[email protected]803f6b52013-09-12 00:51:26473 float expected_width = 30.f * sqrt(2.f);
474 float expected_position = 100.f - 0.5f * expected_width;
[email protected]b4ead7b2014-04-07 18:12:18475 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF(
476 expected_position, expected_position, expected_width, expected_width));
[email protected]035441d92013-03-22 23:21:39477 root_damage_rect =
[email protected]803f6b52013-09-12 00:51:26478 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:18479 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14480}
481
[email protected]035441d92013-03-22 23:21:39482TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) {
483 // If a layer has a perspective transform that causes w < 0, then not
484 // clipping the layer can cause an invalid damage rect. This test checks that
485 // the w < 0 case is tracked properly.
486 //
487 // The transform is constructed so that if w < 0 clipping is not performed,
488 // the incorrect rect will be very small, specifically: position (500.972504,
489 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly
490 // transformed rect should actually be very huge (i.e. in theory, -infinity
491 // on the left), and positioned so that the right-most bound rect will be
492 // approximately 501 units in root surface space.
493 //
[email protected]94f206c12012-08-25 00:09:14494
jaydasikaef64f9e42016-03-12 01:08:18495 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27496 LayerImpl* child = root->children()[0];
[email protected]94f206c12012-08-25 00:09:14497
[email protected]035441d92013-03-22 23:21:39498 gfx::Transform transform;
499 transform.Translate3d(500.0, 500.0, 0.0);
500 transform.ApplyPerspectiveDepth(1.0);
501 transform.RotateAboutYAxis(45.0);
502 transform.Translate3d(-50.0, -50.0, 0.0);
[email protected]94f206c12012-08-25 00:09:14503
[email protected]035441d92013-03-22 23:21:39504 // Set up the child
505 child->SetPosition(gfx::PointF(0.f, 0.f));
506 child->SetBounds(gfx::Size(100, 100));
[email protected]035441d92013-03-22 23:21:39507 child->SetTransform(transform);
jaydasika16515f52016-03-01 00:28:35508 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18509 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14510
[email protected]035441d92013-03-22 23:21:39511 // Sanity check that the child layer's bounds would actually get clipped by
512 // w < 0, otherwise this test is not actually testing the intended scenario.
513 gfx::QuadF test_quad(gfx::RectF(gfx::PointF(), gfx::SizeF(100.f, 100.f)));
514 bool clipped = false;
515 MathUtil::MapQuad(transform, test_quad, &clipped);
516 EXPECT_TRUE(clipped);
[email protected]94f206c12012-08-25 00:09:14517
[email protected]035441d92013-03-22 23:21:39518 // Damage the child without moving it.
jaydasika6b5a32bf2016-04-22 21:56:36519 child->test_properties()->force_render_surface = true;
jaydasika16515f52016-03-01 00:28:35520 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18521 EmulateDrawingOneFrame(root);
522 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:35523 child->OnOpacityAnimated(0.5f);
jaydasikaef64f9e42016-03-12 01:08:18524 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14525
[email protected]035441d92013-03-22 23:21:39526 // The expected damage should cover the entire root surface (500x500), but we
527 // don't care whether the damage rect was clamped or is larger than the
528 // surface for this test.
[email protected]b4ead7b2014-04-07 18:12:18529 gfx::Rect root_damage_rect =
530 root->render_surface()->damage_tracker()->current_damage_rect();
531 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500));
[email protected]035441d92013-03-22 23:21:39532 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about));
[email protected]94f206c12012-08-25 00:09:14533}
534
[email protected]035441d92013-03-22 23:21:39535TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) {
jaydasikaef64f9e42016-03-12 01:08:18536 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:27537 LayerImpl* surface = root->children()[0];
538 LayerImpl* child = surface->children()[0];
[email protected]94f206c12012-08-25 00:09:14539
[email protected]ae6b1a72013-06-25 18:49:29540 FilterOperations filters;
541 filters.Append(FilterOperation::CreateBlurFilter(5.f));
[email protected]035441d92013-03-22 23:21:39542 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:29543 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:14544
[email protected]035441d92013-03-22 23:21:39545 // Setting the filter will damage the whole surface.
jaydasikaef64f9e42016-03-12 01:08:18546 ClearDamageForAllSurfaces(root);
[email protected]35a99a12013-05-09 23:52:29547 surface->SetFilters(filters);
jaydasika16515f52016-03-01 00:28:35548 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18549 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14550
[email protected]035441d92013-03-22 23:21:39551 // Setting the update rect should cause the corresponding damage to the
552 // surface, blurred based on the size of the blur filter.
jaydasikaef64f9e42016-03-12 01:08:18553 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42554 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
jaydasika16515f52016-03-01 00:28:35555 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18556 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14557
[email protected]35a99a12013-05-09 23:52:29558 // Damage position on the surface should be: position of update_rect (1, 2)
559 // relative to the child (300, 300), but expanded by the blur outsets.
[email protected]b4ead7b2014-04-07 18:12:18560 gfx::Rect root_damage_rect =
561 root->render_surface()->damage_tracker()->current_damage_rect();
562 gfx::Rect expected_damage_rect = gfx::Rect(301, 302, 3, 4);
[email protected]035441d92013-03-22 23:21:39563
564 expected_damage_rect.Inset(-outset_left,
565 -outset_top,
566 -outset_right,
567 -outset_bottom);
[email protected]b4ead7b2014-04-07 18:12:18568 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14569}
570
[email protected]035441d92013-03-22 23:21:39571TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) {
jaydasikaef64f9e42016-03-12 01:08:18572 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27573 LayerImpl* child = root->children()[0];
[email protected]b4ead7b2014-04-07 18:12:18574 gfx::Rect root_damage_rect, child_damage_rect;
[email protected]4000abf2012-10-23 04:45:45575
[email protected]035441d92013-03-22 23:21:39576 // Allow us to set damage on child too.
577 child->SetDrawsContent(true);
[email protected]4000abf2012-10-23 04:45:45578
[email protected]1dc7943e2013-09-26 04:41:48579 FilterOperations filters;
tomhudson992ec28b2016-04-27 16:45:39580 filters.Append(FilterOperation::CreateReferenceFilter(
581 SkBlurImageFilter::Make(2, 2, nullptr)));
hendrikw920114d2015-08-24 23:38:35582 int outset_top, outset_right, outset_bottom, outset_left;
583 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]4000abf2012-10-23 04:45:45584
[email protected]035441d92013-03-22 23:21:39585 // Setting the filter will damage the whole surface.
jaydasikaef64f9e42016-03-12 01:08:18586 ClearDamageForAllSurfaces(root);
jaydasika6b5a32bf2016-04-22 21:56:36587 child->test_properties()->force_render_surface = true;
jaydasika16515f52016-03-01 00:28:35588 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18589 EmulateDrawingOneFrame(root);
jaydasika6b5a32bf2016-04-22 21:56:36590 child->OnFilterAnimated(filters);
591 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39592 root_damage_rect =
593 root->render_surface()->damage_tracker()->current_damage_rect();
594 child_damage_rect =
595 child->render_surface()->damage_tracker()->current_damage_rect();
weiliangcd68cf712016-05-02 23:29:07596 EXPECT_EQ(gfx::Rect(100 - outset_left, 100 - outset_top,
597 30 + outset_left + outset_right,
598 30 + outset_top + outset_bottom),
599 root_damage_rect);
hendrikw920114d2015-08-24 23:38:35600 EXPECT_EQ(
601 gfx::Rect(-outset_left, -outset_top, 30 + (outset_left + outset_right),
weiliangcd68cf712016-05-02 23:29:07602 30 + (outset_top + outset_bottom)),
603 child_damage_rect);
[email protected]4000abf2012-10-23 04:45:45604
[email protected]035441d92013-03-22 23:21:39605 // CASE 1: Setting the update rect should damage the whole surface (for now)
jaydasikaef64f9e42016-03-12 01:08:18606 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42607 child->SetUpdateRect(gfx::Rect(1, 1));
jaydasika16515f52016-03-01 00:28:35608 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18609 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39610
611 root_damage_rect =
612 root->render_surface()->damage_tracker()->current_damage_rect();
613 child_damage_rect =
614 child->render_surface()->damage_tracker()->current_damage_rect();
hendrikw920114d2015-08-24 23:38:35615
616 int expect_width = 1 + outset_left + outset_right;
617 int expect_height = 1 + outset_top + outset_bottom;
618 EXPECT_EQ(gfx::Rect(100 - outset_left, 100 - outset_top, expect_width,
weiliangcd68cf712016-05-02 23:29:07619 expect_height),
620 root_damage_rect);
621 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height),
622 child_damage_rect);
623}
624
625TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) {
626 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
627 LayerImpl* child = root->children()[0];
628 gfx::Rect root_damage_rect, child_damage_rect;
629
630 // Allow us to set damage on child too.
631 child->SetDrawsContent(true);
632
633 FilterOperations filters;
634 filters.Append(FilterOperation::CreateReferenceFilter(
635 SkBlurImageFilter::Make(2, 2, nullptr)));
636 int outset_top, outset_right, outset_bottom, outset_left;
637 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
638
639 // Setting the filter will damage the whole surface.
640 gfx::Transform transform;
641 transform.RotateAboutYAxis(60);
642 ClearDamageForAllSurfaces(root);
643 child->test_properties()->force_render_surface = true;
644 child->SetTransform(transform);
645 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
646 EmulateDrawingOneFrame(root);
647 child->OnFilterAnimated(filters);
648 EmulateDrawingOneFrame(root);
649 root_damage_rect =
650 root->render_surface()->damage_tracker()->current_damage_rect();
651 child_damage_rect =
652 child->render_surface()->damage_tracker()->current_damage_rect();
653 int rotated_outset_left = outset_left / 2;
654 int expected_rotated_width = (30 + outset_left + outset_right) / 2;
655 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - outset_top,
656 expected_rotated_width,
657 30 + outset_top + outset_bottom);
658 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30));
659 EXPECT_EQ(expected_root_damage, root_damage_rect);
660 EXPECT_EQ(
661 gfx::Rect(-outset_left, -outset_top, 30 + (outset_left + outset_right),
662 30 + (outset_top + outset_bottom)),
663 child_damage_rect);
664
665 // Setting the update rect should damage the whole surface (for now)
666 ClearDamageForAllSurfaces(root);
667 child->SetUpdateRect(gfx::Rect(30, 30));
668 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
669 EmulateDrawingOneFrame(root);
670
671 root_damage_rect =
672 root->render_surface()->damage_tracker()->current_damage_rect();
673 child_damage_rect =
674 child->render_surface()->damage_tracker()->current_damage_rect();
675
676 int expect_width = 30 + outset_left + outset_right;
677 int expect_height = 30 + outset_top + outset_bottom;
678 EXPECT_EQ(gfx::Rect(100 - outset_left / 2, 100 - outset_top, expect_width / 2,
679 expect_height),
680 root_damage_rect);
681 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height),
682 child_damage_rect);
[email protected]4000abf2012-10-23 04:45:45683}
684
[email protected]035441d92013-03-22 23:21:39685TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) {
jaydasikaef64f9e42016-03-12 01:08:18686 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:27687 LayerImpl* child1 = root->children()[0];
688 LayerImpl* child2 = root->children()[1];
[email protected]94f206c12012-08-25 00:09:14689
[email protected]035441d92013-03-22 23:21:39690 // Allow us to set damage on child1 too.
691 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14692
[email protected]ae6b1a72013-06-25 18:49:29693 FilterOperations filters;
694 filters.Append(FilterOperation::CreateBlurFilter(2.f));
[email protected]035441d92013-03-22 23:21:39695 int outset_top, outset_right, outset_bottom, outset_left;
[email protected]ae6b1a72013-06-25 18:49:29696 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
[email protected]94f206c12012-08-25 00:09:14697
[email protected]035441d92013-03-22 23:21:39698 // Setting the filter will damage the whole surface.
jaydasikaef64f9e42016-03-12 01:08:18699 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:39700 child1->SetBackgroundFilters(filters);
jaydasika16515f52016-03-01 00:28:35701 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18702 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14703
[email protected]035441d92013-03-22 23:21:39704 // CASE 1: Setting the update rect should cause the corresponding damage to
705 // the surface, blurred based on the size of the child's background
jbroman8eb5fb72016-06-01 18:44:16706 // blur filter. Note that child1's render surface has a size of
707 // 206x208 due to contributions from grand_child1 and grand_child2.
jaydasikaef64f9e42016-03-12 01:08:18708 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42709 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2));
jaydasika16515f52016-03-01 00:28:35710 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18711 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14712
[email protected]b4ead7b2014-04-07 18:12:18713 gfx::Rect root_damage_rect =
714 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]035441d92013-03-22 23:21:39715 // Damage position on the surface should be a composition of the damage on
716 // the root and on child2. Damage on the root should be: position of
717 // update_rect (297, 297), but expanded by the blur outsets.
[email protected]b4ead7b2014-04-07 18:12:18718 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2);
[email protected]94f206c12012-08-25 00:09:14719
[email protected]035441d92013-03-22 23:21:39720 expected_damage_rect.Inset(-outset_left,
721 -outset_top,
722 -outset_right,
723 -outset_bottom);
[email protected]b4ead7b2014-04-07 18:12:18724 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14725
[email protected]035441d92013-03-22 23:21:39726 // CASE 2: Setting the update rect should cause the corresponding damage to
727 // the surface, blurred based on the size of the child's background
728 // blur filter. Since the damage extends to the right/bottom outside
729 // of the blurred layer, only the left/top should end up expanded.
jaydasikaef64f9e42016-03-12 01:08:18730 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42731 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30));
jaydasika16515f52016-03-01 00:28:35732 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18733 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14734
[email protected]035441d92013-03-22 23:21:39735 root_damage_rect =
736 root->render_surface()->damage_tracker()->current_damage_rect();
737 // Damage position on the surface should be a composition of the damage on
738 // the root and on child2. Damage on the root should be: position of
739 // update_rect (297, 297), but expanded on the left/top by the blur outsets.
[email protected]b4ead7b2014-04-07 18:12:18740 expected_damage_rect = gfx::Rect(297, 297, 30, 30);
[email protected]94f206c12012-08-25 00:09:14741
[email protected]035441d92013-03-22 23:21:39742 expected_damage_rect.Inset(-outset_left,
743 -outset_top,
744 0,
745 0);
[email protected]b4ead7b2014-04-07 18:12:18746 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14747
[email protected]ed511b8d2013-03-25 03:29:29748 // CASE 3: Setting this update rect outside the blurred content_bounds of the
[email protected]035441d92013-03-22 23:21:39749 // blurred child1 will not cause it to be expanded.
jaydasikaef64f9e42016-03-12 01:08:18750 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42751 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2));
jaydasika16515f52016-03-01 00:28:35752 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18753 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14754
[email protected]035441d92013-03-22 23:21:39755 root_damage_rect =
756 root->render_surface()->damage_tracker()->current_damage_rect();
757 // Damage on the root should be: position of update_rect (30, 30), not
758 // expanded.
[email protected]b4ead7b2014-04-07 18:12:18759 expected_damage_rect = gfx::Rect(30, 30, 2, 2);
[email protected]94f206c12012-08-25 00:09:14760
[email protected]b4ead7b2014-04-07 18:12:18761 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14762
[email protected]ed511b8d2013-03-25 03:29:29763 // CASE 4: Setting this update rect inside the blurred content_bounds but
764 // outside the original content_bounds of the blurred child1 will
[email protected]035441d92013-03-22 23:21:39765 // cause it to be expanded.
jaydasikaef64f9e42016-03-12 01:08:18766 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42767 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1));
jaydasika16515f52016-03-01 00:28:35768 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18769 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14770
[email protected]035441d92013-03-22 23:21:39771 root_damage_rect =
772 root->render_surface()->damage_tracker()->current_damage_rect();
jbroman8eb5fb72016-06-01 18:44:16773 // Damage on the root should be: the originally damaged rect (99,99 1x1)
774 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected
775 // with the surface rect (100,100 206x208). So no additional damage occurs
776 // above or to the left, but there is additional damage within the blurred
777 // area.
778 expected_damage_rect = gfx::Rect(99, 99, 7, 7);
[email protected]b4ead7b2014-04-07 18:12:18779 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]035441d92013-03-22 23:21:39780
781 // CASE 5: Setting the update rect on child2, which is above child1, will
782 // not get blurred by child1, so it does not need to get expanded.
jaydasikaef64f9e42016-03-12 01:08:18783 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42784 child2->SetUpdateRect(gfx::Rect(1, 1));
jaydasika16515f52016-03-01 00:28:35785 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18786 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39787
788 root_damage_rect =
789 root->render_surface()->damage_tracker()->current_damage_rect();
790 // Damage on child2 should be: position of update_rect offset by the child's
791 // position (11, 11), and not expanded by anything.
[email protected]b4ead7b2014-04-07 18:12:18792 expected_damage_rect = gfx::Rect(11, 11, 1, 1);
[email protected]035441d92013-03-22 23:21:39793
[email protected]b4ead7b2014-04-07 18:12:18794 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]035441d92013-03-22 23:21:39795
796 // CASE 6: Setting the update rect on child1 will also blur the damage, so
797 // that any pixels needed for the blur are redrawn in the current
798 // frame.
jaydasikaef64f9e42016-03-12 01:08:18799 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42800 child1->SetUpdateRect(gfx::Rect(1, 1));
jaydasika16515f52016-03-01 00:28:35801 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18802 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39803
804 root_damage_rect =
805 root->render_surface()->damage_tracker()->current_damage_rect();
806 // Damage on child1 should be: position of update_rect offset by the child's
807 // position (100, 100), and expanded by the damage.
[email protected]035441d92013-03-22 23:21:39808
jbroman8eb5fb72016-06-01 18:44:16809 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in
810 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there
811 // should be no damage outside child1 (i.e. none above or to the left of
812 // 100,100.
813 expected_damage_rect = gfx::Rect(100, 100, 7, 7);
[email protected]b4ead7b2014-04-07 18:12:18814 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14815}
816
[email protected]035441d92013-03-22 23:21:39817TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) {
jaydasikaef64f9e42016-03-12 01:08:18818 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27819 LayerImpl* child1 = root->children()[0];
[email protected]94f206c12012-08-25 00:09:14820
[email protected]035441d92013-03-22 23:21:39821 // CASE 1: Adding a new layer should cause the appropriate damage.
822 //
jaydasikaef64f9e42016-03-12 01:08:18823 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:39824 {
danakj60bc3bc2016-04-09 00:24:48825 std::unique_ptr<LayerImpl> child2 =
826 LayerImpl::Create(host_impl_.active_tree(), 3);
[email protected]035441d92013-03-22 23:21:39827 child2->SetPosition(gfx::PointF(400.f, 380.f));
[email protected]035441d92013-03-22 23:21:39828 child2->SetBounds(gfx::Size(6, 8));
[email protected]035441d92013-03-22 23:21:39829 child2->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:10830 root->AddChild(std::move(child2));
[email protected]035441d92013-03-22 23:21:39831 }
jaydasika16515f52016-03-01 00:28:35832 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18833 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14834
[email protected]035441d92013-03-22 23:21:39835 // Sanity check - all 3 layers should be on the same render surface; render
836 // surfaces are tested elsewhere.
837 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:14838
[email protected]b4ead7b2014-04-07 18:12:18839 gfx::Rect root_damage_rect =
840 root->render_surface()->damage_tracker()->current_damage_rect();
841 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14842
[email protected]035441d92013-03-22 23:21:39843 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not
844 // just the last update rect.
[email protected]94f206c12012-08-25 00:09:14845
[email protected]035441d92013-03-22 23:21:39846 // Advance one frame without damage so that we know the damage rect is not
847 // leftover from the previous case.
jaydasikaef64f9e42016-03-12 01:08:18848 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:35849 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18850 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14851
[email protected]035441d92013-03-22 23:21:39852 root_damage_rect =
853 root->render_surface()->damage_tracker()->current_damage_rect();
854 EXPECT_TRUE(root_damage_rect.IsEmpty());
855
856 // Then, test removing child1.
jaydasika6b7c69d2016-04-01 00:54:43857 root->RemoveChildForTesting(child1);
[email protected]035441d92013-03-22 23:21:39858 child1 = NULL;
jaydasika16515f52016-03-01 00:28:35859 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18860 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39861
862 root_damage_rect =
863 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:18864 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(),
865 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14866}
867
[email protected]035441d92013-03-22 23:21:39868TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) {
869 // If child2 is added to the layer tree, but it doesn't have any explicit
870 // damage of its own, it should still indeed damage the target surface.
[email protected]94f206c12012-08-25 00:09:14871
jaydasikaef64f9e42016-03-12 01:08:18872 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
[email protected]94f206c12012-08-25 00:09:14873
jaydasikaef64f9e42016-03-12 01:08:18874 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:39875 {
danakj60bc3bc2016-04-09 00:24:48876 std::unique_ptr<LayerImpl> child2 =
877 LayerImpl::Create(host_impl_.active_tree(), 3);
[email protected]035441d92013-03-22 23:21:39878 child2->SetPosition(gfx::PointF(400.f, 380.f));
[email protected]035441d92013-03-22 23:21:39879 child2->SetBounds(gfx::Size(6, 8));
[email protected]035441d92013-03-22 23:21:39880 child2->SetDrawsContent(true);
jaydasikaef64f9e42016-03-12 01:08:18881 root->AddChild(std::move(child2));
jaydasikad6f778b2016-05-19 22:51:26882 host_impl_.active_tree()->ResetAllChangeTracking();
jaydasikaef64f9e42016-03-12 01:08:18883 LayerImpl* child2_ptr = host_impl_.active_tree()->LayerById(3);
[email protected]035441d92013-03-22 23:21:39884 // Sanity check the initial conditions of the test, if these asserts
885 // trigger, it means the test no longer actually covers the intended
886 // scenario.
jaydasikaef64f9e42016-03-12 01:08:18887 ASSERT_FALSE(child2_ptr->LayerPropertyChanged());
888 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty());
[email protected]035441d92013-03-22 23:21:39889 }
jaydasika16515f52016-03-01 00:28:35890 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18891 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14892
[email protected]035441d92013-03-22 23:21:39893 // Sanity check - all 3 layers should be on the same render surface; render
894 // surfaces are tested elsewhere.
895 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:14896
[email protected]b4ead7b2014-04-07 18:12:18897 gfx::Rect root_damage_rect =
898 root->render_surface()->damage_tracker()->current_damage_rect();
899 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14900}
901
[email protected]035441d92013-03-22 23:21:39902TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) {
jaydasikaef64f9e42016-03-12 01:08:18903 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:27904 LayerImpl* child1 = root->children()[0];
[email protected]94f206c12012-08-25 00:09:14905
[email protected]035441d92013-03-22 23:21:39906 // In this test we don't want the above tree manipulation to be considered
907 // part of the same frame.
jaydasikaef64f9e42016-03-12 01:08:18908 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:39909 {
danakj60bc3bc2016-04-09 00:24:48910 std::unique_ptr<LayerImpl> child2 =
911 LayerImpl::Create(host_impl_.active_tree(), 3);
[email protected]035441d92013-03-22 23:21:39912 child2->SetPosition(gfx::PointF(400.f, 380.f));
[email protected]035441d92013-03-22 23:21:39913 child2->SetBounds(gfx::Size(6, 8));
[email protected]035441d92013-03-22 23:21:39914 child2->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:10915 root->AddChild(std::move(child2));
[email protected]035441d92013-03-22 23:21:39916 }
vollick83fbfc82016-03-22 18:33:27917 LayerImpl* child2 = root->children()[1];
jaydasika16515f52016-03-01 00:28:35918 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18919 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:14920
[email protected]035441d92013-03-22 23:21:39921 // Damaging two layers simultaneously should cause combined damage.
[email protected]b4ead7b2014-04-07 18:12:18922 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2);
923 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4);
jaydasikaef64f9e42016-03-12 01:08:18924 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:42925 child1->SetUpdateRect(gfx::Rect(1, 2));
926 child2->SetUpdateRect(gfx::Rect(3, 4));
jaydasika16515f52016-03-01 00:28:35927 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18928 EmulateDrawingOneFrame(root);
[email protected]b4ead7b2014-04-07 18:12:18929 gfx::Rect root_damage_rect =
930 root->render_surface()->damage_tracker()->current_damage_rect();
931 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(),
932 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14933}
934
[email protected]035441d92013-03-22 23:21:39935TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) {
jaydasikaef64f9e42016-03-12 01:08:18936 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:27937 LayerImpl* child1 = root->children()[0];
938 LayerImpl* child2 = root->children()[1];
939 LayerImpl* grand_child1 = root->children()[0]->children()[0];
jaydasika6b5a32bf2016-04-22 21:56:36940 child2->test_properties()->force_render_surface = true;
941 grand_child1->test_properties()->force_render_surface = true;
jaydasika16515f52016-03-01 00:28:35942 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18943 EmulateDrawingOneFrame(root);
[email protected]b4ead7b2014-04-07 18:12:18944 gfx::Rect child_damage_rect;
945 gfx::Rect root_damage_rect;
[email protected]94f206c12012-08-25 00:09:14946
[email protected]035441d92013-03-22 23:21:39947 // CASE 1: Damage to a descendant surface should propagate properly to
948 // ancestor surface.
jaydasikaef64f9e42016-03-12 01:08:18949 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:35950 grand_child1->OnOpacityAnimated(0.5f);
jaydasikaef64f9e42016-03-12 01:08:18951 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39952 child_damage_rect =
953 child1->render_surface()->damage_tracker()->current_damage_rect();
954 root_damage_rect =
955 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:18956 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString());
957 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14958
[email protected]035441d92013-03-22 23:21:39959 // CASE 2: Same as previous case, but with additional damage elsewhere that
960 // should be properly unioned.
961 // - child1 surface damage in root surface space:
[email protected]b4ead7b2014-04-07 18:12:18962 // gfx::Rect(300, 300, 6, 8);
[email protected]035441d92013-03-22 23:21:39963 // - child2 damage in root surface space:
[email protected]b4ead7b2014-04-07 18:12:18964 // gfx::Rect(11, 11, 18, 18);
jaydasikaef64f9e42016-03-12 01:08:18965 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:35966 grand_child1->OnOpacityAnimated(0.7f);
967 child2->OnOpacityAnimated(0.7f);
jaydasikaef64f9e42016-03-12 01:08:18968 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39969 child_damage_rect =
970 child1->render_surface()->damage_tracker()->current_damage_rect();
971 root_damage_rect =
972 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:18973 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString());
974 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(),
975 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:14976}
977
[email protected]035441d92013-03-22 23:21:39978TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) {
979 // If descendant layer changes and affects the content bounds of the render
980 // surface, then the entire descendant surface should be damaged, and it
981 // should damage its ancestor surface with the old and new surface regions.
[email protected]94f206c12012-08-25 00:09:14982
[email protected]035441d92013-03-22 23:21:39983 // This is a tricky case, since only the first grand_child changes, but the
984 // entire surface should be marked dirty.
[email protected]94f206c12012-08-25 00:09:14985
jaydasikaef64f9e42016-03-12 01:08:18986 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:27987 LayerImpl* child1 = root->children()[0];
988 LayerImpl* grand_child1 = root->children()[0]->children()[0];
[email protected]b4ead7b2014-04-07 18:12:18989 gfx::Rect child_damage_rect;
990 gfx::Rect root_damage_rect;
[email protected]94f206c12012-08-25 00:09:14991
jaydasikaef64f9e42016-03-12 01:08:18992 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:39993 grand_child1->SetPosition(gfx::PointF(195.f, 205.f));
jaydasika16515f52016-03-01 00:28:35994 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:18995 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:39996 child_damage_rect =
997 child1->render_surface()->damage_tracker()->current_damage_rect();
998 root_damage_rect =
999 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141000
[email protected]035441d92013-03-22 23:21:391001 // The new surface bounds should be damaged entirely, even though only one of
1002 // the layers changed.
[email protected]b4ead7b2014-04-07 18:12:181003 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(),
1004 child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141005
[email protected]035441d92013-03-22 23:21:391006 // Damage to the root surface should be the union of child1's *entire* render
1007 // surface (in target space), and its old exposed area (also in target
1008 // space).
[email protected]b4ead7b2014-04-07 18:12:181009 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(),
1010 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141011}
1012
[email protected]035441d92013-03-22 23:21:391013TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) {
1014 // An ancestor/owning layer changes that affects the position/transform of
[email protected]ed511b8d2013-03-25 03:29:291015 // the render surface. Note that in this case, the layer_property_changed flag
[email protected]035441d92013-03-22 23:21:391016 // already propagates to the subtree (tested in LayerImpltest), which damages
1017 // the entire child1 surface, but the damage tracker still needs the correct
1018 // logic to compute the exposed region on the root surface.
[email protected]94f206c12012-08-25 00:09:141019
[email protected]27d851ab2013-06-28 01:09:501020 // TODO(shawnsingh): the expectations of this test case should change when we
1021 // add support for a unique scissor_rect per RenderSurface. In that case, the
1022 // child1 surface should be completely unchanged, since we are only
1023 // transforming it, while the root surface would be damaged appropriately.
[email protected]94f206c12012-08-25 00:09:141024
jaydasikaef64f9e42016-03-12 01:08:181025 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271026 LayerImpl* child1 = root->children()[0];
1027 LayerImpl* grand_child1 = child1->children()[0];
1028 LayerImpl* grand_child2 = child1->children()[1];
[email protected]b4ead7b2014-04-07 18:12:181029 gfx::Rect child_damage_rect;
1030 gfx::Rect root_damage_rect;
[email protected]94f206c12012-08-25 00:09:141031
jaydasikaef64f9e42016-03-12 01:08:181032 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:391033 child1->SetPosition(gfx::PointF(50.f, 50.f));
jaydasikaadfec8e2016-02-17 02:46:111034 child1->NoteLayerPropertyChanged();
1035 grand_child1->NoteLayerPropertyChanged();
1036 grand_child2->NoteLayerPropertyChanged();
jaydasika16515f52016-03-01 00:28:351037 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181038 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391039 child_damage_rect =
1040 child1->render_surface()->damage_tracker()->current_damage_rect();
1041 root_damage_rect =
1042 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141043
[email protected]035441d92013-03-22 23:21:391044 // The new surface bounds should be damaged entirely.
[email protected]b4ead7b2014-04-07 18:12:181045 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
1046 child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141047
[email protected]035441d92013-03-22 23:21:391048 // The entire child1 surface and the old exposed child1 surface should damage
1049 // the root surface.
[email protected]b4ead7b2014-04-07 18:12:181050 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18)
1051 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18)
1052 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(),
1053 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141054}
1055
[email protected]035441d92013-03-22 23:21:391056TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) {
jaydasikaef64f9e42016-03-12 01:08:181057 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271058 LayerImpl* child1 = root->children()[0];
[email protected]b4ead7b2014-04-07 18:12:181059 gfx::Rect child_damage_rect;
1060 gfx::Rect root_damage_rect;
[email protected]94f206c12012-08-25 00:09:141061
[email protected]035441d92013-03-22 23:21:391062 // CASE 1: If a descendant surface disappears, its entire old area becomes
1063 // exposed.
jaydasikaef64f9e42016-03-12 01:08:181064 ClearDamageForAllSurfaces(root);
jaydasika6b5a32bf2016-04-22 21:56:361065 child1->test_properties()->force_render_surface = false;
jaydasika16515f52016-03-01 00:28:351066 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181067 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141068
[email protected]035441d92013-03-22 23:21:391069 // Sanity check that there is only one surface now.
1070 ASSERT_FALSE(child1->render_surface());
1071 ASSERT_EQ(4u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:141072
[email protected]035441d92013-03-22 23:21:391073 root_damage_rect =
1074 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181075 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
1076 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141077
[email protected]035441d92013-03-22 23:21:391078 // CASE 2: If a descendant surface appears, its entire old area becomes
1079 // exposed.
[email protected]94f206c12012-08-25 00:09:141080
[email protected]035441d92013-03-22 23:21:391081 // Cycle one frame of no change, just to sanity check that the next rect is
1082 // not because of the old damage state.
jaydasikaef64f9e42016-03-12 01:08:181083 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:351084 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181085 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391086 root_damage_rect =
1087 root->render_surface()->damage_tracker()->current_damage_rect();
1088 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141089
[email protected]035441d92013-03-22 23:21:391090 // Then change the tree so that the render surface is added back.
jaydasikaef64f9e42016-03-12 01:08:181091 ClearDamageForAllSurfaces(root);
jaydasika6b5a32bf2016-04-22 21:56:361092 child1->test_properties()->force_render_surface = true;
awoloszyne83f28c2014-12-22 15:40:001093
jaydasika16515f52016-03-01 00:28:351094 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181095 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141096
[email protected]035441d92013-03-22 23:21:391097 // Sanity check that there is a new surface now.
1098 ASSERT_TRUE(child1->render_surface());
1099 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
1100 EXPECT_EQ(2u, child1->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:141101
[email protected]035441d92013-03-22 23:21:391102 child_damage_rect =
1103 child1->render_surface()->damage_tracker()->current_damage_rect();
1104 root_damage_rect =
1105 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181106 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
1107 child_damage_rect.ToString());
1108 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
1109 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141110}
1111
[email protected]035441d92013-03-22 23:21:391112TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) {
jaydasikaef64f9e42016-03-12 01:08:181113 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271114 LayerImpl* child1 = root->children()[0];
[email protected]b4ead7b2014-04-07 18:12:181115 gfx::Rect child_damage_rect;
1116 gfx::Rect root_damage_rect;
[email protected]94f206c12012-08-25 00:09:141117
[email protected]035441d92013-03-22 23:21:391118 // CASE 1: If nothing changes, the damage rect should be empty.
1119 //
jaydasikaef64f9e42016-03-12 01:08:181120 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:351121 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181122 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391123 child_damage_rect =
1124 child1->render_surface()->damage_tracker()->current_damage_rect();
1125 root_damage_rect =
1126 root->render_surface()->damage_tracker()->current_damage_rect();
1127 EXPECT_TRUE(child_damage_rect.IsEmpty());
1128 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141129
[email protected]035441d92013-03-22 23:21:391130 // CASE 2: If nothing changes twice in a row, the damage rect should still be
1131 // empty.
1132 //
jaydasikaef64f9e42016-03-12 01:08:181133 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:351134 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181135 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391136 child_damage_rect =
1137 child1->render_surface()->damage_tracker()->current_damage_rect();
1138 root_damage_rect =
1139 root->render_surface()->damage_tracker()->current_damage_rect();
1140 EXPECT_TRUE(child_damage_rect.IsEmpty());
1141 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141142}
1143
[email protected]035441d92013-03-22 23:21:391144TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) {
jaydasikaef64f9e42016-03-12 01:08:181145 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271146 LayerImpl* child1 = root->children()[0];
[email protected]b4ead7b2014-04-07 18:12:181147 gfx::Rect child_damage_rect;
1148 gfx::Rect root_damage_rect;
[email protected]94f206c12012-08-25 00:09:141149
[email protected]035441d92013-03-22 23:21:391150 // In our specific tree, the update rect of child1 should not cause any
1151 // damage to any surface because it does not actually draw content.
jaydasikaef64f9e42016-03-12 01:08:181152 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:421153 child1->SetUpdateRect(gfx::Rect(1, 2));
jaydasika16515f52016-03-01 00:28:351154 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181155 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391156 child_damage_rect =
1157 child1->render_surface()->damage_tracker()->current_damage_rect();
1158 root_damage_rect =
1159 root->render_surface()->damage_tracker()->current_damage_rect();
1160 EXPECT_TRUE(child_damage_rect.IsEmpty());
1161 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141162}
1163
[email protected]035441d92013-03-22 23:21:391164TEST_F(DamageTrackerTest, VerifyDamageForReplica) {
jaydasikaef64f9e42016-03-12 01:08:181165 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271166 LayerImpl* child1 = root->children()[0];
1167 LayerImpl* grand_child1 = child1->children()[0];
1168 LayerImpl* grand_child2 = child1->children()[1];
[email protected]94f206c12012-08-25 00:09:141169
[email protected]035441d92013-03-22 23:21:391170 // Damage on a surface that has a reflection should cause the target surface
1171 // to receive the surface's damage and the surface's reflected damage.
[email protected]94f206c12012-08-25 00:09:141172
[email protected]035441d92013-03-22 23:21:391173 // For this test case, we modify grand_child2, and add grand_child3 to extend
1174 // the bounds of child1's surface. This way, we can test reflection changes
[email protected]ed511b8d2013-03-25 03:29:291175 // without changing content_bounds of the surface.
[email protected]035441d92013-03-22 23:21:391176 grand_child2->SetPosition(gfx::PointF(180.f, 180.f));
1177 {
danakj60bc3bc2016-04-09 00:24:481178 std::unique_ptr<LayerImpl> grand_child3 =
1179 LayerImpl::Create(host_impl_.active_tree(), 6);
[email protected]035441d92013-03-22 23:21:391180 grand_child3->SetPosition(gfx::PointF(240.f, 240.f));
[email protected]035441d92013-03-22 23:21:391181 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]035441d92013-03-22 23:21:391182 grand_child3->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:101183 child1->AddChild(std::move(grand_child3));
[email protected]035441d92013-03-22 23:21:391184 }
jaydasikaab317e02016-06-01 00:53:181185 child1->test_properties()->opacity = 0.5f;
jaydasika16515f52016-03-01 00:28:351186 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181187 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141188
[email protected]035441d92013-03-22 23:21:391189 // CASE 1: adding a reflection about the left edge of grand_child1.
1190 //
jaydasikaef64f9e42016-03-12 01:08:181191 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:391192 {
danakj60bc3bc2016-04-09 00:24:481193 std::unique_ptr<LayerImpl> grand_child1_replica =
1194 LayerImpl::Create(host_impl_.active_tree(), 7);
[email protected]035441d92013-03-22 23:21:391195 grand_child1_replica->SetPosition(gfx::PointF());
[email protected]035441d92013-03-22 23:21:391196 gfx::Transform reflection;
1197 reflection.Scale3d(-1.0, 1.0, 1.0);
1198 grand_child1_replica->SetTransform(reflection);
danakja04855a2015-11-18 20:39:101199 grand_child1->SetReplicaLayer(std::move(grand_child1_replica));
jaydasika6b5a32bf2016-04-22 21:56:361200 grand_child1->test_properties()->force_render_surface = true;
1201 grand_child1->NoteLayerPropertyChanged();
[email protected]035441d92013-03-22 23:21:391202 }
jaydasika16515f52016-03-01 00:28:351203 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181204 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141205
[email protected]b4ead7b2014-04-07 18:12:181206 gfx::Rect grand_child_damage_rect =
1207 grand_child1->render_surface()->damage_tracker()->current_damage_rect();
1208 gfx::Rect child_damage_rect =
1209 child1->render_surface()->damage_tracker()->current_damage_rect();
1210 gfx::Rect root_damage_rect =
1211 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141212
[email protected]035441d92013-03-22 23:21:391213 // The grand_child surface damage should not include its own replica. The
1214 // child surface damage should include the normal and replica surfaces.
[email protected]b4ead7b2014-04-07 18:12:181215 EXPECT_EQ(gfx::Rect(6, 8).ToString(), grand_child_damage_rect.ToString());
1216 EXPECT_EQ(gfx::Rect(194, 200, 12, 8).ToString(),
1217 child_damage_rect.ToString());
1218 EXPECT_EQ(gfx::Rect(294, 300, 12, 8).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141219
[email protected]035441d92013-03-22 23:21:391220 // CASE 2: moving the descendant surface should cause both the original and
1221 // reflected areas to be damaged on the target.
jaydasikaef64f9e42016-03-12 01:08:181222 ClearDamageForAllSurfaces(root);
[email protected]035441d92013-03-22 23:21:391223 gfx::Rect old_content_rect = child1->render_surface()->content_rect();
1224 grand_child1->SetPosition(gfx::PointF(195.f, 205.f));
jaydasikaadfec8e2016-02-17 02:46:111225 grand_child1->NoteLayerPropertyChanged();
jaydasika16515f52016-03-01 00:28:351226 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181227 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391228 ASSERT_EQ(old_content_rect.width(),
1229 child1->render_surface()->content_rect().width());
1230 ASSERT_EQ(old_content_rect.height(),
1231 child1->render_surface()->content_rect().height());
[email protected]94f206c12012-08-25 00:09:141232
[email protected]035441d92013-03-22 23:21:391233 grand_child_damage_rect =
1234 grand_child1->render_surface()->
1235 damage_tracker()->current_damage_rect();
1236 child_damage_rect =
1237 child1->render_surface()->damage_tracker()->current_damage_rect();
1238 root_damage_rect =
1239 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141240
[email protected]035441d92013-03-22 23:21:391241 // The child surface damage should include normal and replica surfaces for
1242 // both old and new locations.
[email protected]b4ead7b2014-04-07 18:12:181243 // - old location in target space: gfx::Rect(194, 200, 12, 8)
1244 // - new location in target space: gfx::Rect(189, 205, 12, 8)
1245 EXPECT_EQ(gfx::Rect(6, 8).ToString(), grand_child_damage_rect.ToString());
1246 EXPECT_EQ(gfx::Rect(189, 200, 17, 13).ToString(),
1247 child_damage_rect.ToString());
1248 EXPECT_EQ(gfx::Rect(289, 300, 17, 13).ToString(),
1249 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141250
[email protected]035441d92013-03-22 23:21:391251 // CASE 3: removing the reflection should cause the entire region including
1252 // reflection to damage the target surface.
jaydasikaef64f9e42016-03-12 01:08:181253 ClearDamageForAllSurfaces(root);
danakj968153f32014-10-15 22:52:161254 grand_child1->SetReplicaLayer(nullptr);
jaydasika6b5a32bf2016-04-22 21:56:361255 grand_child1->test_properties()->force_render_surface = false;
1256 grand_child1->NoteLayerPropertyChanged();
jaydasika16515f52016-03-01 00:28:351257 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181258 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391259 ASSERT_EQ(old_content_rect.width(),
1260 child1->render_surface()->content_rect().width());
1261 ASSERT_EQ(old_content_rect.height(),
1262 child1->render_surface()->content_rect().height());
[email protected]94f206c12012-08-25 00:09:141263
[email protected]035441d92013-03-22 23:21:391264 EXPECT_FALSE(grand_child1->render_surface());
1265 child_damage_rect =
1266 child1->render_surface()->damage_tracker()->current_damage_rect();
1267 root_damage_rect =
1268 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141269
[email protected]b4ead7b2014-04-07 18:12:181270 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(),
1271 child_damage_rect.ToString());
1272 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141273}
1274
[email protected]035441d92013-03-22 23:21:391275TEST_F(DamageTrackerTest, VerifyDamageForMask) {
jaydasikaef64f9e42016-03-12 01:08:181276 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:271277 LayerImpl* child = root->children()[0];
[email protected]94f206c12012-08-25 00:09:141278
[email protected]035441d92013-03-22 23:21:391279 // In the current implementation of the damage tracker, changes to mask
1280 // layers should damage the entire corresponding surface.
[email protected]94f206c12012-08-25 00:09:141281
jaydasikaef64f9e42016-03-12 01:08:181282 ClearDamageForAllSurfaces(root);
[email protected]94f206c12012-08-25 00:09:141283
[email protected]035441d92013-03-22 23:21:391284 // Set up the mask layer.
1285 {
danakj60bc3bc2016-04-09 00:24:481286 std::unique_ptr<LayerImpl> mask_layer =
1287 LayerImpl::Create(host_impl_.active_tree(), 3);
[email protected]035441d92013-03-22 23:21:391288 mask_layer->SetPosition(child->position());
bokancccfde72014-10-08 15:15:221289 mask_layer->SetBounds(child->bounds());
danakja04855a2015-11-18 20:39:101290 child->SetMaskLayer(std::move(mask_layer));
jaydasika6b5a32bf2016-04-22 21:56:361291 child->test_properties()->force_render_surface = true;
[email protected]035441d92013-03-22 23:21:391292 }
1293 LayerImpl* mask_layer = child->mask_layer();
[email protected]94f206c12012-08-25 00:09:141294
[email protected]035441d92013-03-22 23:21:391295 // Add opacity and a grand_child so that the render surface persists even
1296 // after we remove the mask.
[email protected]035441d92013-03-22 23:21:391297 {
danakj60bc3bc2016-04-09 00:24:481298 std::unique_ptr<LayerImpl> grand_child =
1299 LayerImpl::Create(host_impl_.active_tree(), 4);
[email protected]035441d92013-03-22 23:21:391300 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
[email protected]035441d92013-03-22 23:21:391301 grand_child->SetBounds(gfx::Size(2, 2));
[email protected]035441d92013-03-22 23:21:391302 grand_child->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:101303 child->AddChild(std::move(grand_child));
[email protected]035441d92013-03-22 23:21:391304 }
jaydasika16515f52016-03-01 00:28:351305 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181306 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141307
[email protected]035441d92013-03-22 23:21:391308 // CASE 1: the update_rect on a mask layer should damage the entire target
1309 // surface.
jaydasikaef64f9e42016-03-12 01:08:181310 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:421311 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
jaydasika16515f52016-03-01 00:28:351312 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181313 EmulateDrawingOneFrame(root);
[email protected]b4ead7b2014-04-07 18:12:181314 gfx::Rect child_damage_rect =
1315 child->render_surface()->damage_tracker()->current_damage_rect();
1316 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141317
[email protected]035441d92013-03-22 23:21:391318 // CASE 2: a property change on the mask layer should damage the entire
1319 // target surface.
[email protected]94f206c12012-08-25 00:09:141320
[email protected]035441d92013-03-22 23:21:391321 // Advance one frame without damage so that we know the damage rect is not
1322 // leftover from the previous case.
jaydasikaef64f9e42016-03-12 01:08:181323 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:351324 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181325 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391326 child_damage_rect =
1327 child->render_surface()->damage_tracker()->current_damage_rect();
1328 EXPECT_TRUE(child_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141329
[email protected]035441d92013-03-22 23:21:391330 // Then test the property change.
jaydasikaef64f9e42016-03-12 01:08:181331 ClearDamageForAllSurfaces(root);
jaydasika865fd482016-02-24 09:26:151332 mask_layer->NoteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:141333
jaydasika16515f52016-03-01 00:28:351334 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181335 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391336 child_damage_rect =
1337 child->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181338 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141339
[email protected]035441d92013-03-22 23:21:391340 // CASE 3: removing the mask also damages the entire target surface.
1341 //
[email protected]94f206c12012-08-25 00:09:141342
[email protected]035441d92013-03-22 23:21:391343 // Advance one frame without damage so that we know the damage rect is not
1344 // leftover from the previous case.
jaydasikaef64f9e42016-03-12 01:08:181345 ClearDamageForAllSurfaces(root);
jaydasika16515f52016-03-01 00:28:351346 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181347 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391348 child_damage_rect =
1349 child->render_surface()->damage_tracker()->current_damage_rect();
1350 EXPECT_TRUE(child_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141351
[email protected]035441d92013-03-22 23:21:391352 // Then test mask removal.
jaydasikaef64f9e42016-03-12 01:08:181353 ClearDamageForAllSurfaces(root);
danakj968153f32014-10-15 22:52:161354 child->SetMaskLayer(nullptr);
jaydasika03a99c42016-02-11 21:07:081355 child->NoteLayerPropertyChanged();
[email protected]035441d92013-03-22 23:21:391356 ASSERT_TRUE(child->LayerPropertyChanged());
jaydasika16515f52016-03-01 00:28:351357 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181358 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141359
[email protected]035441d92013-03-22 23:21:391360 // Sanity check that a render surface still exists.
1361 ASSERT_TRUE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:141362
[email protected]035441d92013-03-22 23:21:391363 child_damage_rect =
1364 child->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181365 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141366}
1367
[email protected]035441d92013-03-22 23:21:391368TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) {
jaydasikaef64f9e42016-03-12 01:08:181369 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271370 LayerImpl* child1 = root->children()[0];
1371 LayerImpl* grand_child1 = child1->children()[0];
[email protected]94f206c12012-08-25 00:09:141372
[email protected]035441d92013-03-22 23:21:391373 // Changes to a replica's mask should not damage the original surface,
1374 // because it is not masked. But it does damage the ancestor target surface.
[email protected]94f206c12012-08-25 00:09:141375
jaydasikaef64f9e42016-03-12 01:08:181376 ClearDamageForAllSurfaces(root);
[email protected]94f206c12012-08-25 00:09:141377
[email protected]035441d92013-03-22 23:21:391378 // Create a reflection about the left edge of grand_child1.
1379 {
danakj60bc3bc2016-04-09 00:24:481380 std::unique_ptr<LayerImpl> grand_child1_replica =
1381 LayerImpl::Create(host_impl_.active_tree(), 6);
[email protected]035441d92013-03-22 23:21:391382 grand_child1_replica->SetPosition(gfx::PointF());
[email protected]035441d92013-03-22 23:21:391383 gfx::Transform reflection;
1384 reflection.Scale3d(-1.0, 1.0, 1.0);
1385 grand_child1_replica->SetTransform(reflection);
danakja04855a2015-11-18 20:39:101386 grand_child1->SetReplicaLayer(std::move(grand_child1_replica));
jaydasika6b5a32bf2016-04-22 21:56:361387 grand_child1->test_properties()->force_render_surface = true;
[email protected]035441d92013-03-22 23:21:391388 }
1389 LayerImpl* grand_child1_replica = grand_child1->replica_layer();
[email protected]94f206c12012-08-25 00:09:141390
[email protected]035441d92013-03-22 23:21:391391 // Set up the mask layer on the replica layer
1392 {
danakj60bc3bc2016-04-09 00:24:481393 std::unique_ptr<LayerImpl> replica_mask_layer =
1394 LayerImpl::Create(host_impl_.active_tree(), 7);
[email protected]035441d92013-03-22 23:21:391395 replica_mask_layer->SetPosition(gfx::PointF());
bokancccfde72014-10-08 15:15:221396 replica_mask_layer->SetBounds(grand_child1->bounds());
danakja04855a2015-11-18 20:39:101397 grand_child1_replica->SetMaskLayer(std::move(replica_mask_layer));
[email protected]035441d92013-03-22 23:21:391398 }
1399 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer();
[email protected]94f206c12012-08-25 00:09:141400
jaydasika16515f52016-03-01 00:28:351401 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181402 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141403
[email protected]035441d92013-03-22 23:21:391404 // Sanity check that the appropriate render surfaces were created
1405 ASSERT_TRUE(grand_child1->render_surface());
[email protected]94f206c12012-08-25 00:09:141406
[email protected]035441d92013-03-22 23:21:391407 // CASE 1: a property change on the mask should damage only the reflected
1408 // region on the target surface.
jaydasikaef64f9e42016-03-12 01:08:181409 ClearDamageForAllSurfaces(root);
jaydasika865fd482016-02-24 09:26:151410 replica_mask_layer->NoteLayerPropertyChanged();
jaydasika16515f52016-03-01 00:28:351411 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181412 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141413
[email protected]b4ead7b2014-04-07 18:12:181414 gfx::Rect grand_child_damage_rect =
1415 grand_child1->render_surface()->damage_tracker()->current_damage_rect();
1416 gfx::Rect child_damage_rect =
1417 child1->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141418
[email protected]035441d92013-03-22 23:21:391419 EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
[email protected]b4ead7b2014-04-07 18:12:181420 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141421
[email protected]035441d92013-03-22 23:21:391422 // CASE 2: removing the replica mask damages only the reflected region on the
1423 // target surface.
1424 //
jaydasikaef64f9e42016-03-12 01:08:181425 ClearDamageForAllSurfaces(root);
danakj968153f32014-10-15 22:52:161426 grand_child1_replica->SetMaskLayer(nullptr);
jaydasika16515f52016-03-01 00:28:351427 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181428 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141429
[email protected]035441d92013-03-22 23:21:391430 grand_child_damage_rect =
1431 grand_child1->render_surface()->damage_tracker()->
1432 current_damage_rect();
1433 child_damage_rect =
1434 child1->render_surface()->damage_tracker()->current_damage_rect();
[email protected]94f206c12012-08-25 00:09:141435
[email protected]035441d92013-03-22 23:21:391436 EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
[email protected]b4ead7b2014-04-07 18:12:181437 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141438}
1439
[email protected]a2566412014-06-05 03:14:201440TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) {
jaydasikaef64f9e42016-03-12 01:08:181441 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
vollick83fbfc82016-03-22 18:33:271442 LayerImpl* child1 = root->children()[0];
1443 LayerImpl* grand_child1 = child1->children()[0];
[email protected]94f206c12012-08-25 00:09:141444
[email protected]ed511b8d2013-03-25 03:29:291445 // Verify that the correct replica_origin_transform is used for the
1446 // replica_mask.
jaydasikaef64f9e42016-03-12 01:08:181447 ClearDamageForAllSurfaces(root);
[email protected]94f206c12012-08-25 00:09:141448
[email protected]a2566412014-06-05 03:14:201449 // This is not actually the transform origin point being tested, but by
1450 // convention its
[email protected]035441d92013-03-22 23:21:391451 // expected to be the same as the replica's anchor point.
jaydasika38be7a822016-04-21 16:07:061452 grand_child1->test_properties()->transform_origin =
1453 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f);
[email protected]94f206c12012-08-25 00:09:141454
[email protected]035441d92013-03-22 23:21:391455 {
danakj60bc3bc2016-04-09 00:24:481456 std::unique_ptr<LayerImpl> grand_child1_replica =
1457 LayerImpl::Create(host_impl_.active_tree(), 6);
[email protected]035441d92013-03-22 23:21:391458 grand_child1_replica->SetPosition(gfx::PointF());
[email protected]94f206c12012-08-25 00:09:141459
[email protected]035441d92013-03-22 23:21:391460 // This is the anchor being tested.
jaydasika38be7a822016-04-21 16:07:061461 grand_child1_replica->test_properties()->transform_origin =
1462 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f);
[email protected]035441d92013-03-22 23:21:391463 gfx::Transform reflection;
1464 reflection.Scale3d(-1.0, 1.0, 1.0);
1465 grand_child1_replica->SetTransform(reflection);
jaydasika5017a332016-03-31 01:06:221466 // We need to set parent on replica layer for property tree building.
1467 grand_child1_replica->SetParent(grand_child1);
danakja04855a2015-11-18 20:39:101468 grand_child1->SetReplicaLayer(std::move(grand_child1_replica));
jaydasika6b5a32bf2016-04-22 21:56:361469 grand_child1->test_properties()->force_render_surface = true;
[email protected]035441d92013-03-22 23:21:391470 }
1471 LayerImpl* grand_child1_replica = grand_child1->replica_layer();
[email protected]94f206c12012-08-25 00:09:141472
[email protected]035441d92013-03-22 23:21:391473 // Set up the mask layer on the replica layer
1474 {
danakj60bc3bc2016-04-09 00:24:481475 std::unique_ptr<LayerImpl> replica_mask_layer =
1476 LayerImpl::Create(host_impl_.active_tree(), 7);
[email protected]035441d92013-03-22 23:21:391477 replica_mask_layer->SetPosition(gfx::PointF());
[email protected]a2566412014-06-05 03:14:201478 // Note: this is not the transform origin being tested.
bokancccfde72014-10-08 15:15:221479 replica_mask_layer->SetBounds(grand_child1->bounds());
danakja04855a2015-11-18 20:39:101480 grand_child1_replica->SetMaskLayer(std::move(replica_mask_layer));
[email protected]035441d92013-03-22 23:21:391481 }
1482 LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer();
[email protected]94f206c12012-08-25 00:09:141483
jaydasika16515f52016-03-01 00:28:351484 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181485 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141486
[email protected]035441d92013-03-22 23:21:391487 // Sanity check that the appropriate render surfaces were created
1488 ASSERT_TRUE(grand_child1->render_surface());
[email protected]94f206c12012-08-25 00:09:141489
[email protected]ed511b8d2013-03-25 03:29:291490 // A property change on the replica_mask should damage the reflected region on
[email protected]035441d92013-03-22 23:21:391491 // the target surface.
jaydasikaef64f9e42016-03-12 01:08:181492 ClearDamageForAllSurfaces(root);
jaydasika865fd482016-02-24 09:26:151493 replica_mask_layer->NoteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:141494
jaydasika16515f52016-03-01 00:28:351495 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181496 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391497
[email protected]b4ead7b2014-04-07 18:12:181498 gfx::Rect child_damage_rect =
1499 child1->render_surface()->damage_tracker()->current_damage_rect();
1500 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141501}
1502
[email protected]e0341352013-04-06 05:01:201503TEST_F(DamageTrackerTest, DamageWhenAddedExternally) {
jaydasikaef64f9e42016-03-12 01:08:181504 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:271505 LayerImpl* child = root->children()[0];
[email protected]94f206c12012-08-25 00:09:141506
[email protected]e0341352013-04-06 05:01:201507 // Case 1: This test ensures that when the tracker is given damage, that
1508 // it is included with any other partial damage.
[email protected]035441d92013-03-22 23:21:391509 //
jaydasikaef64f9e42016-03-12 01:08:181510 ClearDamageForAllSurfaces(root);
danakj19f0c9e2014-10-11 03:24:421511 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
[email protected]e0341352013-04-06 05:01:201512 root->render_surface()->damage_tracker()->AddDamageNextUpdate(
[email protected]b4ead7b2014-04-07 18:12:181513 gfx::Rect(15, 16, 32, 33));
jaydasika16515f52016-03-01 00:28:351514 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181515 EmulateDrawingOneFrame(root);
[email protected]b4ead7b2014-04-07 18:12:181516 gfx::Rect root_damage_rect =
[email protected]e0341352013-04-06 05:01:201517 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181518 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33),
1519 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(),
1520 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141521
[email protected]e0341352013-04-06 05:01:201522 // Case 2: An additional sanity check that adding damage works even when
1523 // nothing on the layer tree changed.
[email protected]035441d92013-03-22 23:21:391524 //
jaydasikaef64f9e42016-03-12 01:08:181525 ClearDamageForAllSurfaces(root);
[email protected]e0341352013-04-06 05:01:201526 root->render_surface()->damage_tracker()->AddDamageNextUpdate(
[email protected]b4ead7b2014-04-07 18:12:181527 gfx::Rect(30, 31, 14, 15));
jaydasika16515f52016-03-01 00:28:351528 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181529 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391530 root_damage_rect =
[email protected]e0341352013-04-06 05:01:201531 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181532 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141533}
1534
[email protected]035441d92013-03-22 23:21:391535TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) {
1536 // Though it should never happen, its a good idea to verify that the damage
[email protected]ed511b8d2013-03-25 03:29:291537 // tracker does not crash when it receives an empty layer_list.
[email protected]94f206c12012-08-25 00:09:141538
danakj60bc3bc2016-04-09 00:24:481539 std::unique_ptr<LayerImpl> root =
1540 LayerImpl::Create(host_impl_.active_tree(), 1);
jaydasika6b5a32bf2016-04-22 21:56:361541 root->test_properties()->force_render_surface = true;
jaydasika2411692c2016-03-23 01:56:091542 host_impl_.active_tree()->SetRootLayer(std::move(root));
1543 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer();
1544 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
1545 EmulateDrawingOneFrame(root_ptr);
[email protected]94f206c12012-08-25 00:09:141546
weiliangc189c1a12016-04-11 16:16:251547 DCHECK_EQ(root_ptr->render_surface(), root_ptr->render_target());
jaydasika2411692c2016-03-23 01:56:091548 RenderSurfaceImpl* target_surface = root_ptr->render_surface();
[email protected]989386c2013-07-18 21:37:231549
1550 LayerImplList empty_list;
[email protected]035441d92013-03-22 23:21:391551 target_surface->damage_tracker()->UpdateDamageTrackingState(
weiliangc4012ef72016-04-11 22:04:061552 empty_list, target_surface, false, gfx::Rect(), NULL, FilterOperations());
[email protected]94f206c12012-08-25 00:09:141553
[email protected]b4ead7b2014-04-07 18:12:181554 gfx::Rect damage_rect =
1555 target_surface->damage_tracker()->current_damage_rect();
[email protected]035441d92013-03-22 23:21:391556 EXPECT_TRUE(damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141557}
1558
[email protected]035441d92013-03-22 23:21:391559TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) {
1560 // If damage is not cleared, it should accumulate.
[email protected]94f206c12012-08-25 00:09:141561
jaydasikaef64f9e42016-03-12 01:08:181562 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:271563 LayerImpl* child = root->children()[0];
[email protected]94f206c12012-08-25 00:09:141564
jaydasikaef64f9e42016-03-12 01:08:181565 ClearDamageForAllSurfaces(root);
[email protected]b4ead7b2014-04-07 18:12:181566 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f));
jaydasika16515f52016-03-01 00:28:351567 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181568 EmulateDrawingOneFrame(root);
[email protected]94f206c12012-08-25 00:09:141569
[email protected]035441d92013-03-22 23:21:391570 // Sanity check damage after the first frame; this isnt the actual test yet.
[email protected]b4ead7b2014-04-07 18:12:181571 gfx::Rect root_damage_rect =
1572 root->render_surface()->damage_tracker()->current_damage_rect();
1573 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141574
[email protected]035441d92013-03-22 23:21:391575 // New damage, without having cleared the previous damage, should be unioned
1576 // to the previous one.
danakj19f0c9e2014-10-11 03:24:421577 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2));
jaydasika16515f52016-03-01 00:28:351578 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181579 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391580 root_damage_rect =
1581 root->render_surface()->damage_tracker()->current_damage_rect();
[email protected]b4ead7b2014-04-07 18:12:181582 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(),
1583 root_damage_rect.ToString());
[email protected]94f206c12012-08-25 00:09:141584
[email protected]035441d92013-03-22 23:21:391585 // If we notify the damage tracker that we drew the damaged area, then damage
1586 // should be emptied.
1587 root->render_surface()->damage_tracker()->DidDrawDamagedArea();
1588 root_damage_rect =
1589 root->render_surface()->damage_tracker()->current_damage_rect();
1590 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141591
[email protected]035441d92013-03-22 23:21:391592 // Damage should remain empty even after one frame, since there's yet no new
1593 // damage.
jaydasika16515f52016-03-01 00:28:351594 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181595 EmulateDrawingOneFrame(root);
[email protected]035441d92013-03-22 23:21:391596 root_damage_rect =
1597 root->render_surface()->damage_tracker()->current_damage_rect();
1598 EXPECT_TRUE(root_damage_rect.IsEmpty());
[email protected]94f206c12012-08-25 00:09:141599}
1600
[email protected]b4ead7b2014-04-07 18:12:181601TEST_F(DamageTrackerTest, HugeDamageRect) {
1602 // This number is so large that we start losting floating point accuracy.
1603 const int kBigNumber = 900000000;
1604 // Walk over a range to find floating point inaccuracy boundaries that move
1605 // toward the wrong direction.
1606 const int kRange = 5000;
1607
1608 for (int i = 0; i < kRange; ++i) {
jaydasikaef64f9e42016-03-12 01:08:181609 LayerImpl* root = CreateTestTreeWithOneSurface();
vollick83fbfc82016-03-22 18:33:271610 LayerImpl* child = root->children()[0];
[email protected]b4ead7b2014-04-07 18:12:181611
1612 gfx::Transform transform;
1613 transform.Translate(-kBigNumber, -kBigNumber);
1614
1615 // The child layer covers (0, 0, i, i) of the viewport,
1616 // but has a huge negative position.
1617 child->SetPosition(gfx::PointF());
1618 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i));
[email protected]b4ead7b2014-04-07 18:12:181619 child->SetTransform(transform);
jaydasika16515f52016-03-01 00:28:351620 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaef64f9e42016-03-12 01:08:181621 EmulateDrawingOneFrame(root);
[email protected]b4ead7b2014-04-07 18:12:181622
1623 // The expected damage should cover the visible part of the child layer,
1624 // which is (0, 0, i, i) in the viewport.
1625 gfx::Rect root_damage_rect =
1626 root->render_surface()->damage_tracker()->current_damage_rect();
1627 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1628 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1629 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1630 }
1631}
1632
[email protected]ba565742012-11-10 09:29:481633} // namespace
1634} // namespace cc