| 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" |
| 11 #include "DMSrcSinkAndroid.h" | 11 #include "DMSrcSinkAndroid.h" |
| 12 #include "ProcStats.h" | 12 #include "ProcStats.h" |
| 13 #include "Resources.h" | 13 #include "Resources.h" |
| 14 #include "SkBBHFactory.h" | 14 #include "SkBBHFactory.h" |
| 15 #include "SkChecksum.h" | 15 #include "SkChecksum.h" |
| 16 #include "SkCodec.h" | 16 #include "SkCodec.h" |
| 17 #include "SkColorPriv.h" |
| 17 #include "SkCommonFlags.h" | 18 #include "SkCommonFlags.h" |
| 18 #include "SkCommonFlagsConfig.h" | 19 #include "SkCommonFlagsConfig.h" |
| 19 #include "SkFontMgr.h" | 20 #include "SkFontMgr.h" |
| 20 #include "SkGraphics.h" | 21 #include "SkGraphics.h" |
| 22 #include "SkHalf.h" |
| 21 #include "SkMD5.h" | 23 #include "SkMD5.h" |
| 22 #include "SkMutex.h" | 24 #include "SkMutex.h" |
| 23 #include "SkOSFile.h" | 25 #include "SkOSFile.h" |
| 26 #include "SkPM4fPriv.h" |
| 24 #include "SkSpinlock.h" | 27 #include "SkSpinlock.h" |
| 25 #include "SkTHash.h" | 28 #include "SkTHash.h" |
| 26 #include "SkTaskGroup.h" | 29 #include "SkTaskGroup.h" |
| 27 #include "SkThreadUtils.h" | 30 #include "SkThreadUtils.h" |
| 28 #include "Test.h" | 31 #include "Test.h" |
| 29 #include "Timer.h" | 32 #include "Timer.h" |
| 30 #include "sk_tool_utils.h" | 33 #include "sk_tool_utils.h" |
| 31 | 34 |
| 32 #ifdef SK_PDF_IMAGE_STATS | 35 #ifdef SK_PDF_IMAGE_STATS |
| 33 extern void SkPDFImageDumpStats(); | 36 extern void SkPDFImageDumpStats(); |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 696 |
| 694 #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink
(__VA_ARGS__); } | 697 #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink
(__VA_ARGS__); } |
| 695 | 698 |
| 696 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 699 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 697 SINK("hwui", HWUISink); | 700 SINK("hwui", HWUISink); |
| 698 #endif | 701 #endif |
| 699 | 702 |
| 700 if (FLAGS_cpu) { | 703 if (FLAGS_cpu) { |
| 701 SINK("565", RasterSink, kRGB_565_SkColorType); | 704 SINK("565", RasterSink, kRGB_565_SkColorType); |
| 702 SINK("8888", RasterSink, kN32_SkColorType); | 705 SINK("8888", RasterSink, kN32_SkColorType); |
| 706 SINK("srgb", RasterSink, kN32_SkColorType, kSRGB_SkColorProfileType); |
| 707 SINK("f16", RasterSink, kRGBA_F16_SkColorType); |
| 703 SINK("pdf", PDFSink, "Pdfium"); | 708 SINK("pdf", PDFSink, "Pdfium"); |
| 704 SINK("pdf_poppler", PDFSink, "Poppler"); | 709 SINK("pdf_poppler", PDFSink, "Poppler"); |
| 705 SINK("skp", SKPSink); | 710 SINK("skp", SKPSink); |
| 706 SINK("svg", SVGSink); | 711 SINK("svg", SVGSink); |
| 707 SINK("null", NullSink); | 712 SINK("null", NullSink); |
| 708 SINK("xps", XPSSink); | 713 SINK("xps", XPSSink); |
| 709 } | 714 } |
| 710 #undef SINK | 715 #undef SINK |
| 711 return nullptr; | 716 return nullptr; |
| 712 } | 717 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 } | 775 } |
| 771 if (sink) { | 776 if (sink) { |
| 772 push_sink(config, sink); | 777 push_sink(config, sink); |
| 773 } | 778 } |
| 774 } | 779 } |
| 775 } | 780 } |
| 776 | 781 |
| 777 static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { | 782 static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 778 const int w = bitmap.width(), | 783 const int w = bitmap.width(), |
| 779 h = bitmap.height(); | 784 h = bitmap.height(); |
| 785 // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too). |
| 786 // We leave the gamma of these bytes unspecified, to continue the status quo
, |
| 787 // which we think generally is to interpret them as sRGB. |
| 780 | 788 |
| 781 // First get the bitmap into N32 color format. The next step will work only
there. | 789 SkAutoTMalloc<uint32_t> rgba(w*h); |
| 782 if (bitmap.colorType() != kN32_SkColorType) { | 790 |
| 783 SkBitmap n32; | 791 if (bitmap. colorType() == kN32_SkColorType && |
| 784 if (!bitmap.copyTo(&n32, kN32_SkColorType)) { | 792 bitmap.profileType() == kSRGB_SkColorProfileType) { |
| 793 // These are premul sRGB 8-bit pixels in SkPMColor order. |
| 794 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there vi
a floats. |
| 795 bitmap.lockPixels(); |
| 796 auto px = (const uint32_t*)bitmap.getPixels(); |
| 797 if (!px) { |
| 785 return false; | 798 return false; |
| 786 } | 799 } |
| 787 bitmap = n32; | 800 for (int i = 0; i < w*h; i++) { |
| 788 } | 801 Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear float
s. |
| 802 #if defined(SK_PMCOLOR_IS_BGRA) |
| 803 fs = SkNx_shuffle<2,1,0,3>(fs); // Shuffle to RGBA, if not th
ere already. |
| 804 #endif |
| 805 float invA = 1.0f / fs[3]; |
| 806 fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. |
| 807 rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. |
| 808 } |
| 789 | 809 |
| 790 // Convert our N32 bitmap into unpremul RGBA for libpng. | 810 } else if (bitmap.colorType() == kRGBA_F16_SkColorType) { |
| 791 SkAutoTMalloc<uint32_t> rgba(w*h); | 811 // These are premul linear half-float pixels in RGBA order. |
| 792 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpre
mul_SkAlphaType), | 812 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there vi
a floats. |
| 793 rgba, 4*w, 0,0)) { | 813 bitmap.lockPixels(); |
| 794 return false; | 814 auto px = (const uint64_t*)bitmap.getPixels(); |
| 815 if (!px) { |
| 816 return false; |
| 817 } |
| 818 for (int i = 0; i < w*h; i++) { |
| 819 Sk4f fs = SkHalfToFloat_01(px[i]); // Convert up to linear floats
. |
| 820 float invA = 1.0f / fs[3]; |
| 821 fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. |
| 822 rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. |
| 823 } |
| 824 |
| 825 |
| 826 } else { |
| 827 // We "should" gamma correct in here but we don't. |
| 828 // We want Gold to show exactly what our clients are seeing, broken gamm
a. |
| 829 |
| 830 // Convert smaller formats up to premul linear 8-bit (in SkPMColor order
). |
| 831 if (bitmap.colorType() != kN32_SkColorType) { |
| 832 SkBitmap n32; |
| 833 if (!bitmap.copyTo(&n32, kN32_SkColorType)) { |
| 834 return false; |
| 835 } |
| 836 bitmap = n32; |
| 837 } |
| 838 |
| 839 // Convert premul linear 8-bit to unpremul linear 8-bit RGBA. |
| 840 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, |
| 841 kUnpremul_SkAlphaType), |
| 842 rgba, 4*w, 0,0)) { |
| 843 return false; |
| 844 } |
| 795 } | 845 } |
| 796 | 846 |
| 797 // We don't need bitmap anymore. Might as well drop our ref. | 847 // We don't need bitmap anymore. Might as well drop our ref. |
| 798 bitmap.reset(); | 848 bitmap.reset(); |
| 799 | 849 |
| 800 FILE* f = fopen(path, "wb"); | 850 FILE* f = fopen(path, "wb"); |
| 801 if (!f) { return false; } | 851 if (!f) { return false; } |
| 802 | 852 |
| 803 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nu
llptr, nullptr); | 853 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nu
llptr, nullptr); |
| 804 if (!png) { | 854 if (!png) { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 Reporter* reporter, | 1335 Reporter* reporter, |
| 1286 GrContextFactory* fac
tory); | 1336 GrContextFactory* fac
tory); |
| 1287 } // namespace skiatest | 1337 } // namespace skiatest |
| 1288 | 1338 |
| 1289 #if !defined(SK_BUILD_FOR_IOS) | 1339 #if !defined(SK_BUILD_FOR_IOS) |
| 1290 int main(int argc, char** argv) { | 1340 int main(int argc, char** argv) { |
| 1291 SkCommandLineFlags::Parse(argc, argv); | 1341 SkCommandLineFlags::Parse(argc, argv); |
| 1292 return dm_main(); | 1342 return dm_main(); |
| 1293 } | 1343 } |
| 1294 #endif | 1344 #endif |
| OLD | NEW |