aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-27 18:35:16 +0000
committerGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-27 18:35:16 +0000
commit29b19e53cfac5af4f9bd5d361436d1097f349a34 (patch)
treef00138de9091031ecbb929f6800b080be8f7c02e /src/core
parentd1c53aae59ee44377be8bc0cc15e54d46aa530ce (diff)
Change SkTileGride geometry calculations to match the Chromium compositor.
This patch changes the semantics of tileWidth/Height to include the border region, and uses an offset to take into account the fact that there is no outer border for outer tiles. This patch also fixes a previous bug where the right column and bottom row were considered to be included in bounds that are expressed as an SkIRect. Companion Chromium CL required for roll: https://codereview.chromium.org/12221077/ TEST=TileGrid unit test Review URL: https://codereview.appspot.com/7350050 git-svn-id: http://skia.googlecode.com/svn/trunk@7885 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkTileGrid.cpp46
-rw-r--r--src/core/SkTileGrid.h6
-rw-r--r--src/core/SkTileGridPicture.cpp23
3 files changed, 45 insertions, 30 deletions
diff --git a/src/core/SkTileGrid.cpp b/src/core/SkTileGrid.cpp
index 7e078517ea..8a299496ac 100644
--- a/src/core/SkTileGrid.cpp
+++ b/src/core/SkTileGrid.cpp
@@ -8,19 +8,20 @@
#include "SkTileGrid.h"
-SkTileGrid::SkTileGrid(int tileWidth, int tileHeight, int xTileCount, int yTileCount,
- int borderPixels, SkTileGridNextDatumFunctionPtr nextDatumFunction)
+SkTileGrid::SkTileGrid(int xTileCount, int yTileCount, const SkTileGridPicture::TileGridInfo& info,
+ SkTileGridNextDatumFunctionPtr nextDatumFunction)
{
- fTileWidth = tileWidth;
- fTileHeight = tileHeight;
fXTileCount = xTileCount;
fYTileCount = yTileCount;
- // Border padding is offset by 1 as a provision for AA and
+ fInfo = info;
+ // Margin is offset by 1 as a provision for AA and
// to cancel-out the outset applied by getClipDeviceBounds.
- fBorderPixels = borderPixels + 1;
+ fInfo.fMargin.fHeight++;
+ fInfo.fMargin.fWidth++;
fTileCount = fXTileCount * fYTileCount;
fInsertionCount = 0;
- fGridBounds = SkIRect::MakeXYWH(0, 0, fTileWidth * fXTileCount, fTileHeight * fYTileCount);
+ fGridBounds = SkIRect::MakeXYWH(0, 0, fInfo.fTileInterval.width() * fXTileCount,
+ fInfo.fTileInterval.height() * fYTileCount);
fNextDatumFunction = nextDatumFunction;
fTileData = SkNEW_ARRAY(SkTDArray<void *>, fTileCount);
}
@@ -36,16 +37,22 @@ SkTDArray<void *>& SkTileGrid::tile(int x, int y) {
void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) {
SkASSERT(!bounds.isEmpty());
SkIRect dilatedBounds = bounds;
- dilatedBounds.outset(fBorderPixels, fBorderPixels);
-
+ dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height());
+ dilatedBounds.offset(fInfo.fOffset);
if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) {
return;
}
- int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fTileWidth, fXTileCount - 1), 0);
- int maxTileX = SkMax32(SkMin32(dilatedBounds.right() / fTileWidth, fXTileCount - 1), 0);
- int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fTileHeight, fYTileCount -1), 0);
- int maxTileY = SkMax32(SkMin32(dilatedBounds.bottom() / fTileHeight, fYTileCount -1), 0);
+ // Note: SkIRects are non-inclusive of the right() column and bottom() row,
+ // hence the "-1"s in the computations of maxTileX and maxTileY.
+ int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fInfo.fTileInterval.width(),
+ fXTileCount - 1), 0);
+ int maxTileX = SkMax32(SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInterval.width(),
+ fXTileCount - 1), 0);
+ int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fInfo.fTileInterval.height(),
+ fYTileCount -1), 0);
+ int maxTileY = SkMax32(SkMin32((dilatedBounds.bottom() -1) / fInfo.fTileInterval.height(),
+ fYTileCount -1), 0);
for (int x = minTileX; x <= maxTileX; x++) {
for (int y = minTileY; y <= maxTileY; y++) {
@@ -56,13 +63,18 @@ void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) {
}
void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) {
+ SkIRect adjustedQuery = query;
+ adjustedQuery.inset(fInfo.fMargin.width(), fInfo.fMargin.height());
+ adjustedQuery.offset(fInfo.fOffset);
// Convert the query rectangle from device coordinates to tile coordinates
// by rounding outwards to the nearest tile boundary so that the resulting tile
// region includes the query rectangle. (using truncating division to "floor")
- int tileStartX = (query.left() + fBorderPixels) / fTileWidth;
- int tileEndX = (query.right() + fTileWidth - fBorderPixels) / fTileWidth;
- int tileStartY = (query.top() + fBorderPixels) / fTileHeight;
- int tileEndY = (query.bottom() + fTileHeight - fBorderPixels) / fTileHeight;
+ int tileStartX = adjustedQuery.left() / fInfo.fTileInterval.width();
+ int tileEndX = (adjustedQuery.right() + fInfo.fTileInterval.width() - 1) /
+ fInfo.fTileInterval.width();
+ int tileStartY = adjustedQuery.top() / fInfo.fTileInterval.height();
+ int tileEndY = (adjustedQuery.bottom() + fInfo.fTileInterval.height() - 1) /
+ fInfo.fTileInterval.height();
if (tileStartX >= fXTileCount || tileStartY >= fYTileCount || tileEndX <= 0 || tileEndY <= 0) {
return; // query does not intersect the grid
}
diff --git a/src/core/SkTileGrid.h b/src/core/SkTileGrid.h
index c0fd3ddaef..c83a0fd468 100644
--- a/src/core/SkTileGrid.h
+++ b/src/core/SkTileGrid.h
@@ -11,6 +11,7 @@
#include "SkBBoxHierarchy.h"
#include "SkPictureStateTree.h"
+#include "SkTileGridPicture.h" // for TileGridInfo
/**
* Subclass of SkBBoxHierarchy that stores elements in buckets that correspond
@@ -26,7 +27,7 @@ class SkTileGrid : public SkBBoxHierarchy {
public:
typedef void* (*SkTileGridNextDatumFunctionPtr)(SkTDArray<void*>** tileData, SkTDArray<int>& tileIndices);
- SkTileGrid(int tileWidth, int tileHeight, int xTileCount, int yTileCount, int borderPixels,
+ SkTileGrid(int xTileCount, int yTileCount, const SkTileGridPicture::TileGridInfo& info,
SkTileGridNextDatumFunctionPtr nextDatumFunction);
virtual ~SkTileGrid();
@@ -61,7 +62,8 @@ public:
private:
SkTDArray<void*>& tile(int x, int y);
- int fTileWidth, fTileHeight, fXTileCount, fYTileCount, fTileCount, fBorderPixels;
+ int fXTileCount, fYTileCount, fTileCount;
+ SkTileGridPicture::TileGridInfo fInfo;
SkTDArray<void*>* fTileData;
int fInsertionCount;
SkIRect fGridBounds;
diff --git a/src/core/SkTileGridPicture.cpp b/src/core/SkTileGridPicture.cpp
index 8a39d4949b..7a8d5932ac 100644
--- a/src/core/SkTileGridPicture.cpp
+++ b/src/core/SkTileGridPicture.cpp
@@ -10,18 +10,19 @@
#include "SkPictureStateTree.h"
#include "SkTileGrid.h"
-
-SkTileGridPicture::SkTileGridPicture(int tileWidth, int tileHeight, int width, int height,
- int borderPixels) {
- SkASSERT(borderPixels >= 0);
- fTileWidth = tileWidth;
- fTileHeight = tileHeight;
- fXTileCount = (width + tileWidth - 1) / tileWidth;
- fYTileCount = (height + tileHeight - 1) / tileHeight;
- fBorderPixels = borderPixels;
+SkTileGridPicture::SkTileGridPicture(int width, int height, const TileGridInfo& info) {
+ SkASSERT(info.fMargin.width() >= 0);
+ SkASSERT(info.fMargin.height() >= 0);
+ fInfo = info;
+ // Note: SkIRects are non-inclusive of the right() column and bottom() row.
+ // For example, an SkIRect at 0,0 with a size of (1,1) will only have
+ // content at pixel (0,0) and will report left=0 and right=1, hence the
+ // "-1"s below.
+ fXTileCount = (width + info.fTileInterval.width() - 1) / info.fTileInterval.width();
+ fYTileCount = (height + info.fTileInterval.height() - 1) / info.fTileInterval.height();
}
SkBBoxHierarchy* SkTileGridPicture::createBBoxHierarchy() const {
- return SkNEW_ARGS(SkTileGrid, (fTileWidth, fTileHeight, fXTileCount, fYTileCount,
- fBorderPixels, SkTileGridNextDatum<SkPictureStateTree::Draw>));
+ return SkNEW_ARGS(SkTileGrid, (fXTileCount, fYTileCount, fInfo,
+ SkTileGridNextDatum<SkPictureStateTree::Draw>));
}