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"
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
{
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
{
32 void SetupTree() override
{
33 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
34 root
->SetBounds(gfx::Size(100, 100));
35 root
->SetIsDrawable(true);
37 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
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());
59 Occlusion(child
->draw_transform(), SimpleEnclosedRegion(),
60 SimpleEnclosedRegion()),
61 child
->draw_properties().occlusion_in_content_space
);
63 Occlusion(root
->draw_transform(), SimpleEnclosedRegion(),
64 SimpleEnclosedRegion(gfx::Rect(10, 6, 50, 59))),
65 root
->draw_properties().occlusion_in_content_space
);
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
{
78 void SetupTree() override
{
79 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
80 root
->SetBounds(gfx::Size(100, 100));
81 root
->SetIsDrawable(true);
83 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
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(layer_settings());
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());
114 Occlusion(surface
->draw_transform(), SimpleEnclosedRegion(),
115 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))),
116 surface
->occlusion_in_content_space());
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
{
130 void SetupTree() override
{
131 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
132 root
->SetBounds(gfx::Size(100, 100));
133 root
->SetIsDrawable(true);
135 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
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(layer_settings());
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
=
148 PictureLayer::Create(layer_settings(), &client_
);
149 mask
->SetBounds(gfx::Size(30, 40));
150 mask
->SetIsDrawable(true);
151 child
->SetMaskLayer(mask
.get());
153 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
154 child2
->SetBounds(gfx::Size(10, 12));
155 child2
->SetPosition(gfx::PointF(13.f
, 8.5f
));
156 child2
->SetContentsOpaque(true);
157 child2
->SetIsDrawable(true);
158 root
->AddChild(child2
);
160 layer_tree_host()->SetRootLayer(root
);
161 LayerTreeTest::SetupTree();
164 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
166 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
167 LayerImpl
* root
= impl
->active_tree()->root_layer();
168 LayerImpl
* child
= root
->children()[0];
169 RenderSurfaceImpl
* surface
= child
->render_surface();
170 LayerImpl
* mask
= child
->mask_layer();
172 // Verify the draw properties are valid.
173 EXPECT_TRUE(root
->IsDrawnRenderSurfaceLayerListMember());
174 EXPECT_TRUE(child
->IsDrawnRenderSurfaceLayerListMember());
175 EXPECT_EQ(child
, child
->render_target());
177 gfx::Transform transform
= surface
->draw_transform();
178 transform
.PreconcatTransform(child
->draw_transform());
181 Occlusion(transform
, SimpleEnclosedRegion(),
182 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))),
183 mask
->draw_properties().occlusion_in_content_space
);
187 void AfterTest() override
{}
189 FakeContentLayerClient client_
;
192 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestDrawPropertiesOnMask
);
194 // Verify occlusion is set to empty inside the subtree of a replica. This is
195 // done because the tile system does not know about replicas, and so would not
196 // know that something is unoccluded on the replica even though it's occluded on
198 class LayerTreeHostOcclusionTestDrawPropertiesInsideReplica
199 : public LayerTreeHostOcclusionTest
{
201 void SetupTree() override
{
202 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
203 root
->SetBounds(gfx::Size(100, 100));
204 root
->SetIsDrawable(true);
206 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
207 child
->SetBounds(gfx::Size(1, 1));
208 child
->SetPosition(gfx::PointF(10.f
, 5.5f
));
209 child
->SetIsDrawable(true);
210 child
->SetForceRenderSurface(true);
211 root
->AddChild(child
);
213 scoped_refptr
<Layer
> replica
= Layer::Create(layer_settings());
214 gfx::Transform translate
;
215 translate
.Translate(20.f
, 4.f
);
216 replica
->SetTransform(translate
);
217 child
->SetReplicaLayer(replica
.get());
219 scoped_refptr
<Layer
> mask
=
220 PictureLayer::Create(layer_settings(), &client_
);
221 mask
->SetBounds(gfx::Size(30, 40));
222 mask
->SetIsDrawable(true);
223 child
->SetMaskLayer(mask
.get());
225 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
226 child2
->SetBounds(gfx::Size(10, 12));
227 child2
->SetPosition(gfx::PointF(13.f
, 8.5f
));
228 child2
->SetContentsOpaque(true);
229 child2
->SetIsDrawable(true);
230 root
->AddChild(child2
);
232 layer_tree_host()->SetRootLayer(root
);
233 LayerTreeTest::SetupTree();
236 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
238 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
239 LayerImpl
* root
= impl
->active_tree()->root_layer();
240 LayerImpl
* child
= root
->children()[0];
241 RenderSurfaceImpl
* surface
= child
->render_surface();
242 LayerImpl
* mask
= child
->mask_layer();
244 // Verify the draw properties are valid.
245 EXPECT_TRUE(root
->IsDrawnRenderSurfaceLayerListMember());
246 EXPECT_TRUE(child
->IsDrawnRenderSurfaceLayerListMember());
247 EXPECT_EQ(child
, child
->render_target());
249 // No occlusion from on child, which is part of the replica.
250 EXPECT_OCCLUSION_EQ(Occlusion(),
251 child
->draw_properties().occlusion_in_content_space
);
252 // Occlusion on the surface is okay.
254 Occlusion(surface
->draw_transform(), SimpleEnclosedRegion(),
255 SimpleEnclosedRegion(gfx::Rect(13, 9, 10, 11))),
256 surface
->occlusion_in_content_space());
257 // No occlusion on the replica'd mask.
258 EXPECT_OCCLUSION_EQ(Occlusion(),
259 mask
->draw_properties().occlusion_in_content_space
);
263 void AfterTest() override
{}
265 FakeContentLayerClient client_
;
268 SINGLE_AND_MULTI_THREAD_TEST_F(
269 LayerTreeHostOcclusionTestDrawPropertiesInsideReplica
);