OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/io_surface_layer_impl.h" | 5 #include "cc/layers/io_surface_layer_impl.h" |
6 | 6 |
7 #include "cc/layers/append_quads_data.h" | |
8 #include "cc/test/fake_layer_tree_host.h" | |
9 #include "cc/test/layer_test_common.h" | 7 #include "cc/test/layer_test_common.h" |
10 #include "cc/test/mock_quad_culler.h" | |
11 #include "cc/trees/layer_tree_host_common.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
13 | 9 |
14 namespace cc { | 10 namespace cc { |
15 namespace { | 11 namespace { |
16 | 12 |
17 TEST(IOSurfaceLayerImplTest, Occlusion) { | 13 TEST(IOSurfaceLayerImplTest, Occlusion) { |
18 gfx::Size layer_size(1000, 1000); | 14 gfx::Size layer_size(1000, 1000); |
19 gfx::Size viewport_size(1000, 1000); | 15 gfx::Size viewport_size(1000, 1000); |
20 | 16 |
21 LayerTestCommon::LayerImplTest impl; | 17 LayerTestCommon::LayerImplTest impl; |
22 MockQuadCuller quad_culler; | |
23 AppendQuadsData data; | |
24 | 18 |
25 IOSurfaceLayerImpl* io_surface_layer_impl = | 19 IOSurfaceLayerImpl* io_surface_layer_impl = |
26 impl.AddChildToRoot<IOSurfaceLayerImpl>(); | 20 impl.AddChildToRoot<IOSurfaceLayerImpl>(); |
27 io_surface_layer_impl->SetAnchorPoint(gfx::PointF()); | 21 io_surface_layer_impl->SetAnchorPoint(gfx::PointF()); |
28 io_surface_layer_impl->SetBounds(layer_size); | 22 io_surface_layer_impl->SetBounds(layer_size); |
29 io_surface_layer_impl->SetContentBounds(layer_size); | 23 io_surface_layer_impl->SetContentBounds(layer_size); |
30 io_surface_layer_impl->SetDrawsContent(true); | 24 io_surface_layer_impl->SetDrawsContent(true); |
31 | 25 |
32 impl.CalcDrawProps(viewport_size); | 26 impl.CalcDrawProps(viewport_size); |
33 | 27 |
34 // No occlusion. | |
35 { | 28 { |
| 29 SCOPED_TRACE("No occlusion"); |
36 gfx::Rect occluded; | 30 gfx::Rect occluded; |
37 quad_culler.clear_lists(); | 31 impl.AppendQuadsWithOcclusion(io_surface_layer_impl, occluded); |
38 quad_culler.set_occluded_content_rect(occluded); | |
39 io_surface_layer_impl->AppendQuads(&quad_culler, &data); | |
40 | 32 |
41 LayerTestCommon::VerifyQuadsExactlyCoverRect(quad_culler.quad_list(), | 33 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
42 gfx::Rect(viewport_size)); | 34 gfx::Rect(layer_size)); |
43 EXPECT_EQ(1u, quad_culler.quad_list().size()); | 35 EXPECT_EQ(1u, impl.quad_list().size()); |
44 } | 36 } |
45 | 37 |
46 // Full occlusion. | |
47 { | 38 { |
48 gfx::Rect occluded = io_surface_layer_impl->visible_content_rect(); | 39 SCOPED_TRACE("Full occlusion"); |
49 quad_culler.clear_lists(); | 40 gfx::Rect occluded(io_surface_layer_impl->visible_content_rect()); |
50 quad_culler.set_occluded_content_rect(occluded); | 41 impl.AppendQuadsWithOcclusion(io_surface_layer_impl, occluded); |
51 io_surface_layer_impl->AppendQuads(&quad_culler, &data); | |
52 | 42 |
53 LayerTestCommon::VerifyQuadsExactlyCoverRect(quad_culler.quad_list(), | 43 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); |
54 gfx::Rect()); | 44 EXPECT_EQ(impl.quad_list().size(), 0u); |
55 EXPECT_EQ(quad_culler.quad_list().size(), 0u); | |
56 } | 45 } |
57 | 46 |
58 // Partial occlusion. | |
59 { | 47 { |
| 48 SCOPED_TRACE("Partial occlusion"); |
60 gfx::Rect occluded(200, 0, 800, 1000); | 49 gfx::Rect occluded(200, 0, 800, 1000); |
61 quad_culler.clear_lists(); | 50 impl.AppendQuadsWithOcclusion(io_surface_layer_impl, occluded); |
62 quad_culler.set_occluded_content_rect(occluded); | |
63 io_surface_layer_impl->AppendQuads(&quad_culler, &data); | |
64 | 51 |
65 size_t partially_occluded_count = 0; | 52 size_t partially_occluded_count = 0; |
66 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion( | 53 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion( |
67 quad_culler.quad_list(), | 54 impl.quad_list(), |
68 gfx::Rect(viewport_size), | 55 gfx::Rect(layer_size), |
69 occluded, | 56 occluded, |
70 &partially_occluded_count); | 57 &partially_occluded_count); |
71 // The layer outputs one quad, which is partially occluded. | 58 // The layer outputs one quad, which is partially occluded. |
72 EXPECT_EQ(1u, quad_culler.quad_list().size()); | 59 EXPECT_EQ(1u, impl.quad_list().size()); |
73 EXPECT_EQ(1u, partially_occluded_count); | 60 EXPECT_EQ(1u, partially_occluded_count); |
74 } | 61 } |
75 } | 62 } |
76 | 63 |
77 } // namespace | 64 } // namespace |
78 } // namespace cc | 65 } // namespace cc |
OLD | NEW |