Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 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 #include "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 virtual bool read(void* data, size_t offset, size_t length) = 0; | 192 virtual bool read(void* data, size_t offset, size_t length) = 0; |
| 193 | 193 |
| 194 /* | 194 /* |
| 195 * Creates an SkMemoryStream from the offset with size. | 195 * Creates an SkMemoryStream from the offset with size. |
| 196 * Note: for performance reason, this function is destructive to the SkRawSt ream. One should | 196 * Note: for performance reason, this function is destructive to the SkRawSt ream. One should |
| 197 * abandon current object after the function call. | 197 * abandon current object after the function call. |
| 198 */ | 198 */ |
| 199 virtual SkMemoryStream* transferBuffer(size_t offset, size_t size) = 0; | 199 virtual SkMemoryStream* transferBuffer(size_t offset, size_t size) = 0; |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 class SkSizeLimitedDynamicMemoryWStream : public SkDynamicMemoryWStream { | |
| 203 public: | |
| 204 virtual ~SkSizeLimitedDynamicMemoryWStream() {} | |
| 205 | |
| 206 bool write(const void* buffer, size_t size) override { | |
| 207 size_t newSize; | |
| 208 if (!safe_add_to_size_t(this->bytesWritten(), size, &newSize) || | |
|
scroggo
2016/03/09 16:32:45
If we limit to 10,240,000, do we still need to che
yujieqin
2016/03/09 17:40:30
I still prefer to check here, because there is not
| |
| 209 newSize > kMaxStreamSize) { | |
|
scroggo
2016/03/09 16:32:45
nit: this lines up with the line below. Would be b
yujieqin
2016/03/09 17:40:30
Done.
| |
| 210 return false; | |
|
scroggo
2016/03/09 16:32:45
Should we print some kind of error message? It see
yujieqin
2016/03/09 17:40:30
added a SkCodecPrintf
| |
| 211 } | |
| 212 return SkDynamicMemoryWStream::write(buffer, size); | |
|
scroggo
2016/03/09 16:32:45
typically in Skia, we use a typedef INHERITED to r
yujieqin
2016/03/09 17:40:30
Done.
| |
| 213 } | |
| 214 | |
| 215 private: | |
| 216 const size_t kMaxStreamSize = 100 * 1024 * 1024; // 100MB | |
| 217 }; | |
| 218 | |
| 219 // Note: the maximum buffer size is 100MB (limited by SkSizeLimitedDynamicMemory WStream). | |
| 202 class SkRawBufferedStream : public SkRawStream { | 220 class SkRawBufferedStream : public SkRawStream { |
| 203 public: | 221 public: |
| 204 // Will take the ownership of the stream. | 222 // Will take the ownership of the stream. |
| 205 explicit SkRawBufferedStream(SkStream* stream) | 223 explicit SkRawBufferedStream(SkStream* stream) |
| 206 : fStream(stream) | 224 : fStream(stream) |
| 207 , fWholeStreamRead(false) | 225 , fWholeStreamRead(false) |
| 208 { | 226 { |
| 209 // Only use SkRawBufferedStream when the stream is not an asset stream. | 227 // Only use SkRawBufferedStream when the stream is not an asset stream. |
| 210 SkASSERT(!is_asset_stream(*stream)); | 228 SkASSERT(!is_asset_stream(*stream)); |
| 211 } | 229 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); | 312 const size_t bytesRead = fStream->read(tempBuffer.get(), sizeToRead); |
| 295 if (bytesRead < sizeRequested) { | 313 if (bytesRead < sizeRequested) { |
| 296 return false; | 314 return false; |
| 297 } | 315 } |
| 298 return fStreamBuffer.write(tempBuffer.get(), bytesRead); | 316 return fStreamBuffer.write(tempBuffer.get(), bytesRead); |
| 299 } | 317 } |
| 300 | 318 |
| 301 SkAutoTDelete<SkStream> fStream; | 319 SkAutoTDelete<SkStream> fStream; |
| 302 bool fWholeStreamRead; | 320 bool fWholeStreamRead; |
| 303 | 321 |
| 304 SkDynamicMemoryWStream fStreamBuffer; | 322 // Use a size-limited stream to avoid holding too huge buffer. |
| 323 SkSizeLimitedDynamicMemoryWStream fStreamBuffer; | |
| 305 | 324 |
| 306 const size_t kReadToEnd = 0; | 325 const size_t kReadToEnd = 0; |
| 307 }; | 326 }; |
| 308 | 327 |
| 309 class SkRawAssetStream : public SkRawStream { | 328 class SkRawAssetStream : public SkRawStream { |
| 310 public: | 329 public: |
| 311 // Will take the ownership of the stream. | 330 // Will take the ownership of the stream. |
| 312 explicit SkRawAssetStream(SkStream* stream) | 331 explicit SkRawAssetStream(SkStream* stream) |
| 313 : fStream(stream) | 332 : fStream(stream) |
| 314 { | 333 { |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); | 728 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); |
| 710 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); | 729 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); |
| 711 return sizeFloor == dim || sizeCeil == dim; | 730 return sizeFloor == dim || sizeCeil == dim; |
| 712 } | 731 } |
| 713 | 732 |
| 714 SkRawCodec::~SkRawCodec() {} | 733 SkRawCodec::~SkRawCodec() {} |
| 715 | 734 |
| 716 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 735 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
| 717 : INHERITED(dngImage->getImageInfo(), nullptr) | 736 : INHERITED(dngImage->getImageInfo(), nullptr) |
| 718 , fDngImage(dngImage) {} | 737 , fDngImage(dngImage) {} |
| OLD | NEW |