2013-11-26 23:36:51 +00:00
|
|
|
#include "DMTileGridTask.h"
|
|
|
|
#include "DMWriteTask.h"
|
|
|
|
#include "DMUtil.h"
|
|
|
|
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkBBHFactory.h"
|
2013-11-26 23:36:51 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
|
|
|
|
// TODO(mtklein): Tile grid tests are currently failing. (Skia issue 1198). When fixed, -> true.
|
|
|
|
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)
|
2014-02-28 20:31:31 +00:00
|
|
|
: CpuTask(parent)
|
2013-11-26 23:36:51 +00:00
|
|
|
, fName(UnderJoin(parent.name().c_str(), "tilegrid"))
|
|
|
|
, fGM(gm)
|
|
|
|
, fReference(reference)
|
|
|
|
, fTileSize(tileSize)
|
|
|
|
{}
|
|
|
|
|
|
|
|
static int tiles_needed(int fullDimension, int tileDimension) {
|
|
|
|
return (fullDimension + tileDimension - 1) / tileDimension;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileGridTask::draw() {
|
2014-04-17 23:35:06 +00:00
|
|
|
const SkTileGridFactory::TileGridInfo info = {
|
2013-11-26 23:36:51 +00:00
|
|
|
fTileSize,
|
2014-04-17 23:35:06 +00:00
|
|
|
SkISize::Make(0,0), // Overlap between adjacent tiles.
|
|
|
|
SkIPoint::Make(0,0), // Offset.
|
2013-11-26 23:36:51 +00:00
|
|
|
};
|
2014-04-17 23:35:06 +00:00
|
|
|
SkTileGridFactory factory(info);
|
2014-04-14 03:04:57 +00:00
|
|
|
SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(),
|
|
|
|
SkPicture::kUsePathBoundsForClip_RecordingFlag,
|
2014-04-17 23:35:06 +00:00
|
|
|
&factory));
|
2013-11-26 23:36:51 +00:00
|
|
|
|
|
|
|
SkBitmap full;
|
2014-02-16 00:59:25 +00:00
|
|
|
SetupBitmap(fReference.colorType(), fGM.get(), &full);
|
2013-11-26 23:36:51 +00:00
|
|
|
SkCanvas fullCanvas(full);
|
|
|
|
|
|
|
|
SkBitmap tile;
|
2014-02-16 00:59:25 +00:00
|
|
|
tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(),
|
|
|
|
fReference.colorType(), kPremul_SkAlphaType));
|
2013-11-26 23:36:51 +00:00
|
|
|
SkCanvas tileCanvas(tile);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
|
|
|
|
|
|
|
for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) {
|
|
|
|
for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) {
|
|
|
|
SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/);
|
|
|
|
|
2013-11-27 00:04:15 +00:00
|
|
|
const SkScalar xOffset = SkIntToScalar(x * tile.width()),
|
|
|
|
yOffset = SkIntToScalar(y * tile.height());
|
2013-11-26 23:36:51 +00:00
|
|
|
SkMatrix matrix = tileCanvas.getTotalMatrix();
|
|
|
|
matrix.postTranslate(-xOffset, -yOffset);
|
|
|
|
tileCanvas.setMatrix(matrix);
|
|
|
|
|
2014-04-13 19:09:42 +00:00
|
|
|
recorded->draw(&tileCanvas);
|
2013-11-26 23:36:51 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-12-02 22:22:40 +00:00
|
|
|
if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-26 23:36:51 +00:00
|
|
|
return !FLAGS_tileGrid;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|