blob: 86838795d26d0929c4d092c4e6ca00070bf77fce [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.");
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000011
mtklein@google.comd36522d2013-10-16 13:02:15 +000012namespace DM {
13
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000014ReplayTask::ReplayTask(const Task& parent,
mtklein@google.comd36522d2013-10-16 13:02:15 +000015 skiagm::GM* gm,
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000016 SkBitmap reference,
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000017 Mode mode)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000018 : CpuTask(parent)
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000019 , fUseRTree(mode == kRTree_Mode)
20 , fName(UnderJoin(parent.name().c_str(), fUseRTree ? "rtree" : "replay"))
mtklein@google.comd36522d2013-10-16 13:02:15 +000021 , fGM(gm)
22 , fReference(reference)
mtklein@google.comd36522d2013-10-16 13:02:15 +000023 {}
24
25void ReplayTask::draw() {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000026 SkAutoTDelete<SkBBHFactory> factory;
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +000027 if (fUseRTree) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000028 factory.reset(SkNEW(SkRTreeFactory));
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +000029 }
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000030 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), 0, factory.get()));
mtklein@google.comd36522d2013-10-16 13:02:15 +000031
32 SkBitmap bitmap;
commit-bot@chromium.org26642072014-05-15 17:33:31 +000033 AllocatePixels(fReference, &bitmap);
robertphillips@google.com84b18c72014-04-13 19:09:42 +000034 DrawPicture(recorded, &bitmap);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000035 if (!BitmapsEqual(bitmap, fReference)) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000036 this->fail();
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000037 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000038 }
39}
40
41bool ReplayTask::shouldSkip() const {
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000042 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
43 return true;
44 }
45
46 if (FLAGS_rtree && fUseRTree) {
commit-bot@chromium.org96eb6242014-04-29 16:44:00 +000047 return false;
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000048 }
49 if (FLAGS_replay && !fUseRTree) {
50 return false;
51 }
52 return true;
mtklein@google.comd36522d2013-10-16 13:02:15 +000053}
54
mtklein@google.coma7a9f372013-10-18 20:52:44 +000055} // namespace DM