DM: add --rtree.

BUG=
R=epoger@google.com

Author: mtklein@google.com

Review URL: https://codereview.chromium.org/51243003

git-svn-id: http://skia.googlecode.com/svn/trunk@12033 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/dm/DMCpuTask.cpp b/dm/DMCpuTask.cpp
index 7e6f909..1d1d401 100644
--- a/dm/DMCpuTask.cpp
+++ b/dm/DMCpuTask.cpp
@@ -38,7 +38,9 @@
     this->spawnChild(SkNEW_ARGS(PipeTask, (*this, fGMFactory(NULL), bitmap, true, false)));
     this->spawnChild(SkNEW_ARGS(PipeTask, (*this, fGMFactory(NULL), bitmap, true, true)));
 
-    this->spawnChild(SkNEW_ARGS(ReplayTask, (*this, fGMFactory(NULL), bitmap)));
+    this->spawnChild(SkNEW_ARGS(ReplayTask, (*this, fGMFactory(NULL), bitmap, true)));
+    this->spawnChild(SkNEW_ARGS(ReplayTask, (*this, fGMFactory(NULL), bitmap, false)));
+
     this->spawnChild(SkNEW_ARGS(SerializeTask, (*this, fGMFactory(NULL), bitmap)));
     this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
 }
diff --git a/dm/DMReplayTask.cpp b/dm/DMReplayTask.cpp
index a0ecf5f..0ec9e25 100644
--- a/dm/DMReplayTask.cpp
+++ b/dm/DMReplayTask.cpp
@@ -6,21 +6,25 @@
 #include "SkPicture.h"
 
 DEFINE_bool(replay, false, "If true, run picture replay tests.");
+DEFINE_bool(rtree,  false, "If true, run picture replay tests with an rtree.");
 
 namespace DM {
 
 ReplayTask::ReplayTask(const Task& parent,
                        skiagm::GM* gm,
-                       SkBitmap reference)
+                       SkBitmap reference,
+                       bool useRTree)
     : Task(parent)
-    , fName(UnderJoin(parent.name().c_str(), "replay"))
+    , fName(UnderJoin(parent.name().c_str(), useRTree ? "rtree" : "replay"))
     , fGM(gm)
     , fReference(reference)
+    , fUseRTree(useRTree)
     {}
 
 void ReplayTask::draw() {
     SkPicture recorded;
-    RecordPicture(fGM.get(), &recorded);
+    const uint32_t flags = fUseRTree ? SkPicture::kOptimizeForClippedPlayback_RecordingFlag : 0;
+    RecordPicture(fGM.get(), &recorded, flags);
 
     SkBitmap bitmap;
     SetupBitmap(fReference.config(), fGM.get(), &bitmap);
@@ -32,7 +36,17 @@
 }
 
 bool ReplayTask::shouldSkip() const {
-    return !FLAGS_replay || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
+    if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
+        return true;
+    }
+
+    if (FLAGS_rtree && fUseRTree) {
+        return false;
+    }
+    if (FLAGS_replay && !fUseRTree) {
+        return false;
+    }
+    return true;
 }
 
 }  // namespace DM
diff --git a/dm/DMReplayTask.h b/dm/DMReplayTask.h
index bf90f72..1217c07 100644
--- a/dm/DMReplayTask.h
+++ b/dm/DMReplayTask.h
@@ -14,9 +14,10 @@
 class ReplayTask : public Task {
 
 public:
-    ReplayTask(const Task& parent,
-               skiagm::GM*,
-               SkBitmap reference);
+    ReplayTask(const Task& parent,  // ReplayTask must be a child task.  Pass its parent here.
+               skiagm::GM*,         // GM to run through a pipe.  Takes ownership.
+               SkBitmap reference,  // Bitmap to compare pipe results to.
+               bool useRTree);      // Record with an RTree?
 
     virtual void draw() SK_OVERRIDE;
     virtual bool usesGpu() const SK_OVERRIDE { return false; }
@@ -27,6 +28,7 @@
     const SkString fName;
     SkAutoTDelete<skiagm::GM> fGM;
     const SkBitmap fReference;
+    const bool fUseRTree;
 };
 
 }  // namespace DM
diff --git a/dm/DMUtil.cpp b/dm/DMUtil.cpp
index a227ca8..d521484 100644
--- a/dm/DMUtil.cpp
+++ b/dm/DMUtil.cpp
@@ -23,10 +23,10 @@
     return expectations.match(digest);
 }
 
-void RecordPicture(skiagm::GM* gm, SkPicture* picture) {
+void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) {
     SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()),
                                                SkScalarCeilToInt(gm->height()),
-                                               0 /*flags*/);
+                                               recordFlags);
     canvas->concat(gm->getInitialTransform());
     gm->draw(canvas);
     canvas->flush();
diff --git a/dm/DMUtil.h b/dm/DMUtil.h
index 4dd9dd8..512ad64 100644
--- a/dm/DMUtil.h
+++ b/dm/DMUtil.h
@@ -18,8 +18,8 @@
 // Roughly, expectations.match(GmResultDigest(bitmap)), but calculates the digest lazily.
 bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap bitmap);
 
-// Draw gm to picture.
-void RecordPicture(skiagm::GM* gm, SkPicture* picture);
+// Draw gm to picture.  Passes recordFlags to SkPicture::beginRecording().
+void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags = 0);
 
 // Prepare bitmap to have gm draw into it with this config.
 void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap);
diff --git a/dm/README b/dm/README
index 0c842cd..6cde686 100644
--- a/dm/README
+++ b/dm/README
@@ -7,7 +7,6 @@
   --writePicturePath
 
   --deferred
-  --rtree
   --tiledGrid