Index: src/pdf/SkPDFStream.cpp |
diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp |
index 319433f7d049966075d988c691ae81400bb7ab5a..e570976403382cac79dfcb327030391fa9a08253 100644 |
--- a/src/pdf/SkPDFStream.cpp |
+++ b/src/pdf/SkPDFStream.cpp |
@@ -12,7 +12,6 @@ |
#include "SkPDFCatalog.h" |
#include "SkPDFStream.h" |
#include "SkStream.h" |
-#include "SkStreamHelpers.h" // CopyStreamToData |
static bool skip_compression(SkPDFCatalog* catalog) { |
return SkToBool(catalog->getDocumentFlags() & |
@@ -20,17 +19,17 @@ |
} |
SkPDFStream::SkPDFStream(SkStream* stream) : fState(kUnused_State) { |
- this->setData(stream); |
+ setData(stream); |
} |
SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) { |
- this->setData(data); |
+ setData(data); |
} |
SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) |
: SkPDFDict(), |
fState(kUnused_State) { |
- this->setData(pdfStream.fData.get()); |
+ setData(pdfStream.fData.get()); |
bool removeLength = true; |
// Don't uncompress an already compressed stream, but we could. |
if (pdfStream.fState == kCompressed_State) { |
@@ -56,16 +55,14 @@ |
if (indirect) { |
return emitIndirectObject(stream, catalog); |
} |
- SkAutoMutexAcquire lock(fMutex); // multiple threads could be calling emit |
if (!this->populate(catalog)) { |
return fSubstitute->emitObject(stream, catalog, indirect); |
} |
this->INHERITED::emitObject(stream, catalog, false); |
stream->writeText(" stream\n"); |
- if (fData.get()) { |
- stream->write(fData->data(), fData->size()); |
- } |
+ stream->writeStream(fData.get(), fData->getLength()); |
+ fData->rewind(); |
stream->writeText("\nendstream"); |
} |
@@ -73,34 +70,30 @@ |
if (indirect) { |
return getIndirectOutputSize(catalog); |
} |
- SkAutoMutexAcquire lock(fMutex); // multiple threads could be calling emit |
if (!this->populate(catalog)) { |
return fSubstitute->getOutputSize(catalog, indirect); |
} |
return this->INHERITED::getOutputSize(catalog, false) + |
- strlen(" stream\n\nendstream") + this->dataSize(); |
+ strlen(" stream\n\nendstream") + fData->getLength(); |
} |
SkPDFStream::SkPDFStream() : fState(kUnused_State) {} |
void SkPDFStream::setData(SkData* data) { |
- fData.reset(SkSafeRef(data)); |
+ SkMemoryStream* stream = new SkMemoryStream; |
+ stream->setData(data); |
+ fData.reset(stream); // Transfer ownership. |
} |
void SkPDFStream::setData(SkStream* stream) { |
// Code assumes that the stream starts at the beginning and is rewindable. |
if (stream) { |
SkASSERT(stream->getPosition() == 0); |
- fData.reset(CopyStreamToData(stream)); |
SkASSERT(stream->rewind()); |
- } else { |
- fData.reset(NULL); |
} |
-} |
- |
-size_t SkPDFStream::dataSize() const { |
- return fData.get() ? fData->size() : 0; |
+ fData.reset(stream); |
+ SkSafeRef(stream); |
} |
bool SkPDFStream::populate(SkPDFCatalog* catalog) { |
@@ -109,15 +102,17 @@ |
SkDynamicMemoryWStream compressedData; |
SkAssertResult(SkFlate::Deflate(fData.get(), &compressedData)); |
- if (compressedData.getOffset() < this->dataSize()) { |
- fData.reset(compressedData.copyToData()); |
+ if (compressedData.getOffset() < fData->getLength()) { |
+ SkMemoryStream* stream = new SkMemoryStream; |
+ stream->setData(compressedData.copyToData())->unref(); |
+ fData.reset(stream); // Transfer ownership. |
insertName("Filter", "FlateDecode"); |
} |
fState = kCompressed_State; |
} else { |
fState = kNoCompression_State; |
} |
- insertInt("Length", this->dataSize()); |
+ insertInt("Length", fData->getLength()); |
} else if (fState == kNoCompression_State && !skip_compression(catalog) && |
SkFlate::HaveFlate()) { |
if (!fSubstitute.get()) { |