blob: af8669b7d11e1653dda2bd57e2a2ba9505acd93e [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
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00005#include "SkCommandLineFlags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkPicture.h"
7
rmistry@google.comd6bab022013-12-02 13:50:38 +00008DEFINE_bool(replay, true, "If true, run picture replay tests.");
9DEFINE_bool(rtree, true, "If true, run picture replay tests with an rtree.");
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000010
mtklein@google.comd36522d2013-10-16 13:02:15 +000011namespace DM {
12
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000013ReplayTask::ReplayTask(const Task& parent,
mtklein@google.comd36522d2013-10-16 13:02:15 +000014 skiagm::GM* gm,
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000015 SkBitmap reference,
16 bool useRTree)
mtklein@google.comd36522d2013-10-16 13:02:15 +000017 : Task(parent)
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000018 , fName(UnderJoin(parent.name().c_str(), useRTree ? "rtree" : "replay"))
mtklein@google.comd36522d2013-10-16 13:02:15 +000019 , fGM(gm)
20 , fReference(reference)
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000021 , fUseRTree(useRTree)
mtklein@google.comd36522d2013-10-16 13:02:15 +000022 {}
23
24void ReplayTask::draw() {
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000025 SkPicture recorded;
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000026 const uint32_t flags = fUseRTree ? SkPicture::kOptimizeForClippedPlayback_RecordingFlag : 0;
27 RecordPicture(fGM.get(), &recorded, flags);
mtklein@google.comd36522d2013-10-16 13:02:15 +000028
29 SkBitmap bitmap;
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000030 SetupBitmap(fReference.config(), fGM.get(), &bitmap);
31 DrawPicture(&recorded, &bitmap);
32 if (!BitmapsEqual(bitmap, fReference)) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000033 this->fail();
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000034 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000035 }
36}
37
38bool ReplayTask::shouldSkip() const {
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000039 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
40 return true;
41 }
42
43 if (FLAGS_rtree && fUseRTree) {
44 return false;
45 }
46 if (FLAGS_replay && !fUseRTree) {
47 return false;
48 }
49 return true;
mtklein@google.comd36522d2013-10-16 13:02:15 +000050}
51
mtklein@google.coma7a9f372013-10-18 20:52:44 +000052} // namespace DM