| 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 , fSize(size) , fOffset(0), fCurrentOffset(0) { } | 687 , fSize(size) , fOffset(0), fCurrentOffset(0) { } |
| 688 | 688 |
| 689 virtual size_t read(void* buffer, size_t rawCount) SK_OVERRIDE { | 689 virtual size_t read(void* buffer, size_t rawCount) SK_OVERRIDE { |
| 690 size_t count = rawCount; | 690 size_t count = rawCount; |
| 691 if (fOffset + count > fSize) { | 691 if (fOffset + count > fSize) { |
| 692 count = fSize - fOffset; | 692 count = fSize - fOffset; |
| 693 } | 693 } |
| 694 size_t bytesLeftToRead = count; | 694 size_t bytesLeftToRead = count; |
| 695 while (fCurrent != NULL) { | 695 while (fCurrent != NULL) { |
| 696 size_t bytesLeftInCurrent = fCurrent->written() - fCurrentOffset; | 696 size_t bytesLeftInCurrent = fCurrent->written() - fCurrentOffset; |
| 697 size_t bytesFromCurrent = bytesLeftToRead <= bytesLeftInCurrent | 697 size_t bytesFromCurrent = SkTMin(bytesLeftToRead, bytesLeftInCurrent
); |
| 698 ? bytesLeftToRead : bytesLeftInCurrent; | |
| 699 if (buffer) { | 698 if (buffer) { |
| 700 memcpy(buffer, fCurrent->start() + fCurrentOffset, bytesFromCurr
ent); | 699 memcpy(buffer, fCurrent->start() + fCurrentOffset, bytesFromCurr
ent); |
| 700 buffer = SkTAddOffset<void>(buffer, bytesFromCurrent); |
| 701 } | 701 } |
| 702 if (bytesLeftToRead <= bytesFromCurrent) { | 702 if (bytesLeftToRead <= bytesFromCurrent) { |
| 703 fCurrentOffset += bytesFromCurrent; | 703 fCurrentOffset += bytesFromCurrent; |
| 704 fOffset += count; | 704 fOffset += count; |
| 705 return count; | 705 return count; |
| 706 } | 706 } |
| 707 bytesLeftToRead -= bytesFromCurrent; | 707 bytesLeftToRead -= bytesFromCurrent; |
| 708 buffer = SkTAddOffset<void>(buffer, bytesFromCurrent); | |
| 709 fCurrent = fCurrent->fNext; | 708 fCurrent = fCurrent->fNext; |
| 710 fCurrentOffset = 0; | 709 fCurrentOffset = 0; |
| 711 } | 710 } |
| 712 SkASSERT(false); | 711 SkASSERT(false); |
| 713 return 0; | 712 return 0; |
| 714 } | 713 } |
| 715 | 714 |
| 716 virtual bool isAtEnd() const SK_OVERRIDE { | 715 virtual bool isAtEnd() const SK_OVERRIDE { |
| 717 return fOffset == fSize; | 716 return fOffset == fSize; |
| 718 } | 717 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 | 835 |
| 837 // If we get here, then our attempt at using mmap failed, so try normal | 836 // If we get here, then our attempt at using mmap failed, so try normal |
| 838 // file access. | 837 // file access. |
| 839 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); | 838 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); |
| 840 if (!stream->isValid()) { | 839 if (!stream->isValid()) { |
| 841 stream->unref(); | 840 stream->unref(); |
| 842 stream = NULL; | 841 stream = NULL; |
| 843 } | 842 } |
| 844 return stream; | 843 return stream; |
| 845 } | 844 } |
| OLD | NEW |