blob: 7fd58cef6a4cf777ab789366aa80bb005e86f090 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMReplayTask.h"
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00002#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00003#include "DMUtil.h"
4
robertphillips@google.com770963f2014-04-18 18:04:41 +00005#include "SkBBHFactory.h"
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00006#include "SkCommandLineFlags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00007#include "SkPicture.h"
8
rmistry@google.comd6bab022013-12-02 13:50:38 +00009DEFINE_bool(replay, true, "If true, run picture replay tests.");
10DEFINE_bool(rtree, true, "If true, run picture replay tests with an rtree.");
mtklein73734562014-06-24 12:28:34 -070011DEFINE_bool(skr, true, "If true, run picture replay tests with SkRecord backend.");
12
13static const char* kSuffixes[] = { "replay", "rtree", "skr" };
14static const bool* kEnabled[] = { &FLAGS_replay, &FLAGS_rtree, &FLAGS_skr };
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000015
mtklein@google.comd36522d2013-10-16 13:02:15 +000016namespace DM {
17
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000018ReplayTask::ReplayTask(const Task& parent,
mtklein@google.comd36522d2013-10-16 13:02:15 +000019 skiagm::GM* gm,
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000020 SkBitmap reference,
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000021 Mode mode)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000022 : CpuTask(parent)
mtklein73734562014-06-24 12:28:34 -070023 , fMode(mode)
24 , fName(UnderJoin(parent.name().c_str(), kSuffixes[mode]))
mtklein@google.comd36522d2013-10-16 13:02:15 +000025 , fGM(gm)
26 , fReference(reference)
mtklein@google.comd36522d2013-10-16 13:02:15 +000027 {}
28
29void ReplayTask::draw() {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000030 SkAutoTDelete<SkBBHFactory> factory;
mtklein73734562014-06-24 12:28:34 -070031 if (kRTree_Mode == fMode) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000032 factory.reset(SkNEW(SkRTreeFactory));
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +000033 }
mtklein73734562014-06-24 12:28:34 -070034 SkAutoTUnref<SkPicture> recorded(
35 RecordPicture(fGM.get(), factory.get(), kSkRecord_Mode == fMode));
mtklein@google.comd36522d2013-10-16 13:02:15 +000036
37 SkBitmap bitmap;
commit-bot@chromium.org26642072014-05-15 17:33:31 +000038 AllocatePixels(fReference, &bitmap);
mtklein73734562014-06-24 12:28:34 -070039 DrawPicture(*recorded, &bitmap);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000040 if (!BitmapsEqual(bitmap, fReference)) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000041 this->fail();
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000042 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000043 }
44}
45
46bool ReplayTask::shouldSkip() const {
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000047 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
48 return true;
49 }
mtklein73734562014-06-24 12:28:34 -070050 return !*kEnabled[fMode];
mtklein@google.comd36522d2013-10-16 13:02:15 +000051}
52
mtklein@google.coma7a9f372013-10-18 20:52:44 +000053} // namespace DM