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

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: Simpler changes 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/pdf/SkPDFStream.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..2c27c5b1da72a3d44129d1ba9b0d8b59fa43cc54 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -907,3 +907,34 @@ SkData* SkCopyStreamToData(SkStream* stream) {
} while (!stream->isAtEnd());
return tempStream.copyToData();
}
+
+SkStreamRewindable* SkStreamToStreamRewindable(SkStream* stream) {
bungeman-skia 2014/07/11 21:43:38 I would prefer this to be SkStreamRewindableFromSk
hal.canary 2014/07/12 00:58:49 Done.
+ if (!stream) {
+ return NULL;
+ }
+ SkAutoTUnref<SkStreamRewindable> dupStream(stream->duplicate());
+ if (dupStream) {
+ return dupStream.detach();
+ }
+ if (stream->hasLength()) {
+ size_t length = stream->getLength();
+ SkAutoMalloc allocMemory(length);
+ SkAssertResult(stream->rewind());
bungeman-skia 2014/07/11 21:43:38 I wouldn't assert this, just because a stream has
hal.canary 2014/07/12 00:58:49 Done.
+ SkAssertResult(length == stream->read(allocMemory.get(), length));
+ SkAssertResult(stream->rewind());
bungeman-skia 2014/07/11 21:43:38 I see no reason to try to leave this in a known st
hal.canary 2014/07/12 00:58:49 Done.
+ SkAutoTUnref<SkData> data(
+ SkData::NewFromMalloc(allocMemory.get(), length));
+ return SkNEW_ARGS(SkMemoryStream, (data.get()));
+ }
+ SkAssertResult(stream->rewind());
+ 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());
+ SkAssertResult(stream->rewind());
bungeman-skia 2014/07/11 21:43:38 Same as above (line 924), I see no reason to try t
hal.canary 2014/07/12 00:58:49 Done.
+ 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/pdf/SkPDFStream.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698