OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 #include "SkStreamPriv.h" | 10 #include "SkStreamPriv.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkFixed.h" | 12 #include "SkFixed.h" |
| 13 #include "SkMakeUnique.h" |
13 #include "SkString.h" | 14 #include "SkString.h" |
14 #include "SkOSFile.h" | 15 #include "SkOSFile.h" |
15 #include "SkTypes.h" | 16 #include "SkTypes.h" |
16 | 17 |
17 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
18 | 19 |
19 | 20 |
20 int8_t SkStream::readS8() { | 21 int8_t SkStream::readS8() { |
21 int8_t value; | 22 int8_t value; |
22 SkDEBUGCODE(size_t len =) this->read(&value, 1); | 23 SkDEBUGCODE(size_t len =) this->read(&value, 1); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 FILE* file = sk_fopen(path, kRead_SkFILE_Flag); | 848 FILE* file = sk_fopen(path, kRead_SkFILE_Flag); |
848 if (nullptr == file) { | 849 if (nullptr == file) { |
849 return nullptr; | 850 return nullptr; |
850 } | 851 } |
851 | 852 |
852 auto data = SkData::MakeFromFILE(file); | 853 auto data = SkData::MakeFromFILE(file); |
853 sk_fclose(file); | 854 sk_fclose(file); |
854 return data; | 855 return data; |
855 } | 856 } |
856 | 857 |
857 SkStreamAsset* SkStream::NewFromFile(const char path[]) { | 858 std::unique_ptr<SkStreamAsset> SkStream::MakeFromFile(const char path[]) { |
858 auto data(mmap_filename(path)); | 859 auto data(mmap_filename(path)); |
859 if (data) { | 860 if (data) { |
860 return new SkMemoryStream(std::move(data)); | 861 return skstd::make_unique<SkMemoryStream>(std::move(data)); |
861 } | 862 } |
862 | 863 |
863 // If we get here, then our attempt at using mmap failed, so try normal | 864 // If we get here, then our attempt at using mmap failed, so try normal file
access. |
864 // file access. | 865 auto stream = skstd::make_unique<SkFILEStream>(path); |
865 SkFILEStream* stream = new SkFILEStream(path); | |
866 if (!stream->isValid()) { | 866 if (!stream->isValid()) { |
867 delete stream; | 867 return nullptr; |
868 stream = nullptr; | |
869 } | 868 } |
870 return stream; | 869 return std::move(stream); |
871 } | 870 } |
872 | 871 |
873 // Declared in SkStreamPriv.h: | 872 // Declared in SkStreamPriv.h: |
874 sk_sp<SkData> SkCopyStreamToData(SkStream* stream) { | 873 sk_sp<SkData> SkCopyStreamToData(SkStream* stream) { |
875 SkASSERT(stream != nullptr); | 874 SkASSERT(stream != nullptr); |
876 | 875 |
877 if (stream->hasLength()) { | 876 if (stream->hasLength()) { |
878 return SkData::MakeFromStream(stream, stream->getLength()); | 877 return SkData::MakeFromStream(stream, stream->getLength()); |
879 } | 878 } |
880 | 879 |
(...skipping 21 matching lines...) Expand all Loading... |
902 while (true) { | 901 while (true) { |
903 count = input->read(scratch, sizeof(scratch)); | 902 count = input->read(scratch, sizeof(scratch)); |
904 if (0 == count) { | 903 if (0 == count) { |
905 return true; | 904 return true; |
906 } | 905 } |
907 if (!out->write(scratch, count)) { | 906 if (!out->write(scratch, count)) { |
908 return false; | 907 return false; |
909 } | 908 } |
910 } | 909 } |
911 } | 910 } |
OLD | NEW |