Disable flaky UnloadTest.CrossSiteInfiniteBeforeUnloadSync on Mac.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_occlusion.cc
blob9974ae4066b440c171f747d1df22d005a3cb67be
1 // Copyright 2012 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.
5 #include "cc/trees/layer_tree_host.h"
7 #include "cc/layers/layer.h"
8 #include "cc/layers/picture_layer.h"
9 #include "cc/test/fake_content_layer_client.h"
10 #include "cc/test/layer_tree_test.h"
11 #include "cc/trees/layer_tree_impl.h"
13 namespace cc {
14 namespace {
16 #define EXPECT_OCCLUSION_EQ(expected, actual) \
17 EXPECT_TRUE(expected.IsEqual(actual)) \
18 << " Expected: " << expected.ToString() << std::endl \
19 << " Actual: " << actual.ToString();
21 class LayerTreeHostOcclusionTest : public LayerTreeTest {
22 protected:
23 void InitializeSettings(LayerTreeSettings* settings) override {
24 settings->minimum_occlusion_tracking_size = gfx::Size();
28 // Verify occlusion is set on the layer draw properties.
29 class LayerTreeHostOcclusionTestDrawPropertiesOnLayer
30 : public LayerTreeHostOcclusionTest {
31 public:
32 void SetupTree() override {
33 scoped_refptr<Layer> root = Layer::Create();
34 root->SetBounds(gfx::Size(100, 100));
35 root->SetIsDrawable(true);
37 scoped_refptr<Layer> child = Layer::Create();
38 child->SetBounds(gfx::Size(50, 60));
39 child->SetPosition(gfx::PointF(10.f, 5.5f));
40 child->SetContentsOpaque(true);
41 child->SetIsDrawable(true);
42 root->AddChild(child);
44 layer_tree_host()->SetRootLayer(root);
45 LayerTreeTest::SetupTree();
48 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
50 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
51 LayerImpl* root = impl->active_tree()->root_layer();
52 LayerImpl* child = root->children()[0];
54 // Verify the draw properties are valid.
55 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember());
56 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember());
58 EXPECT_OCCLUSION_EQ(
59 Occlusion(child->draw_transform(), SimpleEnclosedRegion(),
60 SimpleEnclosedRegion()),
61 child->draw_properties().occlusion_in_content_space);
62 EXPECT_OCCLUSION_EQ(
63 Occlusion(root->draw_transform(), SimpleEnclosedRegion(),
64 SimpleEnclosedRegion(gfx::Rect(10, 6, 50, 59))),
65 root->draw_properties().occlusion_in_content_space);
66 EndTest();
69 void AfterTest() override {}
72 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnLayer);
74 // Verify occlusion is set on the render surfaces.
75 class LayerTreeHostOcclusionTestDrawPropertiesOnSurface
76 : public LayerTreeHostOcclusionTest {
77 public:
78 void SetupTree() override {
79 scoped_refptr<Layer> root = Layer::Create();
80 root->SetBounds(gfx::Size(100, 100));
81 root->SetIsDrawable(true);
83 scoped_refptr<Layer> child = Layer::Create();
84 child->SetBounds(gfx::Size(1, 1));
85 child->SetPosition(gfx::PointF(10.f, 5.5f));
86 child->SetIsDrawable(true);
87 child->SetForceRenderSurface(true);
88 root->AddChild(child);
90 scoped_refptr<Layer> child2 = Layer::Create();
91 child2->SetBounds(gfx::Size(10, 12));
92 child2->SetPosition(gfx::PointF(13.f, 8.5f));
93 child2->SetContentsOpaque(true);
94 child2->SetIsDrawable(true);
95 root->AddChild(child2);
97 layer_tree_host()->SetRootLayer(root);
98 LayerTreeTest::SetupTree();
101 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
103 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
104 LayerImpl* root = impl->active_tree()->root_layer();
105 LayerImpl* child = root->children()[0];
106 RenderSurfaceImpl* surface = child->render_surface();
108 // Verify the draw properties are valid.
109 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember());
110 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember());
111 EXPECT_EQ(child, child->render_target());
113 EXPECT_OCCLUSION_EQ(
114 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(),
115 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))),
116 surface->occlusion_in_content_space());
117 EndTest();
120 void AfterTest() override {}
123 SINGLE_AND_MULTI_THREAD_TEST_F(
124 LayerTreeHostOcclusionTestDrawPropertiesOnSurface);
126 // Verify occlusion is set on mask layers.
127 class LayerTreeHostOcclusionTestDrawPropertiesOnMask
128 : public LayerTreeHostOcclusionTest {
129 public:
130 void SetupTree() override {
131 scoped_refptr<Layer> root = Layer::Create();
132 root->SetBounds(gfx::Size(100, 100));
133 root->SetIsDrawable(true);
135 scoped_refptr<Layer> child = Layer::Create();
136 child->SetBounds(gfx::Size(30, 40));
137 child->SetPosition(gfx::PointF(10.f, 5.5f));
138 child->SetIsDrawable(true);
139 root->AddChild(child);
141 scoped_refptr<Layer> make_surface_bigger = Layer::Create();
142 make_surface_bigger->SetBounds(gfx::Size(100, 100));
143 make_surface_bigger->SetPosition(gfx::PointF(-10.f, -15.f));
144 make_surface_bigger->SetIsDrawable(true);
145 child->AddChild(make_surface_bigger);
147 scoped_refptr<Layer> mask = PictureLayer::Create(&client_);
148 mask->SetBounds(gfx::Size(30, 40));
149 mask->SetIsDrawable(true);
150 child->SetMaskLayer(mask.get());
152 scoped_refptr<Layer> child2 = Layer::Create();
153 child2->SetBounds(gfx::Size(10, 12));
154 child2->SetPosition(gfx::PointF(13.f, 8.5f));
155 child2->SetContentsOpaque(true);
156 child2->SetIsDrawable(true);
157 root->AddChild(child2);
159 layer_tree_host()->SetRootLayer(root);
160 LayerTreeTest::SetupTree();
163 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
165 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
166 LayerImpl* root = impl->active_tree()->root_layer();
167 LayerImpl* child = root->children()[0];
168 RenderSurfaceImpl* surface = child->render_surface();
169 LayerImpl* mask = child->mask_layer();
171 // Verify the draw properties are valid.
172 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember());
173 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember());
174 EXPECT_EQ(child, child->render_target());
176 gfx::Transform transform = surface->draw_transform();
177 transform.PreconcatTransform(child->draw_transform());
179 EXPECT_OCCLUSION_EQ(
180 Occlusion(transform, SimpleEnclosedRegion(),
181 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))),
182 mask->draw_properties().occlusion_in_content_space);
183 EndTest();
186 void AfterTest() override {}
188 FakeContentLayerClient client_;
191 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnMask);
193 // Verify occlusion is set to empty inside the subtree of a replica. This is
194 // done because the tile system does not know about replicas, and so would not
195 // know that something is unoccluded on the replica even though it's occluded on
196 // the original.
197 class LayerTreeHostOcclusionTestDrawPropertiesInsideReplica
198 : public LayerTreeHostOcclusionTest {
199 public:
200 void SetupTree() override {
201 scoped_refptr<Layer> root = Layer::Create();
202 root->SetBounds(gfx::Size(100, 100));
203 root->SetIsDrawable(true);
205 scoped_refptr<Layer> child = Layer::Create();
206 child->SetBounds(gfx::Size(1, 1));
207 child->SetPosition(gfx::PointF(10.f, 5.5f));
208 child->SetIsDrawable(true);
209 child->SetForceRenderSurface(true);
210 root->AddChild(child);
212 scoped_refptr<Layer> replica = Layer::Create();
213 gfx::Transform translate;
214 translate.Translate(20.f, 4.f);
215 replica->SetTransform(translate);
216 child->SetReplicaLayer(replica.get());
218 scoped_refptr<Layer> mask = PictureLayer::Create(&client_);
219 mask->SetBounds(gfx::Size(30, 40));
220 mask->SetIsDrawable(true);
221 child->SetMaskLayer(mask.get());
223 scoped_refptr<Layer> child2 = Layer::Create();
224 child2->SetBounds(gfx::Size(10, 12));
225 child2->SetPosition(gfx::PointF(13.f, 8.5f));
226 child2->SetContentsOpaque(true);
227 child2->SetIsDrawable(true);
228 root->AddChild(child2);
230 layer_tree_host()->SetRootLayer(root);
231 LayerTreeTest::SetupTree();
234 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
236 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
237 LayerImpl* root = impl->active_tree()->root_layer();
238 LayerImpl* child = root->children()[0];
239 RenderSurfaceImpl* surface = child->render_surface();
240 LayerImpl* mask = child->mask_layer();
242 // Verify the draw properties are valid.
243 EXPECT_TRUE(root->IsDrawnRenderSurfaceLayerListMember());
244 EXPECT_TRUE(child->IsDrawnRenderSurfaceLayerListMember());
245 EXPECT_EQ(child, child->render_target());
247 // No occlusion from on child, which is part of the replica.
248 EXPECT_OCCLUSION_EQ(Occlusion(),
249 child->draw_properties().occlusion_in_content_space);
250 // Occlusion on the surface is okay.
251 EXPECT_OCCLUSION_EQ(
252 Occlusion(surface->draw_transform(), SimpleEnclosedRegion(),
253 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))),
254 surface->occlusion_in_content_space());
255 // No occlusion on the replica'd mask.
256 EXPECT_OCCLUSION_EQ(Occlusion(),
257 mask->draw_properties().occlusion_in_content_space);
258 EndTest();
261 void AfterTest() override {}
263 FakeContentLayerClient client_;
266 SINGLE_AND_MULTI_THREAD_TEST_F(
267 LayerTreeHostOcclusionTestDrawPropertiesInsideReplica);
269 } // namespace
270 } // namespace cc