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

Unified Diff: src/pdf/SkPDFStream.cpp

Issue 2104223003: SkPDF: always assume SkStreamAsset behaves as specified (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFStream.cpp
diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp
index 50735efa6cb112d614e2bbce79d763cdedb53c56..a9b5864c08c4c00e8e0d703473224e77921ff7a1 100644
--- a/src/pdf/SkPDFStream.cpp
+++ b/src/pdf/SkPDFStream.cpp
@@ -32,42 +32,32 @@ void SkPDFStream::emitObject(SkWStream* stream,
stream->writeText("\nendstream");
}
-
void SkPDFStream::setData(SkStreamAsset* stream) {
SkASSERT(!fCompressedData); // Only call this function once.
SkASSERT(stream);
// Code assumes that the stream starts at the beginning.
#ifdef SK_PDF_LESS_COMPRESSION
- std::unique_ptr<SkStreamAsset> duplicate(stream->duplicate());
- SkASSERT(duplicate && duplicate->hasLength());
- if (duplicate && duplicate->hasLength()) {
- this->insertInt("Length", duplicate->getLength());
- fCompressedData.reset(duplicate.release());
- return;
- }
- #endif
+ fCompressedData.reset(stream->duplicate());
+ SkASSERT(fCompressedData && fCompressedData->hasLength());
+ this->insertInt("Length", fCompressedData->getLength());
+ #else
+ SkASSERT(stream->hasLength());
Tom Hudson 2016/06/29 13:37:28 I thought you were getting rid of these?
SkDynamicMemoryWStream compressedData;
SkDeflateWStream deflateWStream(&compressedData);
SkStreamCopy(&deflateWStream, stream);
deflateWStream.finalize();
- size_t length = compressedData.bytesWritten();
+ size_t compressedLength = compressedData.bytesWritten();
+ size_t originalLength = stream->getLength();
- SkASSERT(stream->hasLength());
- if (stream->hasLength()) {
- std::unique_ptr<SkStreamAsset> dup(stream->duplicate());
- SkASSERT(stream->hasLength());
- SkASSERT(stream->getLength() == dup->getLength());
- SkASSERT(dup && dup->hasLength());
- if (dup && dup->hasLength() &&
- dup->getLength() <= length + strlen("/Filter_/FlateDecode_")) {
- this->insertInt("Length", dup->getLength());
- fCompressedData.reset(dup.release());
- return;
- }
+ if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) {
+ fCompressedData.reset(stream->duplicate());
+ this->insertInt("Length", originalLength);
+ return;
}
fCompressedData.reset(compressedData.detachAsStream());
this->insertName("Filter", "FlateDecode");
- this->insertInt("Length", length);
+ this->insertInt("Length", compressedLength);
+ #endif
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698