| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/tiled_layer_impl.h" | 5 #include "cc/layers/tiled_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
| 8 #include "cc/quads/tile_draw_quad.h" | 8 #include "cc/quads/tile_draw_quad.h" |
| 9 #include "cc/resources/layer_tiling_data.h" | 9 #include "cc/resources/layer_tiling_data.h" |
| 10 #include "cc/test/fake_impl_proxy.h" | 10 #include "cc/test/fake_impl_proxy.h" |
| 11 #include "cc/test/fake_layer_tree_host_impl.h" | 11 #include "cc/test/fake_layer_tree_host_impl.h" |
| 12 #include "cc/test/layer_test_common.h" | 12 #include "cc/test/layer_test_common.h" |
| 13 #include "cc/test/mock_quad_culler.h" | |
| 14 #include "cc/trees/single_thread_proxy.h" | 13 #include "cc/trees/single_thread_proxy.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 namespace cc { | 17 namespace cc { |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 class TiledLayerImplTest : public testing::Test { | 20 class TiledLayerImplTest : public testing::Test { |
| 22 public: | 21 public: |
| 23 TiledLayerImplTest() : host_impl_(&proxy_, &shared_bitmap_manager_) {} | 22 TiledLayerImplTest() : host_impl_(&proxy_, &shared_bitmap_manager_) {} |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const gfx::Size& tile_size, | 68 const gfx::Size& tile_size, |
| 70 const gfx::Size& layer_size, | 69 const gfx::Size& layer_size, |
| 71 LayerTilingData::BorderTexelOption border_texel_option, | 70 LayerTilingData::BorderTexelOption border_texel_option, |
| 72 const gfx::Rect& visible_content_rect) { | 71 const gfx::Rect& visible_content_rect) { |
| 73 scoped_ptr<TiledLayerImpl> layer = | 72 scoped_ptr<TiledLayerImpl> layer = |
| 74 CreateLayer(tile_size, layer_size, border_texel_option); | 73 CreateLayer(tile_size, layer_size, border_texel_option); |
| 75 layer->draw_properties().visible_content_rect = visible_content_rect; | 74 layer->draw_properties().visible_content_rect = visible_content_rect; |
| 76 layer->SetBounds(layer_size); | 75 layer->SetBounds(layer_size); |
| 77 | 76 |
| 78 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 77 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 79 MockQuadCuller quad_culler(render_pass, &occlusion_tracker); | |
| 80 AppendQuadsData data; | 78 AppendQuadsData data; |
| 81 layer->AppendQuads(&quad_culler, &data); | 79 layer->AppendQuads(render_pass, occlusion_tracker, &data); |
| 82 } | 80 } |
| 83 | 81 |
| 84 protected: | 82 protected: |
| 85 FakeImplProxy proxy_; | 83 FakeImplProxy proxy_; |
| 86 TestSharedBitmapManager shared_bitmap_manager_; | 84 TestSharedBitmapManager shared_bitmap_manager_; |
| 87 FakeLayerTreeHostImpl host_impl_; | 85 FakeLayerTreeHostImpl host_impl_; |
| 88 }; | 86 }; |
| 89 | 87 |
| 90 TEST_F(TiledLayerImplTest, EmptyQuadList) { | 88 TEST_F(TiledLayerImplTest, EmptyQuadList) { |
| 91 gfx::Size tile_size(90, 90); | 89 gfx::Size tile_size(90, 90); |
| 92 int num_tiles_x = 8; | 90 int num_tiles_x = 8; |
| 93 int num_tiles_y = 4; | 91 int num_tiles_y = 4; |
| 94 gfx::Size layer_size(tile_size.width() * num_tiles_x, | 92 gfx::Size layer_size(tile_size.width() * num_tiles_x, |
| 95 tile_size.height() * num_tiles_y); | 93 tile_size.height() * num_tiles_y); |
| 96 | 94 |
| 97 // Verify default layer does creates quads | 95 // Verify default layer does creates quads |
| 98 { | 96 { |
| 99 scoped_ptr<TiledLayerImpl> layer = | 97 scoped_ptr<TiledLayerImpl> layer = |
| 100 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 98 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 101 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 99 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 102 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 100 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 103 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 104 | 101 |
| 105 AppendQuadsData data; | 102 AppendQuadsData data; |
| 106 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); | 103 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); |
| 107 layer->AppendQuads(&quad_culler, &data); | 104 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 108 layer->DidDraw(NULL); | 105 layer->DidDraw(NULL); |
| 109 unsigned num_tiles = num_tiles_x * num_tiles_y; | 106 unsigned num_tiles = num_tiles_x * num_tiles_y; |
| 110 EXPECT_EQ(quad_culler.quad_list().size(), num_tiles); | 107 EXPECT_EQ(render_pass->quad_list.size(), num_tiles); |
| 111 } | 108 } |
| 112 | 109 |
| 113 // Layer with empty visible layer rect produces no quads | 110 // Layer with empty visible layer rect produces no quads |
| 114 { | 111 { |
| 115 scoped_ptr<TiledLayerImpl> layer = | 112 scoped_ptr<TiledLayerImpl> layer = |
| 116 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 113 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 117 layer->draw_properties().visible_content_rect = gfx::Rect(); | 114 layer->draw_properties().visible_content_rect = gfx::Rect(); |
| 118 | 115 |
| 119 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 116 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 120 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 117 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 121 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 122 | 118 |
| 123 EXPECT_FALSE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); | 119 EXPECT_FALSE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); |
| 124 } | 120 } |
| 125 | 121 |
| 126 // Layer with non-intersecting visible layer rect produces no quads | 122 // Layer with non-intersecting visible layer rect produces no quads |
| 127 { | 123 { |
| 128 scoped_ptr<TiledLayerImpl> layer = | 124 scoped_ptr<TiledLayerImpl> layer = |
| 129 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 125 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 130 | 126 |
| 131 gfx::Rect outside_bounds(-100, -100, 50, 50); | 127 gfx::Rect outside_bounds(-100, -100, 50, 50); |
| 132 layer->draw_properties().visible_content_rect = outside_bounds; | 128 layer->draw_properties().visible_content_rect = outside_bounds; |
| 133 | 129 |
| 134 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 130 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 135 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 131 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 136 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 137 | 132 |
| 138 AppendQuadsData data; | 133 AppendQuadsData data; |
| 139 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); | 134 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); |
| 140 layer->AppendQuads(&quad_culler, &data); | 135 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 141 layer->DidDraw(NULL); | 136 layer->DidDraw(NULL); |
| 142 EXPECT_EQ(quad_culler.quad_list().size(), 0u); | 137 EXPECT_EQ(render_pass->quad_list.size(), 0u); |
| 143 } | 138 } |
| 144 | 139 |
| 145 // Layer with skips draw produces no quads | 140 // Layer with skips draw produces no quads |
| 146 { | 141 { |
| 147 scoped_ptr<TiledLayerImpl> layer = | 142 scoped_ptr<TiledLayerImpl> layer = |
| 148 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 143 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 149 layer->set_skips_draw(true); | 144 layer->set_skips_draw(true); |
| 150 | 145 |
| 151 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 146 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 152 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 147 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 153 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 154 | 148 |
| 155 AppendQuadsData data; | 149 AppendQuadsData data; |
| 156 layer->AppendQuads(&quad_culler, &data); | 150 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 157 EXPECT_EQ(quad_culler.quad_list().size(), 0u); | 151 EXPECT_EQ(render_pass->quad_list.size(), 0u); |
| 158 } | 152 } |
| 159 } | 153 } |
| 160 | 154 |
| 161 TEST_F(TiledLayerImplTest, Checkerboarding) { | 155 TEST_F(TiledLayerImplTest, Checkerboarding) { |
| 162 gfx::Size tile_size(10, 10); | 156 gfx::Size tile_size(10, 10); |
| 163 int num_tiles_x = 2; | 157 int num_tiles_x = 2; |
| 164 int num_tiles_y = 2; | 158 int num_tiles_y = 2; |
| 165 gfx::Size layer_size(tile_size.width() * num_tiles_x, | 159 gfx::Size layer_size(tile_size.width() * num_tiles_x, |
| 166 tile_size.height() * num_tiles_y); | 160 tile_size.height() * num_tiles_y); |
| 167 | 161 |
| 168 scoped_ptr<TiledLayerImpl> layer = | 162 scoped_ptr<TiledLayerImpl> layer = |
| 169 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 163 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 170 | 164 |
| 171 // No checkerboarding | 165 // No checkerboarding |
| 172 { | 166 { |
| 173 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 167 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 174 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 168 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 175 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 176 | 169 |
| 177 AppendQuadsData data; | 170 AppendQuadsData data; |
| 178 layer->AppendQuads(&quad_culler, &data); | 171 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 179 EXPECT_EQ(quad_culler.quad_list().size(), 4u); | 172 EXPECT_EQ(render_pass->quad_list.size(), 4u); |
| 180 EXPECT_EQ(0u, data.num_missing_tiles); | 173 EXPECT_EQ(0u, data.num_missing_tiles); |
| 181 | 174 |
| 182 for (size_t i = 0; i < quad_culler.quad_list().size(); ++i) | 175 for (size_t i = 0; i < render_pass->quad_list.size(); ++i) |
| 183 EXPECT_EQ(quad_culler.quad_list()[i]->material, DrawQuad::TILED_CONTENT); | 176 EXPECT_EQ(render_pass->quad_list[i]->material, DrawQuad::TILED_CONTENT); |
| 184 } | 177 } |
| 185 | 178 |
| 186 for (int i = 0; i < num_tiles_x; ++i) | 179 for (int i = 0; i < num_tiles_x; ++i) |
| 187 for (int j = 0; j < num_tiles_y; ++j) | 180 for (int j = 0; j < num_tiles_y; ++j) |
| 188 layer->PushTileProperties(i, j, 0, gfx::Rect(), false); | 181 layer->PushTileProperties(i, j, 0, gfx::Rect(), false); |
| 189 | 182 |
| 190 // All checkerboarding | 183 // All checkerboarding |
| 191 { | 184 { |
| 192 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 185 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 193 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 186 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 194 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | |
| 195 | 187 |
| 196 AppendQuadsData data; | 188 AppendQuadsData data; |
| 197 layer->AppendQuads(&quad_culler, &data); | 189 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 198 EXPECT_LT(0u, data.num_missing_tiles); | 190 EXPECT_LT(0u, data.num_missing_tiles); |
| 199 EXPECT_EQ(quad_culler.quad_list().size(), 4u); | 191 EXPECT_EQ(render_pass->quad_list.size(), 4u); |
| 200 for (size_t i = 0; i < quad_culler.quad_list().size(); ++i) | 192 for (size_t i = 0; i < render_pass->quad_list.size(); ++i) |
| 201 EXPECT_NE(quad_culler.quad_list()[i]->material, DrawQuad::TILED_CONTENT); | 193 EXPECT_NE(render_pass->quad_list[i]->material, DrawQuad::TILED_CONTENT); |
| 202 } | 194 } |
| 203 } | 195 } |
| 204 | 196 |
| 205 // Test with both border texels and without. | 197 // Test with both border texels and without. |
| 206 #define WITH_AND_WITHOUT_BORDER_TEST(text_fixture_name) \ | 198 #define WITH_AND_WITHOUT_BORDER_TEST(text_fixture_name) \ |
| 207 TEST_F(TiledLayerImplBorderTest, text_fixture_name##NoBorders) { \ | 199 TEST_F(TiledLayerImplBorderTest, text_fixture_name##NoBorders) { \ |
| 208 text_fixture_name(LayerTilingData::NO_BORDER_TEXELS); \ | 200 text_fixture_name(LayerTilingData::NO_BORDER_TEXELS); \ |
| 209 } \ | 201 } \ |
| 210 TEST_F(TiledLayerImplBorderTest, text_fixture_name##HasBorders) { \ | 202 TEST_F(TiledLayerImplBorderTest, text_fixture_name##HasBorders) { \ |
| 211 text_fixture_name(LayerTilingData::HAS_BORDER_TEXELS); \ | 203 text_fixture_name(LayerTilingData::HAS_BORDER_TEXELS); \ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 occluded, | 378 occluded, |
| 387 &partially_occluded_count); | 379 &partially_occluded_count); |
| 388 // The layer outputs one quad, which is partially occluded. | 380 // The layer outputs one quad, which is partially occluded. |
| 389 EXPECT_EQ(100u - 10u, impl.quad_list().size()); | 381 EXPECT_EQ(100u - 10u, impl.quad_list().size()); |
| 390 EXPECT_EQ(10u + 10u, partially_occluded_count); | 382 EXPECT_EQ(10u + 10u, partially_occluded_count); |
| 391 } | 383 } |
| 392 } | 384 } |
| 393 | 385 |
| 394 } // namespace | 386 } // namespace |
| 395 } // namespace cc | 387 } // namespace cc |
| OLD | NEW |