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
This commit is contained in:
mtklein@google.com 2013-11-26 23:36:51 +00:00
parent 49360dfa61
commit 09f2579109
6 changed files with 118 additions and 5 deletions

View File

@ -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

View File

@ -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;

77
dm/DMTileGridTask.cpp Normal file
View File

@ -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

36
dm/DMTileGridTask.h Normal file
View File

@ -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

View File

@ -7,7 +7,6 @@ Current approximate list of missing features:
--writePicturePath
--deferred
--tiledGrid
DM's design is based around Tasks and a TaskRunner.

View File

@ -27,6 +27,7 @@
'../dm/DMSerializeTask.cpp',
'../dm/DMTask.cpp',
'../dm/DMTaskRunner.cpp',
'../dm/DMTileGridTask.cpp',
'../dm/DMUtil.cpp',
'../dm/DMWriteTask.cpp',
'../gm/gm.cpp',