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

Side by Side Diff: src/doc/SkDocument_PDF.cpp

Issue 1777923002: SkPDF: use sk_ref_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | src/pdf/SkPDFDevice.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 2011 Google Inc. 2 * Copyright 2011 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 "SkDocument.h" 8 #include "SkDocument.h"
9 #include "SkPDFCanon.h" 9 #include "SkPDFCanon.h"
10 #include "SkPDFDevice.h" 10 #include "SkPDFDevice.h"
(...skipping 19 matching lines...) Expand all
30 const SkPDFSubstituteMap& substitutes, 30 const SkPDFSubstituteMap& substitutes,
31 SkPDFObject* docCatalog, 31 SkPDFObject* docCatalog,
32 int64_t objCount, 32 int64_t objCount,
33 int32_t xRefFileOffset, 33 int32_t xRefFileOffset,
34 sk_sp<SkPDFObject> info, 34 sk_sp<SkPDFObject> info,
35 sk_sp<SkPDFObject> id) { 35 sk_sp<SkPDFObject> id) {
36 SkPDFDict trailerDict; 36 SkPDFDict trailerDict;
37 // TODO(http://crbug.com/80908): Linearized format will take a 37 // TODO(http://crbug.com/80908): Linearized format will take a
38 // Prev entry too. 38 // Prev entry too.
39 trailerDict.insertInt("Size", int(objCount)); 39 trailerDict.insertInt("Size", int(objCount));
40 trailerDict.insertObjRef("Root", sk_sp<SkPDFObject>(SkRef(docCatalog))); 40 trailerDict.insertObjRef("Root", sk_ref_sp(docCatalog));
41 SkASSERT(info); 41 SkASSERT(info);
42 trailerDict.insertObjRef("Info", std::move(info)); 42 trailerDict.insertObjRef("Info", std::move(info));
43 if (id) { 43 if (id) {
44 trailerDict.insertObject("ID", std::move(id)); 44 trailerDict.insertObject("ID", std::move(id));
45 } 45 }
46 stream->writeText("trailer\n"); 46 stream->writeText("trailer\n");
47 trailerDict.emitObject(stream, objNumMap, substitutes); 47 trailerDict.emitObject(stream, objNumMap, substitutes);
48 stream->writeText("\nstartxref\n"); 48 stream->writeText("\nstartxref\n");
49 stream->writeBigDecAsText(xRefFileOffset); 49 stream->writeBigDecAsText(xRefFileOffset);
50 stream->writeText("\n%%EOF"); 50 stream->writeText("\n%%EOF");
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 break; 118 break;
119 } 119 }
120 120
121 auto newNode = sk_make_sp<SkPDFDict>("Pages"); 121 auto newNode = sk_make_sp<SkPDFDict>("Pages");
122 auto kids = sk_make_sp<SkPDFArray>(); 122 auto kids = sk_make_sp<SkPDFArray>();
123 kids->reserve(kNodeSize); 123 kids->reserve(kNodeSize);
124 124
125 int count = 0; 125 int count = 0;
126 for (; i < curNodes.count() && count < kNodeSize; i++, count++) { 126 for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
127 curNodes[i]->insertObjRef("Parent", newNode); 127 curNodes[i]->insertObjRef("Parent", newNode);
128 kids->appendObjRef(sk_sp<SkPDFDict>(SkRef(curNodes[i]))); 128 kids->appendObjRef(sk_ref_sp(curNodes[i]));
129 129
130 // TODO(vandebo): put the objects in strict access order. 130 // TODO(vandebo): put the objects in strict access order.
131 // Probably doesn't matter because they are so small. 131 // Probably doesn't matter because they are so small.
132 if (curNodes[i] != pages[0]) { 132 if (curNodes[i] != pages[0]) {
133 pageTree->push(curNodes[i]); // Transfer reference. 133 pageTree->push(curNodes[i]); // Transfer reference.
134 } else { 134 } else {
135 SkSafeUnref(curNodes[i]); 135 SkSafeUnref(curNodes[i]);
136 } 136 }
137 } 137 }
138 138
(...skipping 12 matching lines...) Expand all
151 newNode->insertObject("Kids", std::move(kids)); 151 newNode->insertObject("Kids", std::move(kids));
152 nextRoundNodes.push(newNode.release()); // Transfer reference. 152 nextRoundNodes.push(newNode.release()); // Transfer reference.
153 } 153 }
154 154
155 curNodes = nextRoundNodes; 155 curNodes = nextRoundNodes;
156 nextRoundNodes.rewind(); 156 nextRoundNodes.rewind();
157 treeCapacity *= kNodeSize; 157 treeCapacity *= kNodeSize;
158 } while (curNodes.count() > 1); 158 } while (curNodes.count() > 1);
159 159
160 pageTree->push(curNodes[0]); // Transfer reference. 160 pageTree->push(curNodes[0]); // Transfer reference.
161 return sk_sp<SkPDFDict>(SkRef(curNodes[0])); 161 return sk_ref_sp(curNodes[0]);
162 } 162 }
163 163
164 static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevi ces, 164 static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevi ces,
165 const SkPDFMetadata& metadata, 165 const SkPDFMetadata& metadata,
166 SkWStream* stream) { 166 SkWStream* stream) {
167 if (pageDevices.empty()) { 167 if (pageDevices.empty()) {
168 return false; 168 return false;
169 } 169 }
170 170
171 SkTDArray<SkPDFDict*> pages; // TODO: SkTArray<sk_sp<SkPDFDict>> 171 SkTDArray<SkPDFDict*> pages; // TODO: SkTArray<sk_sp<SkPDFDict>>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { 395 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) {
396 SkFILEWStream* stream = new SkFILEWStream(path); 396 SkFILEWStream* stream = new SkFILEWStream(path);
397 if (!stream->isValid()) { 397 if (!stream->isValid()) {
398 delete stream; 398 delete stream;
399 return nullptr; 399 return nullptr;
400 } 400 }
401 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; 401 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; };
402 return new SkDocument_PDF(stream, delete_wstream, dpi, nullptr); 402 return new SkDocument_PDF(stream, delete_wstream, dpi, nullptr);
403 } 403 }
OLDNEW
« no previous file with comments | « no previous file | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698