#include "DMCpuGMTask.h"
#include "DMGpuGMTask.h"
#include "DMGpuSupport.h"
+#include "DMPDFTask.h"
#include "DMReporter.h"
#include "DMSKPTask.h"
#include "DMTask.h"
#include "DMTestTask.h"
#include "DMWriteTask.h"
+#ifdef SK_BUILD_POPPLER
+# include "SkPDFRasterizer.h"
+# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
+#else
+# define RASTERIZE_PDF_PROC NULL
+#endif
+
#include <ctype.h>
using skiagm::GM;
"^ and $ requires an exact match\n"
"If a GM does not match any list entry,\n"
"it is skipped unless some list entry starts with ~");
-DEFINE_string(config, "565 8888 gpu nonrendering",
- "Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 gpunull gpudebug angle mesa");
-DEFINE_bool(dryRun, false, "Just print the tests that would be run, without actually running them.");
+DEFINE_string(config, "565 8888 pdf gpu nonrendering",
+ "Options: 565 8888 pdf gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 "
+ "gpunull gpudebug angle mesa");
+DEFINE_bool(dryRun, false,
+ "Just print the tests that would be run, without actually running them.");
DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
DEFINE_string(skps, "", "Directory to read skps from.");
}
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("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("gpunull", GpuGMTask, null, 0);
+ START("gpudebug", GpuGMTask, debug, 0);
+ START("angle", GpuGMTask, angle, 0);
+ START("mesa", GpuGMTask, mesa, 0);
+ START("pdf", PDFTask, RASTERIZE_PDF_PROC);
}
}
#undef START
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "DMPDFRasterizeTask.h"
+#include "DMExpectationsTask.h"
+#include "DMUtil.h"
+#include "DMWriteTask.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkStream.h"
+
+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();
+ this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
+ }
+}
+
+} // namespace DM
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef DMPDFRasterizeTask_DEFINED
+#define DMPDFRasterizeTask_DEFINED
+
+#include "DMExpectations.h"
+#include "DMTask.h"
+#include "SkBitmap.h"
+#include "SkData.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkTemplates.h"
+
+namespace DM {
+
+typedef bool (*RasterizePdfProc)(SkStream* pdf, SkBitmap* output);
+
+class PDFRasterizeTask : public CpuTask {
+public:
+ PDFRasterizeTask(const Task& parent,
+ SkData* pdf,
+ const Expectations&,
+ RasterizePdfProc);
+
+ virtual void draw() SK_OVERRIDE;
+ virtual bool shouldSkip() const SK_OVERRIDE { return NULL == fRasterize; }
+ virtual SkString name() const SK_OVERRIDE { return fName; }
+
+private:
+ const SkString fName;
+ SkAutoTUnref<SkData> fPdf;
+ const Expectations& fExpectations;
+ RasterizePdfProc fRasterize;
+};
+
+} // namespace DM
+
+#endif // DMPDFRasterizeTask_DEFINED
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "DMPDFTask.h"
+#include "DMExpectationsTask.h"
+#include "DMPDFRasterizeTask.h"
+#include "DMUtil.h"
+#include "DMWriteTask.h"
+#include "SkCommandLineFlags.h"
+#include "SkDocument.h"
+
+DEFINE_bool(pdf, true, "PDF backend master switch.");
+
+namespace DM {
+
+PDFTask::PDFTask(const char* suffix,
+ 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)
+ , fRasterize(rasterizePdfProc) {}
+
+namespace {
+
+class SinglePagePDF {
+public:
+ SinglePagePDF(SkScalar width, SkScalar height)
+ : fDocument(SkDocument::CreatePDF(&fWriteStream))
+ , fCanvas(fDocument->beginPage(width, height)) {}
+
+ SkCanvas* canvas() { return fCanvas; }
+
+ SkData* end() {
+ fCanvas->flush();
+ fDocument->endPage();
+ fDocument->close();
+ return fWriteStream.copyToData();
+ }
+
+private:
+ SkDynamicMemoryWStream fWriteStream;
+ SkAutoTUnref<SkDocument> fDocument;
+ SkCanvas* fCanvas;
+};
+
+} // 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(pdf.end());
+ SkASSERT(pdfData.get());
+
+ if (!(fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag)) {
+ this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
+ (*this, pdfData.get(), fExpectations, fRasterize)));
+ }
+ this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf")));
+}
+
+bool PDFTask::shouldSkip() const {
+ if (!FLAGS_pdf) {
+ return true;
+ }
+ if (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag) {
+ return true;
+ }
+ return false;
+}
+
+} // namespace DM
--- /dev/null
+#ifndef DMPDFTask_DEFINED
+#define DMPDFTask_DEFINED
+
+#include "DMPDFRasterizeTask.h"
+#include "DMExpectations.h"
+#include "DMTask.h"
+#include "SkBitmap.h"
+#include "SkString.h"
+#include "SkTemplates.h"
+#include "gm.h"
+
+namespace DM {
+
+// This task renders a GM using Skia's PDF backend.
+// If rasterizePdfProc is non-NULL, it will spawn a PDFRasterizeTask.
+class PDFTask : public CpuTask {
+public:
+ PDFTask(const char* suffix,
+ Reporter*,
+ TaskRunner*,
+ const Expectations&,
+ skiagm::GMRegistry::Factory,
+ RasterizePdfProc);
+
+ virtual void draw() SK_OVERRIDE;
+
+ virtual bool shouldSkip() const SK_OVERRIDE;
+
+ virtual SkString name() const SK_OVERRIDE { return fName; }
+
+private:
+ SkAutoTDelete<skiagm::GM> fGM;
+ const SkString fName;
+ const Expectations& fExpectations;
+ RasterizePdfProc fRasterize;
+};
+
+} // namespace DM
+
+#endif // DMPDFTask_DEFINED
return consumed;
}
-WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
- : CpuTask(parent), fBitmap(bitmap) {
+inline static SkString find_gm_name(const Task& parent, SkTArray<SkString>* suffixList) {
const int suffixes = parent.depth() + 1;
const SkString& name = parent.name();
- const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffixes);
- fGmName.set(name.c_str(), name.size()-totalSuffixLength);
+ const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), suffixList);
+ return SkString(name.c_str(), name.size() - totalSuffixLength);
}
+WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
+ : CpuTask(parent)
+ , fGmName(find_gm_name(parent, &fSuffixes))
+ , fBitmap(bitmap)
+ , fData(NULL)
+ , fExtension(".png") {}
+
+WriteTask::WriteTask(const Task& parent, SkData *data, const char* ext)
+ : CpuTask(parent)
+ , fGmName(find_gm_name(parent, &fSuffixes))
+ , fData(SkRef(data))
+ , fExtension(ext) {}
+
void WriteTask::makeDirOrFail(SkString dir) {
if (!sk_mkdir(dir.c_str())) {
this->fail();
}
};
+// Does not take ownership of data.
+bool save_data_to_file(const SkData* data, const char* path) {
+ SkFILEWStream stream(path);
+ if (!stream.isValid() || !stream.write(data->data(), data->size())) {
+ SkDebugf("Can't write %s.\n", path);
+ return false;
+ }
+ return true;
+}
+
} // namespace
void WriteTask::draw() {
dir = SkOSPath::SkPathJoin(dir.c_str(), fSuffixes[i].c_str());
this->makeDirOrFail(dir);
}
+
SkString path = SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str());
- path.append(".png");
- if (!PngAndRaw::Encode(fBitmap, path.c_str())) {
+ path.append(fExtension);
+
+ const bool ok = fData.get() ? save_data_to_file(fData, path.c_str())
+ : PngAndRaw::Encode(fBitmap, path.c_str());
+ if (!ok) {
this->fail();
}
}
class WriteTask : public CpuTask {
public:
- WriteTask(const Task& parent, // WriteTask must be a child Task. Pass its parent here.
- SkBitmap bitmap); // Bitmap to write.
+ WriteTask(const Task& parent, // WriteTask must be a child task.
+ SkBitmap bitmap); // Bitmap to encode to PNG and write to disk.
+
+ WriteTask(const Task& parent, // WriteTask must be a child task.
+ SkData *data, // Pre-encoded data to write to disk.
+ const char* ext); // File extension.
virtual void draw() SK_OVERRIDE;
virtual bool shouldSkip() const SK_OVERRIDE;
private:
SkTArray<SkString> fSuffixes;
- SkString fGmName;
+ const SkString fGmName;
const SkBitmap fBitmap;
+ SkAutoTUnref<SkData> fData;
+ const char* fExtension;
void makeDirOrFail(SkString dir);
};
-DM is like GM, but multithreaded. It doesn't do everything GM does yet.
-
-Current approximate list of missing features:
- --config pdf
- --mismatchPath
- --missingExpectationsPath
- --writePicturePath
-
- --deferred
-
+DM is like GM, but multithreaded. It doesn't do everything GM does.
DM's design is based around Tasks and a TaskRunner.
'../dm/DMCpuGMTask.cpp',
'../dm/DMExpectationsTask.cpp',
'../dm/DMGpuGMTask.cpp',
+ '../dm/DMPDFRasterizeTask.cpp',
+ '../dm/DMPDFTask.cpp',
'../dm/DMPipeTask.cpp',
'../dm/DMQuiltTask.cpp',
'../dm/DMRecordTask.cpp',
'../dm/DMReplayTask.cpp',
'../dm/DMReporter.cpp',
- '../dm/DMSerializeTask.cpp',
'../dm/DMSKPTask.cpp',
+ '../dm/DMSerializeTask.cpp',
'../dm/DMTask.cpp',
'../dm/DMTaskRunner.cpp',
'../dm/DMTestTask.cpp',
'record.gyp:*',
],
'conditions': [
- ['skia_android_framework',
- {
+ ['skia_android_framework', {
'libraries': [
- '-lskia',
'-lcutils',
+ '-lskia',
],
- },
- ],
+ }],
+ ['skia_poppler_enabled', {
+ 'sources': [ '../src/utils/SkPDFRasterizer.cpp' ],
+ 'defines': [ 'SK_BUILD_POPPLER' ],
+ 'dependencies': [ 'poppler.gyp:*' ],
+ }],
],
}]
}