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

Unified Diff: src/core/SkStream.cpp

Issue 1520403003: Prototype of RAW decoding in Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: * Add DNG scaling. * Adress all comments. Created 4 years, 11 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
Index: src/core/SkStream.cpp
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index fff8f3382209b9fd9509d55a916b711022d7721e..8d003354cda440706449f267736b16267f8e7e42 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -888,21 +888,9 @@ size_t SkCopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
}
SkDynamicMemoryWStream tempStream;
- // Arbitrary buffer size.
-#if defined(GOOGLE3)
- // Stack frame size is limited in GOOGLE3.
- const size_t bufferSize = 8 * 1024; // 8KB
-#else
- const size_t bufferSize = 256 * 1024; // 256KB
-#endif
- 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());
+ if (!SkStreamCopy(&tempStream, stream)) {
+ return 0;
+ }
const size_t length = tempStream.bytesWritten();
void* dst = storage->reset(length);
tempStream.copyTo(dst);
@@ -976,3 +964,25 @@ bool SkStreamCopy(SkWStream* out, SkStream* input) {
}
}
}
+
+// TODO: optimize for the special case when the input is SkMemoryStream.
scroggo 2016/01/08 19:11:49 The optimization is actually elsewhere - you shoul
yujieqin 2016/01/11 14:03:08 Not sure what you mean here, I moved the TODO into
+bool SkStreamCopy(SkDynamicMemoryWStream* out, SkStream* input) {
+ // Arbitrary buffer size.
+#if defined(GOOGLE3)
+ // Stack frame size is limited in GOOGLE3.
+ const size_t bufferSize = 8 * 1024; // 8KB
+#else
+ const size_t bufferSize = 256 * 1024; // 256KB
+#endif
+ char buffer[bufferSize];
+ SkDEBUGCODE(size_t debugLength = 0;)
+ do {
+ size_t bytesRead = input->read(buffer, bufferSize);
+ if (!out->write(buffer, bytesRead)) {
+ return false;
+ }
+ SkDEBUGCODE(debugLength += bytesRead);
+ SkASSERT(out->bytesWritten() == debugLength);
+ } while (!input->isAtEnd());
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698