Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "DMPDFTask.h" | |
| 9 #include "DMExpectationsTask.h" | |
| 10 #include "DMPDFRasterizeTask.h" | |
| 11 #include "DMUtil.h" | |
| 12 #include "DMWriteTask.h" | |
| 13 #include "SkCommandLineFlags.h" | |
| 14 #include "SkDocument.h" | |
| 15 | |
| 16 DEFINE_bool(pdf, true, "PDF backend master switch."); | |
| 17 | |
| 18 namespace DM { | |
| 19 | |
| 20 PDFTask::PDFTask(const char* suffix, | |
| 21 Reporter* reporter, | |
| 22 TaskRunner* taskRunner, | |
| 23 const Expectations& expectations, | |
| 24 skiagm::GMRegistry::Factory factory, | |
| 25 RasterizePdfProc rasterizePdfProc) | |
| 26 : CpuTask(reporter, taskRunner) | |
| 27 , fGM(factory(NULL)) | |
| 28 , fName(UnderJoin(fGM->getName(), suffix)) | |
| 29 , fExpectations(expectations) | |
| 30 , fRasterize(rasterizePdfProc) {} | |
| 31 | |
| 32 namespace { | |
| 33 | |
| 34 class SinglePagePDF { | |
| 35 public: | |
| 36 SinglePagePDF(SkScalar width, SkScalar height) | |
| 37 : fDocument(SkDocument::CreatePDF(&fWriteStream)) | |
| 38 , fCanvas(fDocument->beginPage(width, height)) {} | |
| 39 | |
| 40 SkCanvas* canvas() { return fCanvas; } | |
| 41 | |
| 42 SkData* end() { | |
| 43 fCanvas->flush(); | |
| 44 fDocument->endPage(); | |
| 45 fDocument->close(); | |
| 46 return fWriteStream.copyToData(); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 SkDynamicMemoryWStream fWriteStream; | |
| 51 SkAutoTUnref<SkDocument> fDocument; | |
| 52 SkCanvas* fCanvas; | |
| 53 }; | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 void PDFTask::draw() { | |
| 58 SinglePagePDF pdf(fGM->width(), fGM->height()); | |
| 59 //TODO(mtklein): GM doesn't do this. Why not? | |
| 60 //pdf.canvas()->concat(fGM->getInitialTransform()); | |
|
vandebo (ex-Chrome)
2014/06/03 20:39:56
Because it passes it into the PDF device: https://
| |
| 61 fGM->draw(pdf.canvas()); | |
| 62 | |
| 63 SkAutoTUnref<SkData> pdfData(pdf.end()); | |
| 64 SkASSERT(pdfData.get()); | |
| 65 | |
| 66 if (!(fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag)) { | |
| 67 this->spawnChild(SkNEW_ARGS(PDFRasterizeTask, | |
| 68 (*this, pdfData.get(), fExpectations, fRaste rize))); | |
| 69 } | |
| 70 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf"))); | |
| 71 } | |
| 72 | |
| 73 bool PDFTask::shouldSkip() const { | |
| 74 if (!FLAGS_pdf) { | |
| 75 return true; | |
| 76 } | |
| 77 if (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag) { | |
| 78 return true; | |
| 79 } | |
| 80 return false; | |
| 81 } | |
| 82 | |
| 83 } // namespace DM | |
| OLD | NEW |