[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "config.h" |
| 6 | |
[email protected] | da2c912 | 2012-10-20 23:13:06 | [diff] [blame] | 7 | #include "cc/tiled_layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 8 | |
[email protected] | aa0a9d3 | 2012-10-24 01:58:10 | [diff] [blame^] | 9 | #include "cc/append_quads_data.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 10 | #include "cc/layer_tiling_data.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 11 | #include "cc/single_thread_proxy.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 12 | #include "cc/test/layer_test_common.h" |
| 13 | #include "cc/test/mock_quad_culler.h" |
[email protected] | da2c912 | 2012-10-20 23:13:06 | [diff] [blame] | 14 | #include "cc/tile_draw_quad.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 15 | #include "testing/gmock/include/gmock/gmock.h" |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 18 | using namespace cc; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 19 | using namespace LayerTestCommon; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | |
| 21 | namespace { |
| 22 | |
| 23 | // Create a default tiled layer with textures for all tiles and a default |
| 24 | // visibility of the entire layer size. |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | static scoped_ptr<TiledLayerImpl> createLayer(const IntSize& tileSize, const IntSize& layerSize, LayerTilingData::BorderTexelOption borderTexels) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 27 | scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1); |
| 28 | scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, borderTexels); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 29 | tiler->setBounds(layerSize); |
| 30 | layer->setTilingData(*tiler); |
| 31 | layer->setSkipsDraw(false); |
| 32 | layer->setVisibleContentRect(IntRect(IntPoint(), layerSize)); |
| 33 | layer->setDrawOpacity(1); |
| 34 | layer->setBounds(layerSize); |
| 35 | layer->setContentBounds(layerSize); |
| 36 | layer->createRenderSurface(); |
| 37 | layer->setRenderTarget(layer.get()); |
| 38 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 39 | ResourceProvider::ResourceId resourceId = 1; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 40 | for (int i = 0; i < tiler->numTilesX(); ++i) |
| 41 | for (int j = 0; j < tiler->numTilesY(); ++j) |
[email protected] | fdc7693 | 2012-10-22 19:51:31 | [diff] [blame] | 42 | layer->pushTileProperties(i, j, resourceId++, IntRect(0, 0, 1, 1), false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 43 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 44 | return layer.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 47 | TEST(TiledLayerImplTest, emptyQuadList) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | { |
| 49 | DebugScopedSetImplThread scopedImplThread; |
| 50 | |
| 51 | const IntSize tileSize(90, 90); |
| 52 | const int numTilesX = 8; |
| 53 | const int numTilesY = 4; |
| 54 | const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY); |
| 55 | |
| 56 | // Verify default layer does creates quads |
| 57 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 58 | scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels); |
| 59 | MockQuadCuller quadCuller; |
| 60 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 61 | layer->appendQuads(quadCuller, data); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 62 | const unsigned numTiles = numTilesX * numTilesY; |
| 63 | EXPECT_EQ(quadCuller.quadList().size(), numTiles); |
| 64 | } |
| 65 | |
| 66 | // Layer with empty visible layer rect produces no quads |
| 67 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 68 | scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | layer->setVisibleContentRect(IntRect()); |
| 70 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 71 | MockQuadCuller quadCuller; |
| 72 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 73 | layer->appendQuads(quadCuller, data); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 74 | EXPECT_EQ(quadCuller.quadList().size(), 0u); |
| 75 | } |
| 76 | |
| 77 | // Layer with non-intersecting visible layer rect produces no quads |
| 78 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 79 | scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 80 | |
| 81 | IntRect outsideBounds(IntPoint(-100, -100), IntSize(50, 50)); |
| 82 | layer->setVisibleContentRect(outsideBounds); |
| 83 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 84 | MockQuadCuller quadCuller; |
| 85 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 86 | layer->appendQuads(quadCuller, data); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 87 | EXPECT_EQ(quadCuller.quadList().size(), 0u); |
| 88 | } |
| 89 | |
| 90 | // Layer with skips draw produces no quads |
| 91 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 92 | scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | layer->setSkipsDraw(true); |
| 94 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 95 | MockQuadCuller quadCuller; |
| 96 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 97 | layer->appendQuads(quadCuller, data); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 98 | EXPECT_EQ(quadCuller.quadList().size(), 0u); |
| 99 | } |
| 100 | } |
| 101 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 102 | TEST(TiledLayerImplTest, checkerboarding) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | { |
| 104 | DebugScopedSetImplThread scopedImplThread; |
| 105 | |
| 106 | const IntSize tileSize(10, 10); |
| 107 | const int numTilesX = 2; |
| 108 | const int numTilesY = 2; |
| 109 | const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY); |
| 110 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 111 | scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 112 | |
| 113 | // No checkerboarding |
| 114 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 115 | MockQuadCuller quadCuller; |
| 116 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 117 | layer->appendQuads(quadCuller, data); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 118 | EXPECT_EQ(quadCuller.quadList().size(), 4u); |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 119 | EXPECT_FALSE(data.hadMissingTiles); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 120 | |
| 121 | for (size_t i = 0; i < quadCuller.quadList().size(); ++i) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 122 | EXPECT_EQ(quadCuller.quadList()[i]->material(), DrawQuad::TiledContent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | for (int i = 0; i < numTilesX; ++i) |
| 126 | for (int j = 0; j < numTilesY; ++j) |
[email protected] | fdc7693 | 2012-10-22 19:51:31 | [diff] [blame] | 127 | layer->pushTileProperties(i, j, 0, IntRect(), false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 128 | |
| 129 | // All checkerboarding |
| 130 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 131 | MockQuadCuller quadCuller; |
| 132 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 133 | layer->appendQuads(quadCuller, data); |
| 134 | EXPECT_TRUE(data.hadMissingTiles); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 135 | EXPECT_EQ(quadCuller.quadList().size(), 4u); |
| 136 | for (size_t i = 0; i < quadCuller.quadList().size(); ++i) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 137 | EXPECT_NE(quadCuller.quadList()[i]->material(), DrawQuad::TiledContent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 141 | static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, IntSize tileSize, const IntSize& layerSize, LayerTilingData::BorderTexelOption borderTexelOption, const IntRect& visibleContentRect) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 142 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 143 | scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTexelOption); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | layer->setVisibleContentRect(visibleContentRect); |
| 145 | layer->setBounds(layerSize); |
| 146 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 147 | MockQuadCuller quadCuller(quads, sharedStates); |
| 148 | AppendQuadsData data; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 149 | layer->appendQuads(quadCuller, data); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // Test with both border texels and without. |
| 153 | #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 154 | TEST(TiledLayerImplTest, testFixtureName##NoBorders) \ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 155 | { \ |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 156 | testFixtureName(LayerTilingData::NoBorderTexels); \ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | } \ |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 158 | TEST(TiledLayerImplTest, testFixtureName##HasBorders) \ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 159 | { \ |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 160 | testFixtureName(LayerTilingData::HasBorderTexels);\ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 161 | } |
| 162 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 163 | static void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOption borders) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 164 | { |
| 165 | DebugScopedSetImplThread scopedImplThread; |
| 166 | |
| 167 | IntSize layerSize(1000, 1000); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 168 | QuadList quads; |
| 169 | SharedQuadStateList sharedStates; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 170 | getQuads(quads, sharedStates, IntSize(100, 100), layerSize, borders, IntRect(IntPoint(), layerSize)); |
| 171 | verifyQuadsExactlyCoverRect(quads, IntRect(IntPoint(), layerSize)); |
| 172 | } |
| 173 | WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries); |
| 174 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 175 | static void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOption borders) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 176 | { |
| 177 | DebugScopedSetImplThread scopedImplThread; |
| 178 | |
| 179 | // This rect intersects the middle 3x3 of the 5x5 tiles. |
| 180 | IntPoint topLeft(65, 73); |
| 181 | IntPoint bottomRight(182, 198); |
| 182 | IntRect visibleContentRect(topLeft, bottomRight - topLeft); |
| 183 | |
| 184 | IntSize layerSize(250, 250); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 185 | QuadList quads; |
| 186 | SharedQuadStateList sharedStates; |
| 187 | getQuads(quads, sharedStates, IntSize(50, 50), IntSize(250, 250), LayerTilingData::NoBorderTexels, visibleContentRect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 188 | verifyQuadsExactlyCoverRect(quads, visibleContentRect); |
| 189 | } |
| 190 | WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles); |
| 191 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 192 | static void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 193 | { |
| 194 | DebugScopedSetImplThread scopedImplThread; |
| 195 | |
| 196 | IntSize layerSize(220, 210); |
| 197 | IntRect visibleContentRect(IntPoint(), layerSize); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 198 | QuadList quads; |
| 199 | SharedQuadStateList sharedStates; |
| 200 | getQuads(quads, sharedStates, IntSize(100, 100), layerSize, LayerTilingData::NoBorderTexels, visibleContentRect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 201 | verifyQuadsExactlyCoverRect(quads, visibleContentRect); |
| 202 | } |
| 203 | WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds); |
| 204 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 205 | TEST(TiledLayerImplTest, textureInfoForLayerNoBorders) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 206 | { |
| 207 | DebugScopedSetImplThread scopedImplThread; |
| 208 | |
| 209 | IntSize tileSize(50, 50); |
| 210 | IntSize layerSize(250, 250); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 211 | QuadList quads; |
| 212 | SharedQuadStateList sharedStates; |
| 213 | getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorderTexels, IntRect(IntPoint(), layerSize)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 214 | |
| 215 | for (size_t i = 0; i < quads.size(); ++i) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 216 | ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i; |
| 217 | TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 218 | |
| 219 | EXPECT_NE(quad->resourceId(), 0u) << quadString << i; |
| 220 | EXPECT_EQ(quad->textureOffset(), IntPoint()) << quadString << i; |
| 221 | EXPECT_EQ(quad->textureSize(), tileSize) << quadString << i; |
[email protected] | 1fea814 | 2012-10-20 04:12:41 | [diff] [blame] | 222 | EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 226 | TEST(TiledLayerImplTest, tileOpaqueRectForLayerNoBorders) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 227 | { |
| 228 | DebugScopedSetImplThread scopedImplThread; |
| 229 | |
| 230 | IntSize tileSize(50, 50); |
| 231 | IntSize layerSize(250, 250); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 232 | QuadList quads; |
| 233 | SharedQuadStateList sharedStates; |
| 234 | getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorderTexels, IntRect(IntPoint(), layerSize)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 235 | |
| 236 | for (size_t i = 0; i < quads.size(); ++i) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 237 | ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i; |
| 238 | TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | |
[email protected] | 1fea814 | 2012-10-20 04:12:41 | [diff] [blame] | 240 | EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | } // namespace |