aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-10-15 14:20:00 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-15 14:20:01 -0700
commit826a50333612e81d1de87a58e32e4f9a3baddefd (patch)
treec81de59c3a71a5080f31e502b2649a8aa7468db3 /src
parent8dfdfff98dd14b0f3bef465411941e1bab8f0261 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/core/SkTileGrid.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp
index 30ca4b9179..fd00253097 100644
--- a/src/core/SkTileGrid.cpp
+++ b/src/core/SkTileGrid.cpp
@@ -62,12 +62,12 @@ void SkTileGrid::commonAdjust(SkRect* rect) const {
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 @@ void SkTileGrid::insert(unsigned opIndex, const SkRect& originalBounds, bool) {
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 @@ void SkTileGrid::search(const SkRect& originalQuery, SkTDArray<unsigned>* result
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 @@ void SkTileGrid::search(const SkRect& originalQuery, SkTDArray<unsigned>* result
// 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++;