Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecodeBench.cpp

Issue 1954673002: Make ImageDecodeBench build again (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix linux_chromium_rel_ng nit. #2 Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "platform/SharedBuffer.h" 20 #include "platform/SharedBuffer.h"
21 #include "platform/image-decoders/ImageDecoder.h" 21 #include "platform/image-decoders/ImageDecoder.h"
22 #include "platform/testing/TestingPlatformSupport.h"
23 #include "public/platform/Platform.h" 22 #include "public/platform/Platform.h"
24 #include "public/web/WebKit.h"
25 #include "wtf/OwnPtr.h" 23 #include "wtf/OwnPtr.h"
26 #include "wtf/PassRefPtr.h" 24 #include "wtf/PassRefPtr.h"
25 #include <base/command_line.h>
Noel Gordon 2016/05/05 13:25:54 Using <base/command_line.h> defeats the DEPS check
27 26
28 #if defined(_WIN32) 27 #if defined(_WIN32)
29 #if defined(WIN32_LEAN_AND_MEAN)
30 #error Fix: WIN32_LEAN_AND_MEAN disables timeBeginPeriod/TimeEndPeriod.
31 #endif
32 #include <mmsystem.h> 28 #include <mmsystem.h>
33 #include <sys/stat.h> 29 #include <sys/stat.h>
34 #include <time.h> 30 #include <time.h>
35 #define stat(x,y) _stat(x,y) 31 #define stat(x,y) _stat(x,y)
36 typedef struct _stat sttype; 32 typedef struct _stat sttype;
37 #else 33 #else
38 #include <sys/stat.h> 34 #include <sys/stat.h>
39 #include <sys/time.h> 35 #include <sys/time.h>
40 typedef struct stat sttype; 36 typedef struct stat sttype;
41 #endif 37 #endif
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 int frameCount = decoder->frameCount(); 269 int frameCount = decoder->frameCount();
274 for (int i = 0; i < frameCount; ++i) { 270 for (int i = 0; i < frameCount; ++i) {
275 if (!decoder->frameBufferAtIndex(i)) 271 if (!decoder->frameBufferAtIndex(i))
276 return false; 272 return false;
277 } 273 }
278 274
279 return !decoder->failed(); 275 return !decoder->failed();
280 } 276 }
281 277
282 RefPtr<SharedBuffer> packetData = SharedBuffer::create(); 278 RefPtr<SharedBuffer> packetData = SharedBuffer::create();
283 unsigned position = 0; 279 size_t position = 0;
284 while (true) { 280 while (true) {
285 const char* packet; 281 const char* packet;
286 unsigned length = data->getSomeData(packet, position); 282 size_t length = data->getSomeData(packet, position);
287 283
288 length = std::min(static_cast<size_t>(length), packetSize); 284 length = std::min(length, packetSize);
289 packetData->append(packet, length); 285 packetData->append(packet, length);
290 position += length; 286 position += length;
291 287
292 bool allDataReceived = position == data->size(); 288 bool allDataReceived = position == data->size();
293 decoder->setData(packetData.get(), allDataReceived); 289 decoder->setData(packetData.get(), allDataReceived);
294 290
295 int frameCount = decoder->frameCount(); 291 int frameCount = decoder->frameCount();
296 for (int i = 0; i < frameCount; ++i) { 292 for (int i = 0; i < frameCount; ++i) {
297 if (!decoder->frameBufferAtIndex(i)) 293 if (!decoder->frameBufferAtIndex(i))
298 break; 294 break;
299 } 295 }
300 296
301 if (allDataReceived || decoder->failed()) 297 if (allDataReceived || decoder->failed())
302 break; 298 break;
303 } 299 }
304 300
305 return !decoder->failed(); 301 return !decoder->failed();
306 } 302 }
307 303
308 int main(int argc, char* argv[]) 304 int main(int argc, char* argv[])
309 { 305 {
310 char* name = argv[0]; 306 base::CommandLine::Init(argc, argv);
311 307
312 // If the platform supports color correction, allow it to be controlled. 308 // If the platform supports color correction, allow it to be controlled.
313 309
314 bool applyColorCorrection = false; 310 bool applyColorCorrection = false;
315 311
316 #if USE(QCMSLIB) 312 #if USE(QCMSLIB)
317 if (argc >= 2 && strcmp(argv[1], "--color-correct") == 0) 313 if (argc >= 2 && strcmp(argv[1], "--color-correct") == 0)
318 applyColorCorrection = (--argc, ++argv, true); 314 applyColorCorrection = (--argc, ++argv, true);
319 315
320 if (argc < 2) { 316 if (argc < 2) {
321 fprintf(stderr, "Usage: %s [--color-correct] file [iterations] [packetSi ze]\n", name); 317 fprintf(stderr, "Usage: %s [--color-correct] file [iterations] [packetSi ze]\n", argv[0]);
322 exit(1); 318 exit(1);
323 } 319 }
324 #else 320 #else
325 if (argc < 2) { 321 if (argc < 2) {
326 fprintf(stderr, "Usage: %s file [iterations] [packetSize]\n", name); 322 fprintf(stderr, "Usage: %s file [iterations] [packetSize]\n", argv[0]);
327 exit(1); 323 exit(1);
328 } 324 }
329 #endif 325 #endif
330 326
331 // Control decode bench iterations and packet size. 327 // Control decode bench iterations and packet size.
332 328
333 size_t iterations = 1; 329 size_t iterations = 1;
334 if (argc >= 3) { 330 if (argc >= 3) {
335 char* end = 0; 331 char* end = 0;
336 iterations = strtol(argv[2], &end, 10); 332 iterations = strtol(argv[2], &end, 10);
(...skipping 11 matching lines...) Expand all
348 if (*end != '\0') { 344 if (*end != '\0') {
349 fprintf(stderr, "Third argument should be packet size. Default is " 345 fprintf(stderr, "Third argument should be packet size. Default is "
350 "0, meaning to decode the entire image in one packet. You " 346 "0, meaning to decode the entire image in one packet. You "
351 "supplied %s\n", argv[3]); 347 "supplied %s\n", argv[3]);
352 exit(1); 348 exit(1);
353 } 349 }
354 } 350 }
355 351
356 // Create a web platform without V8. 352 // Create a web platform without V8.
357 353
358 class WebPlatform : public TestingPlatformSupport { 354 class WebPlatform : public blink::Platform {
359 public: 355 public:
360 void screenColorProfile(WebVector<char>* profile) override 356 void screenColorProfile(WebVector<char>* profile) override
361 { 357 {
362 getScreenColorProfile(profile); // Returns a whacked color profile. 358 getScreenColorProfile(profile); // Returns a whacked color profile.
363 } 359 }
364 }; 360 };
365 361
366 Platform::initialize(new WebPlatform()); 362 Platform::initialize(new WebPlatform());
367 363
368 // Set image decoding Platform options. 364 // Read entire file content to data, and consolidate the SharedBuffer data
369 365 // segments into one, contiguous block of memory.
370 #if USE(QCMSLIB)
371 ImageDecoder::qcmsOutputDeviceProfile(); // Initialize screen colorProfile.
372 #endif
373
374 // Read entire file content to data.
375 366
376 RefPtr<SharedBuffer> data = readFile(argv[1]); 367 RefPtr<SharedBuffer> data = readFile(argv[1]);
377 if (!data.get() || !data->size()) { 368 if (!data.get() || !data->size()) {
378 fprintf(stderr, "Error reading image data from [%s]\n", argv[1]); 369 fprintf(stderr, "Error reading image data from [%s]\n", argv[1]);
379 exit(2); 370 exit(2);
380 } 371 }
381 372
382 // Consolidate the SharedBuffer data segments into one, contiguous block of memory.
383 data->data(); 373 data->data();
384 374
375 // Warm-up: throw out the first iteration for more consistent results.
376
377 if (!decodeImageData(data.get(), applyColorCorrection, packetSize)) {
378 fprintf(stderr, "Image decode failed [%s]\n", argv[1]);
379 exit(3);
380 }
381
385 // Image decode bench for iterations. 382 // Image decode bench for iterations.
386 383
387 double totalTime = 0.0; 384 double totalTime = 0.0;
388 385
389 for (size_t i = 0; i < iterations; ++i) { 386 for (size_t i = 0; i < iterations; ++i) {
390 double startTime = getCurrentTime(); 387 double startTime = getCurrentTime();
391 bool decoded = decodeImageData(data.get(), applyColorCorrection, packetS ize); 388 bool decoded = decodeImageData(data.get(), applyColorCorrection, packetS ize);
392 double elapsedTime = getCurrentTime() - startTime; 389 double elapsedTime = getCurrentTime() - startTime;
393 totalTime += elapsedTime; 390 totalTime += elapsedTime;
394 if (!decoded) { 391 if (!decoded) {
395 fprintf(stderr, "Image decode failed [%s]\n", argv[1]); 392 fprintf(stderr, "Image decode failed [%s]\n", argv[1]);
396 exit(3); 393 exit(3);
397 } 394 }
398 } 395 }
399 396
400 // Results to stdout. 397 // Results to stdout.
401 398
402 double averageTime = totalTime / static_cast<double>(iterations); 399 double averageTime = totalTime / static_cast<double>(iterations);
403 printf("%f %f\n", totalTime, averageTime); 400 printf("%f %f\n", totalTime, averageTime);
404 return 0; 401 return 0;
405 } 402 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/blink_platform_tests.gyp ('k') | third_party/WebKit/Source/web/ImageDecodeBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698