Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(928)

Unified Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 1866243003: Revert of Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c008c4b2c123fdfa9f3645d6c24e5d14f6420e48..663f0d5d1ede08172707f54097054bba8349cca9 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -32,50 +32,66 @@
namespace blink {
-inline bool matchesJPEGSignature(const char* contents)
+static size_t copyFromSharedBuffer(char* buffer, size_t bufferLength, const SharedBuffer& sharedBuffer, size_t offset)
+{
+ size_t bytesExtracted = 0;
+ const char* moreData;
+ while (size_t moreDataLength = sharedBuffer.getSomeData(moreData, offset)) {
+ size_t bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataLength);
+ memcpy(buffer + bytesExtracted, moreData, bytesToCopy);
+ bytesExtracted += bytesToCopy;
+ if (bytesExtracted == bufferLength)
+ break;
+ offset += bytesToCopy;
+ }
+ return bytesExtracted;
+}
+
+inline bool matchesJPEGSignature(char* contents)
{
return !memcmp(contents, "\xFF\xD8\xFF", 3);
}
-inline bool matchesPNGSignature(const char* contents)
+inline bool matchesPNGSignature(char* contents)
{
return !memcmp(contents, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8);
}
-inline bool matchesGIFSignature(const char* contents)
+inline bool matchesGIFSignature(char* contents)
{
return !memcmp(contents, "GIF87a", 6) || !memcmp(contents, "GIF89a", 6);
}
-inline bool matchesWebPSignature(const char* contents)
+inline bool matchesWebPSignature(char* contents)
{
return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6);
}
-inline bool matchesICOSignature(const char* contents)
+inline bool matchesICOSignature(char* contents)
{
return !memcmp(contents, "\x00\x00\x01\x00", 4);
}
-inline bool matchesCURSignature(const char* contents)
+inline bool matchesCURSignature(char* contents)
{
return !memcmp(contents, "\x00\x00\x02\x00", 4);
}
-inline bool matchesBMPSignature(const char* contents)
+inline bool matchesBMPSignature(char* contents)
{
return !memcmp(contents, "BM", 2);
}
-PassOwnPtr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
+PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
{
const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
ASSERT(longestSignatureLength == 14);
- if (length < longestSignatureLength)
+ size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit;
+
+ char contents[longestSignatureLength];
+ if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longestSignatureLength)
return nullptr;
-
- size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit;
if (matchesJPEGSignature(contents))
return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
@@ -96,20 +112,6 @@
return adoptPtr(new BMPImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
return nullptr;
-}
-
-PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
-{
- const char* contents;
- const size_t length = data.getSomeData<size_t>(contents);
- return create(contents, length, alphaOption, colorOptions);
-}
-
-PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
-{
- const char* contents;
- const size_t length = data.getSomeData(contents, 0);
- return create(contents, length, alphaOption, colorOptions);
}
size_t ImageDecoder::frameCount()

Powered by Google App Engine
This is Rietveld 408576698