blob: f9cac07de367be0e2f7f0434dfe2dc04b371da76 [file] [log] [blame]
mtklein@google.com09f25792013-11-26 23:36:51 +00001#include "DMTileGridTask.h"
2#include "DMWriteTask.h"
3#include "DMUtil.h"
4
5#include "SkCommandLineFlags.h"
6#include "SkPicture.h"
7#include "SkTileGridPicture.h"
8
9// TODO(mtklein): Tile grid tests are currently failing. (Skia issue 1198). When fixed, -> true.
10DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid.");
11
12namespace DM {
13
14TileGridTask::TileGridTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, SkISize tileSize)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000015 : CpuTask(parent)
mtklein@google.com09f25792013-11-26 23:36:51 +000016 , fName(UnderJoin(parent.name().c_str(), "tilegrid"))
17 , fGM(gm)
18 , fReference(reference)
19 , fTileSize(tileSize)
20 {}
21
22static int tiles_needed(int fullDimension, int tileDimension) {
23 return (fullDimension + tileDimension - 1) / tileDimension;
24}
25
26void TileGridTask::draw() {
27 const SkTileGridPicture::TileGridInfo info = {
28 fTileSize,
29 SkISize::Make(0,0), // Overlap between adjacent tiles.
30 SkIPoint::Make(0,0), // Offset.
31 };
32 const SkISize size = fGM->getISize();
33 SkTileGridPicture recorded(size.width(), size.height(), info);
34 RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag);
35
36 SkBitmap full;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000037 SetupBitmap(fReference.colorType(), fGM.get(), &full);
mtklein@google.com09f25792013-11-26 23:36:51 +000038 SkCanvas fullCanvas(full);
39
40 SkBitmap tile;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000041 tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(),
42 fReference.colorType(), kPremul_SkAlphaType));
mtklein@google.com09f25792013-11-26 23:36:51 +000043 SkCanvas tileCanvas(tile);
44
45 SkPaint paint;
46 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
47
48 for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) {
49 for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) {
50 SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/);
51
mtklein@google.com73afd372013-11-27 00:04:15 +000052 const SkScalar xOffset = SkIntToScalar(x * tile.width()),
53 yOffset = SkIntToScalar(y * tile.height());
mtklein@google.com09f25792013-11-26 23:36:51 +000054 SkMatrix matrix = tileCanvas.getTotalMatrix();
55 matrix.postTranslate(-xOffset, -yOffset);
56 tileCanvas.setMatrix(matrix);
57
58 recorded.draw(&tileCanvas);
59 tileCanvas.flush();
60 fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint);
61 }
62 }
63
64 if (!BitmapsEqual(full, fReference)) {
65 this->fail();
66 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full)));
67 }
68}
69
70bool TileGridTask::shouldSkip() const {
71 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
72 return true;
73 }
commit-bot@chromium.org9e5a5492013-12-02 22:22:40 +000074 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) {
75 return true;
76 }
mtklein@google.com09f25792013-11-26 23:36:51 +000077 return !FLAGS_tileGrid;
78}
79
80} // namespace DM