blob: e8c066f96132f56e3515b5a359d4720f2475d655 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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]da2c9122012-10-20 23:13:067#include "cc/tiled_layer_impl.h"
[email protected]94f206c12012-08-25 00:09:148
[email protected]aa0a9d32012-10-24 01:58:109#include "cc/append_quads_data.h"
[email protected]d50c6862012-10-23 02:08:3110#include "cc/layer_tiling_data.h"
[email protected]4456eee22012-10-19 18:16:3811#include "cc/single_thread_proxy.h"
[email protected]101441ce2012-10-16 01:45:0312#include "cc/test/layer_test_common.h"
13#include "cc/test/mock_quad_culler.h"
[email protected]da2c9122012-10-20 23:13:0614#include "cc/tile_draw_quad.h"
[email protected]7f0c53db2012-10-02 00:23:1815#include "testing/gmock/include/gmock/gmock.h"
16#include "testing/gtest/include/gtest/gtest.h"
[email protected]94f206c12012-08-25 00:09:1417
[email protected]9c88e562012-09-14 22:21:3018using namespace cc;
[email protected]96baf3e2012-10-22 23:09:5519using namespace LayerTestCommon;
[email protected]94f206c12012-08-25 00:09:1420
21namespace {
22
23// Create a default tiled layer with textures for all tiles and a default
24// visibility of the entire layer size.
[email protected]96baf3e2012-10-22 23:09:5525static scoped_ptr<TiledLayerImpl> createLayer(const IntSize& tileSize, const IntSize& layerSize, LayerTilingData::BorderTexelOption borderTexels)
[email protected]94f206c12012-08-25 00:09:1426{
[email protected]96baf3e2012-10-22 23:09:5527 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1);
28 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, borderTexels);
[email protected]94f206c12012-08-25 00:09:1429 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]96baf3e2012-10-22 23:09:5539 ResourceProvider::ResourceId resourceId = 1;
[email protected]94f206c12012-08-25 00:09:1440 for (int i = 0; i < tiler->numTilesX(); ++i)
41 for (int j = 0; j < tiler->numTilesY(); ++j)
[email protected]fdc76932012-10-22 19:51:3142 layer->pushTileProperties(i, j, resourceId++, IntRect(0, 0, 1, 1), false);
[email protected]94f206c12012-08-25 00:09:1443
[email protected]e0bd43a2012-10-12 16:54:2144 return layer.Pass();
[email protected]94f206c12012-08-25 00:09:1445}
46
[email protected]96baf3e2012-10-22 23:09:5547TEST(TiledLayerImplTest, emptyQuadList)
[email protected]94f206c12012-08-25 00:09:1448{
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]96baf3e2012-10-22 23:09:5558 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels);
59 MockQuadCuller quadCuller;
60 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:3061 layer->appendQuads(quadCuller, data);
[email protected]94f206c12012-08-25 00:09:1462 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]96baf3e2012-10-22 23:09:5568 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels);
[email protected]94f206c12012-08-25 00:09:1469 layer->setVisibleContentRect(IntRect());
70
[email protected]96baf3e2012-10-22 23:09:5571 MockQuadCuller quadCuller;
72 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:3073 layer->appendQuads(quadCuller, data);
[email protected]94f206c12012-08-25 00:09:1474 EXPECT_EQ(quadCuller.quadList().size(), 0u);
75 }
76
77 // Layer with non-intersecting visible layer rect produces no quads
78 {
[email protected]96baf3e2012-10-22 23:09:5579 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels);
[email protected]94f206c12012-08-25 00:09:1480
81 IntRect outsideBounds(IntPoint(-100, -100), IntSize(50, 50));
82 layer->setVisibleContentRect(outsideBounds);
83
[email protected]96baf3e2012-10-22 23:09:5584 MockQuadCuller quadCuller;
85 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:3086 layer->appendQuads(quadCuller, data);
[email protected]94f206c12012-08-25 00:09:1487 EXPECT_EQ(quadCuller.quadList().size(), 0u);
88 }
89
90 // Layer with skips draw produces no quads
91 {
[email protected]96baf3e2012-10-22 23:09:5592 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels);
[email protected]94f206c12012-08-25 00:09:1493 layer->setSkipsDraw(true);
94
[email protected]96baf3e2012-10-22 23:09:5595 MockQuadCuller quadCuller;
96 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:3097 layer->appendQuads(quadCuller, data);
[email protected]94f206c12012-08-25 00:09:1498 EXPECT_EQ(quadCuller.quadList().size(), 0u);
99 }
100}
101
[email protected]96baf3e2012-10-22 23:09:55102TEST(TiledLayerImplTest, checkerboarding)
[email protected]94f206c12012-08-25 00:09:14103{
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]96baf3e2012-10-22 23:09:55111 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTilingData::NoBorderTexels);
[email protected]94f206c12012-08-25 00:09:14112
113 // No checkerboarding
114 {
[email protected]96baf3e2012-10-22 23:09:55115 MockQuadCuller quadCuller;
116 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:30117 layer->appendQuads(quadCuller, data);
[email protected]94f206c12012-08-25 00:09:14118 EXPECT_EQ(quadCuller.quadList().size(), 4u);
[email protected]89228202012-08-29 03:20:30119 EXPECT_FALSE(data.hadMissingTiles);
[email protected]94f206c12012-08-25 00:09:14120
121 for (size_t i = 0; i < quadCuller.quadList().size(); ++i)
[email protected]96baf3e2012-10-22 23:09:55122 EXPECT_EQ(quadCuller.quadList()[i]->material(), DrawQuad::TiledContent);
[email protected]94f206c12012-08-25 00:09:14123 }
124
125 for (int i = 0; i < numTilesX; ++i)
126 for (int j = 0; j < numTilesY; ++j)
[email protected]fdc76932012-10-22 19:51:31127 layer->pushTileProperties(i, j, 0, IntRect(), false);
[email protected]94f206c12012-08-25 00:09:14128
129 // All checkerboarding
130 {
[email protected]96baf3e2012-10-22 23:09:55131 MockQuadCuller quadCuller;
132 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:30133 layer->appendQuads(quadCuller, data);
134 EXPECT_TRUE(data.hadMissingTiles);
[email protected]94f206c12012-08-25 00:09:14135 EXPECT_EQ(quadCuller.quadList().size(), 4u);
136 for (size_t i = 0; i < quadCuller.quadList().size(); ++i)
[email protected]96baf3e2012-10-22 23:09:55137 EXPECT_NE(quadCuller.quadList()[i]->material(), DrawQuad::TiledContent);
[email protected]94f206c12012-08-25 00:09:14138 }
139}
140
[email protected]96baf3e2012-10-22 23:09:55141static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, IntSize tileSize, const IntSize& layerSize, LayerTilingData::BorderTexelOption borderTexelOption, const IntRect& visibleContentRect)
[email protected]94f206c12012-08-25 00:09:14142{
[email protected]96baf3e2012-10-22 23:09:55143 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTexelOption);
[email protected]94f206c12012-08-25 00:09:14144 layer->setVisibleContentRect(visibleContentRect);
145 layer->setBounds(layerSize);
146
[email protected]96baf3e2012-10-22 23:09:55147 MockQuadCuller quadCuller(quads, sharedStates);
148 AppendQuadsData data;
[email protected]89228202012-08-29 03:20:30149 layer->appendQuads(quadCuller, data);
[email protected]94f206c12012-08-25 00:09:14150}
151
152// Test with both border texels and without.
153#define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \
[email protected]96baf3e2012-10-22 23:09:55154 TEST(TiledLayerImplTest, testFixtureName##NoBorders) \
[email protected]94f206c12012-08-25 00:09:14155 { \
[email protected]96baf3e2012-10-22 23:09:55156 testFixtureName(LayerTilingData::NoBorderTexels); \
[email protected]94f206c12012-08-25 00:09:14157 } \
[email protected]96baf3e2012-10-22 23:09:55158 TEST(TiledLayerImplTest, testFixtureName##HasBorders) \
[email protected]94f206c12012-08-25 00:09:14159 { \
[email protected]96baf3e2012-10-22 23:09:55160 testFixtureName(LayerTilingData::HasBorderTexels);\
[email protected]94f206c12012-08-25 00:09:14161 }
162
[email protected]96baf3e2012-10-22 23:09:55163static void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOption borders)
[email protected]94f206c12012-08-25 00:09:14164{
165 DebugScopedSetImplThread scopedImplThread;
166
167 IntSize layerSize(1000, 1000);
[email protected]96baf3e2012-10-22 23:09:55168 QuadList quads;
169 SharedQuadStateList sharedStates;
[email protected]94f206c12012-08-25 00:09:14170 getQuads(quads, sharedStates, IntSize(100, 100), layerSize, borders, IntRect(IntPoint(), layerSize));
171 verifyQuadsExactlyCoverRect(quads, IntRect(IntPoint(), layerSize));
172}
173WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries);
174
[email protected]96baf3e2012-10-22 23:09:55175static void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOption borders)
[email protected]94f206c12012-08-25 00:09:14176{
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]96baf3e2012-10-22 23:09:55185 QuadList quads;
186 SharedQuadStateList sharedStates;
187 getQuads(quads, sharedStates, IntSize(50, 50), IntSize(250, 250), LayerTilingData::NoBorderTexels, visibleContentRect);
[email protected]94f206c12012-08-25 00:09:14188 verifyQuadsExactlyCoverRect(quads, visibleContentRect);
189}
190WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles);
191
[email protected]96baf3e2012-10-22 23:09:55192static void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders)
[email protected]94f206c12012-08-25 00:09:14193{
194 DebugScopedSetImplThread scopedImplThread;
195
196 IntSize layerSize(220, 210);
197 IntRect visibleContentRect(IntPoint(), layerSize);
[email protected]96baf3e2012-10-22 23:09:55198 QuadList quads;
199 SharedQuadStateList sharedStates;
200 getQuads(quads, sharedStates, IntSize(100, 100), layerSize, LayerTilingData::NoBorderTexels, visibleContentRect);
[email protected]94f206c12012-08-25 00:09:14201 verifyQuadsExactlyCoverRect(quads, visibleContentRect);
202}
203WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds);
204
[email protected]96baf3e2012-10-22 23:09:55205TEST(TiledLayerImplTest, textureInfoForLayerNoBorders)
[email protected]94f206c12012-08-25 00:09:14206{
207 DebugScopedSetImplThread scopedImplThread;
208
209 IntSize tileSize(50, 50);
210 IntSize layerSize(250, 250);
[email protected]96baf3e2012-10-22 23:09:55211 QuadList quads;
212 SharedQuadStateList sharedStates;
213 getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorderTexels, IntRect(IntPoint(), layerSize));
[email protected]94f206c12012-08-25 00:09:14214
215 for (size_t i = 0; i < quads.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55216 ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i;
217 TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]);
[email protected]94f206c12012-08-25 00:09:14218
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]1fea8142012-10-20 04:12:41222 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i;
[email protected]94f206c12012-08-25 00:09:14223 }
224}
225
[email protected]96baf3e2012-10-22 23:09:55226TEST(TiledLayerImplTest, tileOpaqueRectForLayerNoBorders)
[email protected]94f206c12012-08-25 00:09:14227{
228 DebugScopedSetImplThread scopedImplThread;
229
230 IntSize tileSize(50, 50);
231 IntSize layerSize(250, 250);
[email protected]96baf3e2012-10-22 23:09:55232 QuadList quads;
233 SharedQuadStateList sharedStates;
234 getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorderTexels, IntRect(IntPoint(), layerSize));
[email protected]94f206c12012-08-25 00:09:14235
236 for (size_t i = 0; i < quads.size(); ++i) {
[email protected]96baf3e2012-10-22 23:09:55237 ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i;
238 TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]);
[email protected]94f206c12012-08-25 00:09:14239
[email protected]1fea8142012-10-20 04:12:41240 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i;
[email protected]94f206c12012-08-25 00:09:14241 }
242}
243
244} // namespace