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

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: 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 | « no previous file | src/core/SkStreamPriv.h » ('j') | no next file with comments »
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..5069bb0a7e070acb797be877dccd9cbdf58b5934 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -907,3 +907,35 @@ 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);
+ SkDEBUGCODE(size_t read =) stream->read(allocMemory.get(), length);
+ SkASSERT(length == read);
+ 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());
+ return tempStream.detachAsStream(); // returns a SkBlockMemoryStream,
+ // cheaper than copying to SkData
+}
« no previous file with comments | « no previous file | src/core/SkStreamPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698