Chromium Code Reviews| Index: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
| diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
| index 874b7d06e12a3f288ac7c7d56ac845b6f1a6bcfa..dd29894273062c8d3ba9fe332ebb3bb24ed2c541 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
| +++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
| @@ -23,6 +23,7 @@ |
| #include "platform/PlatformInstrumentation.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| #include "platform/graphics/BitmapImageMetrics.h" |
| +#include "platform/image-decoders/FastSharedBufferReader.h" |
| #include "platform/image-decoders/bmp/BMPImageDecoder.h" |
| #include "platform/image-decoders/gif/GIFImageDecoder.h" |
| #include "platform/image-decoders/ico/ICOImageDecoder.h" |
| @@ -107,12 +108,16 @@ std::unique_ptr<ImageDecoder> ImageDecoder::create(SniffResult sniffResult, Alph |
| return nullptr; |
| } |
| +namespace { |
| + |
| +constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
| +static_assert(kLongestSignatureLength == 14, "kLongestSignatureLength mismatch"); |
|
Peter Kasting
2016/08/16 22:10:18
Hmm. This static_assert duplicates the old DCHECK
f(malita)
2016/08/17 17:09:31
Done.
Another thing we could do is add static ass
Peter Kasting
2016/08/17 22:46:12
You mean, like, asserting that the length of "BM"
f(malita)
2016/08/17 23:19:08
More like refactoring all signature matchers to ca
|
| + |
| +} // anonymous ns |
| + |
| ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, size_t length) |
| { |
| - const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
| - DCHECK_EQ(14u, longestSignatureLength); |
| - |
| - if (length < longestSignatureLength) |
| + if (length < kLongestSignatureLength) |
| return SniffResult::InsufficientData; |
| if (matchesJPEGSignature(contents)) |
| return SniffResult::JPEG; |
| @@ -131,16 +136,20 @@ ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, |
| ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& data) |
| { |
| - const char* contents; |
| - const size_t length = data.getSomeData<size_t>(contents); |
| - return determineImageType(contents, length); |
| + // TODO(fmalita): refactor the method signature to avoid casting. |
| + RefPtr<SegmentReader> reader = SegmentReader::createFromSharedBuffer(const_cast<SharedBuffer*>(&data)); |
|
f(malita)
2016/08/16 21:54:03
I'm trying to minimize the footprint in order to f
Peter Kasting
2016/08/16 22:10:18
It might be easier to understand to make this CL d
f(malita)
2016/08/17 17:09:31
This is what I have in mind (not ready for review
Peter Kasting
2016/08/17 22:46:13
Sounds like a good plan.
|
| + |
| + return determineImageType(*reader); |
| } |
| ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data) |
| { |
| - const char* contents; |
| - const size_t length = data.getSomeData(contents, 0); |
| - return determineImageType(contents, length); |
| + // TODO(fmalita): refactor the method signature to avoid casting. |
| + const FastSharedBufferReader fastReader(const_cast<SegmentReader*>(&data)); |
| + char buffer[kLongestSignatureLength]; |
| + const size_t len = std::min(kLongestSignatureLength, data.size()); |
| + |
| + return determineImageType(fastReader.getConsecutiveData(0, len, buffer), len); |
| } |
| size_t ImageDecoder::frameCount() |