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

Unified Diff: src/utils/SkDataUtils.cpp

Issue 273703006: extract some common code from PictureRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add TODO Created 6 years, 7 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/utils/SkDataUtils.cpp
diff --git a/src/utils/SkDataUtils.cpp b/src/utils/SkDataUtils.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c5544f71ba3e5a8dc9d74ae0a8b2670564455d32
--- /dev/null
+++ b/src/utils/SkDataUtils.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkData.h"
+#include "SkDataUtils.h"
+#include "SkStream.h"
+
+/*static*/ SkData* SkDataUtils::ReadIntoSkData(SkStream &stream, size_t maxBytes) {
+ if (0 == maxBytes) {
+ return SkData::NewEmpty();
+ }
+ char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes));
+ char* bufPtr = bufStart;
+ size_t bytesRemaining = maxBytes;
+ while (bytesRemaining > 0) {
+ size_t bytesReadThisTime = stream.read(bufPtr, bytesRemaining);
+ if (0 == bytesReadThisTime) {
+ break;
+ }
+ bytesRemaining -= bytesReadThisTime;
+ bufPtr += bytesReadThisTime;
+ }
+ return SkData::NewFromMalloc(bufStart, maxBytes - bytesRemaining);
+}
« gyp/tools.gyp ('K') | « src/utils/SkDataUtils.h ('k') | tools/PictureRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698