[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/damage_tracker.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 9 | #include "cc/base/math_util.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 10 | #include "cc/layers/layer_impl.h" |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 11 | #include "cc/output/filter_operation.h" |
| 12 | #include "cc/output/filter_operations.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 13 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 14 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 15 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 16 | #include "cc/test/test_shared_bitmap_manager.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 17 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 18 | #include "cc/trees/layer_tree_host_common.h" |
miletus | 5032027d | 2015-06-10 01:27:47 | [diff] [blame] | 19 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 20 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 21 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 22 | #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 23 | #include "ui/gfx/geometry/quad_f.h" |
| 24 | #include "ui/gfx/geometry/rect_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 25 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 26 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 27 | namespace { |
| 28 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 29 | void ExecuteCalculateDrawProperties(LayerImpl* root, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 30 | LayerImplList* render_surface_layer_list) { |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 31 | // 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] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 34 | ASSERT_FALSE(render_surface_layer_list->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 35 | |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 36 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 37 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 38 | root, root->bounds(), render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 39 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 40 | ASSERT_TRUE(root->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 41 | } |
| 42 | |
sunxd | b2e13c9 | 2016-04-23 01:00:05 | [diff] [blame] | 43 | void 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 50 | void EmulateDrawingOneFrame(LayerImpl* root) { |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 51 | // 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] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 54 | // 3. resetting all update_rects and property_changed flags for all layers |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 55 | // and surfaces. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 57 | LayerImplList render_surface_layer_list; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 58 | ExecuteCalculateDrawProperties(root, &render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 59 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 60 | // Iterate back-to-front, so that damage correctly propagates from descendant |
| 61 | // surfaces to ancestors. |
vmpstr | 4581606 | 2015-06-10 23:00:00 | [diff] [blame] | 62 | 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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 65 | RenderSurfaceImpl* target_surface = |
vmpstr | 4581606 | 2015-06-10 23:00:00 | [diff] [blame] | 66 | render_surface_layer_list[index]->render_surface(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 67 | target_surface->damage_tracker()->UpdateDamageTrackingState( |
weiliangc | 4012ef7 | 2016-04-11 22:04:06 | [diff] [blame] | 68 | target_surface->layer_list(), target_surface, |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 69 | target_surface->SurfacePropertyChangedOnlyFromDescendant(), |
| 70 | target_surface->content_rect(), |
vmpstr | 4581606 | 2015-06-10 23:00:00 | [diff] [blame] | 71 | render_surface_layer_list[index]->mask_layer(), |
| 72 | render_surface_layer_list[index]->filters()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 73 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 74 | |
jaydasika | d6f778b | 2016-05-19 22:51:26 | [diff] [blame] | 75 | root->layer_tree_impl()->ResetAllChangeTracking(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 78 | class DamageTrackerTest : public testing::Test { |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 79 | public: |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 80 | DamageTrackerTest() |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 81 | : host_impl_(&task_runner_provider_, |
| 82 | &shared_bitmap_manager_, |
| 83 | &task_graph_runner_) {} |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 84 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 85 | LayerImpl* CreateTestTreeWithOneSurface() { |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame^] | 86 | host_impl_.active_tree()->DetachLayers(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 87 | 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] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 91 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 92 | root->SetPosition(gfx::PointF()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 93 | root->SetBounds(gfx::Size(500, 500)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 94 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 95 | root->test_properties()->force_render_surface = true; |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 96 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 97 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 98 | child->SetBounds(gfx::Size(30, 30)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 99 | child->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 100 | root->AddChild(std::move(child)); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 101 | host_impl_.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 102 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 103 | return host_impl_.active_tree()->root_layer(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 104 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 105 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 106 | LayerImpl* CreateTestTreeWithTwoSurfaces() { |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 107 | // 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] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 110 | |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame^] | 111 | host_impl_.active_tree()->DetachLayers(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 112 | 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] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 122 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 123 | root->SetPosition(gfx::PointF()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 124 | root->SetBounds(gfx::Size(500, 500)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 125 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 126 | root->test_properties()->force_render_surface = true; |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 127 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 128 | child1->SetPosition(gfx::PointF(100.f, 100.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 129 | child1->SetBounds(gfx::Size(30, 30)); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 130 | // 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 |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 132 | // create its own RenderSurface. |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 133 | child1->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 134 | child1->test_properties()->force_render_surface = true; |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 135 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 136 | child2->SetPosition(gfx::PointF(11.f, 11.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 137 | child2->SetBounds(gfx::Size(18, 18)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 138 | child2->SetDrawsContent(true); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 139 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 140 | grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 141 | grand_child1->SetBounds(gfx::Size(6, 8)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 142 | grand_child1->SetDrawsContent(true); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 143 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 144 | grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 145 | grand_child2->SetBounds(gfx::Size(6, 8)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 146 | grand_child2->SetDrawsContent(true); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 147 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 148 | 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)); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 152 | host_impl_.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 153 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 154 | return host_impl_.active_tree()->root_layer(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 155 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 156 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 157 | LayerImpl* CreateAndSetUpTestTreeWithOneSurface() { |
| 158 | LayerImpl* root = CreateTestTreeWithOneSurface(); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 159 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 160 | // Setup includes going past the first frame which always damages |
| 161 | // everything, so that we can actually perform specific tests. |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 162 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 163 | EmulateDrawingOneFrame(root); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 164 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 165 | return root; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 166 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 167 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 168 | LayerImpl* CreateAndSetUpTestTreeWithTwoSurfaces() { |
| 169 | LayerImpl* root = CreateTestTreeWithTwoSurfaces(); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 170 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 171 | // Setup includes going past the first frame which always damages |
| 172 | // everything, so that we can actually perform specific tests. |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 173 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 174 | EmulateDrawingOneFrame(root); |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 175 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 176 | return root; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 177 | } |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 178 | |
[email protected] | b50e06d | 2013-03-26 09:16:55 | [diff] [blame] | 179 | protected: |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 180 | FakeImplTaskRunnerProvider task_runner_provider_; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 181 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 182 | TestTaskGraphRunner task_graph_runner_; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 183 | FakeLayerTreeHostImpl host_impl_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 184 | }; |
| 185 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 186 | TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { |
| 187 | // Sanity check that the simple test tree will actually produce the expected |
| 188 | // render surfaces and layer lists. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 189 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 190 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 191 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 192 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 195 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 196 | gfx::Rect root_damage_rect = |
| 197 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 198 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 199 | EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 202 | TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
| 203 | // Sanity check that the complex test tree will actually produce the expected |
| 204 | // render surfaces and layer lists. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 205 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 206 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 207 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 208 | LayerImpl* child1 = root->children()[0]; |
| 209 | LayerImpl* child2 = root->children()[1]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 210 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 214 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 215 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 219 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 220 | // The render surface for child1 only has a content_rect that encloses |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 221 | // grand_child1 and grand_child2, because child1 does not draw content. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 222 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 225 | } |
| 226 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 227 | TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 228 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 229 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 230 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 231 | // CASE 1: Setting the update rect should cause the corresponding damage to |
| 232 | // the surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 233 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 234 | child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 235 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 236 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 237 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 238 | // Damage position on the surface should be: position of update_rect (10, 11) |
| 239 | // relative to the child (100, 100). |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 240 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 244 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 245 | // CASE 2: The same update rect twice in a row still produces the same |
| 246 | // damage. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 247 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 248 | child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 249 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 250 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 251 | root_damage_rect = |
| 252 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 253 | EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), |
| 254 | root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 255 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 256 | // CASE 3: Setting a different update rect should cause damage on the new |
| 257 | // update region, but no additional exposed old region. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 258 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 259 | child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 260 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 261 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 262 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 263 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 267 | EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 270 | TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 271 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 272 | LayerImpl* child = root->children()[0]; |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 273 | |
| 274 | // CASE 1: Adding the layer damage rect should cause the corresponding damage |
| 275 | // to the surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 276 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 277 | child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 278 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 279 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 280 | |
| 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 289 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 290 | child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 291 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 292 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 293 | 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 299 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 300 | child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 301 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 302 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 303 | |
| 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 312 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 313 | child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); |
| 314 | child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 315 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 316 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 317 | |
| 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 | |
| 326 | TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 327 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 328 | LayerImpl* child = root->children()[0]; |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 329 | |
| 330 | // CASE 1: Adding the layer damage rect and update rect should cause the |
| 331 | // corresponding damage to the surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 332 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 333 | child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 334 | child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 335 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 336 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 337 | |
| 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 347 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 348 | child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 349 | child->SetUpdateRect(gfx::Rect(10, 11, 14, 15)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 350 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 351 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 352 | 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 358 | ClearDamageForAllSurfaces(root); |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 359 | child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 360 | child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 361 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 362 | EmulateDrawingOneFrame(root); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 363 | |
| 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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 371 | TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 372 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 373 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 374 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 375 | // CASE 1: The layer's property changed flag takes priority over update rect. |
| 376 | // |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 377 | child->test_properties()->force_render_surface = true; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 378 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 379 | EmulateDrawingOneFrame(root); |
| 380 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 381 | child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 382 | child->OnOpacityAnimated(0.5f); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 383 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 384 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 385 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 386 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 387 | // Damage should be the entire child layer in target_surface space. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 388 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 392 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 393 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 396 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 397 | // Cycle one frame of no change, just to sanity check that the next rect is |
| 398 | // not because of the old damage state. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 399 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 400 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 401 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 402 | root_damage_rect = |
| 403 | root->render_surface()->damage_tracker()->current_damage_rect(); |
| 404 | EXPECT_TRUE(root_damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 405 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 406 | // Then, test the actual layer movement. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 407 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 408 | child->SetPosition(gfx::PointF(200.f, 230.f)); |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 409 | child->NoteLayerPropertyChanged(); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 410 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 411 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 412 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 413 | // Expect damage to be the combination of the previous one and the new one. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 414 | expected_rect.Union(gfx::Rect(200, 230, 30, 30)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 415 | root_damage_rect = |
| 416 | root->render_surface()->damage_tracker()->current_damage_rect(); |
| 417 | EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 418 | } |
| 419 | |
jaydasika | cf22376 | 2016-05-16 23:02:09 | [diff] [blame] | 420 | TEST_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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 438 | TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { |
| 439 | // If a layer is transformed, the damage rect should still enclose the entire |
| 440 | // transformed layer. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 441 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 442 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 443 | LayerImpl* child = root->children()[0]; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 444 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 445 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 446 | gfx::Transform rotation; |
| 447 | rotation.Rotate(45.0); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 448 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 449 | ClearDamageForAllSurfaces(root); |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 450 | child->test_properties()->transform_origin = gfx::Point3F( |
| 451 | child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 452 | child->SetPosition(gfx::PointF(85.f, 85.f)); |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 453 | child->NoteLayerPropertyChanged(); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 454 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 455 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 456 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 457 | // Sanity check that the layer actually moved to (85, 85), damaging its old |
| 458 | // location and new location. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 459 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 462 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 463 | // 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 465 | ClearDamageForAllSurfaces(root); |
jaydasika | 503f617 | 2016-03-01 18:04:33 | [diff] [blame] | 466 | child->OnTransformAnimated(rotation); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 467 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 468 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 469 | // 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] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 473 | float expected_width = 30.f * sqrt(2.f); |
| 474 | float expected_position = 100.f - 0.5f * expected_width; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 475 | gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( |
| 476 | expected_position, expected_position, expected_width, expected_width)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 477 | root_damage_rect = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 478 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 479 | EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 480 | } |
| 481 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 482 | TEST_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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 494 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 495 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 496 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 497 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 498 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 503 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 504 | // Set up the child |
| 505 | child->SetPosition(gfx::PointF(0.f, 0.f)); |
| 506 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 507 | child->SetTransform(transform); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 508 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 509 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 510 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 511 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 517 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 518 | // Damage the child without moving it. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 519 | child->test_properties()->force_render_surface = true; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 520 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 521 | EmulateDrawingOneFrame(root); |
| 522 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 523 | child->OnOpacityAnimated(0.5f); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 524 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 525 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 526 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 529 | 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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 532 | EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 533 | } |
| 534 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 535 | TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 536 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 537 | LayerImpl* surface = root->children()[0]; |
| 538 | LayerImpl* child = surface->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 539 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 540 | FilterOperations filters; |
| 541 | filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 542 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 543 | filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 544 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 545 | // Setting the filter will damage the whole surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 546 | ClearDamageForAllSurfaces(root); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 547 | surface->SetFilters(filters); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 548 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 549 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 550 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 551 | // Setting the update rect should cause the corresponding damage to the |
| 552 | // surface, blurred based on the size of the blur filter. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 553 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 554 | child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 555 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 556 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 557 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 558 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 560 | 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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 563 | |
| 564 | expected_damage_rect.Inset(-outset_left, |
| 565 | -outset_top, |
| 566 | -outset_right, |
| 567 | -outset_bottom); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 568 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 569 | } |
| 570 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 571 | TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 572 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 573 | LayerImpl* child = root->children()[0]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 574 | gfx::Rect root_damage_rect, child_damage_rect; |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 575 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 576 | // Allow us to set damage on child too. |
| 577 | child->SetDrawsContent(true); |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 578 | |
[email protected] | 1dc7943e | 2013-09-26 04:41:48 | [diff] [blame] | 579 | FilterOperations filters; |
tomhudson | 992ec28b | 2016-04-27 16:45:39 | [diff] [blame] | 580 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 581 | SkBlurImageFilter::Make(2, 2, nullptr))); |
hendrikw | 920114d | 2015-08-24 23:38:35 | [diff] [blame] | 582 | int outset_top, outset_right, outset_bottom, outset_left; |
| 583 | filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 584 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 585 | // Setting the filter will damage the whole surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 586 | ClearDamageForAllSurfaces(root); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 587 | child->test_properties()->force_render_surface = true; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 588 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 589 | EmulateDrawingOneFrame(root); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 590 | child->OnFilterAnimated(filters); |
| 591 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 592 | 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(); |
weiliangc | d68cf71 | 2016-05-02 23:29:07 | [diff] [blame] | 596 | 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); |
hendrikw | 920114d | 2015-08-24 23:38:35 | [diff] [blame] | 600 | EXPECT_EQ( |
| 601 | gfx::Rect(-outset_left, -outset_top, 30 + (outset_left + outset_right), |
weiliangc | d68cf71 | 2016-05-02 23:29:07 | [diff] [blame] | 602 | 30 + (outset_top + outset_bottom)), |
| 603 | child_damage_rect); |
[email protected] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 604 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 605 | // CASE 1: Setting the update rect should damage the whole surface (for now) |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 606 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 607 | child->SetUpdateRect(gfx::Rect(1, 1)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 608 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 609 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 610 | |
| 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(); |
hendrikw | 920114d | 2015-08-24 23:38:35 | [diff] [blame] | 615 | |
| 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, |
weiliangc | d68cf71 | 2016-05-02 23:29:07 | [diff] [blame] | 619 | 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 | |
| 625 | TEST_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] | 4000abf | 2012-10-23 04:45:45 | [diff] [blame] | 683 | } |
| 684 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 685 | TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 686 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 687 | LayerImpl* child1 = root->children()[0]; |
| 688 | LayerImpl* child2 = root->children()[1]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 689 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 690 | // Allow us to set damage on child1 too. |
| 691 | child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 692 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 693 | FilterOperations filters; |
| 694 | filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 695 | int outset_top, outset_right, outset_bottom, outset_left; |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 696 | filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 697 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 698 | // Setting the filter will damage the whole surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 699 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 700 | child1->SetBackgroundFilters(filters); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 701 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 702 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 703 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 704 | // 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 |
jbroman | 8eb5fb7 | 2016-06-01 18:44:16 | [diff] [blame] | 706 | // blur filter. Note that child1's render surface has a size of |
| 707 | // 206x208 due to contributions from grand_child1 and grand_child2. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 708 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 709 | root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 710 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 711 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 713 | gfx::Rect root_damage_rect = |
| 714 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 715 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 718 | gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 719 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 720 | expected_damage_rect.Inset(-outset_left, |
| 721 | -outset_top, |
| 722 | -outset_right, |
| 723 | -outset_bottom); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 724 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 725 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 726 | // 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 730 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 731 | root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 732 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 733 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 734 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 735 | 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 740 | expected_damage_rect = gfx::Rect(297, 297, 30, 30); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 741 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 742 | expected_damage_rect.Inset(-outset_left, |
| 743 | -outset_top, |
| 744 | 0, |
| 745 | 0); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 746 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 747 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 748 | // CASE 3: Setting this update rect outside the blurred content_bounds of the |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 749 | // blurred child1 will not cause it to be expanded. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 750 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 751 | root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 752 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 753 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 754 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 755 | 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 759 | expected_damage_rect = gfx::Rect(30, 30, 2, 2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 760 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 761 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 762 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 763 | // 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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 765 | // cause it to be expanded. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 766 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 767 | root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 768 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 769 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 770 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 771 | root_damage_rect = |
| 772 | root->render_surface()->damage_tracker()->current_damage_rect(); |
jbroman | 8eb5fb7 | 2016-06-01 18:44:16 | [diff] [blame] | 773 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 779 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 780 | |
| 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 783 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 784 | child2->SetUpdateRect(gfx::Rect(1, 1)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 785 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 786 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 787 | |
| 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 792 | expected_damage_rect = gfx::Rect(11, 11, 1, 1); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 793 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 794 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 795 | |
| 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 799 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 800 | child1->SetUpdateRect(gfx::Rect(1, 1)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 801 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 802 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 803 | |
| 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] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 808 | |
jbroman | 8eb5fb7 | 2016-06-01 18:44:16 | [diff] [blame] | 809 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 814 | EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 815 | } |
| 816 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 817 | TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 818 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 819 | LayerImpl* child1 = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 820 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 821 | // CASE 1: Adding a new layer should cause the appropriate damage. |
| 822 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 823 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 824 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 825 | std::unique_ptr<LayerImpl> child2 = |
| 826 | LayerImpl::Create(host_impl_.active_tree(), 3); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 827 | child2->SetPosition(gfx::PointF(400.f, 380.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 828 | child2->SetBounds(gfx::Size(6, 8)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 829 | child2->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 830 | root->AddChild(std::move(child2)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 831 | } |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 832 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 833 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 834 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 835 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 838 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 839 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 842 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 843 | // CASE 2: If the layer is removed, its entire old layer becomes exposed, not |
| 844 | // just the last update rect. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 845 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 846 | // Advance one frame without damage so that we know the damage rect is not |
| 847 | // leftover from the previous case. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 848 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 849 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 850 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 851 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 852 | 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. |
jaydasika | 6b7c69d | 2016-04-01 00:54:43 | [diff] [blame] | 857 | root->RemoveChildForTesting(child1); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 858 | child1 = NULL; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 859 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 860 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 861 | |
| 862 | root_damage_rect = |
| 863 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 864 | EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), |
| 865 | root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 866 | } |
| 867 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 868 | TEST_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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 871 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 872 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 873 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 874 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 875 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 876 | std::unique_ptr<LayerImpl> child2 = |
| 877 | LayerImpl::Create(host_impl_.active_tree(), 3); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 878 | child2->SetPosition(gfx::PointF(400.f, 380.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 879 | child2->SetBounds(gfx::Size(6, 8)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 880 | child2->SetDrawsContent(true); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 881 | root->AddChild(std::move(child2)); |
jaydasika | d6f778b | 2016-05-19 22:51:26 | [diff] [blame] | 882 | host_impl_.active_tree()->ResetAllChangeTracking(); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 883 | LayerImpl* child2_ptr = host_impl_.active_tree()->LayerById(3); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 884 | // 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 887 | ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); |
| 888 | ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 889 | } |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 890 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 891 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 892 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 893 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 896 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 897 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 900 | } |
| 901 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 902 | TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 903 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 904 | LayerImpl* child1 = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 905 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 906 | // In this test we don't want the above tree manipulation to be considered |
| 907 | // part of the same frame. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 908 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 909 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 910 | std::unique_ptr<LayerImpl> child2 = |
| 911 | LayerImpl::Create(host_impl_.active_tree(), 3); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 912 | child2->SetPosition(gfx::PointF(400.f, 380.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 913 | child2->SetBounds(gfx::Size(6, 8)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 914 | child2->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 915 | root->AddChild(std::move(child2)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 916 | } |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 917 | LayerImpl* child2 = root->children()[1]; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 918 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 919 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 920 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 921 | // Damaging two layers simultaneously should cause combined damage. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 922 | // - 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); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 924 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 925 | child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 926 | child2->SetUpdateRect(gfx::Rect(3, 4)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 927 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 928 | EmulateDrawingOneFrame(root); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 929 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 933 | } |
| 934 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 935 | TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 936 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 937 | LayerImpl* child1 = root->children()[0]; |
| 938 | LayerImpl* child2 = root->children()[1]; |
| 939 | LayerImpl* grand_child1 = root->children()[0]->children()[0]; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 940 | child2->test_properties()->force_render_surface = true; |
| 941 | grand_child1->test_properties()->force_render_surface = true; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 942 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 943 | EmulateDrawingOneFrame(root); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 944 | gfx::Rect child_damage_rect; |
| 945 | gfx::Rect root_damage_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 946 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 947 | // CASE 1: Damage to a descendant surface should propagate properly to |
| 948 | // ancestor surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 949 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 950 | grand_child1->OnOpacityAnimated(0.5f); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 951 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 952 | 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 956 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 958 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 959 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 962 | // gfx::Rect(300, 300, 6, 8); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 963 | // - child2 damage in root surface space: |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 964 | // gfx::Rect(11, 11, 18, 18); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 965 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 966 | grand_child1->OnOpacityAnimated(0.7f); |
| 967 | child2->OnOpacityAnimated(0.7f); |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 968 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 969 | 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 973 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 976 | } |
| 977 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 978 | TEST_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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 982 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 983 | // This is a tricky case, since only the first grand_child changes, but the |
| 984 | // entire surface should be marked dirty. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 985 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 986 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 987 | LayerImpl* child1 = root->children()[0]; |
| 988 | LayerImpl* grand_child1 = root->children()[0]->children()[0]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 989 | gfx::Rect child_damage_rect; |
| 990 | gfx::Rect root_damage_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 991 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 992 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 993 | grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 994 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 995 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 996 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1000 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1001 | // The new surface bounds should be damaged entirely, even though only one of |
| 1002 | // the layers changed. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1003 | EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), |
| 1004 | child_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1005 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1006 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1009 | EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), |
| 1010 | root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1011 | } |
| 1012 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1013 | TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) { |
| 1014 | // An ancestor/owning layer changes that affects the position/transform of |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1015 | // the render surface. Note that in this case, the layer_property_changed flag |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1016 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1019 | |
[email protected] | 27d851ab | 2013-06-28 01:09:50 | [diff] [blame] | 1020 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1024 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1025 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1026 | LayerImpl* child1 = root->children()[0]; |
| 1027 | LayerImpl* grand_child1 = child1->children()[0]; |
| 1028 | LayerImpl* grand_child2 = child1->children()[1]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1029 | gfx::Rect child_damage_rect; |
| 1030 | gfx::Rect root_damage_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1031 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1032 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1033 | child1->SetPosition(gfx::PointF(50.f, 50.f)); |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 1034 | child1->NoteLayerPropertyChanged(); |
| 1035 | grand_child1->NoteLayerPropertyChanged(); |
| 1036 | grand_child2->NoteLayerPropertyChanged(); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1037 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1038 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1039 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1043 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1044 | // The new surface bounds should be damaged entirely. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1045 | EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1046 | child_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1047 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1048 | // The entire child1 surface and the old exposed child1 surface should damage |
| 1049 | // the root surface. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1050 | // - 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1054 | } |
| 1055 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1056 | TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1057 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1058 | LayerImpl* child1 = root->children()[0]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1059 | gfx::Rect child_damage_rect; |
| 1060 | gfx::Rect root_damage_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1061 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1062 | // CASE 1: If a descendant surface disappears, its entire old area becomes |
| 1063 | // exposed. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1064 | ClearDamageForAllSurfaces(root); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1065 | child1->test_properties()->force_render_surface = false; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1066 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1067 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1068 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1069 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1072 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1073 | root_damage_rect = |
| 1074 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1075 | EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1076 | root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1077 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1078 | // CASE 2: If a descendant surface appears, its entire old area becomes |
| 1079 | // exposed. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1080 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1081 | // Cycle one frame of no change, just to sanity check that the next rect is |
| 1082 | // not because of the old damage state. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1083 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1084 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1085 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1086 | root_damage_rect = |
| 1087 | root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1088 | EXPECT_TRUE(root_damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1089 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1090 | // Then change the tree so that the render surface is added back. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1091 | ClearDamageForAllSurfaces(root); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1092 | child1->test_properties()->force_render_surface = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 1093 | |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1094 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1095 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1096 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1097 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1101 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1102 | 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1106 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1110 | } |
| 1111 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1112 | TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1113 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1114 | LayerImpl* child1 = root->children()[0]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1115 | gfx::Rect child_damage_rect; |
| 1116 | gfx::Rect root_damage_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1117 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1118 | // CASE 1: If nothing changes, the damage rect should be empty. |
| 1119 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1120 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1121 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1122 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1123 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1129 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1130 | // CASE 2: If nothing changes twice in a row, the damage rect should still be |
| 1131 | // empty. |
| 1132 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1133 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1134 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1135 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1136 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1142 | } |
| 1143 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1144 | TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1145 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1146 | LayerImpl* child1 = root->children()[0]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1147 | gfx::Rect child_damage_rect; |
| 1148 | gfx::Rect root_damage_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1149 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1150 | // 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. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1152 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 1153 | child1->SetUpdateRect(gfx::Rect(1, 2)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1154 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1155 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1156 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1164 | TEST_F(DamageTrackerTest, VerifyDamageForReplica) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1165 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1166 | LayerImpl* child1 = root->children()[0]; |
| 1167 | LayerImpl* grand_child1 = child1->children()[0]; |
| 1168 | LayerImpl* grand_child2 = child1->children()[1]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1169 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1170 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1172 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1173 | // 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] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1175 | // without changing content_bounds of the surface. |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1176 | grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); |
| 1177 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1178 | std::unique_ptr<LayerImpl> grand_child3 = |
| 1179 | LayerImpl::Create(host_impl_.active_tree(), 6); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1180 | grand_child3->SetPosition(gfx::PointF(240.f, 240.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1181 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1182 | grand_child3->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1183 | child1->AddChild(std::move(grand_child3)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1184 | } |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1185 | child1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1186 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1187 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1188 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1189 | // CASE 1: adding a reflection about the left edge of grand_child1. |
| 1190 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1191 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1192 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1193 | std::unique_ptr<LayerImpl> grand_child1_replica = |
| 1194 | LayerImpl::Create(host_impl_.active_tree(), 7); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1195 | grand_child1_replica->SetPosition(gfx::PointF()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1196 | gfx::Transform reflection; |
| 1197 | reflection.Scale3d(-1.0, 1.0, 1.0); |
| 1198 | grand_child1_replica->SetTransform(reflection); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1199 | grand_child1->SetReplicaLayer(std::move(grand_child1_replica)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1200 | grand_child1->test_properties()->force_render_surface = true; |
| 1201 | grand_child1->NoteLayerPropertyChanged(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1202 | } |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1203 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1204 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1205 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1206 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1212 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1213 | // 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1215 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1219 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1220 | // CASE 2: moving the descendant surface should cause both the original and |
| 1221 | // reflected areas to be damaged on the target. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1222 | ClearDamageForAllSurfaces(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1223 | gfx::Rect old_content_rect = child1->render_surface()->content_rect(); |
| 1224 | grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 1225 | grand_child1->NoteLayerPropertyChanged(); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1226 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1227 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1228 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1232 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1233 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1240 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1241 | // The child surface damage should include normal and replica surfaces for |
| 1242 | // both old and new locations. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1243 | // - 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1250 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1251 | // CASE 3: removing the reflection should cause the entire region including |
| 1252 | // reflection to damage the target surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1253 | ClearDamageForAllSurfaces(root); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 1254 | grand_child1->SetReplicaLayer(nullptr); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1255 | grand_child1->test_properties()->force_render_surface = false; |
| 1256 | grand_child1->NoteLayerPropertyChanged(); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1257 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1258 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1259 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1263 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1264 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1269 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1270 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1273 | } |
| 1274 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1275 | TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1276 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1277 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1278 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1279 | // In the current implementation of the damage tracker, changes to mask |
| 1280 | // layers should damage the entire corresponding surface. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1281 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1282 | ClearDamageForAllSurfaces(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1283 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1284 | // Set up the mask layer. |
| 1285 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1286 | std::unique_ptr<LayerImpl> mask_layer = |
| 1287 | LayerImpl::Create(host_impl_.active_tree(), 3); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1288 | mask_layer->SetPosition(child->position()); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1289 | mask_layer->SetBounds(child->bounds()); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1290 | child->SetMaskLayer(std::move(mask_layer)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1291 | child->test_properties()->force_render_surface = true; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1292 | } |
| 1293 | LayerImpl* mask_layer = child->mask_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1294 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1295 | // Add opacity and a grand_child so that the render surface persists even |
| 1296 | // after we remove the mask. |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1297 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1298 | std::unique_ptr<LayerImpl> grand_child = |
| 1299 | LayerImpl::Create(host_impl_.active_tree(), 4); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1300 | grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1301 | grand_child->SetBounds(gfx::Size(2, 2)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1302 | grand_child->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1303 | child->AddChild(std::move(grand_child)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1304 | } |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1305 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1306 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1307 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1308 | // CASE 1: the update_rect on a mask layer should damage the entire target |
| 1309 | // surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1310 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 1311 | mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1312 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1313 | EmulateDrawingOneFrame(root); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1314 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1317 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1318 | // CASE 2: a property change on the mask layer should damage the entire |
| 1319 | // target surface. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1320 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1321 | // Advance one frame without damage so that we know the damage rect is not |
| 1322 | // leftover from the previous case. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1323 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1324 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1325 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1326 | child_damage_rect = |
| 1327 | child->render_surface()->damage_tracker()->current_damage_rect(); |
| 1328 | EXPECT_TRUE(child_damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1329 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1330 | // Then test the property change. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1331 | ClearDamageForAllSurfaces(root); |
jaydasika | 865fd48 | 2016-02-24 09:26:15 | [diff] [blame] | 1332 | mask_layer->NoteLayerPropertyChanged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1333 | |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1334 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1335 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1336 | child_damage_rect = |
| 1337 | child->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1338 | EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1339 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1340 | // CASE 3: removing the mask also damages the entire target surface. |
| 1341 | // |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1342 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1343 | // Advance one frame without damage so that we know the damage rect is not |
| 1344 | // leftover from the previous case. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1345 | ClearDamageForAllSurfaces(root); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1346 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1347 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1348 | child_damage_rect = |
| 1349 | child->render_surface()->damage_tracker()->current_damage_rect(); |
| 1350 | EXPECT_TRUE(child_damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1351 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1352 | // Then test mask removal. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1353 | ClearDamageForAllSurfaces(root); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 1354 | child->SetMaskLayer(nullptr); |
jaydasika | 03a99c4 | 2016-02-11 21:07:08 | [diff] [blame] | 1355 | child->NoteLayerPropertyChanged(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1356 | ASSERT_TRUE(child->LayerPropertyChanged()); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1357 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1358 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1359 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1360 | // Sanity check that a render surface still exists. |
| 1361 | ASSERT_TRUE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1362 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1363 | child_damage_rect = |
| 1364 | child->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1365 | EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1366 | } |
| 1367 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1368 | TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1369 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1370 | LayerImpl* child1 = root->children()[0]; |
| 1371 | LayerImpl* grand_child1 = child1->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1372 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1373 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1375 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1376 | ClearDamageForAllSurfaces(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1377 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1378 | // Create a reflection about the left edge of grand_child1. |
| 1379 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1380 | std::unique_ptr<LayerImpl> grand_child1_replica = |
| 1381 | LayerImpl::Create(host_impl_.active_tree(), 6); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1382 | grand_child1_replica->SetPosition(gfx::PointF()); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1383 | gfx::Transform reflection; |
| 1384 | reflection.Scale3d(-1.0, 1.0, 1.0); |
| 1385 | grand_child1_replica->SetTransform(reflection); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1386 | grand_child1->SetReplicaLayer(std::move(grand_child1_replica)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1387 | grand_child1->test_properties()->force_render_surface = true; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1388 | } |
| 1389 | LayerImpl* grand_child1_replica = grand_child1->replica_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1390 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1391 | // Set up the mask layer on the replica layer |
| 1392 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1393 | std::unique_ptr<LayerImpl> replica_mask_layer = |
| 1394 | LayerImpl::Create(host_impl_.active_tree(), 7); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1395 | replica_mask_layer->SetPosition(gfx::PointF()); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1396 | replica_mask_layer->SetBounds(grand_child1->bounds()); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1397 | grand_child1_replica->SetMaskLayer(std::move(replica_mask_layer)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1398 | } |
| 1399 | LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1400 | |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1401 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1402 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1403 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1404 | // Sanity check that the appropriate render surfaces were created |
| 1405 | ASSERT_TRUE(grand_child1->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1406 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1407 | // CASE 1: a property change on the mask should damage only the reflected |
| 1408 | // region on the target surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1409 | ClearDamageForAllSurfaces(root); |
jaydasika | 865fd48 | 2016-02-24 09:26:15 | [diff] [blame] | 1410 | replica_mask_layer->NoteLayerPropertyChanged(); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1411 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1412 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1413 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1414 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1418 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1419 | EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1420 | EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1421 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1422 | // CASE 2: removing the replica mask damages only the reflected region on the |
| 1423 | // target surface. |
| 1424 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1425 | ClearDamageForAllSurfaces(root); |
danakj | 968153f3 | 2014-10-15 22:52:16 | [diff] [blame] | 1426 | grand_child1_replica->SetMaskLayer(nullptr); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1427 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1428 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1429 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1430 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1435 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1436 | EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1437 | EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1438 | } |
| 1439 | |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1440 | TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1441 | LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1442 | LayerImpl* child1 = root->children()[0]; |
| 1443 | LayerImpl* grand_child1 = child1->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1444 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1445 | // Verify that the correct replica_origin_transform is used for the |
| 1446 | // replica_mask. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1447 | ClearDamageForAllSurfaces(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1448 | |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1449 | // This is not actually the transform origin point being tested, but by |
| 1450 | // convention its |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1451 | // expected to be the same as the replica's anchor point. |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 1452 | grand_child1->test_properties()->transform_origin = |
| 1453 | gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1454 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1455 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1456 | std::unique_ptr<LayerImpl> grand_child1_replica = |
| 1457 | LayerImpl::Create(host_impl_.active_tree(), 6); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1458 | grand_child1_replica->SetPosition(gfx::PointF()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1459 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1460 | // This is the anchor being tested. |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 1461 | grand_child1_replica->test_properties()->transform_origin = |
| 1462 | gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1463 | gfx::Transform reflection; |
| 1464 | reflection.Scale3d(-1.0, 1.0, 1.0); |
| 1465 | grand_child1_replica->SetTransform(reflection); |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 1466 | // We need to set parent on replica layer for property tree building. |
| 1467 | grand_child1_replica->SetParent(grand_child1); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1468 | grand_child1->SetReplicaLayer(std::move(grand_child1_replica)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1469 | grand_child1->test_properties()->force_render_surface = true; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1470 | } |
| 1471 | LayerImpl* grand_child1_replica = grand_child1->replica_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1472 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1473 | // Set up the mask layer on the replica layer |
| 1474 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1475 | std::unique_ptr<LayerImpl> replica_mask_layer = |
| 1476 | LayerImpl::Create(host_impl_.active_tree(), 7); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1477 | replica_mask_layer->SetPosition(gfx::PointF()); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1478 | // Note: this is not the transform origin being tested. |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1479 | replica_mask_layer->SetBounds(grand_child1->bounds()); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 1480 | grand_child1_replica->SetMaskLayer(std::move(replica_mask_layer)); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1481 | } |
| 1482 | LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1483 | |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1484 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1485 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1486 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1487 | // Sanity check that the appropriate render surfaces were created |
| 1488 | ASSERT_TRUE(grand_child1->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1489 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1490 | // A property change on the replica_mask should damage the reflected region on |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1491 | // the target surface. |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1492 | ClearDamageForAllSurfaces(root); |
jaydasika | 865fd48 | 2016-02-24 09:26:15 | [diff] [blame] | 1493 | replica_mask_layer->NoteLayerPropertyChanged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1494 | |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1495 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1496 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1497 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1498 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1501 | } |
| 1502 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1503 | TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1504 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1505 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1506 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1507 | // Case 1: This test ensures that when the tracker is given damage, that |
| 1508 | // it is included with any other partial damage. |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1509 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1510 | ClearDamageForAllSurfaces(root); |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 1511 | child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1512 | root->render_surface()->damage_tracker()->AddDamageNextUpdate( |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1513 | gfx::Rect(15, 16, 32, 33)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1514 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1515 | EmulateDrawingOneFrame(root); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1516 | gfx::Rect root_damage_rect = |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1517 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1518 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1521 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1522 | // Case 2: An additional sanity check that adding damage works even when |
| 1523 | // nothing on the layer tree changed. |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1524 | // |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1525 | ClearDamageForAllSurfaces(root); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1526 | root->render_surface()->damage_tracker()->AddDamageNextUpdate( |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1527 | gfx::Rect(30, 31, 14, 15)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1528 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1529 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1530 | root_damage_rect = |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1531 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1532 | EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1533 | } |
| 1534 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1535 | TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) { |
| 1536 | // Though it should never happen, its a good idea to verify that the damage |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1537 | // tracker does not crash when it receives an empty layer_list. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1538 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1539 | std::unique_ptr<LayerImpl> root = |
| 1540 | LayerImpl::Create(host_impl_.active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1541 | root->test_properties()->force_render_surface = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 1542 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1546 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 1547 | DCHECK_EQ(root_ptr->render_surface(), root_ptr->render_target()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 1548 | RenderSurfaceImpl* target_surface = root_ptr->render_surface(); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1549 | |
| 1550 | LayerImplList empty_list; |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1551 | target_surface->damage_tracker()->UpdateDamageTrackingState( |
weiliangc | 4012ef7 | 2016-04-11 22:04:06 | [diff] [blame] | 1552 | empty_list, target_surface, false, gfx::Rect(), NULL, FilterOperations()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1553 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1554 | gfx::Rect damage_rect = |
| 1555 | target_surface->damage_tracker()->current_damage_rect(); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1556 | EXPECT_TRUE(damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1557 | } |
| 1558 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1559 | TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
| 1560 | // If damage is not cleared, it should accumulate. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1561 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1562 | LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1563 | LayerImpl* child = root->children()[0]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1564 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1565 | ClearDamageForAllSurfaces(root); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1566 | child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1567 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1568 | EmulateDrawingOneFrame(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1569 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1570 | // Sanity check damage after the first frame; this isnt the actual test yet. |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1571 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1574 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1575 | // New damage, without having cleared the previous damage, should be unioned |
| 1576 | // to the previous one. |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 1577 | child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1578 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1579 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1580 | root_damage_rect = |
| 1581 | root->render_surface()->damage_tracker()->current_damage_rect(); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1582 | EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), |
| 1583 | root_damage_rect.ToString()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1584 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1585 | // 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1591 | |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1592 | // Damage should remain empty even after one frame, since there's yet no new |
| 1593 | // damage. |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1594 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1595 | EmulateDrawingOneFrame(root); |
[email protected] | 035441d9 | 2013-03-22 23:21:39 | [diff] [blame] | 1596 | root_damage_rect = |
| 1597 | root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1598 | EXPECT_TRUE(root_damage_rect.IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1599 | } |
| 1600 | |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1601 | TEST_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) { |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1609 | LayerImpl* root = CreateTestTreeWithOneSurface(); |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 1610 | LayerImpl* child = root->children()[0]; |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1611 | |
| 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] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1619 | child->SetTransform(transform); |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 1620 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 1621 | EmulateDrawingOneFrame(root); |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 1622 | |
| 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] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 1633 | } // namespace |
| 1634 | } // namespace cc |