2014-04-30 13:20:45 +00:00
|
|
|
#include "DMQuiltTask.h"
|
2013-11-26 23:36:51 +00:00
|
|
|
#include "DMUtil.h"
|
2014-04-30 13:20:45 +00:00
|
|
|
#include "DMWriteTask.h"
|
2013-11-26 23:36:51 +00:00
|
|
|
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
|
2014-04-30 13:20:45 +00:00
|
|
|
DEFINE_bool(quilt, true, "If true, draw into a quilt of small tiles and compare.");
|
|
|
|
DEFINE_int32(quiltTile, 16, "Dimension of (square) quilt tile.");
|
2013-11-26 23:36:51 +00:00
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
2014-04-30 13:20:45 +00:00
|
|
|
QuiltTask::QuiltTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
|
2014-02-28 20:31:31 +00:00
|
|
|
: CpuTask(parent)
|
2014-04-30 13:20:45 +00:00
|
|
|
, fName(UnderJoin(parent.name().c_str(), "quilt"))
|
2013-11-26 23:36:51 +00:00
|
|
|
, fGM(gm)
|
|
|
|
, fReference(reference)
|
|
|
|
{}
|
|
|
|
|
|
|
|
static int tiles_needed(int fullDimension, int tileDimension) {
|
|
|
|
return (fullDimension + tileDimension - 1) / tileDimension;
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:20:45 +00:00
|
|
|
void QuiltTask::draw() {
|
|
|
|
SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get()));
|
2013-11-26 23:36:51 +00:00
|
|
|
|
|
|
|
SkBitmap full;
|
2014-05-15 17:33:31 +00:00
|
|
|
AllocatePixels(fReference, &full);
|
2013-11-26 23:36:51 +00:00
|
|
|
SkCanvas fullCanvas(full);
|
|
|
|
|
|
|
|
SkBitmap tile;
|
2014-04-30 13:20:45 +00:00
|
|
|
tile.allocPixels(SkImageInfo::Make(FLAGS_quiltTile, FLAGS_quiltTile,
|
2014-02-16 00:59:25 +00:00
|
|
|
fReference.colorType(), kPremul_SkAlphaType));
|
2013-11-26 23:36:51 +00:00
|
|
|
SkCanvas tileCanvas(tile);
|
|
|
|
|
|
|
|
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();
|
2014-04-30 13:20:45 +00:00
|
|
|
fullCanvas.drawBitmap(tile, xOffset, yOffset, NULL);
|
2013-11-26 23:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BitmapsEqual(full, fReference)) {
|
|
|
|
this->fail();
|
|
|
|
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:20:45 +00:00
|
|
|
bool QuiltTask::shouldSkip() const {
|
2013-11-26 23:36:51 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-04-30 13:20:45 +00:00
|
|
|
return !FLAGS_quilt;
|
2013-11-26 23:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|