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" |
24 #include "wtf/PassRefPtr.h" | 25 #include "wtf/PassRefPtr.h" |
25 #include "wtf/PtrUtil.h" | |
26 #include <memory> | |
27 | 26 |
28 #if defined(_WIN32) | 27 #if defined(_WIN32) |
29 #include <mmsystem.h> | 28 #include <mmsystem.h> |
30 #include <sys/stat.h> | 29 #include <sys/stat.h> |
31 #include <time.h> | 30 #include <time.h> |
32 #define stat(x,y) _stat(x,y) | 31 #define stat(x,y) _stat(x,y) |
33 typedef struct _stat sttype; | 32 typedef struct _stat sttype; |
34 #else | 33 #else |
35 #include <sys/stat.h> | 34 #include <sys/stat.h> |
36 #include <sys/time.h> | 35 #include <sys/time.h> |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 fprintf(stderr, "Can't open file %s\n", fileName); | 239 fprintf(stderr, "Can't open file %s\n", fileName); |
241 exit(2); | 240 exit(2); |
242 } | 241 } |
243 | 242 |
244 sttype s; | 243 sttype s; |
245 stat(fileName, &s); | 244 stat(fileName, &s); |
246 size_t fileSize = s.st_size; | 245 size_t fileSize = s.st_size; |
247 if (s.st_size <= 0) | 246 if (s.st_size <= 0) |
248 return SharedBuffer::create(); | 247 return SharedBuffer::create(); |
249 | 248 |
250 std::unique_ptr<unsigned char[]> buffer = wrapArrayUnique(new unsigned char[
fileSize]); | 249 OwnPtr<unsigned char[]> buffer = adoptArrayPtr(new unsigned char[fileSize]); |
251 if (fileSize != fread(buffer.get(), 1, fileSize, fp)) { | 250 if (fileSize != fread(buffer.get(), 1, fileSize, fp)) { |
252 fprintf(stderr, "Error reading file %s\n", fileName); | 251 fprintf(stderr, "Error reading file %s\n", fileName); |
253 exit(2); | 252 exit(2); |
254 } | 253 } |
255 | 254 |
256 fclose(fp); | 255 fclose(fp); |
257 return SharedBuffer::create(buffer.get(), fileSize); | 256 return SharedBuffer::create(buffer.get(), fileSize); |
258 } | 257 } |
259 | 258 |
260 bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t packetSize
) | 259 bool decodeImageData(SharedBuffer* data, bool colorCorrection, size_t packetSize
) |
261 { | 260 { |
262 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(*data, | 261 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, |
263 ImageDecoder::AlphaPremultiplied, colorCorrection ? | 262 ImageDecoder::AlphaPremultiplied, colorCorrection ? |
264 ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndCo
lorProfileIgnored); | 263 ImageDecoder::GammaAndColorProfileApplied : ImageDecoder::GammaAndCo
lorProfileIgnored); |
265 | 264 |
266 if (!packetSize) { | 265 if (!packetSize) { |
267 bool allDataReceived = true; | 266 bool allDataReceived = true; |
268 decoder->setData(data, allDataReceived); | 267 decoder->setData(data, allDataReceived); |
269 | 268 |
270 int frameCount = decoder->frameCount(); | 269 int frameCount = decoder->frameCount(); |
271 for (int i = 0; i < frameCount; ++i) { | 270 for (int i = 0; i < frameCount; ++i) { |
272 if (!decoder->frameBufferAtIndex(i)) | 271 if (!decoder->frameBufferAtIndex(i)) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 exit(3); | 393 exit(3); |
395 } | 394 } |
396 } | 395 } |
397 | 396 |
398 // Results to stdout. | 397 // Results to stdout. |
399 | 398 |
400 double averageTime = totalTime / static_cast<double>(iterations); | 399 double averageTime = totalTime / static_cast<double>(iterations); |
401 printf("%f %f\n", totalTime, averageTime); | 400 printf("%f %f\n", totalTime, averageTime); |
402 return 0; | 401 return 0; |
403 } | 402 } |
OLD | NEW |