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

Side by Side Diff: dm/DMPDFTask.cpp

Issue 502193002: SkData to SkStreamAsset to avoid unneeded copying (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Another Patch Set Created 6 years, 3 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/DMPDFRasterizeTask.cpp ('k') | dm/DMWriteTask.h » ('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 "DMPDFRasterizeTask.h" 9 #include "DMPDFRasterizeTask.h"
10 #include "DMUtil.h" 10 #include "DMUtil.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 namespace { 43 namespace {
44 44
45 class SinglePagePDF { 45 class SinglePagePDF {
46 public: 46 public:
47 SinglePagePDF(SkScalar width, SkScalar height) 47 SinglePagePDF(SkScalar width, SkScalar height)
48 : fDocument(SkDocument::CreatePDF(&fWriteStream)) 48 : fDocument(SkDocument::CreatePDF(&fWriteStream))
49 , fCanvas(fDocument->beginPage(width, height)) {} 49 , fCanvas(fDocument->beginPage(width, height)) {}
50 50
51 SkCanvas* canvas() { return fCanvas; } 51 SkCanvas* canvas() { return fCanvas; }
52 52
53 SkData* end() { 53 SkStreamAsset* end() {
54 fCanvas->flush(); 54 fCanvas->flush();
55 fDocument->endPage(); 55 fDocument->endPage();
56 fDocument->close(); 56 fDocument->close();
57 return fWriteStream.copyToData(); 57 return fWriteStream.detachAsStream();
58 } 58 }
59 59
60 private: 60 private:
61 SkDynamicMemoryWStream fWriteStream; 61 SkDynamicMemoryWStream fWriteStream;
62 SkAutoTUnref<SkDocument> fDocument; 62 SkAutoTUnref<SkDocument> fDocument;
63 SkCanvas* fCanvas; 63 SkCanvas* fCanvas;
64 }; 64 };
65 65
66 } // namespace 66 } // namespace
67 67
68 void PDFTask::draw() { 68 void PDFTask::draw() {
69 SkAutoTUnref<SkData> pdfData; 69 SkAutoTDelete<SkStreamAsset> pdfData;
70 bool rasterize = true; 70 bool rasterize = true;
71 if (fGM.get()) { 71 if (fGM.get()) {
72 rasterize = 0 == (fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Fl ag); 72 rasterize = 0 == (fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Fl ag);
73 SinglePagePDF pdf(fGM->width(), fGM->height()); 73 SinglePagePDF pdf(fGM->width(), fGM->height());
74 //TODO(mtklein): GM doesn't do this. Why not? 74 //TODO(mtklein): GM doesn't do this. Why not?
75 //pdf.canvas()->concat(fGM->getInitialTransform()); 75 //pdf.canvas()->concat(fGM->getInitialTransform());
76 fGM->draw(pdf.canvas()); 76 fGM->draw(pdf.canvas());
77 pdfData.reset(pdf.end()); 77 pdfData.reset(pdf.end());
78 } else { 78 } else {
79 SinglePagePDF pdf(SkIntToScalar(fPicture->width()), SkIntToScalar(fPictu re->height())); 79 SinglePagePDF pdf(SkIntToScalar(fPicture->width()), SkIntToScalar(fPictu re->height()));
80 fPicture->draw(pdf.canvas()); 80 fPicture->draw(pdf.canvas());
81 pdfData.reset(pdf.end()); 81 pdfData.reset(pdf.end());
82 } 82 }
83 83
84 SkASSERT(pdfData.get()); 84 SkASSERT(pdfData.get());
85 if (rasterize) { 85 if (rasterize) {
86 this->spawnChild(SkNEW_ARGS(PDFRasterizeTask, (*this, pdfData.get(), fRa sterize))); 86 this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
87 (*this, pdfData->duplicate(), fRasterize)));
87 } 88 }
88 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf"))); 89 this->spawnChild(SkNEW_ARGS(WriteTask,
90 (*this, pdfData->duplicate(), ".pdf")));
89 } 91 }
90 92
91 bool PDFTask::shouldSkip() const { 93 bool PDFTask::shouldSkip() const {
92 if (!FLAGS_pdf) { 94 if (!FLAGS_pdf) {
93 return true; 95 return true;
94 } 96 }
95 if (fGM.get() && 0 != (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag)) { 97 if (fGM.get() && 0 != (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag)) {
96 return true; 98 return true;
97 } 99 }
98 return false; 100 return false;
99 } 101 }
100 102
101 } // namespace DM 103 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMPDFRasterizeTask.cpp ('k') | dm/DMWriteTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698