blob: 95a8bbd217cc781c7357660a703a1043164e92d4 [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"
commit-bot@chromium.orgb17a24f2014-04-14 20:33:05 +00005#include "SkRecording.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +00006
7DEFINE_bool(skr, false, "If true, run SKR tests.");
8
9namespace DM {
10
11RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
12 : CpuTask(parent)
13 , fName(UnderJoin(parent.name().c_str(), "skr"))
14 , fGM(gm)
15 , fReference(reference)
16 {}
17
18void RecordTask::draw() {
commit-bot@chromium.orgb17a24f2014-04-14 20:33:05 +000019 using EXPERIMENTAL::SkRecording;
20 using EXPERIMENTAL::SkPlayback;
21
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000022 // Record the GM into an SkRecord.
commit-bot@chromium.orgb17a24f2014-04-14 20:33:05 +000023 SkRecording* recording = SkRecording::Create(fReference.width(), fReference.height());
24 fGM->draw(recording->canvas());
25 SkAutoTDelete<const SkPlayback> playback(SkRecording::Delete(recording));
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000026
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.orgb17a24f2014-04-14 20:33:05 +000031 playback->draw(&target);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000032
33 if (!BitmapsEqual(bitmap, fReference)) {
34 this->fail();
35 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
36 }
37}
38
39bool RecordTask::shouldSkip() const {
40 return !FLAGS_skr;
41}
42
43} // namespace DM