Chromium Code Reviews| Index: Source/web/ImageDecodeBench.cpp |
| diff --git a/Source/web/ImageDecodeBench.cpp b/Source/web/ImageDecodeBench.cpp |
| index 2f6f2b47c90d68347c208ef1f0e10f18f6444e69..f2b585002f75ae7830998075e6ac962bc808f6e7 100644 |
| --- a/Source/web/ImageDecodeBench.cpp |
| +++ b/Source/web/ImageDecodeBench.cpp |
| @@ -15,11 +15,6 @@ during image decoding on supported platforms (default off). Usage: |
| FIXME: Consider adding md5 checksum support to WTF. Use it to compute the |
| decoded image frame md5 and output that value. |
| -FIXME: Consider adding an input data packetization option. Break the input |
| -into network-sized packets, pump the packets into the image decoder until |
| -the input data is complete (allDataReceived). This to include any internal |
| -SharedBuffer costs, such as buffer coalescing, in the reported results. |
| - |
| FIXME: Consider integrating this tool in Chrome telemetry for realz, using |
| the image corpii used to assess Blink image decode performance. Refer to |
| http://crbug.com/398235#c103 and http://crbug.com/258324#c5 |
| @@ -270,19 +265,45 @@ PassRefPtr<SharedBuffer> readFile(const char* fileName) |
| return SharedBuffer::create(buffer.get(), fileSize); |
| } |
| -bool decodeImageData(SharedBuffer* data, bool colorCorrection) |
| +bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t chunkSize) |
| { |
| OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, |
| ImageDecoder::AlphaPremultiplied, colorCorrection ? |
| ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndColorProfileIgnored); |
| - bool allDataReceived = true; |
| - decoder->setData(data, allDataReceived); |
| + if (!chunkSize) { |
| + bool allDataReceived = true; |
| + decoder->setData(data, allDataReceived); |
| + |
| + int frameCount = decoder->frameCount(); |
| + for (int i = 0; i < frameCount; ++i) { |
| + if (!decoder->frameBufferAtIndex(i)) |
| + return false; |
| + } |
| + |
| + return !decoder->failed(); |
| + } |
| + |
| + RefPtr<SharedBuffer> incrementalData = SharedBuffer::create(); |
|
Noel Gordon
2015/09/02 23:29:35
incrementalData -> packetData ?
scroggo
2015/09/03 22:10:26
Done.
|
| + unsigned position = 0; |
| + while (true) { |
| + const char* segment; |
|
Noel Gordon
2015/09/02 23:29:35
segment -> packet
scroggo
2015/09/03 22:10:26
Done.
|
| + unsigned length = data->getSomeData(segment, position); |
| + |
| + length = std::min(static_cast<size_t>(length), chunkSize); |
| + incrementalData->append(segment, length); |
| + position += length; |
| + bool allDataReceived = position == data->size(); |
|
Noel Gordon
2015/09/02 23:29:35
Space before this line.
scroggo
2015/09/03 22:10:26
Done.
|
| + decoder->setData(incrementalData.get(), allDataReceived); |
| + |
| + int frameCount = decoder->frameCount(); |
| + for (int i = 0; i < frameCount; ++i) { |
| + if (!decoder->frameBufferAtIndex(i)) |
| + break; |
| + } |
| - int frameCount = decoder->frameCount(); |
| - for (int i = 0; i < frameCount; ++i) { |
| - if (!decoder->frameBufferAtIndex(i)) |
| - return false; |
| + if (allDataReceived || decoder->failed()) |
| + break; |
| } |
| return !decoder->failed(); |
| @@ -301,12 +322,12 @@ int main(int argc, char* argv[]) |
| applyColorCorrection = (--argc, ++argv, true); |
| if (argc < 2) { |
| - fprintf(stderr, "Usage: %s [--color-correct] file [iterations]\n", name); |
| + fprintf(stderr, "Usage: %s [--color-correct] file [iterations] [chunkSize]\n", name); |
| exit(1); |
| } |
| #else |
| if (argc < 2) { |
| - fprintf(stderr, "Usage: %s file [iterations]\n", name); |
| + fprintf(stderr, "Usage: %s file [iterations] [chunkSize]\n", name); |
| exit(1); |
| } |
| #endif |
| @@ -324,6 +345,18 @@ int main(int argc, char* argv[]) |
| } |
| } |
| + size_t chunkSize = 0; |
| + if (argc >= 4) { |
| + char* end = 0; |
| + chunkSize = strtol(argv[3], &end, 10); |
| + if (*end != '\0') { |
| + fprintf(stderr, "Third argument should be chunk size. Default is " |
| + "0, meaning to decode the entire image in one chunk. You " |
| + "supplied %s\n", argv[3]); |
| + exit(1); |
| + } |
| + } |
| + |
| // Create a web platform without V8. |
| class WebPlatform : public blink::Platform { |
| @@ -360,13 +393,19 @@ int main(int argc, char* argv[]) |
| exit(2); |
| } |
| + // Merge the buffers. This imitates the MemCache case, where the data is |
|
Noel Gordon
2015/09/02 23:29:35
These details about Memcache and packet chunkSize
scroggo
2015/09/03 22:10:26
Done.
|
| + // consolidated before calling the decoder. This also means that if |
| + // chunkSize is not zero, each call to SharedBuffer::append will be of size |
| + // chunkSize (except the last, which may be smaller). |
| + data->data(); |
| + |
| // Image decode bench for iterations. |
| double totalTime = 0.0; |
| for (size_t i = 0; i < iterations; ++i) { |
| double startTime = getCurrentTime(); |
| - bool decoded = decodeImageData(data.get(), applyColorCorrection); |
| + bool decoded = decodeImageData(data.get(), applyColorCorrection, chunkSize); |
| double elapsedTime = getCurrentTime() - startTime; |
| totalTime += elapsedTime; |
| if (!decoded) { |