2014-04-01 16:24:06 +00:00
|
|
|
#include "DMRecordTask.h"
|
|
|
|
#include "DMUtil.h"
|
|
|
|
#include "DMWriteTask.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
2014-05-06 19:48:02 +00:00
|
|
|
#include "SkRecord.h"
|
|
|
|
#include "SkRecordDraw.h"
|
|
|
|
#include "SkRecordOpts.h"
|
|
|
|
#include "SkRecorder.h"
|
2014-04-01 16:24:06 +00:00
|
|
|
|
2014-05-02 21:23:52 +00:00
|
|
|
DEFINE_bool(skr, true, "If true, run SKR tests.");
|
2014-04-01 16:24:06 +00:00
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
2014-05-14 17:55:32 +00:00
|
|
|
RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference, Mode mode)
|
2014-04-01 16:24:06 +00:00
|
|
|
: CpuTask(parent)
|
2014-05-14 17:55:32 +00:00
|
|
|
, fOptimize(mode == kOptimize_Mode)
|
|
|
|
, fName(UnderJoin(parent.name().c_str(), fOptimize ? "skr" : "skr-noopt"))
|
2014-04-01 16:24:06 +00:00
|
|
|
, fGM(gm)
|
|
|
|
, fReference(reference)
|
2014-05-14 17:55:32 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
RecordTask::RecordTask(const Task& parent, SkPicture* pic, SkBitmap reference, Mode mode)
|
|
|
|
: CpuTask(parent)
|
|
|
|
, fOptimize(mode == kOptimize_Mode)
|
|
|
|
, fName(UnderJoin(parent.name().c_str(), fOptimize ? "skr" : "skr-noopt"))
|
|
|
|
, fPicture(SkRef(pic))
|
|
|
|
, fReference(reference)
|
2014-04-01 16:24:06 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void RecordTask::draw() {
|
2014-05-14 17:55:32 +00:00
|
|
|
// Record into an SkRecord.
|
2014-05-06 19:48:02 +00:00
|
|
|
SkRecord record;
|
|
|
|
SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record,
|
|
|
|
fReference.width(), fReference.height());
|
2014-05-14 17:55:32 +00:00
|
|
|
|
|
|
|
if (fGM.get()) {
|
|
|
|
recorder.concat(fGM->getInitialTransform());
|
|
|
|
fGM->draw(&recorder);
|
|
|
|
} else {
|
|
|
|
fPicture->draw(&recorder);
|
|
|
|
}
|
|
|
|
|
2014-05-06 19:48:02 +00:00
|
|
|
|
|
|
|
if (fOptimize) {
|
|
|
|
SkRecordOptimize(&record);
|
|
|
|
}
|
2014-04-01 16:24:06 +00:00
|
|
|
|
|
|
|
// Draw the SkRecord back into a bitmap.
|
|
|
|
SkBitmap bitmap;
|
2014-05-15 17:33:31 +00:00
|
|
|
AllocatePixels(fReference, &bitmap);
|
2014-04-01 16:24:06 +00:00
|
|
|
SkCanvas target(bitmap);
|
2014-05-06 19:48:02 +00:00
|
|
|
SkRecordDraw(record, &target);
|
2014-04-01 16:24:06 +00:00
|
|
|
|
|
|
|
if (!BitmapsEqual(bitmap, fReference)) {
|
|
|
|
this->fail();
|
|
|
|
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RecordTask::shouldSkip() const {
|
|
|
|
return !FLAGS_skr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|