OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "CrashHandler.h" | 8 #include "CrashHandler.h" |
9 #include "DMJsonWriter.h" | 9 #include "DMJsonWriter.h" |
10 #include "DMSrcSink.h" | 10 #include "DMSrcSink.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "SkMD5.h" | 21 #include "SkMD5.h" |
22 #include "SkMutex.h" | 22 #include "SkMutex.h" |
23 #include "SkOSFile.h" | 23 #include "SkOSFile.h" |
24 #include "SkTHash.h" | 24 #include "SkTHash.h" |
25 #include "SkTaskGroup.h" | 25 #include "SkTaskGroup.h" |
26 #include "SkThreadUtils.h" | 26 #include "SkThreadUtils.h" |
27 #include "Test.h" | 27 #include "Test.h" |
28 #include "Timer.h" | 28 #include "Timer.h" |
29 #include "sk_tool_utils.h" | 29 #include "sk_tool_utils.h" |
30 | 30 |
31 #ifdef SKIA_PNG_PREFIXED | |
32 // this must proceed png.h | |
33 #include "pngprefix.h" | |
34 #endif | |
35 #include "png.h" | |
36 | |
37 DEFINE_string(src, "tests gm skp image", "Source types to test."); | 31 DEFINE_string(src, "tests gm skp image", "Source types to test."); |
38 DEFINE_bool(nameByHash, false, | 32 DEFINE_bool(nameByHash, false, |
39 "If true, write to FLAGS_writePath[0]/<hash>.png instead of " | 33 "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
40 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.
png"); | 34 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.
png"); |
41 DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); | 35 DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
42 DEFINE_string(matrix, "1 0 0 1", | 36 DEFINE_string(matrix, "1 0 0 1", |
43 "2x2 scale+skew matrix to apply or upright when using " | 37 "2x2 scale+skew matrix to apply or upright when using " |
44 "'matrix' or 'upright' in config."); | 38 "'matrix' or 'upright' in config."); |
45 DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); | 39 DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); |
46 | 40 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 break; | 460 break; |
467 } | 461 } |
468 sink = next; | 462 sink = next; |
469 } | 463 } |
470 if (sink) { | 464 if (sink) { |
471 push_sink(config, sink); | 465 push_sink(config, sink); |
472 } | 466 } |
473 } | 467 } |
474 } | 468 } |
475 | 469 |
476 static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { | |
477 // Covert whatever we've been passed to RGBA, to make unpremultiplying each
row for PNG easy. | |
478 { | |
479 SkBitmap n32; | |
480 if (!bitmap.copyTo(&n32, kRGBA_8888_SkColorType)) { | |
481 return false; | |
482 } | |
483 bitmap = n32; | |
484 } | |
485 | |
486 FILE* f = fopen(path, "w"); | |
487 if (!f) { return false; } | |
488 | |
489 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nu
llptr, nullptr); | |
490 if (!png) { | |
491 fclose(f); | |
492 return false; | |
493 } | |
494 | |
495 png_infop info = png_create_info_struct(png); | |
496 if (!info) { | |
497 png_destroy_write_struct(&png, &info); | |
498 fclose(f); | |
499 return false; | |
500 } | |
501 | |
502 png_text text[2]; | |
503 text[0].key = (png_charp)"Author"; | |
504 text[0].text = (png_charp)"DM dump_png()"; | |
505 text[0].compression = PNG_TEXT_COMPRESSION_NONE; | |
506 text[1].key = (png_charp)"Description"; | |
507 text[1].text = (png_charp)md5; | |
508 text[1].compression = PNG_TEXT_COMPRESSION_NONE; | |
509 png_set_text(png, info, text, 2); | |
510 | |
511 png_init_io(png, f); | |
512 png_set_IHDR(png, info, (png_uint_32)bitmap.width(), (png_uint_32)bitmap.hei
ght(), 8, | |
513 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, | |
514 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
515 png_write_info(png, info); | |
516 | |
517 SkAutoLockPixels alp(bitmap); | |
518 SkAutoSTMalloc<1024, uint32_t> row(bitmap.width()); | |
519 for (int j = 0; j < bitmap.height(); j++) { | |
520 // Convert the row to unpremultiplied RGBA uint32_t. | |
521 const SkPMColor* pm = bitmap.getAddr32(0,j); | |
522 for (int i = 0; i < bitmap.width(); i++) { | |
523 row[i] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(pm[i]); | |
524 } | |
525 | |
526 png_bytep row_ptr = (png_bytep)row.get(); | |
527 png_write_rows(png, &row_ptr, 1); | |
528 } | |
529 png_write_end(png, info); | |
530 | |
531 png_destroy_write_struct(&png, &info); | |
532 fclose(f); | |
533 return true; | |
534 } | |
535 | |
536 static bool match(const char* needle, const char* haystack) { | 470 static bool match(const char* needle, const char* haystack) { |
537 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); | 471 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); |
538 } | 472 } |
539 | 473 |
540 static ImplicitString is_blacklisted(const char* sink, const char* src, | 474 static ImplicitString is_blacklisted(const char* sink, const char* src, |
541 const char* srcOptions, const char* name) { | 475 const char* srcOptions, const char* name) { |
542 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { | 476 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
543 if (match(FLAGS_blacklist[i+0], sink) && | 477 if (match(FLAGS_blacklist[i+0], sink) && |
544 match(FLAGS_blacklist[i+1], src) && | 478 match(FLAGS_blacklist[i+1], src) && |
545 match(FLAGS_blacklist[i+2], srcOptions) && | 479 match(FLAGS_blacklist[i+2], srcOptions) && |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 sk_mkdir(path.c_str()); | 629 sk_mkdir(path.c_str()); |
696 if (strcmp(task.src.options, "") != 0) { | 630 if (strcmp(task.src.options, "") != 0) { |
697 path = SkOSPath::Join(path.c_str(), task.src.options); | 631 path = SkOSPath::Join(path.c_str(), task.src.options); |
698 sk_mkdir(path.c_str()); | 632 sk_mkdir(path.c_str()); |
699 } | 633 } |
700 path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); | 634 path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
701 path.append("."); | 635 path.append("."); |
702 path.append(ext); | 636 path.append(ext); |
703 } | 637 } |
704 | 638 |
| 639 SkFILEWStream file(path.c_str()); |
| 640 if (!file.isValid()) { |
| 641 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 642 return; |
| 643 } |
| 644 |
705 if (bitmap) { | 645 if (bitmap) { |
706 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { | 646 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 647 SkBitmap converted; |
| 648 if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 649 if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 650 fail("Can't convert A8 to 8888.\n"); |
| 651 return; |
| 652 } |
| 653 bitmap = &converted; |
| 654 } |
| 655 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kP
NG_Type, 100)) { |
707 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); | 656 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
708 return; | 657 return; |
709 } | 658 } |
710 } else { | 659 } else { |
711 SkFILEWStream file(path.c_str()); | |
712 if (!file.isValid()) { | |
713 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()
)); | |
714 return; | |
715 } | |
716 if (!file.writeStream(data, len)) { | 660 if (!file.writeStream(data, len)) { |
717 fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); | 661 fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
718 return; | 662 return; |
719 } | 663 } |
720 } | 664 } |
721 } | 665 } |
722 }; | 666 }; |
723 | 667 |
724 // Run all tasks in the same enclave serially on the same thread. | 668 // Run all tasks in the same enclave serially on the same thread. |
725 // They can't possibly run concurrently with each other. | 669 // They can't possibly run concurrently with each other. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 } | 849 } |
906 return 0; | 850 return 0; |
907 } | 851 } |
908 | 852 |
909 #if !defined(SK_BUILD_FOR_IOS) | 853 #if !defined(SK_BUILD_FOR_IOS) |
910 int main(int argc, char** argv) { | 854 int main(int argc, char** argv) { |
911 SkCommandLineFlags::Parse(argc, argv); | 855 SkCommandLineFlags::Parse(argc, argv); |
912 return dm_main(); | 856 return dm_main(); |
913 } | 857 } |
914 #endif | 858 #endif |
OLD | NEW |