| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifdef WTF | 5 #ifdef WTF |
| 6 | 6 |
| 7 Provides a minimal wrapping of the Blink image decoders. Used to perform | 7 Provides a minimal wrapping of the Blink image decoders. Used to perform |
| 8 a non-threaded, memory-to-memory image decode using micro second accuracy | 8 a non-threaded, memory-to-memory image decode using micro second accuracy |
| 9 clocks to measure image decode time. Optionally applies color correction | 9 clocks to measure image decode time. Optionally applies color correction |
| 10 during image decoding on supported platforms (default off). Usage: | 10 during image decoding on supported platforms (default off). Usage: |
| 11 | 11 |
| 12 % ninja -C /out/Release image_decode_bench && | 12 % ninja -C /out/Release image_decode_bench && |
| 13 ./out/Release/image_decode_bench file [iterations] | 13 ./out/Release/image_decode_bench file [iterations] |
| 14 | 14 |
| 15 FIXME: Consider adding md5 checksum support to WTF. Use it to compute the | 15 FIXME: Consider adding md5 checksum support to WTF. Use it to compute the |
| 16 decoded image frame md5 and output that value. | 16 decoded image frame md5 and output that value. |
| 17 | 17 |
| 18 FIXME: Consider integrating this tool in Chrome telemetry for realz, using | 18 FIXME: Consider integrating this tool in Chrome telemetry for realz, using |
| 19 the image corpii used to assess Blink image decode performance. Refer to | 19 the image corpii used to assess Blink image decode performance. Refer to |
| 20 http://crbug.com/398235#c103 and http://crbug.com/258324#c5 | 20 http://crbug.com/398235#c103 and http://crbug.com/258324#c5 |
| 21 | 21 |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 #include "platform/SharedBuffer.h" | 24 #include "platform/SharedBuffer.h" |
| 25 #include "platform/image-decoders/ImageDecoder.h" | 25 #include "platform/image-decoders/ImageDecoder.h" |
| 26 #include "platform/image-decoders/SharedBufferSegmentReader.h" |
| 26 #include "platform/testing/TestingPlatformSupport.h" | 27 #include "platform/testing/TestingPlatformSupport.h" |
| 27 #include "public/platform/Platform.h" | 28 #include "public/platform/Platform.h" |
| 28 #include "public/web/WebKit.h" | 29 #include "public/web/WebKit.h" |
| 29 #include "wtf/OwnPtr.h" | 30 #include "wtf/OwnPtr.h" |
| 30 #include "wtf/PassRefPtr.h" | 31 #include "wtf/PassRefPtr.h" |
| 31 | 32 |
| 32 #if defined(_WIN32) | 33 #if defined(_WIN32) |
| 33 #if defined(WIN32_LEAN_AND_MEAN) | 34 #if defined(WIN32_LEAN_AND_MEAN) |
| 34 #error Fix: WIN32_LEAN_AND_MEAN disables timeBeginPeriod/TimeEndPeriod. | 35 #error Fix: WIN32_LEAN_AND_MEAN disables timeBeginPeriod/TimeEndPeriod. |
| 35 #endif | 36 #endif |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 fprintf(stderr, "Error reading file %s\n", fileName); | 260 fprintf(stderr, "Error reading file %s\n", fileName); |
| 260 exit(2); | 261 exit(2); |
| 261 } | 262 } |
| 262 | 263 |
| 263 fclose(fp); | 264 fclose(fp); |
| 264 return SharedBuffer::create(buffer.get(), fileSize); | 265 return SharedBuffer::create(buffer.get(), fileSize); |
| 265 } | 266 } |
| 266 | 267 |
| 267 bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t packetSize
) | 268 bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t packetSize
) |
| 268 { | 269 { |
| 269 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, | 270 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS
egmentReader(data)); |
| 271 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*segmentReader.get(), |
| 270 ImageDecoder::AlphaPremultiplied, colorCorrection ? | 272 ImageDecoder::AlphaPremultiplied, colorCorrection ? |
| 271 ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndCo
lorProfileIgnored); | 273 ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndCo
lorProfileIgnored); |
| 272 | 274 |
| 273 if (!packetSize) { | 275 if (!packetSize) { |
| 274 bool allDataReceived = true; | 276 bool allDataReceived = true; |
| 275 decoder->setData(data, allDataReceived); | 277 decoder->setData(segmentReader.get(), allDataReceived); |
| 276 | 278 |
| 277 int frameCount = decoder->frameCount(); | 279 int frameCount = decoder->frameCount(); |
| 278 for (int i = 0; i < frameCount; ++i) { | 280 for (int i = 0; i < frameCount; ++i) { |
| 279 if (!decoder->frameBufferAtIndex(i)) | 281 if (!decoder->frameBufferAtIndex(i)) |
| 280 return false; | 282 return false; |
| 281 } | 283 } |
| 282 | 284 |
| 283 return !decoder->failed(); | 285 return !decoder->failed(); |
| 284 } | 286 } |
| 285 | 287 |
| 286 RefPtr<SharedBuffer> packetData = SharedBuffer::create(); | 288 RefPtr<SharedBuffer> packetData = SharedBuffer::create(); |
| 289 segmentReader = adoptRef(new SharedBufferSegmentReader(packetData)); |
| 287 unsigned position = 0; | 290 unsigned position = 0; |
| 288 while (true) { | 291 while (true) { |
| 289 const char* packet; | 292 const char* packet; |
| 290 unsigned length = data->getSomeData(packet, position); | 293 unsigned length = data->getSomeData(packet, position); |
| 291 | 294 |
| 292 length = std::min(static_cast<size_t>(length), packetSize); | 295 length = std::min(static_cast<size_t>(length), packetSize); |
| 293 packetData->append(packet, length); | 296 packetData->append(packet, length); |
| 294 position += length; | 297 position += length; |
| 295 | 298 |
| 296 bool allDataReceived = position == data->size(); | 299 bool allDataReceived = position == data->size(); |
| 297 decoder->setData(packetData.get(), allDataReceived); | 300 decoder->setData(segmentReader.get(), allDataReceived); |
| 298 | 301 |
| 299 int frameCount = decoder->frameCount(); | 302 int frameCount = decoder->frameCount(); |
| 300 for (int i = 0; i < frameCount; ++i) { | 303 for (int i = 0; i < frameCount; ++i) { |
| 301 if (!decoder->frameBufferAtIndex(i)) | 304 if (!decoder->frameBufferAtIndex(i)) |
| 302 break; | 305 break; |
| 303 } | 306 } |
| 304 | 307 |
| 305 if (allDataReceived || decoder->failed()) | 308 if (allDataReceived || decoder->failed()) |
| 306 break; | 309 break; |
| 307 } | 310 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 exit(3); | 403 exit(3); |
| 401 } | 404 } |
| 402 } | 405 } |
| 403 | 406 |
| 404 // Results to stdout. | 407 // Results to stdout. |
| 405 | 408 |
| 406 double averageTime = totalTime / static_cast<double>(iterations); | 409 double averageTime = totalTime / static_cast<double>(iterations); |
| 407 printf("%f %f\n", totalTime, averageTime); | 410 printf("%f %f\n", totalTime, averageTime); |
| 408 return 0; | 411 return 0; |
| 409 } | 412 } |
| OLD | NEW |