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

Unified Diff: src/pdf/SkPDFStream.cpp

Issue 354043005: Revert of Switch SkPDFStream's internal storage from SkStream to SkData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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 | « 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 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()) {
« 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