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

Side by Side Diff: tests/TileGridTest.cpp

Issue 13860011: Fixing numerical rounding edge case in SkTileGrid (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months 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 | « src/core/SkTileGrid.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 canvas->drawRect(rect2, paint); 171 canvas->drawRect(rect2, paint);
172 canvas->drawRect(rect3, paint); 172 canvas->drawRect(rect3, paint);
173 picture.endRecording(); 173 picture.endRecording();
174 174
175 SkBitmap tileBitmap; 175 SkBitmap tileBitmap;
176 tileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); 176 tileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
177 tileBitmap.allocPixels(); 177 tileBitmap.allocPixels();
178 SkBitmap moreThanATileBitmap; 178 SkBitmap moreThanATileBitmap;
179 moreThanATileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 11, 11); 179 moreThanATileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 11, 11);
180 moreThanATileBitmap.allocPixels(); 180 moreThanATileBitmap.allocPixels();
181 SkBitmap tinyBitmap;
182 tinyBitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
183 tinyBitmap.allocPixels();
181 // Test parts of top-left tile 184 // Test parts of top-left tile
182 { 185 {
183 // The offset should cancel the top and left borders of the top left tile 186 // The offset should cancel the top and left borders of the top left tile
184 // So a look-up at interval 0-10 should be grid aligned, 187 // So a look-up at interval 0-10 should be grid aligned,
185 SkDevice device(tileBitmap); 188 SkDevice device(tileBitmap);
186 MockCanvas mockCanvas(&device); 189 MockCanvas mockCanvas(&device);
187 picture.draw(&mockCanvas); 190 picture.draw(&mockCanvas);
188 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count()); 191 REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
189 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]); 192 REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
190 } 193 }
(...skipping 28 matching lines...) Expand all
219 } 222 }
220 { 223 {
221 SkDevice device(tileBitmap); 224 SkDevice device(tileBitmap);
222 MockCanvas mockCanvas(&device); 225 MockCanvas mockCanvas(&device);
223 mockCanvas.translate(SkFloatToScalar(-8.1f), SkFloatToScalar(-8.1f)) ; 226 mockCanvas.translate(SkFloatToScalar(-8.1f), SkFloatToScalar(-8.1f)) ;
224 picture.draw(&mockCanvas); 227 picture.draw(&mockCanvas);
225 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count()); 228 REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count());
226 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); 229 REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
227 REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]); 230 REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]);
228 } 231 }
232 {
233 // Regression test for crbug.com/234688
234 // Once the 2x2 device region is inset by margin, it yields an empty
235 // adjusted region, sitting right on top of the tile boundary.
236 SkDevice device(tinyBitmap);
237 MockCanvas mockCanvas(&device);
238 mockCanvas.translate(SkFloatToScalar(-8.0f), SkFloatToScalar(-8.0f)) ;
239 picture.draw(&mockCanvas);
240 // This test passes by not asserting. We do not validate the rects r ecorded
241 // because the result is numerically unstable (floating point equali ty).
242 // The content of any one of the four tiles of the tilegrid would be a valid
243 // result since any bbox that covers the center point of the canvas will be
244 // recorded in all four tiles.
245 }
229 } 246 }
230 247
231 static void Test(skiatest::Reporter* reporter) { 248 static void Test(skiatest::Reporter* reporter) {
232 // Out of bounds 249 // Out of bounds
233 verifyTileHits(reporter, SkIRect::MakeXYWH(30, 0, 1, 1), 0); 250 verifyTileHits(reporter, SkIRect::MakeXYWH(30, 0, 1, 1), 0);
234 verifyTileHits(reporter, SkIRect::MakeXYWH(0, 30, 1, 1), 0); 251 verifyTileHits(reporter, SkIRect::MakeXYWH(0, 30, 1, 1), 0);
235 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, 0, 1, 1), 0); 252 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, 0, 1, 1), 0);
236 verifyTileHits(reporter, SkIRect::MakeXYWH(0, -10, 1, 1), 0); 253 verifyTileHits(reporter, SkIRect::MakeXYWH(0, -10, 1, 1), 0);
237 254
238 // Dilation for AA consideration 255 // Dilation for AA consideration
(...skipping 18 matching lines...) Expand all
257 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile ); 274 verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile );
258 275
259 TestUnalignedQuery(reporter); 276 TestUnalignedQuery(reporter);
260 TestOverlapOffsetQueryAlignment(reporter); 277 TestOverlapOffsetQueryAlignment(reporter);
261 } 278 }
262 }; 279 };
263 280
264 281
265 #include "TestClassDef.h" 282 #include "TestClassDef.h"
266 DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test) 283 DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test)
OLDNEW
« no previous file with comments | « src/core/SkTileGrid.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698