| 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 // Provides a minimal wrapping of the Blink image decoders. Used to perform | 5 // Provides a minimal wrapping of the Blink image decoders. Used to perform |
| 6 // a non-threaded, memory-to-memory image decode using micro second accuracy | 6 // a non-threaded, memory-to-memory image decode using micro second accuracy |
| 7 // clocks to measure image decode time. Optionally applies color correction | 7 // clocks to measure image decode time. Optionally applies color correction |
| 8 // during image decoding on supported platforms (default off). Usage: | 8 // during image decoding on supported platforms (default off). Usage: |
| 9 // | 9 // |
| 10 // % ninja -C out/Release image_decode_bench && | 10 // % ninja -C out/Release image_decode_bench && |
| 11 // ./out/Release/image_decode_bench file [iterations] | 11 // ./out/Release/image_decode_bench file [iterations] |
| 12 // | 12 // |
| 13 // TODO(noel): Consider adding md5 checksum support to WTF. Use it to compute | 13 // TODO(noel): Consider adding md5 checksum support to WTF. Use it to compute |
| 14 // the decoded image frame md5 and output that value. | 14 // the decoded image frame md5 and output that value. |
| 15 // | 15 // |
| 16 // TODO(noel): Consider integrating this tool in Chrome telemetry for realz, | 16 // TODO(noel): Consider integrating this tool in Chrome telemetry for realz, |
| 17 // using the image corpii used to assess Blink image decode performance. Refer | 17 // using the image corpii used to assess Blink image decode performance. Refer |
| 18 // to http://crbug.com/398235#c103 and http://crbug.com/258324#c5 | 18 // to http://crbug.com/398235#c103 and http://crbug.com/258324#c5 |
| 19 | 19 |
| 20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 21 #include "platform/SharedBuffer.h" | 21 #include "platform/SharedBuffer.h" |
| 22 #include "platform/image-decoders/ImageDecoder.h" | 22 #include "platform/image-decoders/ImageDecoder.h" |
| 23 #include "public/platform/Platform.h" | 23 #include "public/platform/Platform.h" |
| 24 #include "wtf/OwnPtr.h" | |
| 25 #include "wtf/PassRefPtr.h" | 24 #include "wtf/PassRefPtr.h" |
| 25 #include "wtf/PtrUtil.h" |
| 26 #include <memory> |
| 26 | 27 |
| 27 #if defined(_WIN32) | 28 #if defined(_WIN32) |
| 28 #include <mmsystem.h> | 29 #include <mmsystem.h> |
| 29 #include <sys/stat.h> | 30 #include <sys/stat.h> |
| 30 #include <time.h> | 31 #include <time.h> |
| 31 #define stat(x,y) _stat(x,y) | 32 #define stat(x,y) _stat(x,y) |
| 32 typedef struct _stat sttype; | 33 typedef struct _stat sttype; |
| 33 #else | 34 #else |
| 34 #include <sys/stat.h> | 35 #include <sys/stat.h> |
| 35 #include <sys/time.h> | 36 #include <sys/time.h> |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 fprintf(stderr, "Can't open file %s\n", fileName); | 240 fprintf(stderr, "Can't open file %s\n", fileName); |
| 240 exit(2); | 241 exit(2); |
| 241 } | 242 } |
| 242 | 243 |
| 243 sttype s; | 244 sttype s; |
| 244 stat(fileName, &s); | 245 stat(fileName, &s); |
| 245 size_t fileSize = s.st_size; | 246 size_t fileSize = s.st_size; |
| 246 if (s.st_size <= 0) | 247 if (s.st_size <= 0) |
| 247 return SharedBuffer::create(); | 248 return SharedBuffer::create(); |
| 248 | 249 |
| 249 OwnPtr<unsigned char[]> buffer = adoptArrayPtr(new unsigned char[fileSize]); | 250 std::unique_ptr<unsigned char[]> buffer = wrapArrayUnique(new unsigned char[
fileSize]); |
| 250 if (fileSize != fread(buffer.get(), 1, fileSize, fp)) { | 251 if (fileSize != fread(buffer.get(), 1, fileSize, fp)) { |
| 251 fprintf(stderr, "Error reading file %s\n", fileName); | 252 fprintf(stderr, "Error reading file %s\n", fileName); |
| 252 exit(2); | 253 exit(2); |
| 253 } | 254 } |
| 254 | 255 |
| 255 fclose(fp); | 256 fclose(fp); |
| 256 return SharedBuffer::create(buffer.get(), fileSize); | 257 return SharedBuffer::create(buffer.get(), fileSize); |
| 257 } | 258 } |
| 258 | 259 |
| 259 bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t packetSize
) | 260 bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t packetSize
) |
| 260 { | 261 { |
| 261 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, | 262 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(*data, |
| 262 ImageDecoder::AlphaPremultiplied, colorCorrection ? | 263 ImageDecoder::AlphaPremultiplied, colorCorrection ? |
| 263 ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndCo
lorProfileIgnored); | 264 ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndCo
lorProfileIgnored); |
| 264 | 265 |
| 265 if (!packetSize) { | 266 if (!packetSize) { |
| 266 bool allDataReceived = true; | 267 bool allDataReceived = true; |
| 267 decoder->setData(data, allDataReceived); | 268 decoder->setData(data, allDataReceived); |
| 268 | 269 |
| 269 int frameCount = decoder->frameCount(); | 270 int frameCount = decoder->frameCount(); |
| 270 for (int i = 0; i < frameCount; ++i) { | 271 for (int i = 0; i < frameCount; ++i) { |
| 271 if (!decoder->frameBufferAtIndex(i)) | 272 if (!decoder->frameBufferAtIndex(i)) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 exit(3); | 394 exit(3); |
| 394 } | 395 } |
| 395 } | 396 } |
| 396 | 397 |
| 397 // Results to stdout. | 398 // Results to stdout. |
| 398 | 399 |
| 399 double averageTime = totalTime / static_cast<double>(iterations); | 400 double averageTime = totalTime / static_cast<double>(iterations); |
| 400 printf("%f %f\n", totalTime, averageTime); | 401 printf("%f %f\n", totalTime, averageTime); |
| 401 return 0; | 402 return 0; |
| 402 } | 403 } |
| OLD | NEW |