OLD | NEW |
---|---|
(Empty) | |
1 #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 // Tile grid tests are currently failing. (Skia issue 1198). When fixed, defau lt 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.
| |
10 DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid ."); | |
11 | |
12 namespace DM { | |
13 | |
14 TileGridTask::TileGridTask(const Task& parent, skiagm::GM* gm, SkBitmap referenc e, SkISize tileSize) | |
15 : Task(parent) | |
16 , fName(UnderJoin(parent.name().c_str(), "tilegrid")) | |
17 , fGM(gm) | |
18 , fReference(reference) | |
19 , fTileSize(tileSize) | |
20 {} | |
21 | |
22 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.
| |
23 return (x + y - 1) / y; | |
24 } | |
25 | |
26 void 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_Recordi ngFlag); | |
35 | |
36 SkBitmap full; | |
37 SetupBitmap(fReference.config(), fGM.get(), &full); | |
38 SkCanvas fullCanvas(full); | |
39 | |
40 SkBitmap tile; | |
41 tile.setConfig(fReference.config(), fTileSize.width(), fTileSize.height()); | |
42 tile.allocPixels(); | |
43 SkCanvas tileCanvas(tile); | |
44 | |
45 SkPaint paint; | |
46 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
47 | |
48 for (int y = 0; y < divide_round(full.height(), tile.height()); y++) { | |
49 for (int x = 0; x < divide_round(full.width(), tile.width()); x++) { | |
50 SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/); | |
51 | |
52 const SkScalar xOffset = x * tile.width(), | |
53 yOffset = y * tile.height(); | |
54 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 | |
70 bool TileGridTask::shouldSkip() const { | |
71 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { | |
72 return true; | |
73 } | |
74 return !FLAGS_tileGrid; | |
75 } | |
76 | |
77 } // namespace DM | |
OLD | NEW |