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

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

Issue 340783013: Switch SkPDFStream's internal storage from SkStream to SkData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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 | « gyp/images.gyp ('k') | 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"
11 #include "SkStreamPriv.h"
11 #include "SkData.h" 12 #include "SkData.h"
12 #include "SkFixed.h" 13 #include "SkFixed.h"
13 #include "SkString.h" 14 #include "SkString.h"
14 #include "SkOSFile.h" 15 #include "SkOSFile.h"
16 #include "SkTypes.h"
15 17
16 /////////////////////////////////////////////////////////////////////////////// 18 ///////////////////////////////////////////////////////////////////////////////
17 19
18 20
19 int8_t SkStream::readS8() { 21 int8_t SkStream::readS8() {
20 int8_t value; 22 int8_t value;
21 SkDEBUGCODE(size_t len =) this->read(&value, 1); 23 SkDEBUGCODE(size_t len =) this->read(&value, 1);
22 SkASSERT(1 == len); 24 SkASSERT(1 == len);
23 return value; 25 return value;
24 } 26 }
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 846
845 // If we get here, then our attempt at using mmap failed, so try normal 847 // If we get here, then our attempt at using mmap failed, so try normal
846 // file access. 848 // file access.
847 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); 849 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
848 if (!stream->isValid()) { 850 if (!stream->isValid()) {
849 stream->unref(); 851 stream->unref();
850 stream = NULL; 852 stream = NULL;
851 } 853 }
852 return stream; 854 return stream;
853 } 855 }
856
857 // Declared in SkStreamPriv.h:
858 size_t SkCopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
859 SkASSERT(storage != NULL);
860 SkASSERT(stream != NULL);
861
862 if (stream->hasLength()) {
863 const size_t length = stream->getLength();
864 void* dst = storage->reset(length);
865 if (stream->read(dst, length) != length) {
866 return 0;
867 }
868 return length;
869 }
870
871 SkDynamicMemoryWStream tempStream;
872 // Arbitrary buffer size.
873 const size_t bufferSize = 256 * 1024; // 256KB
874 char buffer[bufferSize];
875 SkDEBUGCODE(size_t debugLength = 0;)
876 do {
877 size_t bytesRead = stream->read(buffer, bufferSize);
878 tempStream.write(buffer, bytesRead);
879 SkDEBUGCODE(debugLength += bytesRead);
880 SkASSERT(tempStream.bytesWritten() == debugLength);
881 } while (!stream->isAtEnd());
882 const size_t length = tempStream.bytesWritten();
883 void* dst = storage->reset(length);
884 tempStream.copyTo(dst);
885 return length;
886 }
887
888 // Declared in SkStreamPriv.h:
889 SkData* SkCopyStreamToData(SkStream* stream) {
890 SkASSERT(stream != NULL);
891
892 if (stream->hasLength()) {
893 const size_t length = stream->getLength();
894 SkAutoMalloc dst(length);
895 if (stream->read(dst.get(), length) != length) {
896 return NULL;
897 }
898 return SkData::NewFromMalloc(dst.detach(), length);
899 }
900
901 SkDynamicMemoryWStream tempStream;
902 const size_t bufferSize = 4096;
903 char buffer[bufferSize];
904 do {
905 size_t bytesRead = stream->read(buffer, bufferSize);
906 tempStream.write(buffer, bytesRead);
907 } while (!stream->isAtEnd());
908 return tempStream.copyToData();
909 }
OLDNEW
« no previous file with comments | « gyp/images.gyp ('k') | src/core/SkStreamPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698