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

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) 09:27:41 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..ff96db7500a255d3c35405ad30a549c78a17c5b4 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -724,6 +724,30 @@ 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;
scroggo 2015/05/21 14:13:18 Patch set 2 separates out the code for dealing wit
hal.canary 2015/05/21 14:35:47 reverted
+ size_t bytesFromCurrent =
+ SkTMin(current->written() - fCurrentOffset, size);
+ memcpy(buffer, current->start() + fCurrentOffset, bytesFromCurrent);
+ size -= bytesFromCurrent;
+ buffer += bytesFromCurrent;
+ current = current->fNext;
+ while (size) {
+ SkASSERT(current);
+ bytesFromCurrent = SkTMin(current->written(), size);
+ memcpy(buffer, current->start(), bytesFromCurrent);
+ size -= bytesFromCurrent;
+ buffer += bytesFromCurrent;
+ current = current->fNext;
+ }
+ 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