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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 if (size > dataSize - fOffset) { | 360 if (size > dataSize - fOffset) { |
361 size = dataSize - fOffset; | 361 size = dataSize - fOffset; |
362 } | 362 } |
363 if (buffer) { | 363 if (buffer) { |
364 memcpy(buffer, fData->bytes() + fOffset, size); | 364 memcpy(buffer, fData->bytes() + fOffset, size); |
365 } | 365 } |
366 fOffset += size; | 366 fOffset += size; |
367 return size; | 367 return size; |
368 } | 368 } |
369 | 369 |
| 370 bool SkMemoryStream::peek(void* buffer, size_t size) const { |
| 371 SkASSERT(buffer != NULL); |
| 372 const size_t position = fOffset; |
| 373 if (size > fData->size() - position) { |
| 374 // The stream is not large enough to satisfy this request. |
| 375 return false; |
| 376 } |
| 377 SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this); |
| 378 SkDEBUGCODE(const size_t bytesRead =) nonConstThis->read(buffer, size); |
| 379 SkASSERT(bytesRead == size); |
| 380 nonConstThis->fOffset = position; |
| 381 return true; |
| 382 } |
| 383 |
370 bool SkMemoryStream::isAtEnd() const { | 384 bool SkMemoryStream::isAtEnd() const { |
371 return fOffset == fData->size(); | 385 return fOffset == fData->size(); |
372 } | 386 } |
373 | 387 |
374 bool SkMemoryStream::rewind() { | 388 bool SkMemoryStream::rewind() { |
375 fOffset = 0; | 389 fOffset = 0; |
376 return true; | 390 return true; |
377 } | 391 } |
378 | 392 |
379 SkMemoryStream* SkMemoryStream::duplicate() const { | 393 SkMemoryStream* SkMemoryStream::duplicate() const { |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 SkDynamicMemoryWStream tempStream; | 922 SkDynamicMemoryWStream tempStream; |
909 const size_t bufferSize = 4096; | 923 const size_t bufferSize = 4096; |
910 char buffer[bufferSize]; | 924 char buffer[bufferSize]; |
911 do { | 925 do { |
912 size_t bytesRead = stream->read(buffer, bufferSize); | 926 size_t bytesRead = stream->read(buffer, bufferSize); |
913 tempStream.write(buffer, bytesRead); | 927 tempStream.write(buffer, bytesRead); |
914 } while (!stream->isAtEnd()); | 928 } while (!stream->isAtEnd()); |
915 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, | 929 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
916 // cheaper than copying to SkData | 930 // cheaper than copying to SkData |
917 } | 931 } |
OLD | NEW |