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

Unified Diff: src/core/SkStream.cpp

Issue 387863005: Move SkPDFStream back to SkStream to save memory. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reed commants 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 | « no previous file | src/core/SkStreamPriv.h » ('j') | src/core/SkStreamPriv.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkStream.cpp
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index 1022d183d93cc4bb36526f437c04f89f520ff856..2c42000f7100665d64f8b6b840ab300ccdafd60e 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -907,3 +907,36 @@ SkData* SkCopyStreamToData(SkStream* stream) {
} while (!stream->isAtEnd());
return tempStream.copyToData();
}
+
+SkStreamRewindable* SkStreamRewindableFromSkStream(SkStream* stream) {
+ if (!stream) {
+ return NULL;
+ }
+ SkAutoTUnref<SkStreamRewindable> dupStream(stream->duplicate());
+ if (dupStream) {
+ return dupStream.detach();
+ }
+ stream->rewind();
+ if (stream->hasLength()) {
+ size_t length = stream->getLength();
+ if (stream->hasPosition()) { // If stream has length, but can't rewind.
+ length -= stream->getPosition();
+ }
+ SkAutoMalloc allocMemory(length);
+ SkAssertResult(length == stream->read(allocMemory.get(), length));
+ stream->rewind();
+ SkAutoTUnref<SkData> data(
+ SkData::NewFromMalloc(allocMemory.detach(), length));
+ return SkNEW_ARGS(SkMemoryStream, (data.get()));
+ }
+ SkDynamicMemoryWStream tempStream;
+ const size_t bufferSize = 4096;
+ char buffer[bufferSize];
+ do {
+ size_t bytesRead = stream->read(buffer, bufferSize);
+ tempStream.write(buffer, bytesRead);
+ } while (!stream->isAtEnd());
+ stream->rewind();
+ return tempStream.detachAsStream(); // returns a SkBlockMemoryStream,
+ // cheaper than copying to SkData
+}
« no previous file with comments | « no previous file | src/core/SkStreamPriv.h » ('j') | src/core/SkStreamPriv.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698