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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/StreamTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 fCurrentOffset = 0; 717 fCurrentOffset = 0;
718 } 718 }
719 SkASSERT(false); 719 SkASSERT(false);
720 return 0; 720 return 0;
721 } 721 }
722 722
723 bool isAtEnd() const override { 723 bool isAtEnd() const override {
724 return fOffset == fSize; 724 return fOffset == fSize;
725 } 725 }
726 726
727 bool peek(void* buff, size_t size) const override {
728 SkASSERT(buff != NULL);
729 if (fOffset + size > fSize) {
730 return false;
731 }
732 char* buffer = static_cast<char*>(buff);
733 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
734 size_t bytesFromCurrent =
735 SkTMin(current->written() - fCurrentOffset, size);
736 memcpy(buffer, current->start() + fCurrentOffset, bytesFromCurrent);
737 size -= bytesFromCurrent;
738 buffer += bytesFromCurrent;
739 current = current->fNext;
740 while (size) {
741 SkASSERT(current);
742 bytesFromCurrent = SkTMin(current->written(), size);
743 memcpy(buffer, current->start(), bytesFromCurrent);
744 size -= bytesFromCurrent;
745 buffer += bytesFromCurrent;
746 current = current->fNext;
747 }
748 return true;
749 }
750
727 bool rewind() override { 751 bool rewind() override {
728 fCurrent = fBlockMemory->fHead; 752 fCurrent = fBlockMemory->fHead;
729 fOffset = 0; 753 fOffset = 0;
730 fCurrentOffset = 0; 754 fCurrentOffset = 0;
731 return true; 755 return true;
732 } 756 }
733 757
734 SkBlockMemoryStream* duplicate() const override { 758 SkBlockMemoryStream* duplicate() const override {
735 return SkNEW_ARGS(SkBlockMemoryStream, (fBlockMemory.get(), fSize)); 759 return SkNEW_ARGS(SkBlockMemoryStream, (fBlockMemory.get(), fSize));
736 } 760 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 SkDynamicMemoryWStream tempStream; 946 SkDynamicMemoryWStream tempStream;
923 const size_t bufferSize = 4096; 947 const size_t bufferSize = 4096;
924 char buffer[bufferSize]; 948 char buffer[bufferSize];
925 do { 949 do {
926 size_t bytesRead = stream->read(buffer, bufferSize); 950 size_t bytesRead = stream->read(buffer, bufferSize);
927 tempStream.write(buffer, bytesRead); 951 tempStream.write(buffer, bytesRead);
928 } while (!stream->isAtEnd()); 952 } while (!stream->isAtEnd());
929 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, 953 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream,
930 // cheaper than copying to SkData 954 // cheaper than copying to SkData
931 } 955 }
OLDNEW
« 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