Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: src/core/SkStream.cpp

Issue 1044953002: Add a method to read a stream without advancing it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Stop declaring parameters I do not use. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkStream.h ('k') | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « include/core/SkStream.h ('k') | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698