Chromium Code Reviews| 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 & Skia raster. |
| 6 // a non-threaded, memory-to-memory image decode using micro second accuracy | 6 // Used to perform a non-threaded, memory-to-memory image decode/raster using |
| 7 // clocks to measure image decode time. Optionally applies color correction | 7 // micro second accuracy clocks to measure image decode time. Optionally |
| 8 // during image decoding on supported platforms (default off). Usage: | 8 // applies color correction during image decoding on supported platforms |
| 9 // (default off). Usage: | |
| 9 // | 10 // |
| 10 // % ninja -C out/Release image_decode_bench && | 11 // % ninja -C out/Release image_decode_bench && |
| 11 // ./out/Release/image_decode_bench file [iterations] | 12 // ./out/Release/image_decode_bench file [--raster] [iterations] |
| 12 // | 13 // |
| 13 // The output is formatted for use in a csv file (comma-separated variable). | 14 // The output is formatted for use in a csv file (comma-separated variable). |
| 14 // Each row represents successive frames in an animated image. | 15 // Each row represents successive frames in an animated image. |
| 15 // Each column represents a successive iteration of decoding the whole animated | 16 // Each column represents a successive iteration of decoding the whole animated |
| 16 // image. | 17 // image. |
| 17 // This means non-animated images will show up as one column. | 18 // This means non-animated images will show up as one column. |
| 19 // Raster timing also shows up as one column. | |
| 18 // | 20 // |
| 19 // TODO(noel): Consider adding md5 checksum support to WTF. Use it to compute | 21 // TODO(noel): Consider adding md5 checksum support to WTF. Use it to compute |
| 20 // the decoded image frame md5 and output that value. | 22 // the decoded image frame md5 and output that value. |
| 21 // | 23 // |
| 22 // TODO(noel): Consider integrating this tool in Chrome telemetry for realz, | 24 // TODO(noel): Consider integrating this tool in Chrome telemetry for realz, |
| 23 // using the image corpii used to assess Blink image decode performance. Refer | 25 // using the image corpii used to assess Blink image decode performance. Refer |
| 24 // to http://crbug.com/398235#c103 and http://crbug.com/258324#c5 | 26 // to http://crbug.com/398235#c103 and http://crbug.com/258324#c5 |
| 25 | 27 |
| 26 #include <memory> | 28 #include <memory> |
| 27 #include <vector> | 29 #include <vector> |
| 28 #include "base/command_line.h" | 30 #include "base/command_line.h" |
| 29 #include "platform/SharedBuffer.h" | 31 #include "platform/SharedBuffer.h" |
| 30 #include "platform/image-decoders/ImageDecoder.h" | 32 #include "platform/image-decoders/ImageDecoder.h" |
| 31 #include "platform/wtf/PassRefPtr.h" | 33 #include "platform/wtf/PassRefPtr.h" |
| 32 #include "platform/wtf/PtrUtil.h" | 34 #include "platform/wtf/PtrUtil.h" |
| 33 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 36 #include "third_party/skia/include/core/SkCanvas.h" | |
| 37 #include "third_party/skia/include/core/SkSurface.h" | |
| 34 #include "ui/gfx/test/icc_profiles.h" | 38 #include "ui/gfx/test/icc_profiles.h" |
| 35 | 39 |
| 36 #if defined(_WIN32) | 40 #if defined(_WIN32) |
| 37 #include <mmsystem.h> | 41 #include <mmsystem.h> |
| 38 #include <sys/stat.h> | 42 #include <sys/stat.h> |
| 39 #include <time.h> | 43 #include <time.h> |
| 40 #define stat(x, y) _stat(x, y) | 44 #define stat(x, y) _stat(x, y) |
| 41 typedef struct _stat sttype; | 45 typedef struct _stat sttype; |
| 42 #else | 46 #else |
| 43 #include <sys/stat.h> | 47 #include <sys/stat.h> |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 307 |
| 304 if (all_data_received || decoder->Failed()) { | 308 if (all_data_received || decoder->Failed()) { |
| 305 fprintf(stderr, "Image decode failed\n"); | 309 fprintf(stderr, "Image decode failed\n"); |
| 306 exit(3); | 310 exit(3); |
| 307 } | 311 } |
| 308 } | 312 } |
| 309 | 313 |
| 310 Print2DResults(timings); | 314 Print2DResults(timings); |
| 311 } | 315 } |
| 312 | 316 |
| 317 void TimeRaster(ImageDecoder* decoder, | |
| 318 PassRefPtr<SharedBuffer> data, | |
| 319 size_t iterations) { | |
| 320 const bool all_data_received = true; | |
| 321 decoder->SetData(data.Get(), all_data_received); | |
| 322 | |
| 323 if (!decoder->IsSizeAvailable()) { | |
| 324 fprintf(stderr, "failed to decode size\n"); | |
| 325 exit(3); | |
|
scroggo_chromium
2017/05/23 15:57:09
Right now it looks like we pass the following valu
cblume
2017/05/23 18:07:31
ImageDecodeBench currently (prior to this patch) r
| |
| 326 } | |
| 327 const auto size = decoder->Size(); | |
| 328 | |
| 329 ImageFrame* frame = decoder->FrameBufferAtIndex(0); | |
| 330 if (frame->GetStatus() != ImageFrame::kFrameComplete) { | |
| 331 fprintf(stderr, "failed to decode first frame\n"); | |
| 332 exit(3); | |
| 333 } | |
| 334 | |
| 335 auto surface = SkSurface::MakeRasterN32Premul(size.Width(), size.Height()); | |
| 336 auto canvas = surface->getCanvas(); | |
| 337 | |
| 338 std::vector<double> timings(iterations); | |
| 339 for (size_t i = 0; i < iterations; ++i) { | |
| 340 double start_time = GetCurrentTime(); | |
| 341 canvas->drawBitmap(frame->Bitmap(), 0, 0, nullptr); | |
| 342 double elapsed_time = GetCurrentTime() - start_time; | |
| 343 timings[i] = elapsed_time; | |
| 344 } | |
| 345 | |
| 346 for (double iteration_time : timings) { | |
| 347 printf("%f,\n", iteration_time); | |
| 348 } | |
| 349 printf("\n"); | |
| 350 } | |
| 351 | |
| 313 } // namespace | 352 } // namespace |
| 314 | 353 |
| 315 int Main(int argc, char* argv[]) { | 354 int Main(int argc, char* argv[]) { |
| 316 base::CommandLine::Init(argc, argv); | 355 base::CommandLine::Init(argc, argv); |
| 317 | 356 |
| 318 // If the platform supports color correction, allow it to be controlled. | 357 // If the platform supports color correction, allow it to be controlled. |
| 319 | 358 |
| 320 bool apply_color_correction = false; | 359 bool apply_color_correction = false; |
| 321 if (argc >= 2 && strcmp(argv[1], "--color-correct") == 0) { | 360 if (argc >= 2 && strcmp(argv[1], "--color-correct") == 0) { |
| 322 --argc; | 361 --argc; |
| 323 ++argv; | 362 ++argv; |
| 324 apply_color_correction = true; | 363 apply_color_correction = true; |
| 325 gfx::ICCProfile profile = gfx::ICCProfileForTestingColorSpin(); | 364 gfx::ICCProfile profile = gfx::ICCProfileForTestingColorSpin(); |
| 326 ColorBehavior::SetGlobalTargetColorProfile(profile); | 365 ColorBehavior::SetGlobalTargetColorProfile(profile); |
| 327 } | 366 } |
| 328 | 367 |
| 368 bool time_raster = false; | |
| 369 if (argc >= 2 && strcmp(argv[1], "--raster") == 0) { | |
| 370 --argc; | |
| 371 ++argv; | |
| 372 time_raster = true; | |
| 373 } | |
| 374 | |
| 329 if (argc < 2) { | 375 if (argc < 2) { |
| 330 fprintf(stderr, | 376 fprintf(stderr, |
| 331 "Usage: %s [--color-correct] file [iterations] [packetSize]\n", | 377 "Usage: %s [--color-correct] [--raster] file [iterations] " |
| 378 "[packetSize]\n", | |
| 332 argv[0]); | 379 argv[0]); |
| 333 exit(1); | 380 exit(1); |
| 334 } | 381 } |
| 335 | 382 |
| 336 // Control decode bench iterations and packet size. | 383 // Control decode bench iterations and packet size. |
| 337 | 384 |
| 338 size_t iterations = 1; | 385 size_t iterations = 1; |
| 339 if (argc >= 3) { | 386 if (argc >= 3) { |
| 340 char* end = 0; | 387 char* end = 0; |
| 341 iterations = strtol(argv[2], &end, 10); | 388 iterations = strtol(argv[2], &end, 10); |
| 342 if (*end != '\0' || !iterations) { | 389 if (*end != '\0' || !iterations) { |
| 343 fprintf(stderr, | 390 fprintf(stderr, |
| 344 "Second argument should be number of iterations. " | 391 "Second argument should be number of iterations. " |
| 345 "The default is 1. You supplied %s\n", | 392 "The default is 1. You supplied %s\n", |
| 346 argv[2]); | 393 argv[2]); |
| 347 exit(1); | 394 exit(1); |
| 348 } | 395 } |
| 349 } | 396 } |
| 350 | 397 |
| 351 size_t packet_size = 0; | 398 size_t packet_size = 0; |
| 352 if (argc >= 4) { | 399 if (argc >= 4) { |
| 353 char* end = 0; | 400 char* end = 0; |
| 354 packet_size = strtol(argv[3], &end, 10); | 401 packet_size = strtol(argv[3], &end, 10); |
|
scroggo_chromium
2017/05/23 15:57:09
What should happen if a user combines packet_size
cblume
2017/05/23 18:07:31
Packet size should be silently ignored in that cas
scroggo_chromium
2017/05/23 18:41:18
My vote is for an error. Since it shouldn't matter
cblume
2017/05/23 19:18:39
Yeah, I think you're right.
I added an error for i
| |
| 355 if (*end != '\0') { | 402 if (*end != '\0') { |
| 356 fprintf(stderr, | 403 fprintf(stderr, |
| 357 "Third argument should be packet size. Default is " | 404 "Third argument should be packet size. Default is " |
| 358 "0, meaning to decode the entire image in one packet. You " | 405 "0, meaning to decode the entire image in one packet. You " |
| 359 "supplied %s\n", | 406 "supplied %s\n", |
| 360 argv[3]); | 407 argv[3]); |
| 361 exit(1); | 408 exit(1); |
| 362 } | 409 } |
| 363 } | 410 } |
| 364 | 411 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 379 } | 426 } |
| 380 | 427 |
| 381 data->Data(); | 428 data->Data(); |
| 382 | 429 |
| 383 // Image decode bench for iterations. | 430 // Image decode bench for iterations. |
| 384 | 431 |
| 385 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create( | 432 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::Create( |
| 386 data, true, ImageDecoder::kAlphaPremultiplied, | 433 data, true, ImageDecoder::kAlphaPremultiplied, |
| 387 apply_color_correction ? ColorBehavior::TransformToTargetForTesting() | 434 apply_color_correction ? ColorBehavior::TransformToTargetForTesting() |
| 388 : ColorBehavior::Ignore()); | 435 : ColorBehavior::Ignore()); |
| 389 if (packet_size) { | 436 if (time_raster) { |
| 390 TimePacketedDecode(decoder.get(), data.Get(), packet_size, iterations); | 437 TimeRaster(decoder.get(), data.Get(), iterations); |
| 391 } else { | 438 } else { |
| 392 TimeDecode(decoder.get(), data.Get(), iterations); | 439 if (packet_size) { |
| 440 TimePacketedDecode(decoder.get(), data.Get(), packet_size, | |
| 441 iterations); | |
| 442 } else { | |
| 443 TimeDecode(decoder.get(), data.Get(), iterations); | |
| 444 } | |
| 393 } | 445 } |
| 394 | 446 |
| 395 return 0; | 447 return 0; |
| 396 } | 448 } |
| 397 | 449 |
| 398 } // namespace blink | 450 } // namespace blink |
| 399 | 451 |
| 400 int main(int argc, char* argv[]) { | 452 int main(int argc, char* argv[]) { |
| 401 return blink::Main(argc, argv); | 453 return blink::Main(argc, argv); |
| 402 } | 454 } |
| OLD | NEW |