1#include "DMReplayTask.h" 2#include "DMWriteTask.h" 3#include "DMUtil.h" 4 5#include "SkBBHFactory.h" 6#include "SkCommandLineFlags.h" 7#include "SkPicture.h" 8 9DEFINE_bool(replay, true, "If true, run picture replay tests."); 10DEFINE_bool(rtree, true, "If true, run picture replay tests with an rtree."); 11 12namespace DM { 13 14ReplayTask::ReplayTask(const Task& parent, 15 skiagm::GM* gm, 16 SkBitmap reference, 17 Mode mode) 18 : CpuTask(parent) 19 , fUseRTree(mode == kRTree_Mode) 20 , fName(UnderJoin(parent.name().c_str(), fUseRTree ? "rtree" : "replay")) 21 , fGM(gm) 22 , fReference(reference) 23 {} 24 25void ReplayTask::draw() { 26 SkAutoTDelete<SkBBHFactory> factory; 27 if (fUseRTree) { 28 factory.reset(SkNEW(SkRTreeFactory)); 29 } 30 SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), 0, factory.get())); 31 32 SkBitmap bitmap; 33 AllocatePixels(fReference, &bitmap); 34 DrawPicture(recorded, &bitmap); 35 if (!BitmapsEqual(bitmap, fReference)) { 36 this->fail(); 37 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); 38 } 39} 40 41bool ReplayTask::shouldSkip() const { 42 if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) { 43 return true; 44 } 45 46 if (FLAGS_rtree && fUseRTree) { 47 return false; 48 } 49 if (FLAGS_replay && !fUseRTree) { 50 return false; 51 } 52 return true; 53} 54 55} // namespace DM 56