| OLD | NEW |
| 1 #include "DMTileGridTask.h" | 1 #include "DMTileGridTask.h" |
| 2 #include "DMWriteTask.h" | 2 #include "DMWriteTask.h" |
| 3 #include "DMUtil.h" | 3 #include "DMUtil.h" |
| 4 | 4 |
| 5 #include "SkCommandLineFlags.h" | 5 #include "SkCommandLineFlags.h" |
| 6 #include "SkPicture.h" | 6 #include "SkPicture.h" |
| 7 #include "SkTileGridPicture.h" | 7 #include "SkTileGridPicture.h" |
| 8 | 8 |
| 9 // TODO(mtklein): Tile grid tests are currently failing. (Skia issue 1198). Wh
en fixed, -> true. | 9 // TODO(mtklein): Tile grid tests are currently failing. (Skia issue 1198). Wh
en fixed, -> true. |
| 10 DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid
."); | 10 DEFINE_bool(tileGrid, false, "If true, run picture replay tests with a tile grid
."); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 static int tiles_needed(int fullDimension, int tileDimension) { | 22 static int tiles_needed(int fullDimension, int tileDimension) { |
| 23 return (fullDimension + tileDimension - 1) / tileDimension; | 23 return (fullDimension + tileDimension - 1) / tileDimension; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void TileGridTask::draw() { | 26 void TileGridTask::draw() { |
| 27 const SkTileGridPicture::TileGridInfo info = { | 27 const SkTileGridPicture::TileGridInfo info = { |
| 28 fTileSize, | 28 fTileSize, |
| 29 SkISize::Make(0,0), // Overlap between adjacent tiles. | 29 SkISize::Make(0,0), // Overlap between adjacent tiles. |
| 30 SkIPoint::Make(0,0), // Offset. | 30 SkIPoint::Make(0,0), // Offset. |
| 31 }; | 31 }; |
| 32 const SkISize size = fGM->getISize(); | 32 SkAutoTUnref<SkPictureFactory> factory(SkNEW_ARGS(SkTileGridPictureFactory,
(info))); |
| 33 SkTileGridPicture recorded(size.width(), size.height(), info); | 33 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), |
| 34 RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_Recordi
ngFlag); | 34 SkPicture::kUsePathBoundsForC
lip_RecordingFlag, |
| 35 factory)); |
| 35 | 36 |
| 36 SkBitmap full; | 37 SkBitmap full; |
| 37 SetupBitmap(fReference.colorType(), fGM.get(), &full); | 38 SetupBitmap(fReference.colorType(), fGM.get(), &full); |
| 38 SkCanvas fullCanvas(full); | 39 SkCanvas fullCanvas(full); |
| 39 | 40 |
| 40 SkBitmap tile; | 41 SkBitmap tile; |
| 41 tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(), | 42 tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(), |
| 42 fReference.colorType(), kPremul_SkAlphaTy
pe)); | 43 fReference.colorType(), kPremul_SkAlphaTy
pe)); |
| 43 SkCanvas tileCanvas(tile); | 44 SkCanvas tileCanvas(tile); |
| 44 | 45 |
| 45 SkPaint paint; | 46 SkPaint paint; |
| 46 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 47 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 47 | 48 |
| 48 for (int y = 0; y < tiles_needed(full.height(), tile.height()); y++) { | 49 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 for (int x = 0; x < tiles_needed(full.width(), tile.width()); x++) { |
| 50 SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/); | 51 SkAutoCanvasRestore ar(&tileCanvas, true/*also save now*/); |
| 51 | 52 |
| 52 const SkScalar xOffset = SkIntToScalar(x * tile.width()), | 53 const SkScalar xOffset = SkIntToScalar(x * tile.width()), |
| 53 yOffset = SkIntToScalar(y * tile.height()); | 54 yOffset = SkIntToScalar(y * tile.height()); |
| 54 SkMatrix matrix = tileCanvas.getTotalMatrix(); | 55 SkMatrix matrix = tileCanvas.getTotalMatrix(); |
| 55 matrix.postTranslate(-xOffset, -yOffset); | 56 matrix.postTranslate(-xOffset, -yOffset); |
| 56 tileCanvas.setMatrix(matrix); | 57 tileCanvas.setMatrix(matrix); |
| 57 | 58 |
| 58 recorded.draw(&tileCanvas); | 59 recorded->draw(&tileCanvas); |
| 59 tileCanvas.flush(); | 60 tileCanvas.flush(); |
| 60 fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint); | 61 fullCanvas.drawBitmap(tile, xOffset, yOffset, &paint); |
| 61 } | 62 } |
| 62 } | 63 } |
| 63 | 64 |
| 64 if (!BitmapsEqual(full, fReference)) { | 65 if (!BitmapsEqual(full, fReference)) { |
| 65 this->fail(); | 66 this->fail(); |
| 66 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full))); | 67 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, full))); |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool TileGridTask::shouldSkip() const { | 71 bool TileGridTask::shouldSkip() const { |
| 71 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { | 72 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { |
| 72 return true; | 73 return true; |
| 73 } | 74 } |
| 74 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) { | 75 if (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) { |
| 75 return true; | 76 return true; |
| 76 } | 77 } |
| 77 return !FLAGS_tileGrid; | 78 return !FLAGS_tileGrid; |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace DM | 81 } // namespace DM |
| OLD | NEW |