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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 SkStreamAsset* SkFILEStream::duplicate() const { | 232 SkStreamAsset* SkFILEStream::duplicate() const { |
233 if (NULL == fFILE) { | 233 if (NULL == fFILE) { |
234 return new SkMemoryStream(); | 234 return new SkMemoryStream(); |
235 } | 235 } |
236 | 236 |
237 if (fData.get()) { | 237 if (fData.get()) { |
238 return new SkMemoryStream(fData); | 238 return new SkMemoryStream(fData); |
239 } | 239 } |
240 | 240 |
241 if (!fName.isEmpty()) { | 241 if (!fName.isEmpty()) { |
242 SkAutoTUnref<SkFILEStream> that(new SkFILEStream(fName.c_str())); | 242 SkAutoTDelete<SkFILEStream> that(new SkFILEStream(fName.c_str())); |
243 if (sk_fidentical(that->fFILE, this->fFILE)) { | 243 if (sk_fidentical(that->fFILE, this->fFILE)) { |
244 return that.detach(); | 244 return that.detach(); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 fData.reset(SkData::NewFromFILE(fFILE)); | 248 fData.reset(SkData::NewFromFILE(fFILE)); |
249 if (NULL == fData.get()) { | 249 if (NULL == fData.get()) { |
250 return NULL; | 250 return NULL; |
251 } | 251 } |
252 return new SkMemoryStream(fData); | 252 return new SkMemoryStream(fData); |
253 } | 253 } |
254 | 254 |
255 size_t SkFILEStream::getPosition() const { | 255 size_t SkFILEStream::getPosition() const { |
256 return sk_ftell(fFILE); | 256 return sk_ftell(fFILE); |
257 } | 257 } |
258 | 258 |
259 bool SkFILEStream::seek(size_t position) { | 259 bool SkFILEStream::seek(size_t position) { |
260 return sk_fseek(fFILE, position); | 260 return sk_fseek(fFILE, position); |
261 } | 261 } |
262 | 262 |
263 bool SkFILEStream::move(long offset) { | 263 bool SkFILEStream::move(long offset) { |
264 return sk_fmove(fFILE, offset); | 264 return sk_fmove(fFILE, offset); |
265 } | 265 } |
266 | 266 |
267 SkStreamAsset* SkFILEStream::fork() const { | 267 SkStreamAsset* SkFILEStream::fork() const { |
268 SkAutoTUnref<SkStreamAsset> that(this->duplicate()); | 268 SkAutoTDelete<SkStreamAsset> that(this->duplicate()); |
269 that->seek(this->getPosition()); | 269 that->seek(this->getPosition()); |
270 return that.detach(); | 270 return that.detach(); |
271 } | 271 } |
272 | 272 |
273 size_t SkFILEStream::getLength() const { | 273 size_t SkFILEStream::getLength() const { |
274 return sk_fgetsize(fFILE); | 274 return sk_fgetsize(fFILE); |
275 } | 275 } |
276 | 276 |
277 const void* SkFILEStream::getMemoryBase() { | 277 const void* SkFILEStream::getMemoryBase() { |
278 if (NULL == fData.get()) { | 278 if (NULL == fData.get()) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 ? fData->size() | 389 ? fData->size() |
390 : position; | 390 : position; |
391 return true; | 391 return true; |
392 } | 392 } |
393 | 393 |
394 bool SkMemoryStream::move(long offset) { | 394 bool SkMemoryStream::move(long offset) { |
395 return this->seek(fOffset + offset); | 395 return this->seek(fOffset + offset); |
396 } | 396 } |
397 | 397 |
398 SkMemoryStream* SkMemoryStream::fork() const { | 398 SkMemoryStream* SkMemoryStream::fork() const { |
399 SkAutoTUnref<SkMemoryStream> that(this->duplicate()); | 399 SkAutoTDelete<SkMemoryStream> that(this->duplicate()); |
400 that->seek(fOffset); | 400 that->seek(fOffset); |
401 return that.detach(); | 401 return that.detach(); |
402 } | 402 } |
403 | 403 |
404 size_t SkMemoryStream::getLength() const { | 404 size_t SkMemoryStream::getLength() const { |
405 return fData->size(); | 405 return fData->size(); |
406 } | 406 } |
407 | 407 |
408 const void* SkMemoryStream::getMemoryBase() { | 408 const void* SkMemoryStream::getMemoryBase() { |
409 return fData->data(); | 409 return fData->data(); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 } | 734 } |
735 // Otherwise rewind and move forward. | 735 // Otherwise rewind and move forward. |
736 return this->rewind() && this->skip(position) == position; | 736 return this->rewind() && this->skip(position) == position; |
737 } | 737 } |
738 | 738 |
739 bool move(long offset) SK_OVERRIDE { | 739 bool move(long offset) SK_OVERRIDE { |
740 return seek(fOffset + offset); | 740 return seek(fOffset + offset); |
741 } | 741 } |
742 | 742 |
743 SkBlockMemoryStream* fork() const SK_OVERRIDE { | 743 SkBlockMemoryStream* fork() const SK_OVERRIDE { |
744 SkAutoTUnref<SkBlockMemoryStream> that(this->duplicate()); | 744 SkAutoTDelete<SkBlockMemoryStream> that(this->duplicate()); |
745 that->fCurrent = this->fCurrent; | 745 that->fCurrent = this->fCurrent; |
746 that->fOffset = this->fOffset; | 746 that->fOffset = this->fOffset; |
747 that->fCurrentOffset = this->fCurrentOffset; | 747 that->fCurrentOffset = this->fCurrentOffset; |
748 return that.detach(); | 748 return that.detach(); |
749 } | 749 } |
750 | 750 |
751 size_t getLength() const SK_OVERRIDE { | 751 size_t getLength() const SK_OVERRIDE { |
752 return fSize; | 752 return fSize; |
753 } | 753 } |
754 | 754 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 SkStreamAsset* SkStream::NewFromFile(const char path[]) { | 820 SkStreamAsset* SkStream::NewFromFile(const char path[]) { |
821 SkAutoTUnref<SkData> data(mmap_filename(path)); | 821 SkAutoTUnref<SkData> data(mmap_filename(path)); |
822 if (data.get()) { | 822 if (data.get()) { |
823 return SkNEW_ARGS(SkMemoryStream, (data.get())); | 823 return SkNEW_ARGS(SkMemoryStream, (data.get())); |
824 } | 824 } |
825 | 825 |
826 // If we get here, then our attempt at using mmap failed, so try normal | 826 // If we get here, then our attempt at using mmap failed, so try normal |
827 // file access. | 827 // file access. |
828 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); | 828 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); |
829 if (!stream->isValid()) { | 829 if (!stream->isValid()) { |
830 stream->unref(); | 830 SkDELETE(stream); |
831 stream = NULL; | 831 stream = NULL; |
832 } | 832 } |
833 return stream; | 833 return stream; |
834 } | 834 } |
835 | 835 |
836 // Declared in SkStreamPriv.h: | 836 // Declared in SkStreamPriv.h: |
837 size_t SkCopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) { | 837 size_t SkCopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) { |
838 SkASSERT(storage != NULL); | 838 SkASSERT(storage != NULL); |
839 SkASSERT(stream != NULL); | 839 SkASSERT(stream != NULL); |
840 | 840 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 size_t bytesRead = stream->read(buffer, bufferSize); | 879 size_t bytesRead = stream->read(buffer, bufferSize); |
880 tempStream.write(buffer, bytesRead); | 880 tempStream.write(buffer, bytesRead); |
881 } while (!stream->isAtEnd()); | 881 } while (!stream->isAtEnd()); |
882 return tempStream.copyToData(); | 882 return tempStream.copyToData(); |
883 } | 883 } |
884 | 884 |
885 SkStreamRewindable* SkStreamRewindableFromSkStream(SkStream* stream) { | 885 SkStreamRewindable* SkStreamRewindableFromSkStream(SkStream* stream) { |
886 if (!stream) { | 886 if (!stream) { |
887 return NULL; | 887 return NULL; |
888 } | 888 } |
889 SkAutoTUnref<SkStreamRewindable> dupStream(stream->duplicate()); | 889 SkAutoTDelete<SkStreamRewindable> dupStream(stream->duplicate()); |
890 if (dupStream) { | 890 if (dupStream) { |
891 return dupStream.detach(); | 891 return dupStream.detach(); |
892 } | 892 } |
893 stream->rewind(); | 893 stream->rewind(); |
894 if (stream->hasLength()) { | 894 if (stream->hasLength()) { |
895 size_t length = stream->getLength(); | 895 size_t length = stream->getLength(); |
896 if (stream->hasPosition()) { // If stream has length, but can't rewind. | 896 if (stream->hasPosition()) { // If stream has length, but can't rewind. |
897 length -= stream->getPosition(); | 897 length -= stream->getPosition(); |
898 } | 898 } |
899 SkAutoTUnref<SkData> data(SkData::NewFromStream(stream, length)); | 899 SkAutoTUnref<SkData> data(SkData::NewFromStream(stream, length)); |
900 return SkNEW_ARGS(SkMemoryStream, (data.get())); | 900 return SkNEW_ARGS(SkMemoryStream, (data.get())); |
901 } | 901 } |
902 SkDynamicMemoryWStream tempStream; | 902 SkDynamicMemoryWStream tempStream; |
903 const size_t bufferSize = 4096; | 903 const size_t bufferSize = 4096; |
904 char buffer[bufferSize]; | 904 char buffer[bufferSize]; |
905 do { | 905 do { |
906 size_t bytesRead = stream->read(buffer, bufferSize); | 906 size_t bytesRead = stream->read(buffer, bufferSize); |
907 tempStream.write(buffer, bytesRead); | 907 tempStream.write(buffer, bytesRead); |
908 } while (!stream->isAtEnd()); | 908 } while (!stream->isAtEnd()); |
909 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, | 909 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
910 // cheaper than copying to SkData | 910 // cheaper than copying to SkData |
911 } | 911 } |
OLD | NEW |