DM: SKP source / PDF backend
authormtklein <mtklein@chromium.org>
Fri, 6 Jun 2014 16:28:43 +0000 (09:28 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 6 Jun 2014 16:28:43 +0000 (09:28 -0700)
Removed expectations code for PDF backend for now, given that we don't have any, and refactored a little to make that cleaner.

We can now test .skp -> .pdf -> .png in DM.  Neat eh?

BUG=skia:2598
R=halcanary@google.com, mtklein@google.com

Author: mtklein@chromium.org

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

12 files changed:
dm/DM.cpp
dm/DMCpuGMTask.cpp
dm/DMCpuGMTask.h
dm/DMGpuGMTask.cpp
dm/DMGpuGMTask.h
dm/DMPDFRasterizeTask.cpp
dm/DMPDFRasterizeTask.h
dm/DMPDFTask.cpp
dm/DMPDFTask.h
dm/DMSKPTask.cpp
dm/DMUtil.cpp
dm/DMUtil.h

index 1b7c1d8..8755598 100644 (file)
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -103,24 +103,23 @@ static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
                          const DM::Expectations& expectations,
                          DM::Reporter* reporter,
                          DM::TaskRunner* tasks) {
-#define START(name, type, ...)                                                        \
-    if (lowercase(configs[j]).equals(name)) {                                         \
-        tasks->add(SkNEW_ARGS(DM::type,                                               \
-                    (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__)));  \
+#define START(name, type, ...)                                                              \
+    if (lowercase(configs[j]).equals(name)) {                                               \
+        tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__)));  \
     }
     for (int i = 0; i < gms.count(); i++) {
         for (int j = 0; j < configs.count(); j++) {
-            START("565",        CpuGMTask, kRGB_565_SkColorType);
-            START("8888",       CpuGMTask, kN32_SkColorType);
-            START("gpu",        GpuGMTask, native, 0);
-            START("msaa4",      GpuGMTask, native, 4);
-            START("msaa16",     GpuGMTask, native, 16);
-            START("nvprmsaa4",  GpuGMTask, nvpr,  4);
-            START("nvprmsaa16", GpuGMTask, nvpr, 16);
-            START("gpunull",    GpuGMTask, null,   0);
-            START("gpudebug",   GpuGMTask, debug,  0);
-            START("angle",      GpuGMTask, angle,  0);
-            START("mesa",       GpuGMTask, mesa,   0);
+            START("565",        CpuGMTask, expectations, kRGB_565_SkColorType);
+            START("8888",       CpuGMTask, expectations, kN32_SkColorType);
+            START("gpu",        GpuGMTask, expectations, native, 0);
+            START("msaa4",      GpuGMTask, expectations, native, 4);
+            START("msaa16",     GpuGMTask, expectations, native, 16);
+            START("nvprmsaa4",  GpuGMTask, expectations, nvpr,   4);
+            START("nvprmsaa16", GpuGMTask, expectations, nvpr,   16);
+            START("gpunull",    GpuGMTask, expectations, null,   0);
+            START("gpudebug",   GpuGMTask, expectations, debug,  0);
+            START("angle",      GpuGMTask, expectations, angle,  0);
+            START("mesa",       GpuGMTask, expectations, mesa,   0);
             START("pdf",        PDFTask,   RASTERIZE_PDF_PROC);
         }
     }
@@ -192,7 +191,9 @@ static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
             exit(1);
         }
 
-        tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic.detach(), filename)));
+        tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic->clone(), filename)));
+        tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic->clone(), filename,
+                                            RASTERIZE_PDF_PROC)));
     }
 }
 
