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 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 SkDynamicMemoryWStream tempStream; | 943 SkDynamicMemoryWStream tempStream; |
944 const size_t bufferSize = 4096; | 944 const size_t bufferSize = 4096; |
945 char buffer[bufferSize]; | 945 char buffer[bufferSize]; |
946 do { | 946 do { |
947 size_t bytesRead = stream->read(buffer, bufferSize); | 947 size_t bytesRead = stream->read(buffer, bufferSize); |
948 tempStream.write(buffer, bytesRead); | 948 tempStream.write(buffer, bytesRead); |
949 } while (!stream->isAtEnd()); | 949 } while (!stream->isAtEnd()); |
950 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, | 950 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
951 // cheaper than copying to SkData | 951 // cheaper than copying to SkData |
952 } | 952 } |
953 | |
954 bool SkStreamCopy(SkWStream* out, SkStream* input) { | |
955 const char* base = static_cast<const char*>(input->getMemoryBase()); | |
956 if (base && input->hasPosition() && input->hasLength()) { | |
957 // Shortcut that avoids the do-while loop. | |
958 size_t position = input->getPosition(); | |
959 size_t length = input->getLength(); | |
960 SkASSERT(length >= position); | |
961 return out->write(&base[position], length - position); | |
962 } | |
963 char scratch[4096]; | |
mtklein_C
2015/08/18 19:33:09
Let's make sure this path is tested too.
hal.canary
2015/08/18 20:06:23
Done.
| |
964 size_t count; | |
965 while (true) { | |
966 count = input->read(scratch, sizeof(scratch)); | |
967 if (0 == count) { | |
968 return true; | |
969 } | |
970 if (!out->write(scratch, count)) { | |
971 return false; | |
972 } | |
973 } | |
974 } | |
OLD | NEW |