| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkFrontBufferedStream.h" | 10 #include "SkFrontBufferedStream.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 336 } |
| 337 stream_peek_test(rep, asset, expected); | 337 stream_peek_test(rep, asset, expected); |
| 338 } | 338 } |
| 339 | 339 |
| 340 namespace { | 340 namespace { |
| 341 class DumbStream : public SkStream { | 341 class DumbStream : public SkStream { |
| 342 public: | 342 public: |
| 343 DumbStream(const uint8_t* data, size_t n) | 343 DumbStream(const uint8_t* data, size_t n) |
| 344 : fData(data), fCount(n), fIdx(0) {} | 344 : fData(data), fCount(n), fIdx(0) {} |
| 345 size_t read(void* buffer, size_t size) override { | 345 size_t read(void* buffer, size_t size) override { |
| 346 size_t c = SkTMin(fCount - fIdx, size); | 346 size_t copyCount = SkTMin(fCount - fIdx, size); |
| 347 if (c) { | 347 if (copyCount) { |
| 348 memcpy(buffer, &fData[fIdx], size); | 348 memcpy(buffer, &fData[fIdx], copyCount); |
| 349 fIdx += c; | 349 fIdx += copyCount; |
| 350 } | 350 } |
| 351 return c; | 351 return copyCount; |
| 352 } | 352 } |
| 353 bool isAtEnd() const override { | 353 bool isAtEnd() const override { |
| 354 return fCount > fIdx; | 354 return fCount == fIdx; |
| 355 } | 355 } |
| 356 private: | 356 private: |
| 357 const uint8_t* fData; | 357 const uint8_t* fData; |
| 358 size_t fCount, fIdx; | 358 size_t fCount, fIdx; |
| 359 }; | 359 }; |
| 360 } // namespace | 360 } // namespace |
| 361 | 361 |
| 362 static void stream_copy_test(skiatest::Reporter* reporter, | 362 static void stream_copy_test(skiatest::Reporter* reporter, |
| 363 const void* srcData, | 363 const void* srcData, |
| 364 size_t N, | 364 size_t N, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 386 for (int j = 0; j < N; ++j) { | 386 for (int j = 0; j < N; ++j) { |
| 387 src[j] = random.nextU() & 0xff; | 387 src[j] = random.nextU() & 0xff; |
| 388 } | 388 } |
| 389 // SkStreamCopy had two code paths; this test both. | 389 // SkStreamCopy had two code paths; this test both. |
| 390 DumbStream dumbStream(src.get(), (size_t)N); | 390 DumbStream dumbStream(src.get(), (size_t)N); |
| 391 stream_copy_test(reporter, src, N, &dumbStream); | 391 stream_copy_test(reporter, src, N, &dumbStream); |
| 392 SkMemoryStream smartStream(src.get(), (size_t)N); | 392 SkMemoryStream smartStream(src.get(), (size_t)N); |
| 393 stream_copy_test(reporter, src, N, &smartStream); | 393 stream_copy_test(reporter, src, N, &smartStream); |
| 394 | 394 |
| 395 } | 395 } |
| OLD | NEW |