From: junov@chromium.org Date: Wed, 24 Apr 2013 15:39:11 +0000 (+0000) Subject: Fixing numerical rounding edge case in SkTileGrid X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~12621 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5cfdfffc8c63c6f1cceb46a9bcd5c555a7baa28;p=platform%2Fupstream%2FlibSkiaSharp.git Fixing numerical rounding edge case in SkTileGrid BUG=https://code.google.com/p/chromium/issues/detail?id=234688 TEST=TileGrid skia unit test Review URL: https://codereview.chromium.org/13860011 git-svn-id: http://skia.googlecode.com/svn/trunk@8839 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp index 7a9c8ee..c39e21b 100644 --- a/src/core/SkTileGrid.cpp +++ b/src/core/SkTileGrid.cpp @@ -81,9 +81,9 @@ void SkTileGrid::search(const SkIRect& query, SkTDArray* results) { fInfo.fTileInterval.height(); tileStartX = SkPin32(tileStartX, 0, fXTileCount - 1); - tileEndX = SkPin32(tileEndX, 1, fXTileCount); + tileEndX = SkPin32(tileEndX, tileStartX+1, fXTileCount); tileStartY = SkPin32(tileStartY, 0, fYTileCount - 1); - tileEndY = SkPin32(tileEndY, 1, fYTileCount); + tileEndY = SkPin32(tileEndY, tileStartY+1, fYTileCount); int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY); SkASSERT(queryTileCount); diff --git a/tests/TileGridTest.cpp b/tests/TileGridTest.cpp index 78620b4..e409afd 100644 --- a/tests/TileGridTest.cpp +++ b/tests/TileGridTest.cpp @@ -178,6 +178,9 @@ public: SkBitmap moreThanATileBitmap; moreThanATileBitmap.setConfig(SkBitmap::kARGB_8888_Config, 11, 11); moreThanATileBitmap.allocPixels(); + SkBitmap tinyBitmap; + tinyBitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); + tinyBitmap.allocPixels(); // Test parts of top-left tile { // The offset should cancel the top and left borders of the top left tile @@ -226,6 +229,20 @@ public: REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]); REPORTER_ASSERT(reporter, rect3 == mockCanvas.fRects[1]); } + { + // Regression test for crbug.com/234688 + // Once the 2x2 device region is inset by margin, it yields an empty + // adjusted region, sitting right on top of the tile boundary. + SkDevice device(tinyBitmap); + MockCanvas mockCanvas(&device); + mockCanvas.translate(SkFloatToScalar(-8.0f), SkFloatToScalar(-8.0f)); + picture.draw(&mockCanvas); + // This test passes by not asserting. We do not validate the rects recorded + // because the result is numerically unstable (floating point equality). + // The content of any one of the four tiles of the tilegrid would be a valid + // result since any bbox that covers the center point of the canvas will be + // recorded in all four tiles. + } } static void Test(skiatest::Reporter* reporter) {