Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: dm/DMPDFTask.cpp

Issue 316643003: DM: SKP source / PDF backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cast Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dm/DMPDFTask.h ('k') | dm/DMSKPTask.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "DMPDFTask.h" 8 #include "DMPDFTask.h"
9 #include "DMExpectationsTask.h"
10 #include "DMPDFRasterizeTask.h" 9 #include "DMPDFRasterizeTask.h"
11 #include "DMUtil.h" 10 #include "DMUtil.h"
12 #include "DMWriteTask.h" 11 #include "DMWriteTask.h"
13 #include "SkCommandLineFlags.h" 12 #include "SkCommandLineFlags.h"
14 #include "SkDocument.h" 13 #include "SkDocument.h"
15 14
16 // The PDF backend is not threadsafe. If you run dm with --pdf repeatedly, you 15 // The PDF backend is not threadsafe. If you run dm with --pdf repeatedly, you
17 // will quickly find yourself crashed. (while catchsegv out/Release/dm;; end). 16 // will quickly find yourself crashed. (while catchsegv out/Release/dm;; end).
18 // 17 //
19 // TODO(mtklein): re-enable by default, maybe moving to its own single thread. 18 // TODO(mtklein): re-enable by default, maybe moving to its own single thread.
20 DEFINE_bool(pdf, false, "PDF backend master switch."); 19 DEFINE_bool(pdf, false, "PDF backend master switch.");
21 20
22 namespace DM { 21 namespace DM {
23 22
24 PDFTask::PDFTask(const char* suffix, 23 PDFTask::PDFTask(const char* config,
25 Reporter* reporter, 24 Reporter* reporter,
26 TaskRunner* taskRunner, 25 TaskRunner* taskRunner,
27 const Expectations& expectations,
28 skiagm::GMRegistry::Factory factory, 26 skiagm::GMRegistry::Factory factory,
29 RasterizePdfProc rasterizePdfProc) 27 RasterizePdfProc rasterizePdfProc)
30 : CpuTask(reporter, taskRunner) 28 : CpuTask(reporter, taskRunner)
31 , fGM(factory(NULL)) 29 , fGM(factory(NULL))
32 , fName(UnderJoin(fGM->getName(), suffix)) 30 , fName(UnderJoin(fGM->getName(), config))
33 , fExpectations(expectations) 31 , fRasterize(rasterizePdfProc) {}
32
33 PDFTask::PDFTask(Reporter* reporter,
34 TaskRunner* taskRunner,
35 SkPicture* picture,
36 SkString filename,
37 RasterizePdfProc rasterizePdfProc)
38 : CpuTask(reporter, taskRunner)
39 , fPicture(SkRef(picture))
40 , fName(UnderJoin(FileToTaskName(filename).c_str(), "pdf"))
34 , fRasterize(rasterizePdfProc) {} 41 , fRasterize(rasterizePdfProc) {}
35 42
36 namespace { 43 namespace {
37 44
38 class SinglePagePDF { 45 class SinglePagePDF {
39 public: 46 public:
40 SinglePagePDF(SkScalar width, SkScalar height) 47 SinglePagePDF(SkScalar width, SkScalar height)
41 : fDocument(SkDocument::CreatePDF(&fWriteStream)) 48 : fDocument(SkDocument::CreatePDF(&fWriteStream))
42 , fCanvas(fDocument->beginPage(width, height)) {} 49 , fCanvas(fDocument->beginPage(width, height)) {}
43 50
44 SkCanvas* canvas() { return fCanvas; } 51 SkCanvas* canvas() { return fCanvas; }
45 52
46 SkData* end() { 53 SkData* end() {
47 fCanvas->flush(); 54 fCanvas->flush();
48 fDocument->endPage(); 55 fDocument->endPage();
49 fDocument->close(); 56 fDocument->close();
50 return fWriteStream.copyToData(); 57 return fWriteStream.copyToData();
51 } 58 }
52 59
53 private: 60 private:
54 SkDynamicMemoryWStream fWriteStream; 61 SkDynamicMemoryWStream fWriteStream;
55 SkAutoTUnref<SkDocument> fDocument; 62 SkAutoTUnref<SkDocument> fDocument;
56 SkCanvas* fCanvas; 63 SkCanvas* fCanvas;
57 }; 64 };
58 65
59 } // namespace 66 } // namespace
60 67
61 void PDFTask::draw() { 68 void PDFTask::draw() {
62 SinglePagePDF pdf(fGM->width(), fGM->height()); 69 SkAutoTUnref<SkData> pdfData;
63 //TODO(mtklein): GM doesn't do this. Why not? 70 bool rasterize = true;
64 //pdf.canvas()->concat(fGM->getInitialTransform()); 71 if (fGM.get()) {
65 fGM->draw(pdf.canvas()); 72 rasterize = 0 == (fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Fl ag);
73 SinglePagePDF pdf(fGM->width(), fGM->height());
74 //TODO(mtklein): GM doesn't do this. Why not?
75 //pdf.canvas()->concat(fGM->getInitialTransform());
76 fGM->draw(pdf.canvas());
77 pdfData.reset(pdf.end());
78 } else {
79 SinglePagePDF pdf(SkIntToScalar(fPicture->width()), SkIntToScalar(fPictu re->height()));
80 fPicture->draw(pdf.canvas());
81 pdfData.reset(pdf.end());
82 }
66 83
67 SkAutoTUnref<SkData> pdfData(pdf.end());
68 SkASSERT(pdfData.get()); 84 SkASSERT(pdfData.get());
69 85 if (rasterize) {
70 if (!(fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag)) { 86 this->spawnChild(SkNEW_ARGS(PDFRasterizeTask, (*this, pdfData.get(), fRa sterize)));
71 this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
72 (*this, pdfData.get(), fExpectations, fRaste rize)));
73 } 87 }
74 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf"))); 88 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf")));
75 } 89 }
76 90
77 bool PDFTask::shouldSkip() const { 91 bool PDFTask::shouldSkip() const {
78 if (!FLAGS_pdf) { 92 if (!FLAGS_pdf) {
79 return true; 93 return true;
80 } 94 }
81 if (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag) { 95 if (fGM.get() && 0 != (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag)) {
82 return true; 96 return true;
83 } 97 }
84 return false; 98 return false;
85 } 99 }
86 100
87 } // namespace DM 101 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMPDFTask.h ('k') | dm/DMSKPTask.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698