blob: eb8ceecbbd09dbca414df088ec1df68ae89a959e [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() {
19 // Record the GM into an SkRecord.
commit-bot@chromium.org732bd662014-04-24 15:22:55 +000020 EXPERIMENTAL::SkRecording recording(fReference.width(), fReference.height());
commit-bot@chromium.org90d81c92014-05-01 21:06:39 +000021 recording.canvas()->concat(fGM->getInitialTransform());
commit-bot@chromium.org732bd662014-04-24 15:22:55 +000022 fGM->draw(recording.canvas());
23 SkAutoTDelete<const EXPERIMENTAL::SkPlayback> playback(recording.releasePlayback());
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000024
25 // Draw the SkRecord back into a bitmap.
26 SkBitmap bitmap;
27 SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
28 SkCanvas target(bitmap);
commit-bot@chromium.orgb17a24f2014-04-14 20:33:05 +000029 playback->draw(&target);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000030
31 if (!BitmapsEqual(bitmap, fReference)) {
32 this->fail();
33 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
34 }
35}
36
37bool RecordTask::shouldSkip() const {
38 return !FLAGS_skr;
39}
40
41} // namespace DM