| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void GetQuads(RenderPass* render_pass, | 63 void GetQuads(RenderPass* render_pass, |
| 64 const gfx::Size& tile_size, | 64 const gfx::Size& tile_size, |
| 65 const gfx::Size& layer_size, | 65 const gfx::Size& layer_size, |
| 66 LayerTilingData::BorderTexelOption border_texel_option, | 66 LayerTilingData::BorderTexelOption border_texel_option, |
| 67 const gfx::Rect& visible_content_rect) { | 67 const gfx::Rect& visible_content_rect) { |
| 68 scoped_ptr<TiledLayerImpl> layer = | 68 scoped_ptr<TiledLayerImpl> layer = |
| 69 CreateLayer(tile_size, layer_size, border_texel_option); | 69 CreateLayer(tile_size, layer_size, border_texel_option); |
| 70 layer->draw_properties().visible_content_rect = visible_content_rect; | 70 layer->draw_properties().visible_content_rect = visible_content_rect; |
| 71 layer->SetBounds(layer_size); | 71 layer->SetBounds(layer_size); |
| 72 | 72 |
| 73 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 74 AppendQuadsData data; | 73 AppendQuadsData data; |
| 75 layer->AppendQuads(render_pass, occlusion_tracker, &data); | 74 layer->AppendQuads(render_pass, Occlusion(), &data); |
| 76 } | 75 } |
| 77 | 76 |
| 78 protected: | 77 protected: |
| 79 FakeImplProxy proxy_; | 78 FakeImplProxy proxy_; |
| 80 TestSharedBitmapManager shared_bitmap_manager_; | 79 TestSharedBitmapManager shared_bitmap_manager_; |
| 81 FakeLayerTreeHostImpl host_impl_; | 80 FakeLayerTreeHostImpl host_impl_; |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 TEST_F(TiledLayerImplTest, EmptyQuadList) { | 83 TEST_F(TiledLayerImplTest, EmptyQuadList) { |
| 85 gfx::Size tile_size(90, 90); | 84 gfx::Size tile_size(90, 90); |
| 86 int num_tiles_x = 8; | 85 int num_tiles_x = 8; |
| 87 int num_tiles_y = 4; | 86 int num_tiles_y = 4; |
| 88 gfx::Size layer_size(tile_size.width() * num_tiles_x, | 87 gfx::Size layer_size(tile_size.width() * num_tiles_x, |
| 89 tile_size.height() * num_tiles_y); | 88 tile_size.height() * num_tiles_y); |
| 90 | 89 |
| 91 // Verify default layer does creates quads | 90 // Verify default layer does creates quads |
| 92 { | 91 { |
| 93 scoped_ptr<TiledLayerImpl> layer = | 92 scoped_ptr<TiledLayerImpl> layer = |
| 94 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 93 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 95 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 96 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 94 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 97 | 95 |
| 98 AppendQuadsData data; | 96 AppendQuadsData data; |
| 99 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); | 97 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); |
| 100 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 98 layer->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 101 layer->DidDraw(NULL); | 99 layer->DidDraw(NULL); |
| 102 unsigned num_tiles = num_tiles_x * num_tiles_y; | 100 unsigned num_tiles = num_tiles_x * num_tiles_y; |
| 103 EXPECT_EQ(render_pass->quad_list.size(), num_tiles); | 101 EXPECT_EQ(render_pass->quad_list.size(), num_tiles); |
| 104 } | 102 } |
| 105 | 103 |
| 106 // Layer with empty visible layer rect produces no quads | 104 // Layer with empty visible layer rect produces no quads |
| 107 { | 105 { |
| 108 scoped_ptr<TiledLayerImpl> layer = | 106 scoped_ptr<TiledLayerImpl> layer = |
| 109 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 107 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 110 layer->draw_properties().visible_content_rect = gfx::Rect(); | 108 layer->draw_properties().visible_content_rect = gfx::Rect(); |
| 111 | 109 |
| 112 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 113 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 110 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 114 | 111 |
| 115 EXPECT_FALSE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); | 112 EXPECT_FALSE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); |
| 116 } | 113 } |
| 117 | 114 |
| 118 // Layer with non-intersecting visible layer rect produces no quads | 115 // Layer with non-intersecting visible layer rect produces no quads |
| 119 { | 116 { |
| 120 scoped_ptr<TiledLayerImpl> layer = | 117 scoped_ptr<TiledLayerImpl> layer = |
| 121 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 118 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 122 | 119 |
| 123 gfx::Rect outside_bounds(-100, -100, 50, 50); | 120 gfx::Rect outside_bounds(-100, -100, 50, 50); |
| 124 layer->draw_properties().visible_content_rect = outside_bounds; | 121 layer->draw_properties().visible_content_rect = outside_bounds; |
| 125 | 122 |
| 126 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 127 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 123 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 128 | 124 |
| 129 AppendQuadsData data; | 125 AppendQuadsData data; |
| 130 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); | 126 EXPECT_TRUE(layer->WillDraw(DRAW_MODE_HARDWARE, NULL)); |
| 131 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 127 layer->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 132 layer->DidDraw(NULL); | 128 layer->DidDraw(NULL); |
| 133 EXPECT_EQ(render_pass->quad_list.size(), 0u); | 129 EXPECT_EQ(render_pass->quad_list.size(), 0u); |
| 134 } | 130 } |
| 135 | 131 |
| 136 // Layer with skips draw produces no quads | 132 // Layer with skips draw produces no quads |
| 137 { | 133 { |
| 138 scoped_ptr<TiledLayerImpl> layer = | 134 scoped_ptr<TiledLayerImpl> layer = |
| 139 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 135 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 140 layer->set_skips_draw(true); | 136 layer->set_skips_draw(true); |
| 141 | 137 |
| 142 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 143 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 138 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 144 | 139 |
| 145 AppendQuadsData data; | 140 AppendQuadsData data; |
| 146 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 141 layer->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 147 EXPECT_EQ(render_pass->quad_list.size(), 0u); | 142 EXPECT_EQ(render_pass->quad_list.size(), 0u); |
| 148 } | 143 } |
| 149 } | 144 } |
| 150 | 145 |
| 151 TEST_F(TiledLayerImplTest, Checkerboarding) { | 146 TEST_F(TiledLayerImplTest, Checkerboarding) { |
| 152 gfx::Size tile_size(10, 10); | 147 gfx::Size tile_size(10, 10); |
| 153 int num_tiles_x = 2; | 148 int num_tiles_x = 2; |
| 154 int num_tiles_y = 2; | 149 int num_tiles_y = 2; |
| 155 gfx::Size layer_size(tile_size.width() * num_tiles_x, | 150 gfx::Size layer_size(tile_size.width() * num_tiles_x, |
| 156 tile_size.height() * num_tiles_y); | 151 tile_size.height() * num_tiles_y); |
| 157 | 152 |
| 158 scoped_ptr<TiledLayerImpl> layer = | 153 scoped_ptr<TiledLayerImpl> layer = |
| 159 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); | 154 CreateLayer(tile_size, layer_size, LayerTilingData::NO_BORDER_TEXELS); |
| 160 | 155 |
| 161 // No checkerboarding | 156 // No checkerboarding |
| 162 { | 157 { |
| 163 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 164 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 158 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 165 | 159 |
| 166 AppendQuadsData data; | 160 AppendQuadsData data; |
| 167 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 161 layer->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 168 EXPECT_EQ(render_pass->quad_list.size(), 4u); | 162 EXPECT_EQ(render_pass->quad_list.size(), 4u); |
| 169 EXPECT_EQ(0u, data.num_missing_tiles); | 163 EXPECT_EQ(0u, data.num_missing_tiles); |
| 170 | 164 |
| 171 for (const auto& quad : render_pass->quad_list) | 165 for (const auto& quad : render_pass->quad_list) |
| 172 EXPECT_EQ(quad.material, DrawQuad::TILED_CONTENT); | 166 EXPECT_EQ(quad.material, DrawQuad::TILED_CONTENT); |
| 173 } | 167 } |
| 174 | 168 |
| 175 for (int i = 0; i < num_tiles_x; ++i) | 169 for (int i = 0; i < num_tiles_x; ++i) |
| 176 for (int j = 0; j < num_tiles_y; ++j) | 170 for (int j = 0; j < num_tiles_y; ++j) |
| 177 layer->PushTileProperties(i, j, 0, false); | 171 layer->PushTileProperties(i, j, 0, false); |
| 178 | 172 |
| 179 // All checkerboarding | 173 // All checkerboarding |
| 180 { | 174 { |
| 181 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 182 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 175 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 183 | 176 |
| 184 AppendQuadsData data; | 177 AppendQuadsData data; |
| 185 layer->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 178 layer->AppendQuads(render_pass.get(), Occlusion(), &data); |
| 186 EXPECT_LT(0u, data.num_missing_tiles); | 179 EXPECT_LT(0u, data.num_missing_tiles); |
| 187 EXPECT_EQ(render_pass->quad_list.size(), 4u); | 180 EXPECT_EQ(render_pass->quad_list.size(), 4u); |
| 188 for (const auto& quad : render_pass->quad_list) | 181 for (const auto& quad : render_pass->quad_list) |
| 189 EXPECT_NE(quad.material, DrawQuad::TILED_CONTENT); | 182 EXPECT_NE(quad.material, DrawQuad::TILED_CONTENT); |
| 190 } | 183 } |
| 191 } | 184 } |
| 192 | 185 |
| 193 // Test with both border texels and without. | 186 // Test with both border texels and without. |
| 194 #define WITH_AND_WITHOUT_BORDER_TEST(text_fixture_name) \ | 187 #define WITH_AND_WITHOUT_BORDER_TEST(text_fixture_name) \ |
| 195 TEST_F(TiledLayerImplBorderTest, text_fixture_name##NoBorders) { \ | 188 TEST_F(TiledLayerImplBorderTest, text_fixture_name##NoBorders) { \ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 LayerTestCommon::VerifyQuadsAreOccluded( | 363 LayerTestCommon::VerifyQuadsAreOccluded( |
| 371 impl.quad_list(), occluded, &partially_occluded_count); | 364 impl.quad_list(), occluded, &partially_occluded_count); |
| 372 // The layer outputs one quad, which is partially occluded. | 365 // The layer outputs one quad, which is partially occluded. |
| 373 EXPECT_EQ(100u - 10u, impl.quad_list().size()); | 366 EXPECT_EQ(100u - 10u, impl.quad_list().size()); |
| 374 EXPECT_EQ(10u + 10u, partially_occluded_count); | 367 EXPECT_EQ(10u + 10u, partially_occluded_count); |
| 375 } | 368 } |
| 376 } | 369 } |
| 377 | 370 |
| 378 } // namespace | 371 } // namespace |
| 379 } // namespace cc | 372 } // namespace cc |
| OLD | NEW |