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/quads/render_pass.h"
7 #include "cc/base/math_util.h"
8 #include "cc/base/scoped_ptr_vector.h"
9 #include "cc/output/copy_output_request.h"
10 #include "cc/quads/checkerboard_draw_quad.h"
11 #include "cc/quads/render_pass_draw_quad.h"
12 #include "cc/test/geometry_test_utils.h"
13 #include "cc/test/render_pass_test_common.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
16 #include "ui/gfx/transform.h"
18 using cc::TestRenderPass
;
23 struct RenderPassSize
{
24 // If you add a new field to this class, make sure to add it to the
28 SharedQuadStateList shared_quad_state_list
;
29 gfx::Transform transform_to_root_target
;
30 gfx::Rect output_rect
;
31 gfx::Rect damage_rect
;
32 bool has_transparent_background
;
33 ScopedPtrVector
<CopyOutputRequest
> copy_callbacks
;
36 static void CompareRenderPassLists(const RenderPassList
& expected_list
,
37 const RenderPassList
& actual_list
) {
38 EXPECT_EQ(expected_list
.size(), actual_list
.size());
39 for (size_t i
= 0; i
< actual_list
.size(); ++i
) {
40 RenderPass
* expected
= expected_list
[i
];
41 RenderPass
* actual
= actual_list
[i
];
43 EXPECT_EQ(expected
->id
, actual
->id
);
44 EXPECT_RECT_EQ(expected
->output_rect
, actual
->output_rect
);
45 EXPECT_EQ(expected
->transform_to_root_target
,
46 actual
->transform_to_root_target
);
47 EXPECT_RECT_EQ(expected
->damage_rect
, actual
->damage_rect
);
48 EXPECT_EQ(expected
->has_transparent_background
,
49 actual
->has_transparent_background
);
51 EXPECT_EQ(expected
->shared_quad_state_list
.size(),
52 actual
->shared_quad_state_list
.size());
53 EXPECT_EQ(expected
->quad_list
.size(), actual
->quad_list
.size());
55 for (auto exp_iter
= expected
->quad_list
.cbegin(),
56 act_iter
= actual
->quad_list
.cbegin();
57 exp_iter
!= expected
->quad_list
.cend();
58 ++exp_iter
, ++act_iter
) {
59 EXPECT_EQ(exp_iter
->rect
.ToString(), act_iter
->rect
.ToString());
60 EXPECT_EQ(exp_iter
->shared_quad_state
->content_bounds
.ToString(),
61 act_iter
->shared_quad_state
->content_bounds
.ToString());
66 TEST(RenderPassTest
, CopyShouldBeIdenticalExceptIdAndQuads
) {
67 RenderPassId
id(3, 2);
68 gfx::Rect
output_rect(45, 22, 120, 13);
69 gfx::Transform transform_to_root
=
70 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
71 gfx::Rect
damage_rect(56, 123, 19, 43);
72 bool has_transparent_background
= true;
74 scoped_ptr
<TestRenderPass
> pass
= TestRenderPass::Create();
79 has_transparent_background
);
80 pass
->copy_requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
82 // Stick a quad in the pass, this should not get copied.
83 SharedQuadState
* shared_state
= pass
->CreateAndAppendSharedQuadState();
84 shared_state
->SetAll(gfx::Transform(),
90 SkXfermode::kSrcOver_Mode
,
93 CheckerboardDrawQuad
* checkerboard_quad
=
94 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
95 checkerboard_quad
->SetNew(
96 pass
->shared_quad_state_list
.back(), gfx::Rect(), gfx::Rect(), SkColor());
98 RenderPassId
new_id(63, 4);
100 scoped_ptr
<RenderPass
> copy
= pass
->Copy(new_id
);
101 EXPECT_EQ(new_id
, copy
->id
);
102 EXPECT_RECT_EQ(pass
->output_rect
, copy
->output_rect
);
103 EXPECT_EQ(pass
->transform_to_root_target
, copy
->transform_to_root_target
);
104 EXPECT_RECT_EQ(pass
->damage_rect
, copy
->damage_rect
);
105 EXPECT_EQ(pass
->has_transparent_background
, copy
->has_transparent_background
);
106 EXPECT_EQ(0u, copy
->quad_list
.size());
108 // The copy request should not be copied/duplicated.
109 EXPECT_EQ(1u, pass
->copy_requests
.size());
110 EXPECT_EQ(0u, copy
->copy_requests
.size());
112 EXPECT_EQ(sizeof(RenderPassSize
), sizeof(RenderPass
));
115 TEST(RenderPassTest
, CopyAllShouldBeIdentical
) {
116 RenderPassList pass_list
;
118 RenderPassId
id(3, 2);
119 gfx::Rect
output_rect(45, 22, 120, 13);
120 gfx::Transform transform_to_root
=
121 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
122 gfx::Rect
damage_rect(56, 123, 19, 43);
123 bool has_transparent_background
= true;
125 scoped_ptr
<TestRenderPass
> pass
= TestRenderPass::Create();
130 has_transparent_background
);
132 // Two quads using one shared state.
133 SharedQuadState
* shared_state1
= pass
->CreateAndAppendSharedQuadState();
134 shared_state1
->SetAll(gfx::Transform(),
140 SkXfermode::kSrcOver_Mode
,
143 CheckerboardDrawQuad
* checkerboard_quad1
=
144 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
145 checkerboard_quad1
->SetNew(pass
->shared_quad_state_list
.back(),
146 gfx::Rect(1, 1, 1, 1),
147 gfx::Rect(1, 1, 1, 1),
150 CheckerboardDrawQuad
* checkerboard_quad2
=
151 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
152 checkerboard_quad2
->SetNew(pass
->shared_quad_state_list
.back(),
153 gfx::Rect(2, 2, 2, 2),
154 gfx::Rect(2, 2, 2, 2),
157 // And two quads using another shared state.
158 SharedQuadState
* shared_state2
= pass
->CreateAndAppendSharedQuadState();
159 shared_state2
->SetAll(gfx::Transform(),
165 SkXfermode::kSrcOver_Mode
,
168 CheckerboardDrawQuad
* checkerboard_quad3
=
169 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
170 checkerboard_quad3
->SetNew(pass
->shared_quad_state_list
.back(),
171 gfx::Rect(3, 3, 3, 3),
172 gfx::Rect(3, 3, 3, 3),
175 CheckerboardDrawQuad
* checkerboard_quad4
=
176 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
177 checkerboard_quad4
->SetNew(pass
->shared_quad_state_list
.back(),
178 gfx::Rect(4, 4, 4, 4),
179 gfx::Rect(4, 4, 4, 4),
182 // A second render pass with a quad.
183 RenderPassId
contrib_id(4, 1);
184 gfx::Rect
contrib_output_rect(10, 15, 12, 17);
185 gfx::Transform contrib_transform_to_root
=
186 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
187 gfx::Rect
contrib_damage_rect(11, 16, 10, 15);
188 bool contrib_has_transparent_background
= true;
190 scoped_ptr
<TestRenderPass
> contrib
= TestRenderPass::Create();
191 contrib
->SetAll(contrib_id
,
194 contrib_transform_to_root
,
195 contrib_has_transparent_background
);
197 SharedQuadState
* contrib_shared_state
=
198 contrib
->CreateAndAppendSharedQuadState();
199 contrib_shared_state
->SetAll(gfx::Transform(),
205 SkXfermode::kSrcOver_Mode
,
208 CheckerboardDrawQuad
* contrib_quad
=
209 contrib
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
210 contrib_quad
->SetNew(contrib
->shared_quad_state_list
.back(),
211 gfx::Rect(3, 3, 3, 3),
212 gfx::Rect(3, 3, 3, 3),
215 // And a RenderPassDrawQuad for the contributing pass.
216 scoped_ptr
<RenderPassDrawQuad
> pass_quad
=
217 make_scoped_ptr(new RenderPassDrawQuad
);
218 pass_quad
->SetNew(pass
->shared_quad_state_list
.back(),
222 0, // mask_resource_id
223 gfx::RectF(), // mask_uv_rect
225 gfx::Vector2dF(), // filters_scale
228 pass_list
.push_back(pass
.Pass());
229 pass_list
.push_back(contrib
.Pass());
231 // Make a copy with CopyAll().
232 RenderPassList copy_list
;
233 RenderPass::CopyAll(pass_list
, ©_list
);
235 CompareRenderPassLists(pass_list
, copy_list
);
238 TEST(RenderPassTest
, CopyAllWithCulledQuads
) {
239 RenderPassList pass_list
;
241 RenderPassId
id(3, 2);
242 gfx::Rect
output_rect(45, 22, 120, 13);
243 gfx::Transform transform_to_root
=
244 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
245 gfx::Rect
damage_rect(56, 123, 19, 43);
246 bool has_transparent_background
= true;
248 scoped_ptr
<TestRenderPass
> pass
= TestRenderPass::Create();
253 has_transparent_background
);
255 // A shared state with a quad.
256 SharedQuadState
* shared_state1
= pass
->CreateAndAppendSharedQuadState();
257 shared_state1
->SetAll(gfx::Transform(),
263 SkXfermode::kSrcOver_Mode
,
266 CheckerboardDrawQuad
* checkerboard_quad1
=
267 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
268 checkerboard_quad1
->SetNew(pass
->shared_quad_state_list
.back(),
269 gfx::Rect(1, 1, 1, 1),
270 gfx::Rect(1, 1, 1, 1),
273 // A shared state with no quads, they were culled.
274 SharedQuadState
* shared_state2
= pass
->CreateAndAppendSharedQuadState();
275 shared_state2
->SetAll(gfx::Transform(),
281 SkXfermode::kSrcOver_Mode
,
284 // A second shared state with no quads.
285 SharedQuadState
* shared_state3
= pass
->CreateAndAppendSharedQuadState();
286 shared_state3
->SetAll(gfx::Transform(),
292 SkXfermode::kSrcOver_Mode
,
295 // A last shared state with a quad again.
296 SharedQuadState
* shared_state4
= pass
->CreateAndAppendSharedQuadState();
297 shared_state4
->SetAll(gfx::Transform(),
303 SkXfermode::kSrcOver_Mode
,
306 CheckerboardDrawQuad
* checkerboard_quad2
=
307 pass
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
308 checkerboard_quad2
->SetNew(pass
->shared_quad_state_list
.back(),
309 gfx::Rect(3, 3, 3, 3),
310 gfx::Rect(3, 3, 3, 3),
313 pass_list
.push_back(pass
.Pass());
315 // Make a copy with CopyAll().
316 RenderPassList copy_list
;
317 RenderPass::CopyAll(pass_list
, ©_list
);
319 CompareRenderPassLists(pass_list
, copy_list
);