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

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

Issue 1837553002: SkPDF s/SkAutoTDelete/std::unique_ptr/ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-28 (Monday) 10:22:50 EDT Created 4 years, 8 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') | src/pdf/SkPDFTypes.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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkDeflate.h" 11 #include "SkDeflate.h"
12 #include "SkPDFStream.h" 12 #include "SkPDFStream.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkStreamPriv.h" 14 #include "SkStreamPriv.h"
15 15
16 SkPDFStream::~SkPDFStream() {} 16 SkPDFStream::~SkPDFStream() {}
17 17
18 void SkPDFStream::drop() { 18 void SkPDFStream::drop() {
19 fCompressedData.reset(nullptr); 19 fCompressedData.reset(nullptr);
20 this->SkPDFDict::drop(); 20 this->SkPDFDict::drop();
21 } 21 }
22 22
23 void SkPDFStream::emitObject(SkWStream* stream, 23 void SkPDFStream::emitObject(SkWStream* stream,
24 const SkPDFObjNumMap& objNumMap, 24 const SkPDFObjNumMap& objNumMap,
25 const SkPDFSubstituteMap& substitutes) const { 25 const SkPDFSubstituteMap& substitutes) const {
26 SkASSERT(fCompressedData); 26 SkASSERT(fCompressedData);
27 this->INHERITED::emitObject(stream, objNumMap, substitutes); 27 this->INHERITED::emitObject(stream, objNumMap, substitutes);
28 // duplicate (a cheap operation) preserves const on fCompressedData. 28 // duplicate (a cheap operation) preserves const on fCompressedData.
29 SkAutoTDelete<SkStreamRewindable> dup(fCompressedData->duplicate()); 29 std::unique_ptr<SkStreamRewindable> dup(fCompressedData->duplicate());
30 SkASSERT(dup); 30 SkASSERT(dup);
31 SkASSERT(dup->hasLength()); 31 SkASSERT(dup->hasLength());
32 stream->writeText(" stream\n"); 32 stream->writeText(" stream\n");
33 stream->writeStream(dup.get(), dup->getLength()); 33 stream->writeStream(dup.get(), dup->getLength());
34 stream->writeText("\nendstream"); 34 stream->writeText("\nendstream");
35 } 35 }
36 36
37 void SkPDFStream::setData(SkStream* stream) { 37 void SkPDFStream::setData(SkStream* stream) {
38 SkASSERT(!fCompressedData); // Only call this function once. 38 SkASSERT(!fCompressedData); // Only call this function once.
39 SkASSERT(stream); 39 SkASSERT(stream);
40 // Code assumes that the stream starts at the beginning. 40 // Code assumes that the stream starts at the beginning.
41 41
42 SkDynamicMemoryWStream compressedData; 42 SkDynamicMemoryWStream compressedData;
43 SkDeflateWStream deflateWStream(&compressedData); 43 SkDeflateWStream deflateWStream(&compressedData);
44 SkStreamCopy(&deflateWStream, stream); 44 SkStreamCopy(&deflateWStream, stream);
45 deflateWStream.finalize(); 45 deflateWStream.finalize();
46 size_t length = compressedData.bytesWritten(); 46 size_t length = compressedData.bytesWritten();
47 47
48 if (stream->hasLength()) { 48 if (stream->hasLength()) {
49 SkAutoTDelete<SkStreamRewindable> dup(stream->duplicate()); 49 std::unique_ptr<SkStreamRewindable> dup(stream->duplicate());
50 if (dup && dup->hasLength() && 50 if (dup && dup->hasLength() &&
51 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) { 51 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) {
52 this->insertInt("Length", dup->getLength()); 52 this->insertInt("Length", dup->getLength());
53 fCompressedData.reset(dup.release()); 53 fCompressedData.reset(dup.release());
54 return; 54 return;
55 } 55 }
56 } 56 }
57 fCompressedData.reset(compressedData.detachAsStream()); 57 fCompressedData.reset(compressedData.detachAsStream());
58 this->insertName("Filter", "FlateDecode"); 58 this->insertName("Filter", "FlateDecode");
59 this->insertInt("Length", length); 59 this->insertInt("Length", length);
60 } 60 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698