| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |