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

Unified Diff: src/core/SkData.cpp

Issue 101973005: SkDecodingImageGenerator now uses SkStreamRewindable (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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/SkData.cpp
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index fd963a9ff50b22aedf2d18f30ee6880e08afd598..e7130a1f52a33c1b70d78293c4634c054a9756f3 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -9,6 +9,7 @@
#include "SkFlattenableBuffers.h"
#include "SkOSFile.h"
#include "SkOnce.h"
+#include "SkStream.h"
SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
fPtr = ptr;
@@ -79,6 +80,27 @@ SkData* SkData::NewWithCopy(const void* data, size_t length) {
return new SkData(copy, length, sk_free_releaseproc, NULL);
}
+SkData* SkData::NewWithCopyFromStream(SkStreamRewindable* stream) {
+ if (!stream->hasLength()) {
+ return NULL;
+ }
+ size_t length = stream->getLength();
+ if (0 == length) {
+ return NULL;
+ }
+ void* buffer = sk_malloc_flags(length, 0);
+ if (NULL == buffer) {
+ return NULL;
+ }
+ if (!stream->rewind()) {
+ sk_free(buffer);
+ return NULL;
+ }
+ SkAssertResult(stream->read(buffer, length) == length);
+ return new SkData(buffer, length, sk_free_releaseproc, NULL);
+}
+
+
SkData* SkData::NewWithProc(const void* data, size_t length,
ReleaseProc proc, void* context) {
return new SkData(data, length, proc, context);

Powered by Google App Engine
This is Rietveld 408576698