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

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

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 b660c660eb881bd73c788b7b7b1f43c765f20169..9f196505bdbaf958d5c8687c270372be4b8b26a9 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -32,65 +32,51 @@
namespace blink {
-static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset)
-{
- unsigned bytesExtracted = 0;
- const char* moreData;
- while (unsigned moreDataLength = sharedBuffer.getSomeData(moreData, offset)) {
- unsigned 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)
+inline bool matchesJPEGSignature(const char* contents)
{
return !memcmp(contents, "\xFF\xD8\xFF", 3);
}
-inline bool matchesPNGSignature(char* contents)
+inline bool matchesPNGSignature(const char* contents)
{
return !memcmp(contents, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8);
}
-inline bool matchesGIFSignature(char* contents)
+inline bool matchesGIFSignature(const char* contents)
{
return !memcmp(contents, "GIF87a", 6) || !memcmp(contents, "GIF89a", 6);
}
-inline bool matchesWebPSignature(char* contents)
+inline bool matchesWebPSignature(const char* contents)
{
return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6);
}
-inline bool matchesICOSignature(char* contents)
+inline bool matchesICOSignature(const char* contents)
{
return !memcmp(contents, "\x00\x00\x01\x00", 4);
}
-inline bool matchesCURSignature(char* contents)
+inline bool matchesCURSignature(const char* contents)
{
return !memcmp(contents, "\x00\x00\x02\x00", 4);
}
-inline bool matchesBMPSignature(char* contents)
+inline bool matchesBMPSignature(const char* contents)
{
return !memcmp(contents, "BM", 2);
}
-PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
+PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
{
const unsigned longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
ASSERT(longestSignatureLength == 14);
size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit;
- char contents[longestSignatureLength];
- if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longestSignatureLength)
+ // No implementation of SegmentReader will return less than 14 bytes from a read from the beginning, unless there is no more data.
Peter Kasting 2016/03/23 02:42:58 Does this comment matter? It looks like we check
scroggo_chromium 2016/03/24 13:59:45 Removed.
+ const char* contents;
+ if (data.getSomeData(contents, 0) < longestSignatureLength)
return nullptr;
if (matchesJPEGSignature(contents))

Powered by Google App Engine
This is Rietveld 408576698