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

Unified Diff: src/core/SkStream.cpp

Issue 1146903004: SkBlockMemoryStream implements peek() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-05-21 (Thursday) 11:06:57 EDT Created 5 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
« no previous file with comments | « no previous file | tests/StreamTest.cpp » ('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 ad67a0ba7db43759c8c6f9e03ff2f25bc0ac43ca..ac73adbce54e2045992dbe19903e80ae9207b61b 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -724,6 +724,27 @@ public:
return fOffset == fSize;
}
+ bool peek(void* buff, size_t size) const override {
+ SkASSERT(buff != NULL);
+ if (fOffset + size > fSize) {
+ return false;
+ }
+ char* buffer = static_cast<char*>(buff);
+ const SkDynamicMemoryWStream::Block* current = fCurrent;
+ size_t currentOffset = fCurrentOffset;
+ while (size) {
+ SkASSERT(current);
+ size_t bytesFromCurrent =
+ SkTMin(current->written() - currentOffset, size);
+ memcpy(buffer, current->start() + currentOffset, bytesFromCurrent);
+ size -= bytesFromCurrent;
+ buffer += bytesFromCurrent;
+ current = current->fNext;
+ currentOffset = 0;
+ }
+ return true;
+ }
+
bool rewind() override {
fCurrent = fBlockMemory->fHead;
fOffset = 0;
« no previous file with comments | « no previous file | tests/StreamTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698