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

Side by Side Diff: src/pdf/SkPDFStream.cpp

Issue 2188623004: SkPDF: SkPDFStream takes a unique_ptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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 | « src/pdf/SkPDFStream.h ('k') | tests/PDFPrimitivesTest.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 2010 Google Inc. 2 * Copyright 2010 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 8
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDeflate.h" 10 #include "SkDeflate.h"
(...skipping 14 matching lines...) Expand all
25 this->INHERITED::emitObject(stream, objNumMap, substitutes); 25 this->INHERITED::emitObject(stream, objNumMap, substitutes);
26 // duplicate (a cheap operation) preserves const on fCompressedData. 26 // duplicate (a cheap operation) preserves const on fCompressedData.
27 std::unique_ptr<SkStreamAsset> dup(fCompressedData->duplicate()); 27 std::unique_ptr<SkStreamAsset> dup(fCompressedData->duplicate());
28 SkASSERT(dup); 28 SkASSERT(dup);
29 SkASSERT(dup->hasLength()); 29 SkASSERT(dup->hasLength());
30 stream->writeText(" stream\n"); 30 stream->writeText(" stream\n");
31 stream->writeStream(dup.get(), dup->getLength()); 31 stream->writeStream(dup.get(), dup->getLength());
32 stream->writeText("\nendstream"); 32 stream->writeText("\nendstream");
33 } 33 }
34 34
35 void SkPDFStream::setData(SkStreamAsset* stream) { 35 void SkPDFStream::setData(std::unique_ptr<SkStreamAsset> stream) {
36 SkASSERT(!fCompressedData); // Only call this function once. 36 SkASSERT(!fCompressedData); // Only call this function once.
37 SkASSERT(stream); 37 SkASSERT(stream);
38 // Code assumes that the stream starts at the beginning. 38 // Code assumes that the stream starts at the beginning.
39 39
40 #ifdef SK_PDF_LESS_COMPRESSION 40 #ifdef SK_PDF_LESS_COMPRESSION
41 fCompressedData.reset(stream->duplicate()); 41 fCompressedData = std::move(stream);
42 SkASSERT(fCompressedData && fCompressedData->hasLength()); 42 SkASSERT(fCompressedData && fCompressedData->hasLength());
43 this->insertInt("Length", fCompressedData->getLength()); 43 this->insertInt("Length", fCompressedData->getLength());
44 #else 44 #else
45 45
46 SkASSERT(stream->hasLength()); 46 SkASSERT(stream->hasLength());
47 SkDynamicMemoryWStream compressedData; 47 SkDynamicMemoryWStream compressedData;
48 SkDeflateWStream deflateWStream(&compressedData); 48 SkDeflateWStream deflateWStream(&compressedData);
49 SkStreamCopy(&deflateWStream, stream); 49 SkStreamCopy(&deflateWStream, stream.get());
50 deflateWStream.finalize(); 50 deflateWStream.finalize();
51 size_t compressedLength = compressedData.bytesWritten(); 51 size_t compressedLength = compressedData.bytesWritten();
52 size_t originalLength = stream->getLength(); 52 size_t originalLength = stream->getLength();
53 53
54 if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) { 54 if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) {
55 fCompressedData.reset(stream->duplicate()); 55 SkAssertResult(stream->rewind());
56 fCompressedData = std::move(stream);
56 this->insertInt("Length", originalLength); 57 this->insertInt("Length", originalLength);
57 return; 58 return;
58 } 59 }
59 fCompressedData.reset(compressedData.detachAsStream()); 60 fCompressedData.reset(compressedData.detachAsStream());
60 this->insertName("Filter", "FlateDecode"); 61 this->insertName("Filter", "FlateDecode");
61 this->insertInt("Length", compressedLength); 62 this->insertInt("Length", compressedLength);
62 #endif 63 #endif
63 } 64 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698