junov@chromium.org | adc58e4 | 2012-11-07 17:38:38 +0000 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "Test.h" |
| 10 | #include "SkTileGrid.h" |
| 11 | |
| 12 | enum Tile { |
| 13 | kTopLeft_Tile = 0x1, |
| 14 | kTopRight_Tile = 0x2, |
| 15 | kBottomLeft_Tile = 0x4, |
| 16 | kBottomRight_Tile = 0x8, |
| 17 | |
| 18 | kAll_Tile = kTopLeft_Tile | kTopRight_Tile | kBottomLeft_Tile | kBottomRight_Tile, |
| 19 | }; |
| 20 | |
| 21 | class TileGridTest { |
| 22 | public: |
| 23 | static void verifyTileHits(skiatest::Reporter* reporter, SkIRect rect, uint32_t tileMask) { |
| 24 | SkTileGrid grid(10, 10, 2, 2); |
| 25 | grid.insert(NULL, rect, false); |
| 26 | REPORTER_ASSERT(reporter, grid.tile(0,0).count() == |
| 27 | ((tileMask & kTopLeft_Tile)? 1 : 0)); |
| 28 | REPORTER_ASSERT(reporter, grid.tile(1,0).count() == |
| 29 | ((tileMask & kTopRight_Tile)? 1 : 0)); |
| 30 | REPORTER_ASSERT(reporter, grid.tile(0,1).count() == |
| 31 | ((tileMask & kBottomLeft_Tile)? 1 : 0)); |
| 32 | REPORTER_ASSERT(reporter, grid.tile(1,1).count() == |
| 33 | ((tileMask & kBottomRight_Tile)? 1 : 0)); |
| 34 | } |
| 35 | |
| 36 | static void Test(skiatest::Reporter* reporter) { |
| 37 | // Out of bounds |
| 38 | verifyTileHits(reporter, SkIRect::MakeXYWH(30, 0, 1, 1), 0); |
| 39 | verifyTileHits(reporter, SkIRect::MakeXYWH(0, 30, 1, 1), 0); |
| 40 | verifyTileHits(reporter, SkIRect::MakeXYWH(-10, 0, 1, 1), 0); |
| 41 | verifyTileHits(reporter, SkIRect::MakeXYWH(0, -10, 1, 1), 0); |
| 42 | |
| 43 | // Dilation for AA consideration |
| 44 | verifyTileHits(reporter, SkIRect::MakeXYWH(0, 0, 8, 8), kTopLeft_Tile); |
| 45 | verifyTileHits(reporter, SkIRect::MakeXYWH(0, 0, 9, 9), kAll_Tile); |
| 46 | verifyTileHits(reporter, SkIRect::MakeXYWH(10, 10, 1, 1), kAll_Tile); |
| 47 | verifyTileHits(reporter, SkIRect::MakeXYWH(11, 11, 1, 1), kBottomRight_Tile); |
| 48 | |
| 49 | // BBoxes that overlap tiles |
| 50 | verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 1), kTopLeft_Tile | kTopRight_Tile); |
| 51 | verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 1, 10), kTopLeft_Tile | |
| 52 | kBottomLeft_Tile); |
| 53 | verifyTileHits(reporter, SkIRect::MakeXYWH(5, 5, 10, 10), kAll_Tile); |
| 54 | verifyTileHits(reporter, SkIRect::MakeXYWH(-10, -10, 40, 40), kAll_Tile); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | #include "TestClassDef.h" |
| 60 | DEFINE_TESTCLASS("TileGrid", TileGridTestClass, TileGridTest::Test) |