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

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

Issue 387863005: Move SkPDFStream back to SkStream to save memory. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make compiler happy Created 6 years, 5 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 | « no previous file | src/core/SkStreamPriv.h » ('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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 900
901 SkDynamicMemoryWStream tempStream; 901 SkDynamicMemoryWStream tempStream;
902 const size_t bufferSize = 4096; 902 const size_t bufferSize = 4096;
903 char buffer[bufferSize]; 903 char buffer[bufferSize];
904 do { 904 do {
905 size_t bytesRead = stream->read(buffer, bufferSize); 905 size_t bytesRead = stream->read(buffer, bufferSize);
906 tempStream.write(buffer, bytesRead); 906 tempStream.write(buffer, bytesRead);
907 } while (!stream->isAtEnd()); 907 } while (!stream->isAtEnd());
908 return tempStream.copyToData(); 908 return tempStream.copyToData();
909 } 909 }
910
911 SkStreamRewindable* SkStreamRewindableFromSkStream(SkStream* stream) {
912 if (!stream) {
913 return NULL;
914 }
915 SkAutoTUnref<SkStreamRewindable> dupStream(stream->duplicate());
916 if (dupStream) {
917 return dupStream.detach();
918 }
919 stream->rewind();
920 if (stream->hasLength()) {
921 size_t length = stream->getLength();
922 if (stream->hasPosition()) { // If stream has length, but can't rewind.
923 length -= stream->getPosition();
924 }
925 SkAutoMalloc allocMemory(length);
926 SkDEBUGCODE(size_t read =) stream->read(allocMemory.get(), length);
927 SkASSERT(length == read);
928 SkAutoTUnref<SkData> data(
929 SkData::NewFromMalloc(allocMemory.detach(), length));
930 return SkNEW_ARGS(SkMemoryStream, (data.get()));
931 }
932 SkDynamicMemoryWStream tempStream;
933 const size_t bufferSize = 4096;
934 char buffer[bufferSize];
935 do {
936 size_t bytesRead = stream->read(buffer, bufferSize);
937 tempStream.write(buffer, bytesRead);
938 } while (!stream->isAtEnd());
939 return tempStream.detachAsStream(); // returns a SkBlockMemoryStream,
940 // cheaper than copying to SkData
941 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkStreamPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698