Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 if (sk_frewind(fFILE)) { | 232 if (sk_frewind(fFILE)) { |
| 233 return true; | 233 return true; |
| 234 } | 234 } |
| 235 // we hit an error | 235 // we hit an error |
| 236 sk_fclose(fFILE); | 236 sk_fclose(fFILE); |
| 237 fFILE = NULL; | 237 fFILE = NULL; |
| 238 } | 238 } |
| 239 return false; | 239 return false; |
| 240 } | 240 } |
| 241 | 241 |
| 242 SkData* SkFILEStream::getData() const { | |
| 243 if ((NULL != fFILE) && (NULL == fData.get())) { | |
| 244 fData.reset(SkData::NewFromFILE(fFILE)); | |
| 245 } | |
| 246 return SkSafeRef(fData.get()); | |
| 247 } | |
| 248 | |
| 242 SkStreamAsset* SkFILEStream::duplicate() const { | 249 SkStreamAsset* SkFILEStream::duplicate() const { |
| 243 if (NULL == fFILE) { | 250 if (NULL == fFILE) { |
| 244 return new SkMemoryStream(); | 251 return new SkMemoryStream(); |
| 245 } | 252 } |
| 246 | 253 |
| 247 if (NULL != fData.get()) { | 254 if (NULL != fData.get()) { |
| 248 return new SkMemoryStream(fData); | 255 return new SkMemoryStream(fData); |
| 249 } | 256 } |
| 250 | 257 |
| 251 if (!fName.isEmpty()) { | 258 if (!fName.isEmpty()) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 fData = SkData::NewFromMalloc(src, size); | 342 fData = SkData::NewFromMalloc(src, size); |
| 336 fOffset = 0; | 343 fOffset = 0; |
| 337 } | 344 } |
| 338 | 345 |
| 339 void SkMemoryStream::setMemory(const void* src, size_t size, bool copyData) { | 346 void SkMemoryStream::setMemory(const void* src, size_t size, bool copyData) { |
| 340 fData->unref(); | 347 fData->unref(); |
| 341 fData = newFromParams(src, size, copyData); | 348 fData = newFromParams(src, size, copyData); |
| 342 fOffset = 0; | 349 fOffset = 0; |
| 343 } | 350 } |
| 344 | 351 |
| 352 SkData* SkMemoryStream::getData() const { | |
| 353 return SkSafeRef(fData); | |
|
scroggo
2013/12/05 21:07:18
Could just use SkRef, since fData cannot be NULL.
hal.canary
2013/12/05 22:29:29
Done. I hadn't seen that template.
| |
| 354 } | |
| 355 | |
| 345 SkData* SkMemoryStream::copyToData() const { | 356 SkData* SkMemoryStream::copyToData() const { |
| 346 fData->ref(); | 357 return this->getData(); |
| 347 return fData; | |
| 348 } | 358 } |
| 349 | 359 |
| 350 SkData* SkMemoryStream::setData(SkData* data) { | 360 SkData* SkMemoryStream::setData(SkData* data) { |
| 351 fData->unref(); | 361 fData->unref(); |
| 352 if (NULL == data) { | 362 if (NULL == data) { |
| 353 fData = SkData::NewEmpty(); | 363 fData = SkData::NewEmpty(); |
| 354 } else { | 364 } else { |
| 355 fData = data; | 365 fData = data; |
| 356 fData->ref(); | 366 fData->ref(); |
| 357 } | 367 } |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 | 839 |
| 830 // If we get here, then our attempt at using mmap failed, so try normal | 840 // If we get here, then our attempt at using mmap failed, so try normal |
| 831 // file access. | 841 // file access. |
| 832 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); | 842 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); |
| 833 if (!stream->isValid()) { | 843 if (!stream->isValid()) { |
| 834 stream->unref(); | 844 stream->unref(); |
| 835 stream = NULL; | 845 stream = NULL; |
| 836 } | 846 } |
| 837 return stream; | 847 return stream; |
| 838 } | 848 } |
| OLD | NEW |