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