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

Unified Diff: src/pdf/SkPDFStream.cpp

Issue 387863005: Move SkPDFStream back to SkStream to save memory. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make compiler happy Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pdf/SkPDFStream.h ('k') | 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 8715d9376b7f2f87907c7a65de880fd6fd9a3ebf..60fce0d6f129b86d4f0f74779fe99afceabef449 100644
--- a/src/pdf/SkPDFStream.cpp
+++ b/src/pdf/SkPDFStream.cpp
@@ -30,7 +30,7 @@ SkPDFStream::SkPDFStream(SkData* data) : fState(kUnused_State) {
SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream)
: SkPDFDict(),
fState(kUnused_State) {
- this->setData(pdfStream.fData.get());
+ this->setData(pdfStream.fDataStream.get());
bool removeLength = true;
// Don't uncompress an already compressed stream, but we could.
if (pdfStream.fState == kCompressed_State) {
@@ -57,9 +57,8 @@ void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
this->INHERITED::emitObject(stream, catalog, false);
stream->writeText(" stream\n");
- if (fData.get()) {
- stream->write(fData->data(), fData->size());
- }
+ stream->writeStream(fDataStream.get(), fDataStream->getLength());
+ SkAssertResult(fDataStream->rewind());
stream->writeText("\nendstream");
}
@@ -79,22 +78,31 @@ size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
SkPDFStream::SkPDFStream() : fState(kUnused_State) {}
void SkPDFStream::setData(SkData* data) {
- fData.reset(SkSafeRef(data));
+ fMemoryStream.setData(data);
+ if (&fMemoryStream != fDataStream.get()) {
+ fDataStream.reset(SkRef(&fMemoryStream));
+ }
}
void SkPDFStream::setData(SkStream* stream) {
// Code assumes that the stream starts at the beginning and is rewindable.
+ if (&fMemoryStream == fDataStream.get()) {
+ SkASSERT(&fMemoryStream != stream);
+ fMemoryStream.setData(NULL);
+ }
+ SkASSERT(0 == fMemoryStream.getLength());
if (stream) {
- SkASSERT(stream->getPosition() == 0);
- fData.reset(SkCopyStreamToData(stream));
- SkAssertResult(stream->rewind());
+ // SkStreamRewindableFromSkStream will try stream->duplicate().
+ fDataStream.reset(SkStreamRewindableFromSkStream(stream));
+ SkASSERT(fDataStream.get());
} else {
- fData.reset(NULL);
+ fDataStream.reset(SkRef(&fMemoryStream));
}
}
size_t SkPDFStream::dataSize() const {
- return fData.get() ? fData->size() : 0;
+ SkASSERT(fDataStream->hasLength());
+ return fDataStream->getLength();
}
bool SkPDFStream::populate(SkPDFCatalog* catalog) {
@@ -102,9 +110,11 @@ bool SkPDFStream::populate(SkPDFCatalog* catalog) {
if (!skip_compression(catalog) && SkFlate::HaveFlate()) {
SkDynamicMemoryWStream compressedData;
- SkAssertResult(SkFlate::Deflate(fData.get(), &compressedData));
+ SkAssertResult(
+ SkFlate::Deflate(fDataStream.get(), &compressedData));
+ SkAssertResult(fDataStream->rewind());
if (compressedData.getOffset() < this->dataSize()) {
- fData.reset(compressedData.copyToData());
+ this->setData(compressedData.detachAsStream());
insertName("Filter", "FlateDecode");
}
fState = kCompressed_State;
« 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