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

Unified Diff: src/core/SkStream.cpp

Issue 340783013: Switch SkPDFStream's internal storage from SkStream to SkData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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 | « gyp/images.gyp ('k') | 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 ebaac9ab1503ff2c4002e21948fca6a2180ac236..1022d183d93cc4bb36526f437c04f89f520ff856 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -8,10 +8,12 @@
#include "SkStream.h"
+#include "SkStreamPriv.h"
#include "SkData.h"
#include "SkFixed.h"
#include "SkString.h"
#include "SkOSFile.h"
+#include "SkTypes.h"
///////////////////////////////////////////////////////////////////////////////
@@ -851,3 +853,57 @@ SkStreamAsset* SkStream::NewFromFile(const char path[]) {
}
return stream;
}
+
+// Declared in SkStreamPriv.h:
+size_t SkCopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
+ SkASSERT(storage != NULL);
+ SkASSERT(stream != NULL);
+
+ if (stream->hasLength()) {
+ const size_t length = stream->getLength();
+ void* dst = storage->reset(length);
+ if (stream->read(dst, length) != length) {
+ return 0;
+ }
+ return length;
+ }
+
+ SkDynamicMemoryWStream tempStream;
+ // Arbitrary buffer size.
+ const size_t bufferSize = 256 * 1024; // 256KB
+ char buffer[bufferSize];
+ SkDEBUGCODE(size_t debugLength = 0;)
+ do {
+ size_t bytesRead = stream->read(buffer, bufferSize);
+ tempStream.write(buffer, bytesRead);
+ SkDEBUGCODE(debugLength += bytesRead);
+ SkASSERT(tempStream.bytesWritten() == debugLength);
+ } while (!stream->isAtEnd());
+ const size_t length = tempStream.bytesWritten();
+ void* dst = storage->reset(length);
+ tempStream.copyTo(dst);
+ return length;
+}
+
+// Declared in SkStreamPriv.h:
+SkData* SkCopyStreamToData(SkStream* stream) {
+ SkASSERT(stream != NULL);
+
+ if (stream->hasLength()) {
+ const size_t length = stream->getLength();
+ SkAutoMalloc dst(length);
+ if (stream->read(dst.get(), length) != length) {
+ return NULL;
+ }
+ return SkData::NewFromMalloc(dst.detach(), length);
+ }
+
+ 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.copyToData();
+}
« no previous file with comments | « gyp/images.gyp ('k') | src/core/SkStreamPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698