dm is like gm, but faster and with fewer features.

This is sort of the near-minimal proof-of-concept skeleton.

  - It can run existing GMs.
  - It supports most configs (just not PDF).
  - --replay is the only "fancy" feature it currently supports

Hopefully you will be disturbed by its speed.

BUG=
R=epoger@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@11802 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/dm/DMReplayTask.cpp b/dm/DMReplayTask.cpp
new file mode 100644
index 0000000..bc94f73
--- /dev/null
+++ b/dm/DMReplayTask.cpp
@@ -0,0 +1,50 @@
+#include "DMReplayTask.h"
+#include "DMUtil.h"
+
+#include "SkPicture.h"
+
+namespace DM {
+
+ReplayTask::ReplayTask(const char* suffix,
+                       const Task& parent,
+                       skiagm::GM* gm,
+                       skiagm::GmResultDigest reference,
+                       SkBitmap::Config config)
+    : Task(parent)
+    , fName(underJoin(parent.name().c_str(), suffix))
+    , fGM(gm)
+    , fReference(reference)
+    , fConfig(config)
+    {}
+
+void ReplayTask::draw() {
+    SkPicture picture;
+    SkCanvas* canvas = picture.beginRecording(fGM->width(), fGM->height(), 0 /*flags*/);
+
+    canvas->concat(fGM->getInitialTransform());
+    fGM->draw(canvas);
+    canvas->flush();
+
+    picture.endRecording();
+
+    SkBitmap bitmap;
+    bitmap.setConfig(fConfig, fGM->width(), fGM->height());
+    bitmap.allocPixels();
+    bitmap.eraseColor(0x00000000);
+
+    SkCanvas replay(bitmap);
+    replay.drawPicture(picture);
+    replay.flush();
+
+    const skiagm::GmResultDigest replayDigest(bitmap);
+    if (!replayDigest.equals(fReference)) {
+        this->fail();
+    }
+}
+
+bool ReplayTask::shouldSkip() const {
+    return fGM->getFlags() & skiagm::GM::kGPUOnly_Flag ||
+           fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
+}
+
+}  // namespace