OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "Test.h" | 9 #include "Test.h" |
10 #include "SkTileGrid.h" | 10 #include "SkTileGrid.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 // Intersect bottom right tile, but does not overlap rect 2 | 107 // Intersect bottom right tile, but does not overlap rect 2 |
108 { | 108 { |
109 SkDevice device(store); | 109 SkDevice device(store); |
110 MockCanvas mockCanvas(&device); | 110 MockCanvas mockCanvas(&device); |
111 mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-16.0f
)); | 111 mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-16.0f
)); |
112 picture.draw(&mockCanvas); | 112 picture.draw(&mockCanvas); |
113 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); | 113 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
114 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); | 114 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
115 } | 115 } |
| 116 // Out of bounds queries, snap to border tiles |
| 117 { |
| 118 SkDevice device(store); |
| 119 MockCanvas mockCanvas(&device); |
| 120 mockCanvas.translate(SkFloatToScalar(2.0f), SkFloatToScalar(0.0f)); |
| 121 picture.draw(&mockCanvas); |
| 122 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
| 123 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
| 124 } |
| 125 { |
| 126 SkDevice device(store); |
| 127 MockCanvas mockCanvas(&device); |
| 128 mockCanvas.translate(SkFloatToScalar(0.0f), SkFloatToScalar(2.0f)); |
| 129 picture.draw(&mockCanvas); |
| 130 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
| 131 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); |
| 132 } |
| 133 { |
| 134 SkDevice device(store); |
| 135 MockCanvas mockCanvas(&device); |
| 136 mockCanvas.translate(SkFloatToScalar(-22.0f), SkFloatToScalar(-16.0f
)); |
| 137 picture.draw(&mockCanvas); |
| 138 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
| 139 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
| 140 } |
| 141 { |
| 142 SkDevice device(store); |
| 143 MockCanvas mockCanvas(&device); |
| 144 mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-22.0f
)); |
| 145 picture.draw(&mockCanvas); |
| 146 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); |
| 147 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); |
| 148 } |
116 } | 149 } |
117 | 150 |
118 static void TestOverlapOffsetQueryAlignment(skiatest::Reporter* reporter) { | 151 static void TestOverlapOffsetQueryAlignment(skiatest::Reporter* reporter) { |
119 // Use SkTileGridPicture to generate a SkTileGrid with a helper | 152 // Use SkTileGridPicture to generate a SkTileGrid with a helper |
120 SkTileGridPicture::TileGridInfo info; | 153 SkTileGridPicture::TileGridInfo info; |
121 info.fMargin.set(1, 1); | 154 info.fMargin.set(1, 1); |
122 info.fOffset.set(-1, -1); | 155 info.fOffset.set(-1, -1); |
123 info.fTileInterval.set(8, 8); | 156 info.fTileInterval.set(8, 8); |
124 SkTileGridPicture picture(20, 20, info); | 157 SkTileGridPicture picture(20, 20, info); |
125 | 158 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 verifyTileHits(reporter, SkIRect::MakeXYWH(9, 9, 1, 1), kAll_Tile); | 241 verifyTileHits(reporter, SkIRect::MakeXYWH(9, 9, 1, 1), kAll_Tile); |
209 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kAll_Tile); | 242 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kAll_Tile); |
210 verifyTileHits(reporter, SkIRect::MakeXYWH(11, 11, 1, 1), kBottomRight_
Tile); | 243 verifyTileHits(reporter, SkIRect::MakeXYWH(11, 11, 1, 1), kBottomRight_
Tile); |
211 | 244 |
212 // BorderPixels | 245 // BorderPixels |
213 verifyTileHits(reporter, SkIRect::MakeXYWH(0, 0, 6, 6), kTopLeft_Tile,
1); | 246 verifyTileHits(reporter, SkIRect::MakeXYWH(0, 0, 6, 6), kTopLeft_Tile,
1); |
214 verifyTileHits(reporter, SkIRect::MakeXYWH(0, 0, 7, 7), kAll_Tile, 1); | 247 verifyTileHits(reporter, SkIRect::MakeXYWH(0, 0, 7, 7), kAll_Tile, 1); |
215 verifyTileHits(reporter, SkIRect::MakeXYWH(9, 9, 1, 1), kAll_Tile, 1); | 248 verifyTileHits(reporter, SkIRect::MakeXYWH(9, 9, 1, 1), kAll_Tile, 1); |
216 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_
Tile, 1); | 249 verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kBottomRight_
Tile, 1); |
217 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_
Tile, 1); | 250 verifyTileHits(reporter, SkIRect::MakeXYWH(17, 17, 1, 1), kBottomRight_
Tile, 1); |
218 verifyTileHits(reporter, SkIRect::MakeXYWH(18, 18, 1, 1), 0, 1); | |
219 | 251 |
220 // BBoxes that overlap tiles | 252 // BBoxes that overlap tiles |
221 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile
| kTopRight_Tile); | 253 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile
| kTopRight_Tile); |
222 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile
| | 254 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile
| |
223 kBottomLeft_Tile); | 255 kBottomLeft_Tile); |
224 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); | 256 verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); |
225 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile
); | 257 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile
); |
226 | 258 |
227 TestUnalignedQuery(reporter); | 259 TestUnalignedQuery(reporter); |
228 TestOverlapOffsetQueryAlignment(reporter); | 260 TestOverlapOffsetQueryAlignment(reporter); |
229 } | 261 } |
230 }; | 262 }; |
231 | 263 |
232 | 264 |
233 #include "TestClassDef.h" | 265 #include "TestClassDef.h" |
234 DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test) | 266 DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test) |
OLD | NEW |