2014-06-03 20:57:14 +00:00
|
|
|
/*
|
|
|
|
* 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 "DMPDFRasterizeTask.h"
|
|
|
|
#include "DMUtil.h"
|
|
|
|
#include "DMWriteTask.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkDocument.h"
|
|
|
|
|
2014-06-03 22:59:23 +00:00
|
|
|
// The PDF backend is not threadsafe. If you run dm with --pdf repeatedly, you
|
|
|
|
// will quickly find yourself crashed. (while catchsegv out/Release/dm;; end).
|
|
|
|
//
|
|
|
|
// TODO(mtklein): re-enable by default, maybe moving to its own single thread.
|
|
|
|
DEFINE_bool(pdf, false, "PDF backend master switch.");
|
2014-06-03 20:57:14 +00:00
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
2014-06-06 16:28:43 +00:00
|
|
|
PDFTask::PDFTask(const char* config,
|
2014-06-03 20:57:14 +00:00
|
|
|
Reporter* reporter,
|
|
|
|
TaskRunner* taskRunner,
|
|
|
|
skiagm::GMRegistry::Factory factory,
|
|
|
|
RasterizePdfProc rasterizePdfProc)
|
|
|
|
: CpuTask(reporter, taskRunner)
|
|
|
|
, fGM(factory(NULL))
|
2014-06-06 16:28:43 +00:00
|
|
|
, fName(UnderJoin(fGM->getName(), config))
|
|
|
|
, fRasterize(rasterizePdfProc) {}
|
|
|
|
|
|
|
|
PDFTask::PDFTask(Reporter* reporter,
|
|
|
|
TaskRunner* taskRunner,
|
2014-06-27 19:34:44 +00:00
|
|
|
const SkPicture* picture,
|
2014-06-06 16:28:43 +00:00
|
|
|
SkString filename,
|
|
|
|
RasterizePdfProc rasterizePdfProc)
|
|
|
|
: CpuTask(reporter, taskRunner)
|
|
|
|
, fPicture(SkRef(picture))
|
|
|
|
, fName(UnderJoin(FileToTaskName(filename).c_str(), "pdf"))
|
2014-06-03 20:57:14 +00:00
|
|
|
, fRasterize(rasterizePdfProc) {}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SinglePagePDF {
|
|
|
|
public:
|
|
|
|
SinglePagePDF(SkScalar width, SkScalar height)
|
|
|
|
: fDocument(SkDocument::CreatePDF(&fWriteStream))
|
|
|
|
, fCanvas(fDocument->beginPage(width, height)) {}
|
|
|
|
|
|
|
|
SkCanvas* canvas() { return fCanvas; }
|
|
|
|
|
2014-08-26 17:38:07 +00:00
|
|
|
SkStreamAsset* end() {
|
2014-06-03 20:57:14 +00:00
|
|
|
fCanvas->flush();
|
|
|
|
fDocument->endPage();
|
|
|
|
fDocument->close();
|
2014-08-26 17:38:07 +00:00
|
|
|
return fWriteStream.detachAsStream();
|
2014-06-03 20:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkDynamicMemoryWStream fWriteStream;
|
|
|
|
SkAutoTUnref<SkDocument> fDocument;
|
|
|
|
SkCanvas* fCanvas;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void PDFTask::draw() {
|
2014-08-26 17:38:07 +00:00
|
|
|
SkAutoTDelete<SkStreamAsset> pdfData;
|
2014-06-06 16:28:43 +00:00
|
|
|
bool rasterize = true;
|
|
|
|
if (fGM.get()) {
|
|
|
|
rasterize = 0 == (fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag);
|
|
|
|
SinglePagePDF pdf(fGM->width(), fGM->height());
|
2014-09-11 19:30:12 +00:00
|
|
|
CanvasPreflight(pdf.canvas());
|
2014-06-06 16:28:43 +00:00
|
|
|
//TODO(mtklein): GM doesn't do this. Why not?
|
|
|
|
//pdf.canvas()->concat(fGM->getInitialTransform());
|
|
|
|
fGM->draw(pdf.canvas());
|
|
|
|
pdfData.reset(pdf.end());
|
|
|
|
} else {
|
2014-08-29 15:03:56 +00:00
|
|
|
SinglePagePDF pdf(fPicture->cullRect().width(), fPicture->cullRect().height());
|
2014-09-11 19:30:12 +00:00
|
|
|
CanvasPreflight(pdf.canvas());
|
2014-09-04 15:42:50 +00:00
|
|
|
fPicture->playback(pdf.canvas());
|
2014-06-06 16:28:43 +00:00
|
|
|
pdfData.reset(pdf.end());
|
|
|
|
}
|
2014-06-03 20:57:14 +00:00
|
|
|
|
|
|
|
SkASSERT(pdfData.get());
|
2014-06-06 16:28:43 +00:00
|
|
|
if (rasterize) {
|
2014-08-26 17:38:07 +00:00
|
|
|
this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
|
|
|
|
(*this, pdfData->duplicate(), fRasterize)));
|
2014-06-03 20:57:14 +00:00
|
|
|
}
|
Update DM JSON format.
Ex. dm --match patch -w bad --key arch x86 gpu nvidia model z620 --properties git_hash abcd build_number 20 ->
{
"build_number" : "20",
"git_hash" : "abcd",
"key" : {
"arch" : "x86",
"gpu" : "nvidia",
"model" : "z620"
},
"results" : [
{
"key" : {
"config" : "565",
"name" : "ninepatch-stretch"
},
"md5" : "f78cfafcbabaf815f3dfcf61fb59acc7",
"options" : {
"source_type" : "GM"
}
},
{
"key" : {
"config" : "8888",
"name" : "ninepatch-stretch"
},
"md5" : "3e8a42f35a1e76f00caa191e6310d789",
"options" : {
"source_type" : "GM"
}
},
...
This breaks -r, but that's okay. Going to follow up this CL with one that removes that entirely.
BUG=skia:
R=stephana@google.com, jcgregorio@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/551873003
2014-09-09 14:59:46 +00:00
|
|
|
const char* sourceType = fGM.get() ? "GM" : "SKP";
|
2014-08-26 17:38:07 +00:00
|
|
|
this->spawnChild(SkNEW_ARGS(WriteTask,
|
Update DM JSON format.
Ex. dm --match patch -w bad --key arch x86 gpu nvidia model z620 --properties git_hash abcd build_number 20 ->
{
"build_number" : "20",
"git_hash" : "abcd",
"key" : {
"arch" : "x86",
"gpu" : "nvidia",
"model" : "z620"
},
"results" : [
{
"key" : {
"config" : "565",
"name" : "ninepatch-stretch"
},
"md5" : "f78cfafcbabaf815f3dfcf61fb59acc7",
"options" : {
"source_type" : "GM"
}
},
{
"key" : {
"config" : "8888",
"name" : "ninepatch-stretch"
},
"md5" : "3e8a42f35a1e76f00caa191e6310d789",
"options" : {
"source_type" : "GM"
}
},
...
This breaks -r, but that's okay. Going to follow up this CL with one that removes that entirely.
BUG=skia:
R=stephana@google.com, jcgregorio@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/551873003
2014-09-09 14:59:46 +00:00
|
|
|
(*this, sourceType, pdfData->duplicate(), ".pdf")));
|
2014-06-03 20:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PDFTask::shouldSkip() const {
|
|
|
|
if (!FLAGS_pdf) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-06 16:28:43 +00:00
|
|
|
if (fGM.get() && 0 != (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag)) {
|
2014-06-03 20:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|