Home | History | Annotate | Download | only in dm
      1 #include "DMReplayTask.h"
      2 #include "DMWriteTask.h"
      3 #include "DMUtil.h"
      4 
      5 #include "SkCommandLineFlags.h"
      6 #include "SkPicture.h"
      7 
      8 DEFINE_bool(replay, true, "If true, run picture replay tests.");
      9 DEFINE_bool(rtree,  true, "If true, run picture replay tests with an rtree.");
     10 
     11 namespace DM {
     12 
     13 ReplayTask::ReplayTask(const Task& parent,
     14                        skiagm::GM* gm,
     15                        SkBitmap reference,
     16                        bool useRTree)
     17     : Task(parent)
     18     , fName(UnderJoin(parent.name().c_str(), useRTree ? "rtree" : "replay"))
     19     , fGM(gm)
     20     , fReference(reference)
     21     , fUseRTree(useRTree)
     22     {}
     23 
     24 void ReplayTask::draw() {
     25     SkPicture recorded;
     26     const uint32_t flags = fUseRTree ? SkPicture::kOptimizeForClippedPlayback_RecordingFlag : 0;
     27     RecordPicture(fGM.get(), &recorded, flags);
     28 
     29     SkBitmap bitmap;
     30     SetupBitmap(fReference.config(), fGM.get(), &bitmap);
     31     DrawPicture(&recorded, &bitmap);
     32     if (!BitmapsEqual(bitmap, fReference)) {
     33         this->fail();
     34         this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
     35     }
     36 }
     37 
     38 bool ReplayTask::shouldSkip() const {
     39     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;
     50 }
     51 
     52 }  // namespace DM
     53