Provide an option to bench drawing individual tiles in bench_pictures.
Provides output like the following:
running bench [1236 12045] androidpolice.skp
tile_256x256: tile [0,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [1,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [2,0] out of [5,48]: msecs = 1.00
tile_256x256: tile [3,0] out of [5,48]: msecs = 1.50
tile_256x256: tile [4,0] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,1] out of [5,48]: msecs = 2.00
tile_256x256: tile [1,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [2,1] out of [5,48]: msecs = 3.50
tile_256x256: tile [3,1] out of [5,48]: msecs = 6.00
tile_256x256: tile [4,1] out of [5,48]: msecs = 2.50
tile_256x256: tile [0,2] out of [5,48]: msecs = 2.00
BUG=https://code.google.com/p/skia/issues/detail?id=1016
Review URL: https://codereview.appspot.com/6937047
git-svn-id: http://skia.googlecode.com/svn/trunk@6805 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index ac5e47c..32c19e8 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -321,7 +321,10 @@
, fTileHeight(kDefaultTileHeight)
, fTileWidthPercentage(0.0)
, fTileHeightPercentage(0.0)
- , fTileMinPowerOf2Width(0) { }
+ , fTileMinPowerOf2Width(0)
+ , fCurrentTileOffset(-1)
+ , fTilesX(0)
+ , fTilesY(0) { }
void TiledPictureRenderer::init(SkPicture* pict) {
SkASSERT(pict != NULL);
@@ -348,6 +351,10 @@
} else {
this->setupTiles();
}
+ fCanvas.reset(this->setupCanvas(fTileWidth, fTileHeight));
+ // Initialize to -1 so that the first call to nextTile will set this up to draw tile 0 on the
+ // first call to drawCurrentTile.
+ fCurrentTileOffset = -1;
}
void TiledPictureRenderer::end() {
@@ -360,8 +367,14 @@
const int width = this->getViewWidth();
const int height = this->getViewHeight();
+ fTilesX = fTilesY = 0;
for (int tile_y_start = 0; tile_y_start < height; tile_y_start += fTileHeight) {
+ fTilesY++;
for (int tile_x_start = 0; tile_x_start < width; tile_x_start += fTileWidth) {
+ if (0 == tile_y_start) {
+ // Only count tiles in the X direction on the first pass.
+ fTilesX++;
+ }
*fTileRects.append() = SkRect::MakeXYWH(SkIntToScalar(tile_x_start),
SkIntToScalar(tile_y_start),
SkIntToScalar(fTileWidth),
@@ -370,6 +383,15 @@
}
}
+bool TiledPictureRenderer::tileDimensions(int &x, int &y) {
+ if (fTileRects.count() == 0 || NULL == fPicture) {
+ return false;
+ }
+ x = fTilesX;
+ y = fTilesY;
+ return true;
+}
+
// The goal of the powers of two tiles is to minimize the amount of wasted tile
// space in the width-wise direction and then minimize the number of tiles. The
// constraints are that every tile must have a pixel width that is a power of
@@ -392,8 +414,10 @@
int num_bits = SkScalarCeilToInt(SkScalarLog2(SkIntToScalar(width)));
int largest_possible_tile_size = 1 << num_bits;
+ fTilesX = fTilesY = 0;
// The tile height is constant for a particular picture.
for (int tile_y_start = 0; tile_y_start < height; tile_y_start += fTileHeight) {
+ fTilesY++;
int tile_x_start = 0;
int current_width = largest_possible_tile_size;
// Set fTileWidth to be the width of the widest tile, so that each canvas is large enough
@@ -403,6 +427,10 @@
while (current_width >= fTileMinPowerOf2Width) {
// It is very important this is a bitwise AND.
if (current_width & rounded_value) {
+ if (0 == tile_y_start) {
+ // Only count tiles in the X direction on the first pass.
+ fTilesX++;
+ }
*fTileRects.append() = SkRect::MakeXYWH(SkIntToScalar(tile_x_start),
SkIntToScalar(tile_y_start),
SkIntToScalar(current_width),
@@ -433,21 +461,31 @@
///////////////////////////////////////////////////////////////////////////////////////////////
+bool TiledPictureRenderer::nextTile(int &i, int &j) {
+ if (++fCurrentTileOffset < fTileRects.count()) {
+ i = fCurrentTileOffset % fTilesX;
+ j = fCurrentTileOffset / fTilesX;
+ return true;
+ }
+ return false;
+}
+
+void TiledPictureRenderer::drawCurrentTile() {
+ SkASSERT(fCurrentTileOffset >= 0 && fCurrentTileOffset < fTileRects.count());
+ DrawTileToCanvas(fCanvas, fTileRects[fCurrentTileOffset], fPicture);
+}
+
bool TiledPictureRenderer::render(const SkString* path) {
SkASSERT(fPicture != NULL);
if (NULL == fPicture) {
return false;
}
- // Reuse one canvas for all tiles.
- SkCanvas* canvas = this->setupCanvas(fTileWidth, fTileHeight);
- SkAutoUnref aur(canvas);
-
bool success = true;
for (int i = 0; i < fTileRects.count(); ++i) {
- DrawTileToCanvas(canvas, fTileRects[i], fPicture);
+ DrawTileToCanvas(fCanvas, fTileRects[i], fPicture);
if (NULL != path) {
- success &= writeAppendNumber(canvas, path, i);
+ success &= writeAppendNumber(fCanvas, path, i);
}
}
return success;