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