OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/quads/render_pass.h" | |
6 | |
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" | |
17 | |
18 using cc::TestRenderPass; | |
19 | |
20 namespace cc { | |
21 namespace { | |
22 | |
23 struct RenderPassSize { | |
24 // If you add a new field to this class, make sure to add it to the | |
25 // Copy() tests. | |
26 RenderPassId id; | |
27 QuadList quad_list; | |
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; | |
34 }; | |
35 | |
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]; | |
42 | |
43 EXPECT_EQ(expected->id, actual->id); | |
44 EXPECT_EQ(expected->output_rect, actual->output_rect); | |
45 EXPECT_EQ(expected->transform_to_root_target, | |
46 actual->transform_to_root_target); | |
47 EXPECT_EQ(expected->damage_rect, actual->damage_rect); | |
48 EXPECT_EQ(expected->has_transparent_background, | |
49 actual->has_transparent_background); | |
50 | |
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()); | |
54 | |
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()); | |
62 } | |
63 } | |
64 } | |
65 | |
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; | |
73 | |
74 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | |
75 pass->SetAll(id, | |
76 output_rect, | |
77 damage_rect, | |
78 transform_to_root, | |
79 has_transparent_background); | |
80 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); | |
81 | |
82 // Stick a quad in the pass, this should not get copied. | |
83 SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState(); | |
84 shared_state->SetAll(gfx::Transform(), | |
85 gfx::Size(), | |
86 gfx::Rect(), | |
87 gfx::Rect(), | |
88 false, | |
89 1, | |
90 SkXfermode::kSrcOver_Mode, | |
91 0); | |
92 | |
93 CheckerboardDrawQuad* checkerboard_quad = | |
94 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
95 checkerboard_quad->SetNew(pass->shared_quad_state_list.back(), gfx::Rect(), | |
96 gfx::Rect(), SkColor(), 1.f); | |
97 | |
98 RenderPassId new_id(63, 4); | |
99 | |
100 scoped_ptr<RenderPass> copy = pass->Copy(new_id); | |
101 EXPECT_EQ(new_id, copy->id); | |
102 EXPECT_EQ(pass->output_rect, copy->output_rect); | |
103 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); | |
104 EXPECT_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()); | |
107 | |
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()); | |
111 | |
112 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); | |
113 } | |
114 | |
115 TEST(RenderPassTest, CopyAllShouldBeIdentical) { | |
116 RenderPassList pass_list; | |
117 | |
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; | |
124 | |
125 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | |
126 pass->SetAll(id, | |
127 output_rect, | |
128 damage_rect, | |
129 transform_to_root, | |
130 has_transparent_background); | |
131 | |
132 // Two quads using one shared state. | |
133 SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState(); | |
134 shared_state1->SetAll(gfx::Transform(), | |
135 gfx::Size(1, 1), | |
136 gfx::Rect(), | |
137 gfx::Rect(), | |
138 false, | |
139 1, | |
140 SkXfermode::kSrcOver_Mode, | |
141 0); | |
142 | |
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), gfx::Rect(1, 1, 1, 1), | |
147 SkColor(), 1.f); | |
148 | |
149 CheckerboardDrawQuad* checkerboard_quad2 = | |
150 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
151 checkerboard_quad2->SetNew(pass->shared_quad_state_list.back(), | |
152 gfx::Rect(2, 2, 2, 2), gfx::Rect(2, 2, 2, 2), | |
153 SkColor(), 1.f); | |
154 | |
155 // And two quads using another shared state. | |
156 SharedQuadState* shared_state2 = pass->CreateAndAppendSharedQuadState(); | |
157 shared_state2->SetAll(gfx::Transform(), | |
158 gfx::Size(2, 2), | |
159 gfx::Rect(), | |
160 gfx::Rect(), | |
161 false, | |
162 1, | |
163 SkXfermode::kSrcOver_Mode, | |
164 0); | |
165 | |
166 CheckerboardDrawQuad* checkerboard_quad3 = | |
167 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
168 checkerboard_quad3->SetNew(pass->shared_quad_state_list.back(), | |
169 gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), | |
170 SkColor(), 1.f); | |
171 | |
172 CheckerboardDrawQuad* checkerboard_quad4 = | |
173 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
174 checkerboard_quad4->SetNew(pass->shared_quad_state_list.back(), | |
175 gfx::Rect(4, 4, 4, 4), gfx::Rect(4, 4, 4, 4), | |
176 SkColor(), 1.f); | |
177 | |
178 // A second render pass with a quad. | |
179 RenderPassId contrib_id(4, 1); | |
180 gfx::Rect contrib_output_rect(10, 15, 12, 17); | |
181 gfx::Transform contrib_transform_to_root = | |
182 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | |
183 gfx::Rect contrib_damage_rect(11, 16, 10, 15); | |
184 bool contrib_has_transparent_background = true; | |
185 | |
186 scoped_ptr<TestRenderPass> contrib = TestRenderPass::Create(); | |
187 contrib->SetAll(contrib_id, | |
188 contrib_output_rect, | |
189 contrib_damage_rect, | |
190 contrib_transform_to_root, | |
191 contrib_has_transparent_background); | |
192 | |
193 SharedQuadState* contrib_shared_state = | |
194 contrib->CreateAndAppendSharedQuadState(); | |
195 contrib_shared_state->SetAll(gfx::Transform(), | |
196 gfx::Size(2, 2), | |
197 gfx::Rect(), | |
198 gfx::Rect(), | |
199 false, | |
200 1, | |
201 SkXfermode::kSrcOver_Mode, | |
202 0); | |
203 | |
204 CheckerboardDrawQuad* contrib_quad = | |
205 contrib->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
206 contrib_quad->SetNew(contrib->shared_quad_state_list.back(), | |
207 gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), SkColor(), | |
208 1.f); | |
209 | |
210 // And a RenderPassDrawQuad for the contributing pass. | |
211 scoped_ptr<RenderPassDrawQuad> pass_quad = | |
212 make_scoped_ptr(new RenderPassDrawQuad); | |
213 pass_quad->SetNew(pass->shared_quad_state_list.back(), | |
214 contrib_output_rect, | |
215 contrib_output_rect, | |
216 contrib_id, | |
217 0, | |
218 gfx::Vector2dF(), | |
219 gfx::Size(), | |
220 FilterOperations(), | |
221 gfx::Vector2dF(), | |
222 FilterOperations()); | |
223 | |
224 pass_list.push_back(pass.Pass()); | |
225 pass_list.push_back(contrib.Pass()); | |
226 | |
227 // Make a copy with CopyAll(). | |
228 RenderPassList copy_list; | |
229 RenderPass::CopyAll(pass_list, ©_list); | |
230 | |
231 CompareRenderPassLists(pass_list, copy_list); | |
232 } | |
233 | |
234 TEST(RenderPassTest, CopyAllWithCulledQuads) { | |
235 RenderPassList pass_list; | |
236 | |
237 RenderPassId id(3, 2); | |
238 gfx::Rect output_rect(45, 22, 120, 13); | |
239 gfx::Transform transform_to_root = | |
240 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | |
241 gfx::Rect damage_rect(56, 123, 19, 43); | |
242 bool has_transparent_background = true; | |
243 | |
244 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | |
245 pass->SetAll(id, | |
246 output_rect, | |
247 damage_rect, | |
248 transform_to_root, | |
249 has_transparent_background); | |
250 | |
251 // A shared state with a quad. | |
252 SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState(); | |
253 shared_state1->SetAll(gfx::Transform(), | |
254 gfx::Size(1, 1), | |
255 gfx::Rect(), | |
256 gfx::Rect(), | |
257 false, | |
258 1, | |
259 SkXfermode::kSrcOver_Mode, | |
260 0); | |
261 | |
262 CheckerboardDrawQuad* checkerboard_quad1 = | |
263 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
264 checkerboard_quad1->SetNew(pass->shared_quad_state_list.back(), | |
265 gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), | |
266 SkColor(), 1.f); | |
267 | |
268 // A shared state with no quads, they were culled. | |
269 SharedQuadState* shared_state2 = pass->CreateAndAppendSharedQuadState(); | |
270 shared_state2->SetAll(gfx::Transform(), | |
271 gfx::Size(2, 2), | |
272 gfx::Rect(), | |
273 gfx::Rect(), | |
274 false, | |
275 1, | |
276 SkXfermode::kSrcOver_Mode, | |
277 0); | |
278 | |
279 // A second shared state with no quads. | |
280 SharedQuadState* shared_state3 = pass->CreateAndAppendSharedQuadState(); | |
281 shared_state3->SetAll(gfx::Transform(), | |
282 gfx::Size(2, 2), | |
283 gfx::Rect(), | |
284 gfx::Rect(), | |
285 false, | |
286 1, | |
287 SkXfermode::kSrcOver_Mode, | |
288 0); | |
289 | |
290 // A last shared state with a quad again. | |
291 SharedQuadState* shared_state4 = pass->CreateAndAppendSharedQuadState(); | |
292 shared_state4->SetAll(gfx::Transform(), | |
293 gfx::Size(2, 2), | |
294 gfx::Rect(), | |
295 gfx::Rect(), | |
296 false, | |
297 1, | |
298 SkXfermode::kSrcOver_Mode, | |
299 0); | |
300 | |
301 CheckerboardDrawQuad* checkerboard_quad2 = | |
302 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | |
303 checkerboard_quad2->SetNew(pass->shared_quad_state_list.back(), | |
304 gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), | |
305 SkColor(), 1.f); | |
306 | |
307 pass_list.push_back(pass.Pass()); | |
308 | |
309 // Make a copy with CopyAll(). | |
310 RenderPassList copy_list; | |
311 RenderPass::CopyAll(pass_list, ©_list); | |
312 | |
313 CompareRenderPassLists(pass_list, copy_list); | |
314 } | |
315 | |
316 } // namespace | |
317 } // namespace cc | |
OLD | NEW |