Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: cc/tiled_layer_impl_unittest.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScaleAsVector Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tiled_layer_impl.cc ('k') | cc/tiled_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/tiled_layer_impl.h" 7 #include "cc/tiled_layer_impl.h"
8 8
9 #include "cc/append_quads_data.h" 9 #include "cc/append_quads_data.h"
10 #include "cc/layer_tiling_data.h" 10 #include "cc/layer_tiling_data.h"
11 #include "cc/single_thread_proxy.h" 11 #include "cc/single_thread_proxy.h"
12 #include "cc/test/layer_test_common.h" 12 #include "cc/test/layer_test_common.h"
13 #include "cc/test/mock_quad_culler.h" 13 #include "cc/test/mock_quad_culler.h"
14 #include "cc/tile_draw_quad.h" 14 #include "cc/tile_draw_quad.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using namespace cc; 18 using namespace cc;
19 using namespace LayerTestCommon; 19 using namespace LayerTestCommon;
20 20
21 namespace { 21 namespace {
22 22
23 // Create a default tiled layer with textures for all tiles and a default 23 // Create a default tiled layer with textures for all tiles and a default
24 // visibility of the entire layer size. 24 // visibility of the entire layer size.
25 static scoped_ptr<TiledLayerImpl> createLayer(const IntSize& tileSize, const Int Size& layerSize, LayerTilingData::BorderTexelOption borderTexels) 25 static scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const g fx::Size& layerSize, LayerTilingData::BorderTexelOption borderTexels)
26 { 26 {
27 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1); 27 scoped_ptr<TiledLayerImpl> layer = TiledLayerImpl::create(1);
28 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, border Texels); 28 scoped_ptr<LayerTilingData> tiler = LayerTilingData::create(tileSize, border Texels);
29 tiler->setBounds(layerSize); 29 tiler->setBounds(layerSize);
30 layer->setTilingData(*tiler); 30 layer->setTilingData(*tiler);
31 layer->setSkipsDraw(false); 31 layer->setSkipsDraw(false);
32 layer->setVisibleContentRect(IntRect(IntPoint(), layerSize)); 32 layer->setVisibleContentRect(gfx::Rect(gfx::Point(), layerSize));
33 layer->setDrawOpacity(1); 33 layer->setDrawOpacity(1);
34 layer->setBounds(layerSize); 34 layer->setBounds(layerSize);
35 layer->setContentBounds(layerSize); 35 layer->setContentBounds(layerSize);
36 layer->createRenderSurface(); 36 layer->createRenderSurface();
37 layer->setRenderTarget(layer.get()); 37 layer->setRenderTarget(layer.get());
38 38
39 ResourceProvider::ResourceId resourceId = 1; 39 ResourceProvider::ResourceId resourceId = 1;
40 for (int i = 0; i < tiler->numTilesX(); ++i) 40 for (int i = 0; i < tiler->numTilesX(); ++i)
41 for (int j = 0; j < tiler->numTilesY(); ++j) 41 for (int j = 0; j < tiler->numTilesY(); ++j)
42 layer->pushTileProperties(i, j, resourceId++, IntRect(0, 0, 1, 1), f alse); 42 layer->pushTileProperties(i, j, resourceId++, gfx::Rect(0, 0, 1, 1), false);
43 43
44 return layer.Pass(); 44 return layer.Pass();
45 } 45 }
46 46
47 TEST(TiledLayerImplTest, emptyQuadList) 47 TEST(TiledLayerImplTest, emptyQuadList)
48 { 48 {
49 DebugScopedSetImplThread scopedImplThread; 49 DebugScopedSetImplThread scopedImplThread;
50 50
51 const IntSize tileSize(90, 90); 51 const gfx::Size tileSize(90, 90);
52 const int numTilesX = 8; 52 const int numTilesX = 8;
53 const int numTilesY = 4; 53 const int numTilesY = 4;
54 const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * nu mTilesY); 54 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY);
55 55
56 // Verify default layer does creates quads 56 // Verify default layer does creates quads
57 { 57 {
58 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 58 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
59 MockQuadCuller quadCuller; 59 MockQuadCuller quadCuller;
60 AppendQuadsData data; 60 AppendQuadsData data;
61 layer->appendQuads(quadCuller, data); 61 layer->appendQuads(quadCuller, data);
62 const unsigned numTiles = numTilesX * numTilesY; 62 const unsigned numTiles = numTilesX * numTilesY;
63 EXPECT_EQ(quadCuller.quadList().size(), numTiles); 63 EXPECT_EQ(quadCuller.quadList().size(), numTiles);
64 } 64 }
65 65
66 // Layer with empty visible layer rect produces no quads 66 // Layer with empty visible layer rect produces no quads
67 { 67 {
68 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 68 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
69 layer->setVisibleContentRect(IntRect()); 69 layer->setVisibleContentRect(gfx::Rect());
70 70
71 MockQuadCuller quadCuller; 71 MockQuadCuller quadCuller;
72 AppendQuadsData data; 72 AppendQuadsData data;
73 layer->appendQuads(quadCuller, data); 73 layer->appendQuads(quadCuller, data);
74 EXPECT_EQ(quadCuller.quadList().size(), 0u); 74 EXPECT_EQ(quadCuller.quadList().size(), 0u);
75 } 75 }
76 76
77 // Layer with non-intersecting visible layer rect produces no quads 77 // Layer with non-intersecting visible layer rect produces no quads
78 { 78 {
79 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 79 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
80 80
81 IntRect outsideBounds(IntPoint(-100, -100), IntSize(50, 50)); 81 gfx::Rect outsideBounds(gfx::Point(-100, -100), gfx::Size(50, 50));
82 layer->setVisibleContentRect(outsideBounds); 82 layer->setVisibleContentRect(outsideBounds);
83 83
84 MockQuadCuller quadCuller; 84 MockQuadCuller quadCuller;
85 AppendQuadsData data; 85 AppendQuadsData data;
86 layer->appendQuads(quadCuller, data); 86 layer->appendQuads(quadCuller, data);
87 EXPECT_EQ(quadCuller.quadList().size(), 0u); 87 EXPECT_EQ(quadCuller.quadList().size(), 0u);
88 } 88 }
89 89
90 // Layer with skips draw produces no quads 90 // Layer with skips draw produces no quads
91 { 91 {
92 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels); 92 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, Laye rTilingData::NoBorderTexels);
93 layer->setSkipsDraw(true); 93 layer->setSkipsDraw(true);
94 94
95 MockQuadCuller quadCuller; 95 MockQuadCuller quadCuller;
96 AppendQuadsData data; 96 AppendQuadsData data;
97 layer->appendQuads(quadCuller, data); 97 layer->appendQuads(quadCuller, data);
98 EXPECT_EQ(quadCuller.quadList().size(), 0u); 98 EXPECT_EQ(quadCuller.quadList().size(), 0u);
99 } 99 }
100 } 100 }
101 101
102 TEST(TiledLayerImplTest, checkerboarding) 102 TEST(TiledLayerImplTest, checkerboarding)
103 { 103 {
104 DebugScopedSetImplThread scopedImplThread; 104 DebugScopedSetImplThread scopedImplThread;
105 105
106 const IntSize tileSize(10, 10); 106 const gfx::Size tileSize(10, 10);
107 const int numTilesX = 2; 107 const int numTilesX = 2;
108 const int numTilesY = 2; 108 const int numTilesY = 2;
109 const IntSize layerSize(tileSize.width() * numTilesX, tileSize.height() * nu mTilesY); 109 const gfx::Size layerSize(tileSize.width() * numTilesX, tileSize.height() * numTilesY);
110 110
111 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTil ingData::NoBorderTexels); 111 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, LayerTil ingData::NoBorderTexels);
112 112
113 // No checkerboarding 113 // No checkerboarding
114 { 114 {
115 MockQuadCuller quadCuller; 115 MockQuadCuller quadCuller;
116 AppendQuadsData data; 116 AppendQuadsData data;
117 layer->appendQuads(quadCuller, data); 117 layer->appendQuads(quadCuller, data);
118 EXPECT_EQ(quadCuller.quadList().size(), 4u); 118 EXPECT_EQ(quadCuller.quadList().size(), 4u);
119 EXPECT_FALSE(data.hadMissingTiles); 119 EXPECT_FALSE(data.hadMissingTiles);
120 120
121 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) 121 for (size_t i = 0; i < quadCuller.quadList().size(); ++i)
122 EXPECT_EQ(quadCuller.quadList()[i]->material(), DrawQuad::TiledConte nt); 122 EXPECT_EQ(quadCuller.quadList()[i]->material(), DrawQuad::TiledConte nt);
123 } 123 }
124 124
125 for (int i = 0; i < numTilesX; ++i) 125 for (int i = 0; i < numTilesX; ++i)
126 for (int j = 0; j < numTilesY; ++j) 126 for (int j = 0; j < numTilesY; ++j)
127 layer->pushTileProperties(i, j, 0, IntRect(), false); 127 layer->pushTileProperties(i, j, 0, gfx::Rect(), false);
128 128
129 // All checkerboarding 129 // All checkerboarding
130 { 130 {
131 MockQuadCuller quadCuller; 131 MockQuadCuller quadCuller;
132 AppendQuadsData data; 132 AppendQuadsData data;
133 layer->appendQuads(quadCuller, data); 133 layer->appendQuads(quadCuller, data);
134 EXPECT_TRUE(data.hadMissingTiles); 134 EXPECT_TRUE(data.hadMissingTiles);
135 EXPECT_EQ(quadCuller.quadList().size(), 4u); 135 EXPECT_EQ(quadCuller.quadList().size(), 4u);
136 for (size_t i = 0; i < quadCuller.quadList().size(); ++i) 136 for (size_t i = 0; i < quadCuller.quadList().size(); ++i)
137 EXPECT_NE(quadCuller.quadList()[i]->material(), DrawQuad::TiledConte nt); 137 EXPECT_NE(quadCuller.quadList()[i]->material(), DrawQuad::TiledConte nt);
138 } 138 }
139 } 139 }
140 140
141 static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, IntSize tileSize, const IntSize& layerSize, LayerTilingData::BorderTexelOption borderTe xelOption, const IntRect& visibleContentRect) 141 static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Si ze tileSize, const gfx::Size& layerSize, LayerTilingData::BorderTexelOption bord erTexelOption, const gfx::Rect& visibleContentRect)
142 { 142 {
143 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTe xelOption); 143 scoped_ptr<TiledLayerImpl> layer = createLayer(tileSize, layerSize, borderTe xelOption);
144 layer->setVisibleContentRect(visibleContentRect); 144 layer->setVisibleContentRect(visibleContentRect);
145 layer->setBounds(layerSize); 145 layer->setBounds(layerSize);
146 146
147 MockQuadCuller quadCuller(quads, sharedStates); 147 MockQuadCuller quadCuller(quads, sharedStates);
148 AppendQuadsData data; 148 AppendQuadsData data;
149 layer->appendQuads(quadCuller, data); 149 layer->appendQuads(quadCuller, data);
150 } 150 }
151 151
152 // Test with both border texels and without. 152 // Test with both border texels and without.
153 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \ 153 #define WITH_AND_WITHOUT_BORDER_TEST(testFixtureName) \
154 TEST(TiledLayerImplTest, testFixtureName##NoBorders) \ 154 TEST(TiledLayerImplTest, testFixtureName##NoBorders) \
155 { \ 155 { \
156 testFixtureName(LayerTilingData::NoBorderTexels); \ 156 testFixtureName(LayerTilingData::NoBorderTexels); \
157 } \ 157 } \
158 TEST(TiledLayerImplTest, testFixtureName##HasBorders) \ 158 TEST(TiledLayerImplTest, testFixtureName##HasBorders) \
159 { \ 159 { \
160 testFixtureName(LayerTilingData::HasBorderTexels);\ 160 testFixtureName(LayerTilingData::HasBorderTexels);\
161 } 161 }
162 162
163 static void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOpti on borders) 163 static void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOpti on borders)
164 { 164 {
165 DebugScopedSetImplThread scopedImplThread; 165 DebugScopedSetImplThread scopedImplThread;
166 166
167 IntSize layerSize(1000, 1000); 167 gfx::Size layerSize(1000, 1000);
168 QuadList quads; 168 QuadList quads;
169 SharedQuadStateList sharedStates; 169 SharedQuadStateList sharedStates;
170 getQuads(quads, sharedStates, IntSize(100, 100), layerSize, borders, IntRect (IntPoint(), layerSize)); 170 getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, borders, gfx:: Rect(gfx::Point(), layerSize));
171 verifyQuadsExactlyCoverRect(quads, IntRect(IntPoint(), layerSize)); 171 verifyQuadsExactlyCoverRect(quads, gfx::Rect(gfx::Point(), layerSize));
172 } 172 }
173 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries); 173 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries);
174 174
175 static void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOptio n borders) 175 static void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOptio n borders)
176 { 176 {
177 DebugScopedSetImplThread scopedImplThread; 177 DebugScopedSetImplThread scopedImplThread;
178 178
179 // This rect intersects the middle 3x3 of the 5x5 tiles. 179 // This rect intersects the middle 3x3 of the 5x5 tiles.
180 IntPoint topLeft(65, 73); 180 gfx::Point topLeft(65, 73);
181 IntPoint bottomRight(182, 198); 181 gfx::Point bottomRight(182, 198);
182 IntRect visibleContentRect(topLeft, bottomRight - topLeft); 182 gfx::Rect visibleContentRect = gfx::BoundingRect(topLeft, bottomRight);
183 183
184 IntSize layerSize(250, 250); 184 gfx::Size layerSize(250, 250);
185 QuadList quads; 185 QuadList quads;
186 SharedQuadStateList sharedStates; 186 SharedQuadStateList sharedStates;
187 getQuads(quads, sharedStates, IntSize(50, 50), IntSize(250, 250), LayerTilin gData::NoBorderTexels, visibleContentRect); 187 getQuads(quads, sharedStates, gfx::Size(50, 50), gfx::Size(250, 250), LayerT ilingData::NoBorderTexels, visibleContentRect);
188 verifyQuadsExactlyCoverRect(quads, visibleContentRect); 188 verifyQuadsExactlyCoverRect(quads, visibleContentRect);
189 } 189 }
190 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles); 190 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles);
191 191
192 static void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOpti on borders) 192 static void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOpti on borders)
193 { 193 {
194 DebugScopedSetImplThread scopedImplThread; 194 DebugScopedSetImplThread scopedImplThread;
195 195
196 IntSize layerSize(220, 210); 196 gfx::Size layerSize(220, 210);
197 IntRect visibleContentRect(IntPoint(), layerSize); 197 gfx::Rect visibleContentRect(gfx::Point(), layerSize);
198 QuadList quads; 198 QuadList quads;
199 SharedQuadStateList sharedStates; 199 SharedQuadStateList sharedStates;
200 getQuads(quads, sharedStates, IntSize(100, 100), layerSize, LayerTilingData: :NoBorderTexels, visibleContentRect); 200 getQuads(quads, sharedStates, gfx::Size(100, 100), layerSize, LayerTilingDat a::NoBorderTexels, visibleContentRect);
201 verifyQuadsExactlyCoverRect(quads, visibleContentRect); 201 verifyQuadsExactlyCoverRect(quads, visibleContentRect);
202 } 202 }
203 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds); 203 WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds);
204 204
205 TEST(TiledLayerImplTest, textureInfoForLayerNoBorders) 205 TEST(TiledLayerImplTest, textureInfoForLayerNoBorders)
206 { 206 {
207 DebugScopedSetImplThread scopedImplThread; 207 DebugScopedSetImplThread scopedImplThread;
208 208
209 IntSize tileSize(50, 50); 209 gfx::Size tileSize(50, 50);
210 IntSize layerSize(250, 250); 210 gfx::Size layerSize(250, 250);
211 QuadList quads; 211 QuadList quads;
212 SharedQuadStateList sharedStates; 212 SharedQuadStateList sharedStates;
213 getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorder Texels, IntRect(IntPoint(), layerSize)); 213 getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorder Texels, gfx::Rect(gfx::Point(), layerSize));
214 214
215 for (size_t i = 0; i < quads.size(); ++i) { 215 for (size_t i = 0; i < quads.size(); ++i) {
216 ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i; 216 ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i;
217 TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]); 217 TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]);
218 218
219 EXPECT_NE(quad->resourceId(), 0u) << quadString << i; 219 EXPECT_NE(quad->resourceId(), 0u) << quadString << i;
220 EXPECT_EQ(quad->textureOffset(), IntPoint()) << quadString << i; 220 EXPECT_EQ(quad->textureOffset(), gfx::Vector2d()) << quadString << i;
221 EXPECT_EQ(quad->textureSize(), tileSize) << quadString << i; 221 EXPECT_EQ(quad->textureSize(), tileSize) << quadString << i;
222 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; 222 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i;
223 } 223 }
224 } 224 }
225 225
226 TEST(TiledLayerImplTest, tileOpaqueRectForLayerNoBorders) 226 TEST(TiledLayerImplTest, tileOpaqueRectForLayerNoBorders)
227 { 227 {
228 DebugScopedSetImplThread scopedImplThread; 228 DebugScopedSetImplThread scopedImplThread;
229 229
230 IntSize tileSize(50, 50); 230 gfx::Size tileSize(50, 50);
231 IntSize layerSize(250, 250); 231 gfx::Size layerSize(250, 250);
232 QuadList quads; 232 QuadList quads;
233 SharedQuadStateList sharedStates; 233 SharedQuadStateList sharedStates;
234 getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorder Texels, IntRect(IntPoint(), layerSize)); 234 getQuads(quads, sharedStates, tileSize, layerSize, LayerTilingData::NoBorder Texels, gfx::Rect(gfx::Point(), layerSize));
235 235
236 for (size_t i = 0; i < quads.size(); ++i) { 236 for (size_t i = 0; i < quads.size(); ++i) {
237 ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i; 237 ASSERT_EQ(quads[i]->material(), DrawQuad::TiledContent) << quadString << i;
238 TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]); 238 TileDrawQuad* quad = static_cast<TileDrawQuad*>(quads[i]);
239 239
240 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i; 240 EXPECT_EQ(gfx::Rect(0, 0, 1, 1), quad->opaqueRect()) << quadString << i;
241 } 241 }
242 } 242 }
243 243
244 } // namespace 244 } // namespace
OLDNEW
« no previous file with comments | « cc/tiled_layer_impl.cc ('k') | cc/tiled_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698