Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a seriou...
[chromium-blink-merge.git] / cc / trees / quad_culler_unittest.cc
blob880035a04cd531e8b07550acbdd096e58b2bba67
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/quad_culler.h"
7 #include <vector>
9 #include "cc/base/math_util.h"
10 #include "cc/debug/overdraw_metrics.h"
11 #include "cc/layers/append_quads_data.h"
12 #include "cc/layers/render_surface_impl.h"
13 #include "cc/layers/tiled_layer_impl.h"
14 #include "cc/quads/render_pass_draw_quad.h"
15 #include "cc/quads/solid_color_draw_quad.h"
16 #include "cc/quads/tile_draw_quad.h"
17 #include "cc/resources/layer_tiling_data.h"
18 #include "cc/test/fake_impl_proxy.h"
19 #include "cc/test/fake_layer_tree_host_impl.h"
20 #include "cc/test/occlusion_tracker_test_common.h"
21 #include "cc/trees/occlusion_tracker.h"
22 #include "cc/trees/single_thread_proxy.h"
23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gfx/transform.h"
27 namespace cc {
28 namespace {
30 class TestOcclusionTrackerImpl
31 : public TestOcclusionTrackerBase<LayerImpl, RenderSurfaceImpl> {
32 public:
33 TestOcclusionTrackerImpl(const gfx::Rect& scissor_rect_in_screen,
34 bool record_metrics_for_frame = true)
35 : TestOcclusionTrackerBase(scissor_rect_in_screen,
36 record_metrics_for_frame) {}
38 private:
39 DISALLOW_COPY_AND_ASSIGN(TestOcclusionTrackerImpl);
42 typedef LayerIterator<LayerImpl,
43 LayerImplList,
44 RenderSurfaceImpl,
45 LayerIteratorActions::FrontToBack> LayerIteratorType;
47 class QuadCullerTest : public testing::Test {
48 public:
49 QuadCullerTest()
50 : host_impl_(&proxy_),
51 layer_id_(1) {}
53 scoped_ptr<TiledLayerImpl> MakeLayer(TiledLayerImpl* parent,
54 const gfx::Transform& draw_transform,
55 const gfx::Rect& layer_rect,
56 float opacity,
57 bool opaque,
58 const gfx::Rect& layer_opaque_rect,
59 LayerImplList& surface_layer_list) {
60 scoped_ptr<TiledLayerImpl> layer =
61 TiledLayerImpl::Create(host_impl_.active_tree(), layer_id_++);
62 scoped_ptr<LayerTilingData> tiler = LayerTilingData::Create(
63 gfx::Size(100, 100), LayerTilingData::NO_BORDER_TEXELS);
64 tiler->SetBounds(layer_rect.size());
65 layer->SetTilingData(*tiler);
66 layer->set_skips_draw(false);
67 layer->SetDrawsContent(true);
68 layer->draw_properties().target_space_transform = draw_transform;
69 layer->draw_properties().screen_space_transform = draw_transform;
70 layer->draw_properties().visible_content_rect = layer_rect;
71 layer->draw_properties().opacity = opacity;
72 layer->SetContentsOpaque(opaque);
73 layer->SetBounds(layer_rect.size());
74 layer->SetContentBounds(layer_rect.size());
76 ResourceProvider::ResourceId resource_id = 1;
77 for (int i = 0; i < tiler->num_tiles_x(); ++i) {
78 for (int j = 0; j < tiler->num_tiles_y(); ++j) {
79 gfx::Rect tile_opaque_rect =
80 opaque
81 ? tiler->tile_bounds(i, j)
82 : gfx::IntersectRects(tiler->tile_bounds(i, j), layer_opaque_rect);
83 layer->PushTileProperties(i, j, resource_id++, tile_opaque_rect, false);
87 gfx::Rect rect_in_target = MathUtil::MapClippedRect(
88 layer->draw_transform(), layer->visible_content_rect());
89 if (!parent) {
90 layer->CreateRenderSurface();
91 layer->render_surface()->SetContentRect(rect_in_target);
92 surface_layer_list.push_back(layer.get());
93 layer->render_surface()->layer_list().push_back(layer.get());
94 } else {
95 layer->draw_properties().render_target = parent->render_target();
96 parent->render_surface()->layer_list().push_back(layer.get());
97 rect_in_target.Union(MathUtil::MapClippedRect(
98 parent->draw_transform(), parent->visible_content_rect()));
99 parent->render_surface()->SetContentRect(rect_in_target);
101 layer->draw_properties().drawable_content_rect = rect_in_target;
103 return layer.Pass();
106 void AppendQuads(QuadList* quad_list,
107 SharedQuadStateList* shared_state_list,
108 TiledLayerImpl* layer,
109 LayerIteratorType* it,
110 OcclusionTrackerImpl* occlusion_tracker) {
111 occlusion_tracker->EnterLayer(*it);
112 QuadCuller quad_culler(
113 quad_list, shared_state_list, layer, *occlusion_tracker, false, false);
114 AppendQuadsData data;
115 layer->AppendQuads(&quad_culler, &data);
116 occlusion_tracker->LeaveLayer(*it);
117 ++it;
120 protected:
121 FakeImplProxy proxy_;
122 FakeLayerTreeHostImpl host_impl_;
123 int layer_id_;
125 private:
126 DISALLOW_COPY_AND_ASSIGN(QuadCullerTest);
129 #define DECLARE_AND_INITIALIZE_TEST_QUADS() \
130 QuadList quad_list; \
131 SharedQuadStateList shared_state_list; \
132 LayerImplList render_surface_layer_list; \
133 gfx::Transform child_transform; \
134 gfx::Size root_size = gfx::Size(300, 300); \
135 gfx::Rect root_rect = gfx::Rect(root_size); \
136 gfx::Size child_size = gfx::Size(200, 200); \
137 gfx::Rect child_rect = gfx::Rect(child_size);
139 TEST_F(QuadCullerTest, NoCulling) {
140 DECLARE_AND_INITIALIZE_TEST_QUADS();
142 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
143 gfx::Transform(),
144 root_rect,
145 1.f,
146 true,
147 gfx::Rect(),
148 render_surface_layer_list);
149 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
150 gfx::Transform(),
151 child_rect,
152 1.f,
153 false,
154 gfx::Rect(),
155 render_surface_layer_list);
156 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
157 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
159 AppendQuads(&quad_list,
160 &shared_state_list,
161 child_layer.get(),
162 &it,
163 &occlusion_tracker);
164 AppendQuads(&quad_list,
165 &shared_state_list,
166 root_layer.get(),
167 &it,
168 &occlusion_tracker);
169 EXPECT_EQ(13u, quad_list.size());
170 EXPECT_NEAR(
171 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
172 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(),
173 40000,
175 EXPECT_NEAR(
176 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(), 0, 1);
179 TEST_F(QuadCullerTest, CullChildLinesUpTopLeft) {
180 DECLARE_AND_INITIALIZE_TEST_QUADS();
182 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
183 gfx::Transform(),
184 root_rect,
185 1.f,
186 true,
187 gfx::Rect(),
188 render_surface_layer_list);
189 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
190 gfx::Transform(),
191 child_rect,
192 1.f,
193 true,
194 gfx::Rect(),
195 render_surface_layer_list);
196 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
197 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
199 AppendQuads(&quad_list,
200 &shared_state_list,
201 child_layer.get(),
202 &it,
203 &occlusion_tracker);
204 AppendQuads(&quad_list,
205 &shared_state_list,
206 root_layer.get(),
207 &it,
208 &occlusion_tracker);
209 EXPECT_EQ(9u, quad_list.size());
210 EXPECT_NEAR(
211 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
212 EXPECT_NEAR(
213 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
214 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
215 40000,
219 TEST_F(QuadCullerTest, CullWhenChildOpacityNotOne) {
220 DECLARE_AND_INITIALIZE_TEST_QUADS();
222 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
223 gfx::Transform(),
224 root_rect,
225 1.f,
226 true,
227 gfx::Rect(),
228 render_surface_layer_list);
229 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
230 child_transform,
231 child_rect,
232 0.9f,
233 true,
234 gfx::Rect(),
235 render_surface_layer_list);
236 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
237 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
239 AppendQuads(&quad_list,
240 &shared_state_list,
241 child_layer.get(),
242 &it,
243 &occlusion_tracker);
244 AppendQuads(&quad_list,
245 &shared_state_list,
246 root_layer.get(),
247 &it,
248 &occlusion_tracker);
249 EXPECT_EQ(13u, quad_list.size());
250 EXPECT_NEAR(
251 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
252 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(),
253 40000,
255 EXPECT_NEAR(
256 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(), 0, 1);
259 TEST_F(QuadCullerTest, CullWhenChildOpaqueFlagFalse) {
260 DECLARE_AND_INITIALIZE_TEST_QUADS();
262 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
263 gfx::Transform(),
264 root_rect,
265 1.f,
266 true,
267 gfx::Rect(),
268 render_surface_layer_list);
269 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
270 child_transform,
271 child_rect,
272 1.f,
273 false,
274 gfx::Rect(),
275 render_surface_layer_list);
276 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
277 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
279 AppendQuads(&quad_list,
280 &shared_state_list,
281 child_layer.get(),
282 &it,
283 &occlusion_tracker);
284 AppendQuads(&quad_list,
285 &shared_state_list,
286 root_layer.get(),
287 &it,
288 &occlusion_tracker);
289 EXPECT_EQ(13u, quad_list.size());
290 EXPECT_NEAR(
291 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
292 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(),
293 40000,
295 EXPECT_NEAR(
296 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(), 0, 1);
299 TEST_F(QuadCullerTest, CullCenterTileOnly) {
300 DECLARE_AND_INITIALIZE_TEST_QUADS();
302 child_transform.Translate(50, 50);
303 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
304 gfx::Transform(),
305 root_rect,
306 1.f,
307 true,
308 gfx::Rect(),
309 render_surface_layer_list);
310 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
311 child_transform,
312 child_rect,
313 1.f,
314 true,
315 gfx::Rect(),
316 render_surface_layer_list);
317 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
318 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
320 AppendQuads(&quad_list,
321 &shared_state_list,
322 child_layer.get(),
323 &it,
324 &occlusion_tracker);
325 AppendQuads(&quad_list,
326 &shared_state_list,
327 root_layer.get(),
328 &it,
329 &occlusion_tracker);
330 ASSERT_EQ(quad_list.size(), 12u);
332 gfx::Rect quad_visible_rect1 = quad_list[5]->visible_rect;
333 EXPECT_EQ(50, quad_visible_rect1.height());
335 gfx::Rect quad_visible_rect3 = quad_list[7]->visible_rect;
336 EXPECT_EQ(50, quad_visible_rect3.width());
338 // Next index is 8, not 9, since centre quad culled.
339 gfx::Rect quad_visible_rect4 = quad_list[8]->visible_rect;
340 EXPECT_EQ(50, quad_visible_rect4.width());
341 EXPECT_EQ(250, quad_visible_rect4.x());
343 gfx::Rect quad_visible_rect6 = quad_list[10]->visible_rect;
344 EXPECT_EQ(50, quad_visible_rect6.height());
345 EXPECT_EQ(250, quad_visible_rect6.y());
347 EXPECT_NEAR(
348 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 100000, 1);
349 EXPECT_NEAR(
350 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
351 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
352 30000,
356 TEST_F(QuadCullerTest, CullCenterTileNonIntegralSize1) {
357 DECLARE_AND_INITIALIZE_TEST_QUADS();
359 child_transform.Translate(100, 100);
361 // Make the root layer's quad have extent (99.1, 99.1) -> (200.9, 200.9) to
362 // make sure it doesn't get culled due to transform rounding.
363 gfx::Transform root_transform;
364 root_transform.Translate(99.1f, 99.1f);
365 root_transform.Scale(1.018f, 1.018f);
367 root_rect = child_rect = gfx::Rect(0, 0, 100, 100);
369 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
370 root_transform,
371 root_rect,
372 1.f,
373 true,
374 gfx::Rect(),
375 render_surface_layer_list);
376 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
377 child_transform,
378 child_rect,
379 1.f,
380 true,
381 gfx::Rect(),
382 render_surface_layer_list);
383 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
384 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
386 AppendQuads(&quad_list,
387 &shared_state_list,
388 child_layer.get(),
389 &it,
390 &occlusion_tracker);
391 AppendQuads(&quad_list,
392 &shared_state_list,
393 root_layer.get(),
394 &it,
395 &occlusion_tracker);
396 EXPECT_EQ(2u, quad_list.size());
398 EXPECT_NEAR(
399 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 20363, 1);
400 EXPECT_NEAR(
401 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
402 EXPECT_NEAR(
403 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(), 0, 1);
406 TEST_F(QuadCullerTest, CullCenterTileNonIntegralSize2) {
407 DECLARE_AND_INITIALIZE_TEST_QUADS();
409 // Make the child's quad slightly smaller than, and centred over, the root
410 // layer tile. Verify the child does not cause the quad below to be culled
411 // due to rounding.
412 child_transform.Translate(100.1f, 100.1f);
413 child_transform.Scale(0.982f, 0.982f);
415 gfx::Transform root_transform;
416 root_transform.Translate(100, 100);
418 root_rect = child_rect = gfx::Rect(0, 0, 100, 100);
420 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
421 root_transform,
422 root_rect,
423 1.f,
424 true,
425 gfx::Rect(),
426 render_surface_layer_list);
427 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
428 child_transform,
429 child_rect,
430 1.f,
431 true,
432 gfx::Rect(),
433 render_surface_layer_list);
434 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
435 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
437 AppendQuads(&quad_list,
438 &shared_state_list,
439 child_layer.get(),
440 &it,
441 &occlusion_tracker);
442 AppendQuads(&quad_list,
443 &shared_state_list,
444 root_layer.get(),
445 &it,
446 &occlusion_tracker);
447 EXPECT_EQ(2u, quad_list.size());
449 EXPECT_NEAR(
450 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 19643, 1);
451 EXPECT_NEAR(
452 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
453 EXPECT_NEAR(
454 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(), 0, 1);
457 TEST_F(QuadCullerTest, CullChildLinesUpBottomRight) {
458 DECLARE_AND_INITIALIZE_TEST_QUADS();
460 child_transform.Translate(100, 100);
461 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
462 gfx::Transform(),
463 root_rect,
464 1.f,
465 true,
466 gfx::Rect(),
467 render_surface_layer_list);
468 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
469 child_transform,
470 child_rect,
471 1.f,
472 true,
473 gfx::Rect(),
474 render_surface_layer_list);
475 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
476 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
478 AppendQuads(&quad_list,
479 &shared_state_list,
480 child_layer.get(),
481 &it,
482 &occlusion_tracker);
483 AppendQuads(&quad_list,
484 &shared_state_list,
485 root_layer.get(),
486 &it,
487 &occlusion_tracker);
488 EXPECT_EQ(9u, quad_list.size());
489 EXPECT_NEAR(
490 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
491 EXPECT_NEAR(
492 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
493 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
494 40000,
498 TEST_F(QuadCullerTest, CullSubRegion) {
499 DECLARE_AND_INITIALIZE_TEST_QUADS();
501 child_transform.Translate(50, 50);
502 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
503 gfx::Transform(),
504 root_rect,
505 1.f,
506 true,
507 gfx::Rect(),
508 render_surface_layer_list);
509 gfx::Rect child_opaque_rect(child_rect.x() + child_rect.width() / 4,
510 child_rect.y() + child_rect.height() / 4,
511 child_rect.width() / 2,
512 child_rect.height() / 2);
513 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
514 child_transform,
515 child_rect,
516 1.f,
517 false,
518 child_opaque_rect,
519 render_surface_layer_list);
520 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
521 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
523 AppendQuads(&quad_list,
524 &shared_state_list,
525 child_layer.get(),
526 &it,
527 &occlusion_tracker);
528 AppendQuads(&quad_list,
529 &shared_state_list,
530 root_layer.get(),
531 &it,
532 &occlusion_tracker);
533 EXPECT_EQ(12u, quad_list.size());
534 EXPECT_NEAR(
535 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
536 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(),
537 30000,
539 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
540 10000,
544 TEST_F(QuadCullerTest, CullSubRegion2) {
545 DECLARE_AND_INITIALIZE_TEST_QUADS();
547 child_transform.Translate(50, 10);
548 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
549 gfx::Transform(),
550 root_rect,
551 1.f,
552 true,
553 gfx::Rect(),
554 render_surface_layer_list);
555 gfx::Rect child_opaque_rect(child_rect.x() + child_rect.width() / 4,
556 child_rect.y() + child_rect.height() / 4,
557 child_rect.width() / 2,
558 child_rect.height() * 3 / 4);
559 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
560 child_transform,
561 child_rect,
562 1.f,
563 false,
564 child_opaque_rect,
565 render_surface_layer_list);
566 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
567 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
569 AppendQuads(&quad_list,
570 &shared_state_list,
571 child_layer.get(),
572 &it,
573 &occlusion_tracker);
574 AppendQuads(&quad_list,
575 &shared_state_list,
576 root_layer.get(),
577 &it,
578 &occlusion_tracker);
579 EXPECT_EQ(12u, quad_list.size());
580 EXPECT_NEAR(
581 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
582 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(),
583 25000,
585 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
586 15000,
590 TEST_F(QuadCullerTest, CullSubRegionCheckOvercull) {
591 DECLARE_AND_INITIALIZE_TEST_QUADS();
593 child_transform.Translate(50, 49);
594 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
595 gfx::Transform(),
596 root_rect,
597 1.f,
598 true,
599 gfx::Rect(),
600 render_surface_layer_list);
601 gfx::Rect child_opaque_rect(child_rect.x() + child_rect.width() / 4,
602 child_rect.y() + child_rect.height() / 4,
603 child_rect.width() / 2,
604 child_rect.height() / 2);
605 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
606 child_transform,
607 child_rect,
608 1.f,
609 false,
610 child_opaque_rect,
611 render_surface_layer_list);
612 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
613 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
615 AppendQuads(&quad_list,
616 &shared_state_list,
617 child_layer.get(),
618 &it,
619 &occlusion_tracker);
620 AppendQuads(&quad_list,
621 &shared_state_list,
622 root_layer.get(),
623 &it,
624 &occlusion_tracker);
625 EXPECT_EQ(13u, quad_list.size());
626 EXPECT_NEAR(
627 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 90000, 1);
628 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(),
629 30000,
631 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
632 10000,
636 TEST_F(QuadCullerTest, NonAxisAlignedQuadsDontOcclude) {
637 DECLARE_AND_INITIALIZE_TEST_QUADS();
639 // Use a small rotation so as to not disturb the geometry significantly.
640 child_transform.Rotate(1);
642 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
643 gfx::Transform(),
644 root_rect,
645 1.f,
646 true,
647 gfx::Rect(),
648 render_surface_layer_list);
649 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
650 child_transform,
651 child_rect,
652 1.f,
653 true,
654 gfx::Rect(),
655 render_surface_layer_list);
656 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
657 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
659 AppendQuads(&quad_list,
660 &shared_state_list,
661 child_layer.get(),
662 &it,
663 &occlusion_tracker);
664 AppendQuads(&quad_list,
665 &shared_state_list,
666 root_layer.get(),
667 &it,
668 &occlusion_tracker);
669 EXPECT_EQ(13u, quad_list.size());
670 EXPECT_NEAR(
671 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 130000, 1);
672 EXPECT_NEAR(
673 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
674 EXPECT_NEAR(
675 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(), 0, 1);
678 // This test requires some explanation: here we are rotating the quads to be
679 // culled. The 2x2 tile child layer remains in the top-left corner, unrotated,
680 // but the 3x3 tile parent layer is rotated by 1 degree. Of the four tiles the
681 // child would normally occlude, three will move (slightly) out from under the
682 // child layer, and one moves further under the child. Only this last tile
683 // should be culled.
684 TEST_F(QuadCullerTest, NonAxisAlignedQuadsSafelyCulled) {
685 DECLARE_AND_INITIALIZE_TEST_QUADS();
687 // Use a small rotation so as to not disturb the geometry significantly.
688 gfx::Transform parent_transform;
689 parent_transform.Rotate(1);
691 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
692 parent_transform,
693 root_rect,
694 1.f,
695 true,
696 gfx::Rect(),
697 render_surface_layer_list);
698 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
699 gfx::Transform(),
700 child_rect,
701 1.f,
702 true,
703 gfx::Rect(),
704 render_surface_layer_list);
705 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000));
706 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
708 AppendQuads(&quad_list,
709 &shared_state_list,
710 child_layer.get(),
711 &it,
712 &occlusion_tracker);
713 AppendQuads(&quad_list,
714 &shared_state_list,
715 root_layer.get(),
716 &it,
717 &occlusion_tracker);
718 EXPECT_EQ(12u, quad_list.size());
719 EXPECT_NEAR(
720 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque(), 100600, 1);
721 EXPECT_NEAR(
722 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent(), 0, 1);
723 EXPECT_NEAR(occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing(),
724 29400,
728 TEST_F(QuadCullerTest, WithoutMetrics) {
729 DECLARE_AND_INITIALIZE_TEST_QUADS();
730 scoped_ptr<TiledLayerImpl> root_layer = MakeLayer(NULL,
731 gfx::Transform(),
732 root_rect,
733 1.f,
734 true,
735 gfx::Rect(),
736 render_surface_layer_list);
737 scoped_ptr<TiledLayerImpl> child_layer = MakeLayer(root_layer.get(),
738 gfx::Transform(),
739 child_rect,
740 1.f,
741 true,
742 gfx::Rect(),
743 render_surface_layer_list);
744 bool record_metrics = false;
745 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(-100, -100, 1000, 1000),
746 record_metrics);
747 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
749 AppendQuads(&quad_list,
750 &shared_state_list,
751 child_layer.get(),
752 &it,
753 &occlusion_tracker);
754 AppendQuads(&quad_list,
755 &shared_state_list,
756 root_layer.get(),
757 &it,
758 &occlusion_tracker);
759 EXPECT_EQ(9u, quad_list.size());
760 EXPECT_EQ(0.f,
761 occlusion_tracker.overdraw_metrics()->pixels_drawn_opaque());
762 EXPECT_EQ(0.f,
763 occlusion_tracker.overdraw_metrics()->pixels_drawn_translucent());
764 EXPECT_EQ(0.f,
765 occlusion_tracker.overdraw_metrics()->pixels_culled_for_drawing());
768 TEST_F(QuadCullerTest, PartialCullingNotDestroyed) {
769 DECLARE_AND_INITIALIZE_TEST_QUADS();
771 scoped_ptr<TiledLayerImpl> dummy_layer = MakeLayer(NULL,
772 gfx::Transform(),
773 gfx::Rect(),
774 1.f,
775 true,
776 gfx::Rect(),
777 render_surface_layer_list);
779 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(1000, 1000));
780 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
782 QuadCuller culler(&quad_list,
783 &shared_state_list,
784 dummy_layer.get(),
785 occlusion_tracker,
786 false,
787 false);
789 SharedQuadState* sqs = culler.UseSharedQuadState(SharedQuadState::Create());
791 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
792 color_quad->SetNew(sqs, gfx::Rect(100, 100), SK_ColorRED, false);
794 scoped_ptr<RenderPassDrawQuad> pass_quad = RenderPassDrawQuad::Create();
795 pass_quad->SetNew(sqs,
796 gfx::Rect(100, 100),
797 RenderPass::Id(10, 10),
798 false,
800 gfx::Rect(),
801 gfx::RectF(),
802 FilterOperations(),
803 FilterOperations());
805 scoped_ptr<RenderPassDrawQuad> replica_quad = RenderPassDrawQuad::Create();
806 replica_quad->SetNew(sqs,
807 gfx::Rect(100, 100),
808 RenderPass::Id(10, 10),
809 true,
811 gfx::Rect(),
812 gfx::RectF(),
813 FilterOperations(),
814 FilterOperations());
816 // Set a visible rect on the quads.
817 color_quad->visible_rect = gfx::Rect(20, 30, 10, 11);
818 pass_quad->visible_rect = gfx::Rect(50, 60, 13, 14);
819 replica_quad->visible_rect = gfx::Rect(30, 40, 15, 16);
821 // Nothing is occluding.
822 occlusion_tracker.EnterLayer(it);
824 EXPECT_EQ(0u, quad_list.size());
826 AppendQuadsData data;
827 culler.Append(color_quad.PassAs<DrawQuad>(), &data);
828 culler.Append(pass_quad.PassAs<DrawQuad>(), &data);
829 culler.Append(replica_quad.PassAs<DrawQuad>(), &data);
831 ASSERT_EQ(3u, quad_list.size());
833 // The partial culling is preserved.
834 EXPECT_EQ(gfx::Rect(20, 30, 10, 11).ToString(),
835 quad_list[0]->visible_rect.ToString());
836 EXPECT_EQ(gfx::Rect(50, 60, 13, 14).ToString(),
837 quad_list[1]->visible_rect.ToString());
838 EXPECT_EQ(gfx::Rect(30, 40, 15, 16).ToString(),
839 quad_list[2]->visible_rect.ToString());
842 TEST_F(QuadCullerTest, PartialCullingWithOcclusionNotDestroyed) {
843 DECLARE_AND_INITIALIZE_TEST_QUADS();
845 scoped_ptr<TiledLayerImpl> dummy_layer = MakeLayer(NULL,
846 gfx::Transform(),
847 gfx::Rect(),
848 1.f,
849 true,
850 gfx::Rect(),
851 render_surface_layer_list);
853 TestOcclusionTrackerImpl occlusion_tracker(gfx::Rect(1000, 1000));
854 LayerIteratorType it = LayerIteratorType::Begin(&render_surface_layer_list);
856 QuadCuller culler(&quad_list,
857 &shared_state_list,
858 dummy_layer.get(),
859 occlusion_tracker,
860 false,
861 false);
863 SharedQuadState* sqs = culler.UseSharedQuadState(SharedQuadState::Create());
865 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
866 color_quad->SetNew(sqs, gfx::Rect(100, 100), SK_ColorRED, false);
868 scoped_ptr<RenderPassDrawQuad> pass_quad = RenderPassDrawQuad::Create();
869 pass_quad->SetNew(sqs,
870 gfx::Rect(100, 100),
871 RenderPass::Id(10, 10),
872 false,
874 gfx::Rect(),
875 gfx::RectF(),
876 FilterOperations(),
877 FilterOperations());
879 scoped_ptr<RenderPassDrawQuad> replica_quad = RenderPassDrawQuad::Create();
880 replica_quad->SetNew(sqs,
881 gfx::Rect(100, 100),
882 RenderPass::Id(10, 10),
883 true,
885 gfx::Rect(),
886 gfx::RectF(),
887 FilterOperations(),
888 FilterOperations());
890 // Set a visible rect on the quads.
891 color_quad->visible_rect = gfx::Rect(10, 10, 10, 11);
892 pass_quad->visible_rect = gfx::Rect(10, 20, 13, 14);
893 replica_quad->visible_rect = gfx::Rect(10, 30, 15, 16);
895 // Occlude the left part of the visible rects.
896 occlusion_tracker.EnterLayer(it);
897 occlusion_tracker.set_occlusion_from_outside_target(gfx::Rect(0, 0, 15, 100));
899 EXPECT_EQ(0u, quad_list.size());
901 AppendQuadsData data;
902 culler.Append(color_quad.PassAs<DrawQuad>(), &data);
903 culler.Append(pass_quad.PassAs<DrawQuad>(), &data);
904 culler.Append(replica_quad.PassAs<DrawQuad>(), &data);
906 ASSERT_EQ(3u, quad_list.size());
908 // The partial culling is preserved, while the left side of the quads is newly
909 // occluded.
910 EXPECT_EQ(gfx::Rect(15, 10, 5, 11).ToString(),
911 quad_list[0]->visible_rect.ToString());
912 EXPECT_EQ(gfx::Rect(15, 20, 8, 14).ToString(),
913 quad_list[1]->visible_rect.ToString());
914 EXPECT_EQ(gfx::Rect(15, 30, 10, 16).ToString(),
915 quad_list[2]->visible_rect.ToString());
918 } // namespace
919 } // namespace cc