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

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

Issue 18328026: Added SkPDFStream::setData(SkData*) in preparation for move from SkStream to SkData (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | no next file » | 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 "SkFlate.h" 11 #include "SkFlate.h"
12 #include "SkPDFCatalog.h" 12 #include "SkPDFCatalog.h"
13 #include "SkPDFStream.h" 13 #include "SkPDFStream.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 15
16 static bool skip_compression(SkPDFCatalog* catalog) { 16 static bool skip_compression(SkPDFCatalog* catalog) {
17 return SkToBool(catalog->getDocumentFlags() & 17 return SkToBool(catalog->getDocumentFlags() &
18 SkPDFDocument::kFavorSpeedOverSize_Flags); 18 SkPDFDocument::kFavorSpeedOverSize_Flags);
19 } 19 }
20 20
21 SkPDFStream::SkPDFStream(SkStream* stream) 21 SkPDFStream::SkPDFStream(SkStream* stream)
22 : fState(kUnused_State), 22 : fState(kUnused_State),
23 fData(stream) { 23 fData(stream) {
24 SkSafeRef(stream); 24 SkSafeRef(stream);
25 } 25 }
26 26
27 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { 27 SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) {
28 SkMemoryStream* stream = new SkMemoryStream; 28 setData(data);
29 stream->setData(data);
30 fData.reset(stream); // Transfer ownership.
31 } 29 }
32 30
33 SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) 31 SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
34 : SkPDFDict(), 32 : SkPDFDict(),
35 fState(kUnused_State), 33 fState(kUnused_State),
36 fData(pdfStream.fData.get()) { 34 fData(pdfStream.fData.get()) {
37 fData.get()->ref(); 35 fData.get()->ref();
38 bool removeLength = true; 36 bool removeLength = true;
39 // Don't uncompress an already compressed stream, but we could. 37 // Don't uncompress an already compressed stream, but we could.
40 if (pdfStream.fState == kCompressed_State) { 38 if (pdfStream.fState == kCompressed_State) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (!this->populate(catalog)) { 75 if (!this->populate(catalog)) {
78 return fSubstitute->getOutputSize(catalog, indirect); 76 return fSubstitute->getOutputSize(catalog, indirect);
79 } 77 }
80 78
81 return this->INHERITED::getOutputSize(catalog, false) + 79 return this->INHERITED::getOutputSize(catalog, false) +
82 strlen(" stream\n\nendstream") + fData->getLength(); 80 strlen(" stream\n\nendstream") + fData->getLength();
83 } 81 }
84 82
85 SkPDFStream::SkPDFStream() : fState(kUnused_State) {} 83 SkPDFStream::SkPDFStream() : fState(kUnused_State) {}
86 84
85 void SkPDFStream::setData(SkData* data) {
86 SkMemoryStream* stream = new SkMemoryStream;
87 stream->setData(data);
88 fData.reset(stream); // Transfer ownership.
89 }
90
87 void SkPDFStream::setData(SkStream* stream) { 91 void SkPDFStream::setData(SkStream* stream) {
88 fData.reset(stream); 92 fData.reset(stream);
89 SkSafeRef(stream); 93 SkSafeRef(stream);
90 } 94 }
91 95
92 bool SkPDFStream::populate(SkPDFCatalog* catalog) { 96 bool SkPDFStream::populate(SkPDFCatalog* catalog) {
93 if (fState == kUnused_State) { 97 if (fState == kUnused_State) {
94 if (!skip_compression(catalog) && SkFlate::HaveFlate()) { 98 if (!skip_compression(catalog) && SkFlate::HaveFlate()) {
95 SkDynamicMemoryWStream compressedData; 99 SkDynamicMemoryWStream compressedData;
96 100
(...skipping 12 matching lines...) Expand all
109 } else if (fState == kNoCompression_State && !skip_compression(catalog) && 113 } else if (fState == kNoCompression_State && !skip_compression(catalog) &&
110 SkFlate::HaveFlate()) { 114 SkFlate::HaveFlate()) {
111 if (!fSubstitute.get()) { 115 if (!fSubstitute.get()) {
112 fSubstitute.reset(new SkPDFStream(*this)); 116 fSubstitute.reset(new SkPDFStream(*this));
113 catalog->setSubstitute(this, fSubstitute.get()); 117 catalog->setSubstitute(this, fSubstitute.get());
114 } 118 }
115 return false; 119 return false;
116 } 120 }
117 return true; 121 return true;
118 } 122 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698