blob: fb0e4e6898570fab2710773535f15f66290db998 [file] [log] [blame]
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +00001#include "DMRecordTask.h"
2#include "DMUtil.h"
3#include "DMWriteTask.h"
4#include "SkCommandLineFlags.h"
5#include "SkRecordDraw.h"
6#include "SkRecorder.h"
7
8DEFINE_bool(skr, false, "If true, run SKR tests.");
9
10namespace DM {
11
12RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
13 : CpuTask(parent)
14 , fName(UnderJoin(parent.name().c_str(), "skr"))
15 , fGM(gm)
16 , fReference(reference)
17 {}
18
19void RecordTask::draw() {
20 // Record the GM into an SkRecord.
21 SkRecord record;
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000022 SkRecorder canvas(SkRecorder::kWriteOnly_Mode, &record,
23 fReference.width(), fReference.height());
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000024 canvas.concat(fGM->getInitialTransform());
25 fGM->draw(&canvas);
26
27 // Draw the SkRecord back into a bitmap.
28 SkBitmap bitmap;
29 SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
30 SkCanvas target(bitmap);
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000031
32 SkRecordDraw(record, &target);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000033
34 if (!BitmapsEqual(bitmap, fReference)) {
35 this->fail();
36 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
37 }
38}
39
40bool RecordTask::shouldSkip() const {
41 return !FLAGS_skr;
42}
43
44} // namespace DM