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

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) 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 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;
734 size_t currentOffset = fCurrentOffset;
735 while (size) {
736 SkASSERT(current);
737 size_t bytesFromCurrent =
738 SkTMin(current->written() - currentOffset, size);
739 memcpy(buffer, current->start() + currentOffset, bytesFromCurrent);
740 size -= bytesFromCurrent;
741 buffer += bytesFromCurrent;
742 current = current->fNext;
743 currentOffset = 0;
744 }
745 return true;
746 }
747
727 bool rewind() override { 748 bool rewind() override {
728 fCurrent = fBlockMemory->fHead; 749 fCurrent = fBlockMemory->fHead;
729 fOffset = 0; 750 fOffset = 0;
730 fCurrentOffset = 0; 751 fCurrentOffset = 0;
731 return true; 752 return true;
732 } 753 }
733 754
734 SkBlockMemoryStream* duplicate() const override { 755 SkBlockMemoryStream* duplicate() const override {
735 return SkNEW_ARGS(SkBlockMemoryStream, (fBlockMemory.get(), fSize)); 756 return SkNEW_ARGS(SkBlockMemoryStream, (fBlockMemory.get(), fSize));
736 } 757 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 SkDynamicMemoryWStream tempStream; 943 SkDynamicMemoryWStream tempStream;
923 const size_t bufferSize = 4096; 944 const size_t bufferSize = 4096;
924 char buffer[bufferSize]; 945 char buffer[bufferSize];
925 do { 946 do {
926 size_t bytesRead = stream->read(buffer, bufferSize); 947 size_t bytesRead = stream->read(buffer, bufferSize);
927 tempStream.write(buffer, bytesRead); 948 tempStream.write(buffer, bytesRead);
928 } while (!stream->isAtEnd()); 949 } while (!stream->isAtEnd());
929 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, 950 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream,
930 // cheaper than copying to SkData 951 // cheaper than copying to SkData
931 } 952 }
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