OLD | NEW |
| (Empty) |
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 | |
7 #include "CCTiledLayerImpl.h" | |
8 | |
9 #include "CCAppendQuadsData.h" | |
10 #include "CCLayerTestCommon.h" | |
11 #include "CCLayerTilingData.h" | |
12 #include "CCSingleThreadProxy.h" | |
13 #include "CCTileDrawQuad.h" | |
14 #include "MockCCQuadCuller.h" | |
15 #include "testing/gmock/include/gmock/gmock.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 using namespace cc; | |
19 using namespace CCLayerTestCommon; | |
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. | |
25 static scoped_ptr<CCTiledLayerImpl> createLayer(const IntSize& tileSize, const I
ntSize& layerSize, CCLayerTilingData::BorderTexelOption borderTexels) | |
26 { | |
27 scoped_ptr<CCTiledLayerImpl> layer = CCTiledLayerImpl::create(1); | |
28 OwnPtr<CCLayerTilingData> tiler = CCLayerTilingData::create(tileSize, border
Texels); | |
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 | |
39 CCResourceProvider::ResourceId resourceId = 1; | |
40 for (int i = 0; i < tiler->numTilesX(); ++i) | |
41 for (int j = 0; j < tiler->numTilesY(); ++j) | |
42 layer->pushTileProperties(i, j, resourceId++, IntRect(0, 0, 1, 1)); | |
43 | |
44 return layer.Pass(); | |
45 } | |
46 | |
47 TEST(CCTiledLayerImplTest, emptyQuadList) | |
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() * nu
mTilesY); | |
55 | |
56 // Verify default layer does creates quads | |
57 { | |
58 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); | |
59 MockCCQuadCuller quadCuller; | |
60 CCAppendQuadsData data; | |
61 layer->appendQuads(quadCuller, data); | |
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 { | |
68 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); | |
69 layer->setVisibleContentRect(IntRect()); | |
70 | |
71 MockCCQuadCuller quadCuller; | |
72 CCAppendQuadsData data; | |
73 layer->appendQuads(quadCuller, data); | |
74 EXPECT_EQ(quadCuller.quadList().size(), 0u); | |
75 } | |
76 | |
77 // Layer with non-intersecting visible layer rect produces no quads | |
78 { | |
79 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); | |
80 | |
81 IntRect outsideBounds(IntPoint(-100, -100), IntSize(50, 50)); | |
82 layer->setVisibleContentRect(outsideBounds); | |
83 | |
84 MockCCQuadCuller quadCuller; | |
85 CCAppendQuadsData data; | |
86 layer->appendQuads(quadCuller, data); | |
87 EXPECT_EQ(quadCuller.quadList().size(), 0u); | |
88 } | |
89 | |
90 // Layer with skips draw produces no quads | |
91 { | |
92 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CC
LayerTilingData::NoBorderTexels); | |
93 layer->setSkipsDraw(true); | |
94 | |
95 MockCCQuadCuller quadCuller; | |
96 CCAppendQuadsData data; | |
97 layer->appendQuads(quadCuller, data); | |
98 EXPECT_EQ(quadCuller.quadList().size(), 0u); | |
99 } | |
100 } | |
101 | |
102 TEST(CCTiledLayerImplTest, checkerboarding) | |
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() * nu
mTilesY); | |
110 | |
111 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, CCLaye
rTilingData::NoBorderTexels); | |
112 | |
113 // No checkerboarding | |
114 { | |
115 MockCCQuadCuller quadCuller; | |
116 CCAppendQuadsData data; | |
117 layer->appendQuads(quadCuller, data); | |
118 EXPECT_EQ(quadCuller.quadList().size(), 4u); | |
119 EXPECT_FALSE(data.hadMissingTiles); | |
120 | |
121 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) | |
122 EXPECT_EQ(quadCuller.quadList()[i]->material(), CCDrawQuad::TiledCon
tent); | |
123 } | |
124 | |
125 for (int i = 0; i < numTilesX; ++i) | |
126 for (int j = 0; j < numTilesY; ++j) | |
127 layer->pushTileProperties(i, j, 0, IntRect()); | |
128 | |
129 // All checkerboarding | |
130 { | |
131 MockCCQuadCuller quadCuller; | |
132 CCAppendQuadsData data; | |
133 layer->appendQuads(quadCuller, data); | |
134 EXPECT_TRUE(data.hadMissingTiles); | |
135 EXPECT_EQ(quadCuller.quadList().size(), 4u); | |
136 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) | |
137 EXPECT_NE(quadCuller.quadList()[i]->material(), CCDrawQuad::TiledCon
tent); | |
138 } | |
139 } | |
140 | |
141 static void getQuads(CCQuadList& quads, CCSharedQuadStateList& sharedStates, Int
Size tileSize, const IntSize& layerSize, CCLayerTilingData::BorderTexelOption bo
rderTexelOption, const IntRect& visibleContentRect) | |
142 { | |
143 scoped_ptr<CCTiledLayerImpl> layer = createLayer(tileSize, layerSize, border
TexelOption); | |
144 layer->setVisibleContentRect(visibleContentRect); | |
145 layer->setBounds(layerSize); | |
146 | |
147 MockCCQuadCuller quadCuller(quads, sharedStates); | |
148 CCAppendQuadsData data; | |
149 layer->appendQuads(quadCuller, data); | |
150 } | |
151 | |
152 // Test with both border texels and without. | |
153 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ | |
154 TEST(CCTiledLayerImplTest, testFixtureName##NoBorders) \ | |
155 { \ | |
156 testFixtureName(CCLayerTilingData::NoBorderTexels); \ | |
157 } \ | |
158 TEST(CCTiledLayerImplTest, testFixtureName##HasBorders) \ | |
159 { \ | |
160 testFixtureName(CCLayerTilingData::HasBorderTexels);\ | |
161 } | |
162 | |
163 static void coverageVisibleRectOnTileBoundaries(CCLayerTilingData::BorderTexelOp
tion borders) | |
164 { | |
165 DebugScopedSetImplThread scopedImplThread; | |
166 | |
167 IntSize layerSize(1000, 1000); | |
168 CCQuadList quads; | |
169 CCSharedQuadStateList sharedStates; | |
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 | |
175 static void coverageVisibleRectIntersectsTiles(CCLayerTilingData::BorderTexelOpt
ion borders) | |
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); | |
185 CCQuadList quads; | |
186 CCSharedQuadStateList sharedStates; | |
187 getQuads(quads, sharedStates, IntSize(50, 50), IntSize(250, 250), CCLayerTil
ingData::NoBorderTexels, visibleContentRect); | |
188 verifyQuadsExactlyCoverRect(quads, visibleContentRect); | |
189 } | |
190 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles); | |
191 | |
192 static void coverageVisibleRectIntersectsBounds(CCLayerTilingData::BorderTexelOp
tion borders) | |
193 { | |
194 DebugScopedSetImplThread scopedImplThread; | |
195 | |
196 IntSize layerSize(220, 210); | |
197 IntRect visibleContentRect(IntPoint(), layerSize); | |
198 CCQuadList quads; | |
199 CCSharedQuadStateList sharedStates; | |
200 getQuads(quads, sharedStates, IntSize(100, 100), layerSize, CCLayerTilingDat
a::NoBorderTexels, visibleContentRect); | |
201 verifyQuadsExactlyCoverRect(quads, visibleContentRect); | |
202 } | |
203 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds); | |
204 | |
205 TEST(CCTiledLayerImplTest, textureInfoForLayerNoBorders) | |
206 { | |
207 DebugScopedSetImplThread scopedImplThread; | |
208 | |
209 IntSize tileSize(50, 50); | |
210 IntSize layerSize(250, 250); | |
211 CCQuadList quads; | |
212 CCSharedQuadStateList sharedStates; | |
213 getQuads(quads, sharedStates, tileSize, layerSize, CCLayerTilingData::NoBord
erTexels, IntRect(IntPoint(), layerSize)); | |
214 | |
215 for (size_t i = 0; i < quads.size(); ++i) { | |
216 ASSERT_EQ(quads[i]->material(), CCDrawQuad::TiledContent) << quadString
<< i; | |
217 CCTileDrawQuad* quad = static_cast<CCTileDrawQuad*>(quads[i]); | |
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; | |
222 EXPECT_EQ(IntRect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; | |
223 } | |
224 } | |
225 | |
226 TEST(CCTiledLayerImplTest, tileOpaqueRectForLayerNoBorders) | |
227 { | |
228 DebugScopedSetImplThread scopedImplThread; | |
229 | |
230 IntSize tileSize(50, 50); | |
231 IntSize layerSize(250, 250); | |
232 CCQuadList quads; | |
233 CCSharedQuadStateList sharedStates; | |
234 getQuads(quads, sharedStates, tileSize, layerSize, CCLayerTilingData::NoBord
erTexels, IntRect(IntPoint(), layerSize)); | |
235 | |
236 for (size_t i = 0; i < quads.size(); ++i) { | |
237 ASSERT_EQ(quads[i]->material(), CCDrawQuad::TiledContent) << quadString
<< i; | |
238 CCTileDrawQuad* quad = static_cast<CCTileDrawQuad*>(quads[i]); | |
239 | |
240 EXPECT_EQ(IntRect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; | |
241 } | |
242 } | |
243 | |
244 } // namespace | |
OLD | NEW |