diff options
author | mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-26 23:36:51 +0000 |
---|---|---|
committer | mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-26 23:36:51 +0000 |
commit | 09f25791091db15a61083169cfda9feda0e653f6 (patch) | |
tree | 2749a8a405692be74e8941c569949fb32e5d0e42 /dm | |
parent | 49360dfa6144621db9f3ec25995b8e817a0003c0 (diff) |
DM: add --tileGrid
BUG=
R=epoger@google.com
Review URL: https://codereview.chromium.org/88563003
git-svn-id: http://skia.googlecode.com/svn/trunk@12408 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'dm')
-rw-r--r-- | dm/DMCpuTask.cpp | 4 | ||||
-rw-r--r-- | dm/DMReplayTask.h | 4 | ||||
-rw-r--r-- | dm/DMTileGridTask.cpp | 77 | ||||
-rw-r--r-- | dm/DMTileGridTask.h | 36 | ||||
-rw-r--r-- | dm/README | 1 |
5 files changed, 117 insertions, 5 deletions
diff --git a/dm/DMCpuTask.cpp b/dm/DMCpuTask.cpp index 263e55667e..3f51c8a318 100644 --- a/dm/DMCpuTask.cpp +++ b/dm/DMCpuTask.cpp @@ -3,6 +3,7 @@ #include "DMPipeTask.h" #include "DMReplayTask.h" #include "DMSerializeTask.h" +#include "DMTileGridTask.h" #include "DMUtil.h" #include "DMWriteTask.h" @@ -37,11 +38,10 @@ void CpuTask::draw() { SPAWN(PipeTask, fGMFactory(NULL), bitmap, false, false); SPAWN(PipeTask, fGMFactory(NULL), bitmap, true, false); SPAWN(PipeTask, fGMFactory(NULL), bitmap, true, true); - SPAWN(ReplayTask, fGMFactory(NULL), bitmap, false); SPAWN(ReplayTask, fGMFactory(NULL), bitmap, true); - SPAWN(SerializeTask, fGMFactory(NULL), bitmap); + SPAWN(TileGridTask, fGMFactory(NULL), bitmap, SkISize::Make(16,16)); SPAWN(WriteTask, bitmap); #undef SPAWN diff --git a/dm/DMReplayTask.h b/dm/DMReplayTask.h index 1217c07396..1245009923 100644 --- a/dm/DMReplayTask.h +++ b/dm/DMReplayTask.h @@ -15,8 +15,8 @@ class ReplayTask : public Task { public: ReplayTask(const Task& parent, // ReplayTask must be a child task. Pass its parent here. - skiagm::GM*, // GM to run through a pipe. Takes ownership. - SkBitmap reference, // Bitmap to compare pipe results to. + skiagm::GM*, // GM to run through a picture. Takes ownership. + SkBitmap reference, // Bitmap to compare picture replay results to. bool useRTree); // Record with an RTree? virtual void draw() SK_OVERRIDE; diff --git a/dm/DMTileGridTask.cpp b/dm/DMTileGridTask.cpp new file mode 100644 index 0000000000..67cbbd924a --- /dev/null +++ b/dm/DMTileGridTask.cpp @@ -0,0 +1,77 @@ +#include "DMTileGridTask.h" +#include "DMWriteTask.h" +#include "DMUtil.h" + +#include "SkCommandLineFlags.h" +#include "SkPicture.h" +#include "SkTileGridPicture.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) + : Task(parent) + , 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() { + const SkTileGridPicture::TileGridInfo info = { + fTileSize, + SkISize::Make(0,0), // Overlap between adjacent tiles. + SkIPoint::Make(0,0), // Offset. + }; + const SkISize size = fGM->getISize(); + SkTileGridPicture recorded(size.width(), size.height(), info); + RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag); + + SkBitmap full; + SetupBitmap(fReference.config(), fGM.get(), &full); + SkCanvas fullCanvas(full); + + SkBitmap tile; + tile.setConfig(fReference.config(), fTileSize.width(), fTileSize.height()); + tile.allocPixels(); + 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*/); + + const SkScalar xOffset = x * tile.width(), + yOffset = y * tile.height(); + SkMatrix matrix = tileCanvas.getTotalMatrix(); + matrix.postTranslate(-xOffset, -yOffset); + tileCanvas.setMatrix(matrix); + + recorded.draw(&tileCanvas); + 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; + } + return !FLAGS_tileGrid; +} + +} // namespace DM diff --git a/dm/DMTileGridTask.h b/dm/DMTileGridTask.h new file mode 100644 index 0000000000..4a522b956c --- /dev/null +++ b/dm/DMTileGridTask.h @@ -0,0 +1,36 @@ +#ifndef DMTileGridTask_DEFINED +#define DMTileGridTask_DEFINED + +#include "DMTask.h" +#include "SkBitmap.h" +#include "SkString.h" +#include "SkTemplates.h" +#include "gm.h" + +// Records a GM through an SkPicture, draws it in tiles, and compares against the reference bitmap. + +namespace DM { + +class TileGridTask : public Task { + +public: + TileGridTask(const Task& parent, // TileGridTask must be a child task. Pass its parent here. + skiagm::GM*, // GM to run through a picture. Takes ownership. + SkBitmap reference, // Bitmap to compare picture replay results to. + SkISize tileSize); // Tile size to use. + + virtual void draw() SK_OVERRIDE; + virtual bool usesGpu() const SK_OVERRIDE { return false; } + virtual bool shouldSkip() const SK_OVERRIDE; + virtual SkString name() const SK_OVERRIDE { return fName; } + +private: + const SkString fName; + SkAutoTDelete<skiagm::GM> fGM; + const SkBitmap fReference; + const SkISize fTileSize; +}; + +} // namespace DM + +#endif // DMReplayTask_DEFINED @@ -7,7 +7,6 @@ Current approximate list of missing features: --writePicturePath --deferred - --tiledGrid DM's design is based around Tasks and a TaskRunner. |