Chromium Code Reviews| Index: dm/DMTileGridTask.cpp |
| diff --git a/dm/DMTileGridTask.cpp b/dm/DMTileGridTask.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14ead057096bfdfd7c6aea1357044ebf3b06e21a |
| --- /dev/null |
| +++ b/dm/DMTileGridTask.cpp |
| @@ -0,0 +1,77 @@ |
| +#include "DMTileGridTask.h" |
| +#include "DMWriteTask.h" |
| +#include "DMUtil.h" |
| + |
| +#include "SkCommandLineFlags.h" |
| +#include "SkPicture.h" |
| +#include "SkTileGridPicture.h" |
| + |
| +// Tile grid tests are currently failing. (Skia issue 1198). When fixed, default to true. |
|
epoger
2013/11/26 22:26:01
Maybe make this a TODO(mtklein) for searchability
mtklein
2013/11/26 23:34:34
Done.
|
| +DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid."); |
| + |
| +namespace DM { |
| + |
| +TileGridTask::TileGridTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, SkISize tileSize) |
| + : Task(parent) |
| + , fName(UnderJoin(parent.name().c_str(), "tilegrid")) |
| + , fGM(gm) |
| + , fReference(reference) |
| + , fTileSize(tileSize) |
| + {} |
| + |
| +static int divide_round(int x, int y) { |
|
epoger
2013/11/26 22:26:01
Maybe add documentation and rename to make the ope
mtklein
2013/11/26 23:34:34
Done.
|
| + return (x + y - 1) / y; |
| +} |
| + |
| +void TileGridTask::draw() { |
| + const SkTileGridPicture::TileGridInfo info = { |
| + fTileSize, |
| + SkISize::Make(0,0), // Overlap between adjacent tiles. |
| + SkIPoint::Make(0,0), // Offset. |
| + }; |
| + const SkISize size = fGM->getISize(); |
| + SkTileGridPicture recorded(size.width(), size.height(), info); |
| + RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag); |
| + |
| + SkBitmap full; |
| + SetupBitmap(fReference.config(), fGM.get(), &full); |
| + SkCanvas fullCanvas(full); |
| + |
| + SkBitmap tile; |
| + tile.setConfig(fReference.config(), fTileSize.width(), fTileSize.height()); |
| + tile.allocPixels(); |
| + SkCanvas tileCanvas(tile); |
| + |
| + SkPaint paint; |
| + paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| + |
| + for (int y = 0; y < divide_round(full.height(), tile.height()); y++) { |
| + for (int x = 0; x < divide_round(full.width(), tile.width()); x++) { |
| + SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/); |
| + |
| + const SkScalar xOffset = x * tile.width(), |
| + yOffset = y * tile.height(); |
| + SkMatrix matrix = tileCanvas.getTotalMatrix(); |
| + matrix.postTranslate(-xOffset, -yOffset); |
| + tileCanvas.setMatrix(matrix); |
| + |
| + recorded.draw(&tileCanvas); |
| + tileCanvas.flush(); |
| + fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint); |
| + } |
| + } |
| + |
| + if (!BitmapsEqual(full, fReference)) { |
| + this->fail(); |
| + this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full))); |
| + } |
| +} |
| + |
| +bool TileGridTask::shouldSkip() const { |
| + if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { |
| + return true; |
| + } |
| + return !FLAGS_tileGrid; |
| +} |
| + |
| +} // namespace DM |