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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 if (stream->hasLength()) { | 881 if (stream->hasLength()) { |
882 const size_t length = stream->getLength(); | 882 const size_t length = stream->getLength(); |
883 void* dst = storage->reset(length); | 883 void* dst = storage->reset(length); |
884 if (stream->read(dst, length) != length) { | 884 if (stream->read(dst, length) != length) { |
885 return 0; | 885 return 0; |
886 } | 886 } |
887 return length; | 887 return length; |
888 } | 888 } |
889 | 889 |
890 SkDynamicMemoryWStream tempStream; | 890 SkDynamicMemoryWStream tempStream; |
891 // Arbitrary buffer size. | 891 if (!SkStreamCopy(&tempStream, stream)) { |
892 #if defined(GOOGLE3) | 892 return 0; |
893 // Stack frame size is limited in GOOGLE3. | 893 } |
894 const size_t bufferSize = 8 * 1024; // 8KB | |
895 #else | |
896 const size_t bufferSize = 256 * 1024; // 256KB | |
897 #endif | |
898 char buffer[bufferSize]; | |
899 SkDEBUGCODE(size_t debugLength = 0;) | |
900 do { | |
901 size_t bytesRead = stream->read(buffer, bufferSize); | |
902 tempStream.write(buffer, bytesRead); | |
903 SkDEBUGCODE(debugLength += bytesRead); | |
904 SkASSERT(tempStream.bytesWritten() == debugLength); | |
905 } while (!stream->isAtEnd()); | |
906 const size_t length = tempStream.bytesWritten(); | 894 const size_t length = tempStream.bytesWritten(); |
907 void* dst = storage->reset(length); | 895 void* dst = storage->reset(length); |
908 tempStream.copyTo(dst); | 896 tempStream.copyTo(dst); |
909 return length; | 897 return length; |
910 } | 898 } |
911 | 899 |
912 // Declared in SkStreamPriv.h: | 900 // Declared in SkStreamPriv.h: |
913 SkData* SkCopyStreamToData(SkStream* stream) { | 901 SkData* SkCopyStreamToData(SkStream* stream) { |
914 SkASSERT(stream != nullptr); | 902 SkASSERT(stream != nullptr); |
915 | 903 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 while (true) { | 957 while (true) { |
970 count = input->read(scratch, sizeof(scratch)); | 958 count = input->read(scratch, sizeof(scratch)); |
971 if (0 == count) { | 959 if (0 == count) { |
972 return true; | 960 return true; |
973 } | 961 } |
974 if (!out->write(scratch, count)) { | 962 if (!out->write(scratch, count)) { |
975 return false; | 963 return false; |
976 } | 964 } |
977 } | 965 } |
978 } | 966 } |
| 967 |
| 968 bool SkStreamCopyToDynamicMemoryW(SkDynamicMemoryWStream* out, SkStream* input)
{ |
| 969 // Arbitrary buffer size. |
| 970 #if defined(GOOGLE3) |
| 971 // Stack frame size is limited in GOOGLE3. |
| 972 const size_t bufferSize = 8 * 1024; // 8KB |
| 973 #else |
| 974 const size_t bufferSize = 256 * 1024; // 256KB |
| 975 #endif |
| 976 char buffer[bufferSize]; |
| 977 SkDEBUGCODE(size_t debugLength = 0;) |
| 978 do { |
| 979 size_t bytesRead = input->read(buffer, bufferSize); |
| 980 if (!out->write(buffer, bytesRead)) { |
| 981 return false; |
| 982 } |
| 983 SkDEBUGCODE(debugLength += bytesRead); |
| 984 SkASSERT(out->bytesWritten() == debugLength); |
| 985 } while (!input->isAtEnd()); |
| 986 return true; |
| 987 } |
OLD | NEW |