Add default implementations for AppWindowRegistry::Observer notifications.
[chromium-blink-merge.git] / cc / quads / render_pass_unittest.cc
blobf714dbee738f40da21c29b39adab560e41d90c6a
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;
20 namespace cc {
21 namespace {
23 struct RenderPassSize {
24 // If you add a new field to this class, make sure to add it to the
25 // Copy() tests.
26 RenderPass::Id 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;
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 (size_t i = 0; i < expected->quad_list.size(); ++i) {
56 EXPECT_EQ(expected->quad_list[i]->rect.ToString(),
57 actual->quad_list[i]->rect.ToString());
58 EXPECT_EQ(
59 expected->quad_list[i]->shared_quad_state->content_bounds.ToString(),
60 actual->quad_list[i]->shared_quad_state->content_bounds.ToString());
65 TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) {
66 RenderPass::Id id(3, 2);
67 gfx::Rect output_rect(45, 22, 120, 13);
68 gfx::Transform transform_to_root =
69 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
70 gfx::Rect damage_rect(56, 123, 19, 43);
71 bool has_transparent_background = true;
73 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
74 pass->SetAll(id,
75 output_rect,
76 damage_rect,
77 transform_to_root,
78 has_transparent_background);
79 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest());
81 // Stick a quad in the pass, this should not get copied.
82 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
83 shared_state->SetAll(gfx::Transform(),
84 gfx::Size(),
85 gfx::Rect(),
86 gfx::Rect(),
87 false,
89 SkXfermode::kSrcOver_Mode);
90 pass->AppendSharedQuadState(shared_state.Pass());
92 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad =
93 CheckerboardDrawQuad::Create();
94 checkerboard_quad->SetNew(
95 pass->shared_quad_state_list.back(), gfx::Rect(), gfx::Rect(), SkColor());
96 pass->quad_list.push_back(checkerboard_quad.PassAs<DrawQuad>());
98 RenderPass::Id 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 RenderPass::Id 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();
126 pass->SetAll(id,
127 output_rect,
128 damage_rect,
129 transform_to_root,
130 has_transparent_background);
132 // Two quads using one shared state.
133 scoped_ptr<SharedQuadState> shared_state1 = SharedQuadState::Create();
134 shared_state1->SetAll(gfx::Transform(),
135 gfx::Size(1, 1),
136 gfx::Rect(),
137 gfx::Rect(),
138 false,
140 SkXfermode::kSrcOver_Mode);
141 pass->AppendSharedQuadState(shared_state1.Pass());
143 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad1 =
144 CheckerboardDrawQuad::Create();
145 checkerboard_quad1->SetNew(pass->shared_quad_state_list.back(),
146 gfx::Rect(1, 1, 1, 1),
147 gfx::Rect(1, 1, 1, 1),
148 SkColor());
149 pass->quad_list.push_back(checkerboard_quad1.PassAs<DrawQuad>());
151 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad2 =
152 CheckerboardDrawQuad::Create();
153 checkerboard_quad2->SetNew(pass->shared_quad_state_list.back(),
154 gfx::Rect(2, 2, 2, 2),
155 gfx::Rect(2, 2, 2, 2),
156 SkColor());
157 pass->quad_list.push_back(checkerboard_quad2.PassAs<DrawQuad>());
159 // And two quads using another shared state.
160 scoped_ptr<SharedQuadState> shared_state2 = SharedQuadState::Create();
161 shared_state2->SetAll(gfx::Transform(),
162 gfx::Size(2, 2),
163 gfx::Rect(),
164 gfx::Rect(),
165 false,
167 SkXfermode::kSrcOver_Mode);
168 pass->AppendSharedQuadState(shared_state2.Pass());
170 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad3 =
171 CheckerboardDrawQuad::Create();
172 checkerboard_quad3->SetNew(pass->shared_quad_state_list.back(),
173 gfx::Rect(3, 3, 3, 3),
174 gfx::Rect(3, 3, 3, 3),
175 SkColor());
176 pass->quad_list.push_back(checkerboard_quad3.PassAs<DrawQuad>());
178 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad4 =
179 CheckerboardDrawQuad::Create();
180 checkerboard_quad4->SetNew(pass->shared_quad_state_list.back(),
181 gfx::Rect(4, 4, 4, 4),
182 gfx::Rect(4, 4, 4, 4),
183 SkColor());
184 pass->quad_list.push_back(checkerboard_quad4.PassAs<DrawQuad>());
186 // A second render pass with a quad.
187 RenderPass::Id contrib_id(4, 1);
188 gfx::Rect contrib_output_rect(10, 15, 12, 17);
189 gfx::Transform contrib_transform_to_root =
190 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
191 gfx::Rect contrib_damage_rect(11, 16, 10, 15);
192 bool contrib_has_transparent_background = true;
194 scoped_ptr<TestRenderPass> contrib = TestRenderPass::Create();
195 contrib->SetAll(contrib_id,
196 contrib_output_rect,
197 contrib_damage_rect,
198 contrib_transform_to_root,
199 contrib_has_transparent_background);
201 scoped_ptr<SharedQuadState> contrib_shared_state = SharedQuadState::Create();
202 contrib_shared_state->SetAll(gfx::Transform(),
203 gfx::Size(2, 2),
204 gfx::Rect(),
205 gfx::Rect(),
206 false,
208 SkXfermode::kSrcOver_Mode);
209 contrib->AppendSharedQuadState(contrib_shared_state.Pass());
211 scoped_ptr<CheckerboardDrawQuad> contrib_quad =
212 CheckerboardDrawQuad::Create();
213 contrib_quad->SetNew(contrib->shared_quad_state_list.back(),
214 gfx::Rect(3, 3, 3, 3),
215 gfx::Rect(3, 3, 3, 3),
216 SkColor());
217 contrib->quad_list.push_back(contrib_quad.PassAs<DrawQuad>());
219 // And a RenderPassDrawQuad for the contributing pass.
220 scoped_ptr<RenderPassDrawQuad> pass_quad = RenderPassDrawQuad::Create();
221 pass_quad->SetNew(pass->shared_quad_state_list.back(),
222 contrib_output_rect,
223 contrib_output_rect,
224 contrib_id,
225 false, // is_replica
226 0, // mask_resource_id
227 contrib_damage_rect,
228 gfx::RectF(), // mask_uv_rect
229 FilterOperations(),
230 FilterOperations());
231 pass->quad_list.push_back(pass_quad.PassAs<DrawQuad>());
233 pass_list.push_back(pass.PassAs<RenderPass>());
234 pass_list.push_back(contrib.PassAs<RenderPass>());
236 // Make a copy with CopyAll().
237 RenderPassList copy_list;
238 RenderPass::CopyAll(pass_list, &copy_list);
240 CompareRenderPassLists(pass_list, copy_list);
243 TEST(RenderPassTest, CopyAllWithCulledQuads) {
244 RenderPassList pass_list;
246 RenderPass::Id id(3, 2);
247 gfx::Rect output_rect(45, 22, 120, 13);
248 gfx::Transform transform_to_root =
249 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
250 gfx::Rect damage_rect(56, 123, 19, 43);
251 bool has_transparent_background = true;
253 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
254 pass->SetAll(id,
255 output_rect,
256 damage_rect,
257 transform_to_root,
258 has_transparent_background);
260 // A shared state with a quad.
261 scoped_ptr<SharedQuadState> shared_state1 = SharedQuadState::Create();
262 shared_state1->SetAll(gfx::Transform(),
263 gfx::Size(1, 1),
264 gfx::Rect(),
265 gfx::Rect(),
266 false,
268 SkXfermode::kSrcOver_Mode);
269 pass->AppendSharedQuadState(shared_state1.Pass());
271 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad1 =
272 CheckerboardDrawQuad::Create();
273 checkerboard_quad1->SetNew(pass->shared_quad_state_list.back(),
274 gfx::Rect(1, 1, 1, 1),
275 gfx::Rect(1, 1, 1, 1),
276 SkColor());
277 pass->quad_list.push_back(checkerboard_quad1.PassAs<DrawQuad>());
279 // A shared state with no quads, they were culled.
280 scoped_ptr<SharedQuadState> shared_state2 = SharedQuadState::Create();
281 shared_state2->SetAll(gfx::Transform(),
282 gfx::Size(2, 2),
283 gfx::Rect(),
284 gfx::Rect(),
285 false,
287 SkXfermode::kSrcOver_Mode);
288 pass->AppendSharedQuadState(shared_state2.Pass());
290 // A second shared state with no quads.
291 scoped_ptr<SharedQuadState> shared_state3 = SharedQuadState::Create();
292 shared_state3->SetAll(gfx::Transform(),
293 gfx::Size(2, 2),
294 gfx::Rect(),
295 gfx::Rect(),
296 false,
298 SkXfermode::kSrcOver_Mode);
299 pass->AppendSharedQuadState(shared_state3.Pass());
301 // A last shared state with a quad again.
302 scoped_ptr<SharedQuadState> shared_state4 = SharedQuadState::Create();
303 shared_state4->SetAll(gfx::Transform(),
304 gfx::Size(2, 2),
305 gfx::Rect(),
306 gfx::Rect(),
307 false,
309 SkXfermode::kSrcOver_Mode);
310 pass->AppendSharedQuadState(shared_state4.Pass());
312 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad2 =
313 CheckerboardDrawQuad::Create();
314 checkerboard_quad2->SetNew(pass->shared_quad_state_list.back(),
315 gfx::Rect(3, 3, 3, 3),
316 gfx::Rect(3, 3, 3, 3),
317 SkColor());
318 pass->quad_list.push_back(checkerboard_quad2.PassAs<DrawQuad>());
320 pass_list.push_back(pass.PassAs<RenderPass>());
322 // Make a copy with CopyAll().
323 RenderPassList copy_list;
324 RenderPass::CopyAll(pass_list, &copy_list);
326 CompareRenderPassLists(pass_list, copy_list);
329 } // namespace
330 } // namespace cc