OLD | NEW |
---|---|
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 Loading... | |
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 if (fOffset + size > fSize) { | |
729 return false; | |
730 } | |
731 if (!buff) { | |
scroggo
2015/05/20 15:43:35
In other implementations, we SkASSERT(buff). They
hal.canary
2015/05/21 13:28:02
Done.
| |
732 return true; | |
733 } | |
734 char* buffer = static_cast<char*>(buff); | |
735 SkDynamicMemoryWStream::Block const * current = fCurrent; | |
736 size_t currentOffset = fCurrentOffset; | |
737 while (size) { | |
738 SkASSERT(current); | |
739 size_t bytesFromCurrent = | |
740 SkTMin(current->written() - currentOffset, size); | |
741 memcpy(buffer, current->start() + currentOffset, bytesFromCurrent); | |
742 size -= bytesFromCurrent; | |
743 buffer += bytesFromCurrent; | |
744 current = current->fNext; | |
745 currentOffset = 0; | |
746 } | |
747 return true; | |
748 } | |
749 | |
727 bool rewind() override { | 750 bool rewind() override { |
728 fCurrent = fBlockMemory->fHead; | 751 fCurrent = fBlockMemory->fHead; |
729 fOffset = 0; | 752 fOffset = 0; |
730 fCurrentOffset = 0; | 753 fCurrentOffset = 0; |
731 return true; | 754 return true; |
732 } | 755 } |
733 | 756 |
734 SkBlockMemoryStream* duplicate() const override { | 757 SkBlockMemoryStream* duplicate() const override { |
735 return SkNEW_ARGS(SkBlockMemoryStream, (fBlockMemory.get(), fSize)); | 758 return SkNEW_ARGS(SkBlockMemoryStream, (fBlockMemory.get(), fSize)); |
736 } | 759 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 SkDynamicMemoryWStream tempStream; | 945 SkDynamicMemoryWStream tempStream; |
923 const size_t bufferSize = 4096; | 946 const size_t bufferSize = 4096; |
924 char buffer[bufferSize]; | 947 char buffer[bufferSize]; |
925 do { | 948 do { |
926 size_t bytesRead = stream->read(buffer, bufferSize); | 949 size_t bytesRead = stream->read(buffer, bufferSize); |
927 tempStream.write(buffer, bytesRead); | 950 tempStream.write(buffer, bytesRead); |
928 } while (!stream->isAtEnd()); | 951 } while (!stream->isAtEnd()); |
929 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, | 952 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
930 // cheaper than copying to SkData | 953 // cheaper than copying to SkData |
931 } | 954 } |
OLD | NEW |