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

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

Issue 1840103002: SkPDF: skia_pdf_less_compression - for debugging only (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-29 (Tuesday) 12:43:26 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 | « gyp/pdf.gyp ('k') | src/pdf/SkPDFTypes.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 15 matching lines...) Expand all
26 this->INHERITED::emitObject(stream, objNumMap, substitutes); 26 this->INHERITED::emitObject(stream, objNumMap, substitutes);
27 // duplicate (a cheap operation) preserves const on fCompressedData. 27 // duplicate (a cheap operation) preserves const on fCompressedData.
28 std::unique_ptr<SkStreamRewindable> dup(fCompressedData->duplicate()); 28 std::unique_ptr<SkStreamRewindable> dup(fCompressedData->duplicate());
29 SkASSERT(dup); 29 SkASSERT(dup);
30 SkASSERT(dup->hasLength()); 30 SkASSERT(dup->hasLength());
31 stream->writeText(" stream\n"); 31 stream->writeText(" stream\n");
32 stream->writeStream(dup.get(), dup->getLength()); 32 stream->writeStream(dup.get(), dup->getLength());
33 stream->writeText("\nendstream"); 33 stream->writeText("\nendstream");
34 } 34 }
35 35
36
36 void SkPDFStream::setData(SkStream* stream) { 37 void SkPDFStream::setData(SkStream* stream) {
37 SkASSERT(!fCompressedData); // Only call this function once. 38 SkASSERT(!fCompressedData); // Only call this function once.
38 SkASSERT(stream); 39 SkASSERT(stream);
39 // Code assumes that the stream starts at the beginning. 40 // Code assumes that the stream starts at the beginning.
40 41
42 #ifdef SK_PDF_LESS_COMPRESSION
43 std::unique_ptr<SkStreamRewindable> duplicate(stream->duplicate());
44 if (duplicate && duplicate->hasLength()) {
45 this->insertInt("Length", duplicate->getLength());
46 fCompressedData.reset(duplicate.release());
47 return;
48 }
49 #endif
50
41 SkDynamicMemoryWStream compressedData; 51 SkDynamicMemoryWStream compressedData;
42 SkDeflateWStream deflateWStream(&compressedData); 52 SkDeflateWStream deflateWStream(&compressedData);
43 SkStreamCopy(&deflateWStream, stream); 53 SkStreamCopy(&deflateWStream, stream);
44 deflateWStream.finalize(); 54 deflateWStream.finalize();
45 size_t length = compressedData.bytesWritten(); 55 size_t length = compressedData.bytesWritten();
46 56
47 if (stream->hasLength()) { 57 if (stream->hasLength()) {
48 std::unique_ptr<SkStreamRewindable> dup(stream->duplicate()); 58 std::unique_ptr<SkStreamRewindable> dup(stream->duplicate());
49 if (dup && dup->hasLength() && 59 if (dup && dup->hasLength() &&
50 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) { 60 dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) {
51 this->insertInt("Length", dup->getLength()); 61 this->insertInt("Length", dup->getLength());
52 fCompressedData.reset(dup.release()); 62 fCompressedData.reset(dup.release());
53 return; 63 return;
54 } 64 }
55 } 65 }
56 fCompressedData.reset(compressedData.detachAsStream()); 66 fCompressedData.reset(compressedData.detachAsStream());
57 this->insertName("Filter", "FlateDecode"); 67 this->insertName("Filter", "FlateDecode");
58 this->insertInt("Length", length); 68 this->insertInt("Length", length);
59 } 69 }
OLDNEW
« no previous file with comments | « gyp/pdf.gyp ('k') | src/pdf/SkPDFTypes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698