1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*
* 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"
// 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.");
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
|