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 #ifdef SK_DEBUG | |
bungeman-skia
2015/04/02 18:24:09
Should this be SkDEBUGCODE(...) instead? Then it w
scroggo
2015/04/02 19:49:43
Yes. Much better.
| |
379 const size_t bytesRead = | |
380 #endif | |
381 nonConstThis->read(buffer, size); | |
382 SkASSERT(bytesRead == size); | |
383 nonConstThis->fOffset = position; | |
384 return true; | |
385 } | |
386 | |
370 bool SkMemoryStream::isAtEnd() const { | 387 bool SkMemoryStream::isAtEnd() const { |
371 return fOffset == fData->size(); | 388 return fOffset == fData->size(); |
372 } | 389 } |
373 | 390 |
374 bool SkMemoryStream::rewind() { | 391 bool SkMemoryStream::rewind() { |
375 fOffset = 0; | 392 fOffset = 0; |
376 return true; | 393 return true; |
377 } | 394 } |
378 | 395 |
379 SkMemoryStream* SkMemoryStream::duplicate() const { | 396 SkMemoryStream* SkMemoryStream::duplicate() const { |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 SkDynamicMemoryWStream tempStream; | 925 SkDynamicMemoryWStream tempStream; |
909 const size_t bufferSize = 4096; | 926 const size_t bufferSize = 4096; |
910 char buffer[bufferSize]; | 927 char buffer[bufferSize]; |
911 do { | 928 do { |
912 size_t bytesRead = stream->read(buffer, bufferSize); | 929 size_t bytesRead = stream->read(buffer, bufferSize); |
913 tempStream.write(buffer, bytesRead); | 930 tempStream.write(buffer, bytesRead); |
914 } while (!stream->isAtEnd()); | 931 } while (!stream->isAtEnd()); |
915 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, | 932 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
916 // cheaper than copying to SkData | 933 // cheaper than copying to SkData |
917 } | 934 } |
OLD | NEW |