index add5b38..8bec522 100644 (file)
@@ -13,8 +13,8 @@ namespace DM {
 CpuGMTask::CpuGMTask(const char* config,
                      Reporter* reporter,
                      TaskRunner* taskRunner,
-                     const Expectations& expectations,
                      skiagm::GMRegistry::Factory gmFactory,
+                     const Expectations& expectations,
                      SkColorType colorType)
     : CpuTask(reporter, taskRunner)
     , fGMFactory(gmFactory)
index 7712da8..968dd27 100644 (file)
@@ -20,8 +20,8 @@ public:
     CpuGMTask(const char* config,
               Reporter*,
               TaskRunner*,
-              const Expectations&,
               skiagm::GMRegistry::Factory,
+              const Expectations&,
               SkColorType);
 
     virtual void draw() SK_OVERRIDE;
index a7b1d7b..b384485 100644 (file)
@@ -12,8 +12,8 @@ namespace DM {
 GpuGMTask::GpuGMTask(const char* config,
                      Reporter* reporter,
                      TaskRunner* taskRunner,
-                     const Expectations& expectations,
                      skiagm::GMRegistry::Factory gmFactory,
+                     const Expectations& expectations,
                      GrContextFactory::GLContextType contextType,
                      int sampleCount)
     : GpuTask(reporter, taskRunner)
index 6e076ec..6621a49 100644 (file)
@@ -20,8 +20,8 @@ public:
     GpuGMTask(const char* config,
               Reporter*,
               TaskRunner*,
-              const Expectations&,
               skiagm::GMRegistry::Factory,
+              const Expectations&,
               GrContextFactory::GLContextType,
               int sampleCount);
 
index ce6c109..43be6e5 100644 (file)
@@ -17,24 +17,20 @@ namespace DM {
 
 PDFRasterizeTask::PDFRasterizeTask(const Task& parent,
                                    SkData* pdf,
-                                   const Expectations& expectations,
                                    RasterizePdfProc proc)
     : CpuTask(parent)
     , fName(UnderJoin(parent.name().c_str(), "rasterize"))
     , fPdf(SkRef(pdf))
-    , fExpectations(expectations)
     , fRasterize(proc) {}
 
 void PDFRasterizeTask::draw() {
     SkMemoryStream pdfStream(fPdf.get());
     SkBitmap bitmap;
 
-    if (!fRasterize(&pdfStream, &bitmap)) {
-        this->fail();
-    }
-    if (!fExpectations.check(*this, bitmap)) {
-        this->fail();
+    if (fRasterize(&pdfStream, &bitmap)) {
         this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
+    } else {
+        this->fail();
     }
 }
 
index 2e24b89..2cc1ef7 100644 (file)
@@ -8,7 +8,6 @@
 #ifndef DMPDFRasterizeTask_DEFINED
 #define DMPDFRasterizeTask_DEFINED
 
-#include "DMExpectations.h"
 #include "DMTask.h"
 #include "SkBitmap.h"
 #include "SkData.h"
@@ -24,7 +23,6 @@ class PDFRasterizeTask : public CpuTask {
 public:
     PDFRasterizeTask(const Task& parent,
                      SkData* pdf,
-                     const Expectations&,
                      RasterizePdfProc);
 
     virtual void draw() SK_OVERRIDE;
@@ -34,7 +32,6 @@ public:
 private:
     const SkString fName;
     SkAutoTUnref<SkData> fPdf;
-    const Expectations& fExpectations;
     RasterizePdfProc fRasterize;
 };
 
index e50e9ec..ecca130 100644 (file)
@@ -6,7 +6,6 @@
  */
 
 #include "DMPDFTask.h"
-#include "DMExpectationsTask.h"
 #include "DMPDFRasterizeTask.h"
 #include "DMUtil.h"
 #include "DMWriteTask.h"
@@ -21,16 +20,24 @@ DEFINE_bool(pdf, false, "PDF backend master switch.");
 
 namespace DM {
 
-PDFTask::PDFTask(const char* suffix,
+PDFTask::PDFTask(const char* config,
                  Reporter* reporter,
                  TaskRunner* taskRunner,
-                 const Expectations& expectations,
                  skiagm::GMRegistry::Factory factory,
                  RasterizePdfProc rasterizePdfProc)
     : CpuTask(reporter, taskRunner)
     , fGM(factory(NULL))
-    , fName(UnderJoin(fGM->getName(), suffix))
-    , fExpectations(expectations)
+    , fName(UnderJoin(fGM->getName(), config))
+    , fRasterize(rasterizePdfProc) {}
+
+PDFTask::PDFTask(Reporter* reporter,
+                 TaskRunner* taskRunner,
+                 SkPicture* picture,
+                 SkString filename,
+                 RasterizePdfProc rasterizePdfProc)
+    : CpuTask(reporter, taskRunner)
+    , fPicture(SkRef(picture))
+    , fName(UnderJoin(FileToTaskName(filename).c_str(), "pdf"))
     , fRasterize(rasterizePdfProc) {}
 
 namespace {
@@ -59,17 +66,24 @@ private:
 }  // namespace
 
 void PDFTask::draw() {
-    SinglePagePDF pdf(fGM->width(), fGM->height());
-    //TODO(mtklein): GM doesn't do this.  Why not?
-    //pdf.canvas()->concat(fGM->getInitialTransform());
-    fGM->draw(pdf.canvas());
+    SkAutoTUnref<SkData> pdfData;
+    bool rasterize = true;
+    if (fGM.get()) {
+        rasterize = 0 == (fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag);
+        SinglePagePDF pdf(fGM->width(), fGM->height());
+        //TODO(mtklein): GM doesn't do this.  Why not?
+        //pdf.canvas()->concat(fGM->getInitialTransform());
+        fGM->draw(pdf.canvas());
+        pdfData.reset(pdf.end());
+    } else {
+        SinglePagePDF pdf(SkIntToScalar(fPicture->width()), SkIntToScalar(fPicture->height()));
+        fPicture->draw(pdf.canvas());
+        pdfData.reset(pdf.end());
+    }
 
-    SkAutoTUnref<SkData> pdfData(pdf.end());
     SkASSERT(pdfData.get());
-
-    if (!(fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag)) {
-        this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
-                                    (*this, pdfData.get(), fExpectations, fRasterize)));
+    if (rasterize) {
+        this->spawnChild(SkNEW_ARGS(PDFRasterizeTask, (*this, pdfData.get(), fRasterize)));
     }
     this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf")));
 }
@@ -78,7 +92,7 @@ bool PDFTask::shouldSkip() const {
     if (!FLAGS_pdf) {
         return true;
     }
-    if (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag) {
+    if (fGM.get() && 0 != (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag)) {
         return true;
     }
     return false;
index d273df6..d107611 100644 (file)
@@ -1,27 +1,33 @@
 #ifndef DMPDFTask_DEFINED
 #define DMPDFTask_DEFINED
 
-#include "DMPDFRasterizeTask.h"
 #include "DMExpectations.h"
+#include "DMPDFRasterizeTask.h"
 #include "DMTask.h"
 #include "SkBitmap.h"
+#include "SkPicture.h"
 #include "SkString.h"
 #include "SkTemplates.h"
 #include "gm.h"
 
 namespace DM {
 
-// This task renders a GM using Skia's PDF backend.
+// This task renders a GM or SKP using Skia's PDF backend.
 // If rasterizePdfProc is non-NULL, it will spawn a PDFRasterizeTask.
 class PDFTask : public CpuTask {
 public:
-    PDFTask(const char* suffix,
+    PDFTask(const char*,
             Reporter*,
             TaskRunner*,
-            const Expectations&,
             skiagm::GMRegistry::Factory,
             RasterizePdfProc);
 
+    PDFTask(Reporter*,
+            TaskRunner*,
+            SkPicture*,
+            SkString name,
+            RasterizePdfProc);
+
     virtual void draw() SK_OVERRIDE;
 
     virtual bool shouldSkip() const SK_OVERRIDE;
@@ -29,9 +35,11 @@ public:
     virtual SkString name() const SK_OVERRIDE { return fName; }
 
 private:
+    // One of these two will be set.
     SkAutoTDelete<skiagm::GM> fGM;
+    SkAutoTUnref<SkPicture> fPicture;
+
     const SkString fName;
-    const Expectations& fExpectations;
     RasterizePdfProc fRasterize;
 };
 
index 04c4184..760138f 100644 (file)
@@ -5,17 +5,8 @@
 
 namespace DM {
 
-// foo_bar.skp -> foo-bar_skp
-static SkString filename_to_task_name(SkString filename) {
-    for (size_t i = 0; i < filename.size(); i++) {
-        if ('_' == filename[i]) { filename[i] = '-'; }
-        if ('.' == filename[i]) { filename[i] = '_'; }
-    }
-    return filename;
-}
-
 SKPTask::SKPTask(Reporter* r, TaskRunner* tr, SkPicture* pic, SkString filename)
-    : CpuTask(r, tr), fPicture(SkRef(pic)), fName(filename_to_task_name(filename)) {}
+    : CpuTask(r, tr), fPicture(SkRef(pic)), fName(FileToTaskName(filename)) {}
 
 void SKPTask::draw() {
     SkBitmap bitmap;
index 23634c3..94fdd6e 100644 (file)
@@ -12,6 +12,14 @@ SkString UnderJoin(const char* a, const char* b) {
     return s;
 }
 
+SkString FileToTaskName(SkString filename) {
+    for (size_t i = 0; i < filename.size(); i++) {
+        if ('_' == filename[i]) { filename[i] = '-'; }
+        if ('.' == filename[i]) { filename[i] = '_'; }
+    }
+    return filename;
+}
+
 SkPicture* RecordPicture(skiagm::GM* gm, uint32_t recordFlags, SkBBHFactory* factory) {
     const SkISize size = gm->getISize();
     SkPictureRecorder recorder;
index b5b5e32..8011e96 100644 (file)
@@ -15,6 +15,9 @@ namespace DM {
 // UnderJoin("a", "b") -> "a_b"
 SkString UnderJoin(const char* a, const char* b);
 
+// "foo_bar.skp" -> "foo-bar_skp"
+SkString FileToTaskName(SkString);
+
 // Draw gm to picture.  Passes recordFlags to SkPictureRecorder::beginRecording().
 SkPicture* RecordPicture(skiagm::GM* gm,
                          uint32_t recordFlags = 0,