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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 | 900 |
901 SkDynamicMemoryWStream tempStream; | 901 SkDynamicMemoryWStream tempStream; |
902 const size_t bufferSize = 4096; | 902 const size_t bufferSize = 4096; |
903 char buffer[bufferSize]; | 903 char buffer[bufferSize]; |
904 do { | 904 do { |
905 size_t bytesRead = stream->read(buffer, bufferSize); | 905 size_t bytesRead = stream->read(buffer, bufferSize); |
906 tempStream.write(buffer, bytesRead); | 906 tempStream.write(buffer, bytesRead); |
907 } while (!stream->isAtEnd()); | 907 } while (!stream->isAtEnd()); |
908 return tempStream.copyToData(); | 908 return tempStream.copyToData(); |
909 } | 909 } |
| 910 |
| 911 SkStreamRewindable* SkStreamRewindableFromSkStream(SkStream* stream) { |
| 912 if (!stream) { |
| 913 return NULL; |
| 914 } |
| 915 SkAutoTUnref<SkStreamRewindable> dupStream(stream->duplicate()); |
| 916 if (dupStream) { |
| 917 return dupStream.detach(); |
| 918 } |
| 919 stream->rewind(); |
| 920 if (stream->hasLength()) { |
| 921 size_t length = stream->getLength(); |
| 922 if (stream->hasPosition()) { // If stream has length, but can't rewind. |
| 923 length -= stream->getPosition(); |
| 924 } |
| 925 SkAutoMalloc allocMemory(length); |
| 926 SkDEBUGCODE(size_t read =) stream->read(allocMemory.get(), length); |
| 927 SkASSERT(length == read); |
| 928 SkAutoTUnref<SkData> data( |
| 929 SkData::NewFromMalloc(allocMemory.detach(), length)); |
| 930 return SkNEW_ARGS(SkMemoryStream, (data.get())); |
| 931 } |
| 932 SkDynamicMemoryWStream tempStream; |
| 933 const size_t bufferSize = 4096; |
| 934 char buffer[bufferSize]; |
| 935 do { |
| 936 size_t bytesRead = stream->read(buffer, bufferSize); |
| 937 tempStream.write(buffer, bytesRead); |
| 938 } while (!stream->isAtEnd()); |
| 939 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
| 940 // cheaper than copying to SkData |
| 941 } |
OLD | NEW |