Treat (private, internal) grid bounds as doubly-inclusive in SkTileGrid.
The net effect is that two "+1" instructions are removed from insert().
search() nets no change: two +1 removed, two +1 added.
When vectorized, this removes the need to add in userToGrid() at all and
so the need to read an awkward {0, 0, 1, 1} constant from memory. Mostly
the benefit is less vector code to look at and think about.
BUG=skia:
Review URL: https://codereview.chromium.org/659823004
diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp
index 30ca4b9..fd00253 100644
--- a/src/core/SkTileGrid.cpp
+++ b/src/core/SkTileGrid.cpp
@@ -62,12 +62,12 @@
rect->fBottom -= SK_ScalarNearlyZero;
}
-// Convert user-space bounds to grid tiles they cover (LT inclusive, RB exclusive).
+// Convert user-space bounds to grid tiles they cover (LT and RB both inclusive).
void SkTileGrid::userToGrid(const SkRect& user, SkIRect* grid) const {
grid->fLeft = SkPin32(user.left() * fInvWidth , 0, fXTiles - 1);
grid->fTop = SkPin32(user.top() * fInvHeight, 0, fYTiles - 1);
- grid->fRight = SkPin32(user.right() * fInvWidth , 0, fXTiles - 1) + 1;
- grid->fBottom = SkPin32(user.bottom() * fInvHeight, 0, fYTiles - 1) + 1;
+ grid->fRight = SkPin32(user.right() * fInvWidth , 0, fXTiles - 1);
+ grid->fBottom = SkPin32(user.bottom() * fInvHeight, 0, fYTiles - 1);
}
void SkTileGrid::insert(unsigned opIndex, const SkRect& originalBounds, bool) {
@@ -84,8 +84,8 @@
SkIRect grid;
this->userToGrid(bounds, &grid);
- for (int y = grid.fTop; y < grid.fBottom; y++) {
- for (int x = grid.fLeft; x < grid.fRight; x++) {
+ for (int y = grid.fTop; y <= grid.fBottom; y++) {
+ for (int x = grid.fLeft; x <= grid.fRight; x++) {
fTiles[y * fXTiles + x].push(opIndex);
}
}
@@ -115,7 +115,7 @@
SkIRect grid;
this->userToGrid(query, &grid);
- const int tilesHit = (grid.fRight - grid.fLeft) * (grid.fBottom - grid.fTop);
+ const int tilesHit = (grid.fRight - grid.fLeft + 1) * (grid.fBottom - grid.fTop + 1);
SkASSERT(tilesHit > 0);
if (tilesHit == 1) {
@@ -130,8 +130,8 @@
// Gather pointers to the starts and ends of the tiles to merge.
SkAutoSTArray<kStackAllocationTileCount, const unsigned*> starts(tilesHit), ends(tilesHit);
int i = 0;
- for (int y = grid.fTop; y < grid.fBottom; y++) {
- for (int x = grid.fLeft; x < grid.fRight; x++) {
+ for (int y = grid.fTop; y <= grid.fBottom; y++) {
+ for (int x = grid.fLeft; x <= grid.fRight; x++) {
starts[i] = fTiles[y * fXTiles + x].begin();
ends[i] = fTiles[y * fXTiles + x].end();
i++;