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

Unified Diff: src/pdf/SkPDFTypes.cpp

Issue 1227913008: SkPDF: Memory improvements for PDF Streams (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-19 (Wednesday) 17:47:45 EDT Created 5 years, 4 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/SkPDFTypes.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFTypes.cpp
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 2fe408b1cc879abd910aba5af4e56355a3acb70e..9bb9dee49760840924cee3b022ee90db5d7dcf73 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -6,15 +6,10 @@
* found in the LICENSE file.
*/
+#include "SkDeflate.h"
#include "SkPDFTypes.h"
#include "SkPDFUtils.h"
-#include "SkStream.h"
-
-#ifdef SK_BUILD_FOR_WIN
- #define SNPRINTF _snprintf
-#else
- #define SNPRINTF snprintf
-#endif
+#include "SkStreamPriv.h"
////////////////////////////////////////////////////////////////////////////////
@@ -355,6 +350,13 @@ void SkPDFDict::emitObject(SkWStream* stream,
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& substitutes) const {
stream->writeText("<<");
+ this->emitAll(stream, objNumMap, substitutes);
+ stream->writeText(">>");
+}
+
+void SkPDFDict::emitAll(SkWStream* stream,
+ const SkPDFObjNumMap& objNumMap,
+ const SkPDFSubstituteMap& substitutes) const {
for (int i = 0; i < fRecords.count(); i++) {
fRecords[i].fKey.emitObject(stream, objNumMap, substitutes);
stream->writeText(" ");
@@ -363,7 +365,6 @@ void SkPDFDict::emitObject(SkWStream* stream,
stream->writeText("\n");
}
}
- stream->writeText(">>");
}
void SkPDFDict::addResources(SkPDFObjNumMap* catalog,
@@ -439,6 +440,41 @@ void SkPDFDict::clear() {
////////////////////////////////////////////////////////////////////////////////
+void SkPDFSharedStream::emitObject(
+ SkWStream* stream,
+ const SkPDFObjNumMap& objNumMap,
+ const SkPDFSubstituteMap& substitutes) const {
+ SkDynamicMemoryWStream buffer;
+ SkDeflateWStream deflateWStream(&buffer);
+ // Since emitObject is const, this function doesn't change the dictionary.
+ SkAutoTDelete<SkStreamAsset> dup(fAsset->duplicate()); // Cheap copy
+ SkASSERT(dup);
+ SkStreamCopy(&deflateWStream, dup.get());
+ deflateWStream.finalize();
+ size_t length = buffer.bytesWritten();
+ stream->writeText("<<");
+ fDict->emitAll(stream, objNumMap, substitutes);
+ stream->writeText("\n");
+ SkPDFUnion::Name("Length").emitObject(stream, objNumMap, substitutes);
+ stream->writeText(" ");
+ SkPDFUnion::Int(length).emitObject(stream, objNumMap, substitutes);
+ stream->writeText("\n");
+ SkPDFUnion::Name("Filter").emitObject(stream, objNumMap, substitutes);
+ stream->writeText(" ");
+ SkPDFUnion::Name("FlateDecode").emitObject(stream, objNumMap, substitutes);
+ stream->writeText(">>");
+ stream->writeText(" stream\n");
+ buffer.writeToStream(stream);
+ stream->writeText("\nendstream");
+}
+
+void SkPDFSharedStream::addResources(
+ SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const {
+ fDict->addResources(catalog, substitutes);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFSubstituteMap::~SkPDFSubstituteMap() {
fSubstituteMap.foreach(
[](SkPDFObject*, SkPDFObject** v) { (*v)->unref(); });
« no previous file with comments | « src/pdf/SkPDFTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698