| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 /* | 8 /* |
| 9 * Code for the "gm" (Golden Master) rendering comparison tool. | 9 * Code for the "gm" (Golden Master) rendering comparison tool. |
| 10 * | 10 * |
| 11 * If you make changes to this, re-run the self-tests at gm/tests/run.sh | 11 * If you make changes to this, re-run the self-tests at gm/tests/run.sh |
| 12 * to make sure they still pass... you may need to change the expected | 12 * to make sure they still pass... you may need to change the expected |
| 13 * results of the self-test. | 13 * results of the self-test. |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include "gm.h" | 16 #include "gm.h" |
| 17 #include "gm_error.h" | 17 #include "gm_error.h" |
| 18 #include "gm_expectations.h" | 18 #include "gm_expectations.h" |
| 19 #include "system_preferences.h" | 19 #include "system_preferences.h" |
| 20 #include "SkBitmap.h" | 20 #include "SkBitmap.h" |
| 21 #include "SkBitmapHasher.h" | |
| 22 #include "SkColorPriv.h" | 21 #include "SkColorPriv.h" |
| 23 #include "SkCommandLineFlags.h" | 22 #include "SkCommandLineFlags.h" |
| 24 #include "SkData.h" | 23 #include "SkData.h" |
| 25 #include "SkDeferredCanvas.h" | 24 #include "SkDeferredCanvas.h" |
| 26 #include "SkDevice.h" | 25 #include "SkDevice.h" |
| 27 #include "SkDrawFilter.h" | 26 #include "SkDrawFilter.h" |
| 28 #include "SkGPipe.h" | 27 #include "SkGPipe.h" |
| 29 #include "SkGraphics.h" | 28 #include "SkGraphics.h" |
| 30 #include "SkImageDecoder.h" | 29 #include "SkImageDecoder.h" |
| 31 #include "SkImageEncoder.h" | 30 #include "SkImageEncoder.h" |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 * results to the JSON summary. (This is so that we will always | 742 * results to the JSON summary. (This is so that we will always |
| 744 * report errors across rendering modes, such as pipe vs tiled. | 743 * report errors across rendering modes, such as pipe vs tiled. |
| 745 * See https://codereview.chromium.org/13650002/ ) | 744 * See https://codereview.chromium.org/13650002/ ) |
| 746 */ | 745 */ |
| 747 ErrorCombination compare_to_expectations(Expectations expectations, | 746 ErrorCombination compare_to_expectations(Expectations expectations, |
| 748 const SkBitmap& actualBitmap, | 747 const SkBitmap& actualBitmap, |
| 749 const char *shortName, const char *
configName, | 748 const char *shortName, const char *
configName, |
| 750 const char *renderModeDescriptor, | 749 const char *renderModeDescriptor, |
| 751 bool addToJsonSummary) { | 750 bool addToJsonSummary) { |
| 752 ErrorCombination errors; | 751 ErrorCombination errors; |
| 753 SkHashDigest actualBitmapHash; | 752 GmResultDigest actualResultDigest(actualBitmap); |
| 754 // TODO(epoger): Better handling for error returned by ComputeDigest()? | |
| 755 // For now, we just report a digest of 0 in error cases, like before. | |
| 756 if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { | |
| 757 actualBitmapHash = 0; | |
| 758 } | |
| 759 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, con
figName); | 753 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, con
figName); |
| 760 SkString completeNameString(shortNamePlusConfig); | 754 SkString completeNameString(shortNamePlusConfig); |
| 761 completeNameString.append(renderModeDescriptor); | 755 completeNameString.append(renderModeDescriptor); |
| 762 completeNameString.append("."); | 756 completeNameString.append("."); |
| 763 completeNameString.append(kPNG_FileExtension); | 757 completeNameString.append(kPNG_FileExtension); |
| 764 const char* completeName = completeNameString.c_str(); | 758 const char* completeName = completeNameString.c_str(); |
| 765 | 759 |
| 766 if (expectations.empty()) { | 760 if (expectations.empty()) { |
| 767 errors.add(kMissingExpectations_ErrorType); | 761 errors.add(kMissingExpectations_ErrorType); |
| 768 } else if (!expectations.match(actualBitmapHash)) { | 762 } else if (!expectations.match(actualResultDigest)) { |
| 769 addToJsonSummary = true; | 763 addToJsonSummary = true; |
| 770 // The error mode we record depends on whether this was running | 764 // The error mode we record depends on whether this was running |
| 771 // in a non-standard renderMode. | 765 // in a non-standard renderMode. |
| 772 if ('\0' == *renderModeDescriptor) { | 766 if ('\0' == *renderModeDescriptor) { |
| 773 errors.add(kExpectationsMismatch_ErrorType); | 767 errors.add(kExpectationsMismatch_ErrorType); |
| 774 } else { | 768 } else { |
| 775 errors.add(kRenderModeMismatch_ErrorType); | 769 errors.add(kRenderModeMismatch_ErrorType); |
| 776 } | 770 } |
| 777 | 771 |
| 778 // Write out the "actuals" for any mismatches, if we have | 772 // Write out the "actuals" for any mismatches, if we have |
| 779 // been directed to do so. | 773 // been directed to do so. |
| 780 if (fMismatchPath) { | 774 if (fMismatchPath) { |
| 781 SkString path = | 775 SkString path = |
| 782 make_filename(fMismatchPath, shortName, configName, renderMo
deDescriptor, | 776 make_filename(fMismatchPath, shortName, configName, renderMo
deDescriptor, |
| 783 kPNG_FileExtension); | 777 kPNG_FileExtension); |
| 784 write_bitmap(path, actualBitmap); | 778 write_bitmap(path, actualBitmap); |
| 785 } | 779 } |
| 786 | 780 |
| 787 // If we have access to a single expected bitmap, log more | 781 // If we have access to a single expected bitmap, log more |
| 788 // detail about the mismatch. | 782 // detail about the mismatch. |
| 789 const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); | 783 const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); |
| 790 if (NULL != expectedBitmapPtr) { | 784 if (NULL != expectedBitmapPtr) { |
| 791 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeNa
me); | 785 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeNa
me); |
| 792 } | 786 } |
| 793 } | 787 } |
| 794 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor); | 788 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor); |
| 795 | 789 |
| 796 if (addToJsonSummary) { | 790 if (addToJsonSummary) { |
| 797 add_actual_results_to_json_summary(completeName, actualBitmapHash, e
rrors, | 791 add_actual_results_to_json_summary(completeName, actualResultDigest,
errors, |
| 798 expectations.ignoreFailure()); | 792 expectations.ignoreFailure()); |
| 799 add_expected_results_to_json_summary(completeName, expectations); | 793 add_expected_results_to_json_summary(completeName, expectations); |
| 800 } | 794 } |
| 801 | 795 |
| 802 return errors; | 796 return errors; |
| 803 } | 797 } |
| 804 | 798 |
| 805 /** | 799 /** |
| 806 * Add this result to the appropriate JSON collection of actual results, | 800 * Add this result to the appropriate JSON collection of actual results, |
| 807 * depending on errors encountered. | 801 * depending on errors encountered. |
| 808 */ | 802 */ |
| 809 void add_actual_results_to_json_summary(const char testName[], | 803 void add_actual_results_to_json_summary(const char testName[], |
| 810 const SkHashDigest& actualResult, | 804 const GmResultDigest &actualResultDi
gest, |
| 811 ErrorCombination errors, | 805 ErrorCombination errors, |
| 812 bool ignoreFailure) { | 806 bool ignoreFailure) { |
| 813 Json::Value jsonActualResults = ActualResultAsJsonValue(actualResult); | 807 Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair()
; |
| 814 if (errors.isEmpty()) { | 808 if (errors.isEmpty()) { |
| 815 this->fJsonActualResults_Succeeded[testName] = jsonActualResults; | 809 this->fJsonActualResults_Succeeded[testName] = jsonActualResults; |
| 816 } else { | 810 } else { |
| 817 if (ignoreFailure) { | 811 if (ignoreFailure) { |
| 818 // TODO: Once we have added the ability to compare | 812 // TODO: Once we have added the ability to compare |
| 819 // actual results against expectations in a JSON file | 813 // actual results against expectations in a JSON file |
| 820 // (where we can set ignore-failure to either true or | 814 // (where we can set ignore-failure to either true or |
| 821 // false), add test cases that exercise ignored | 815 // false), add test cases that exercise ignored |
| 822 // failures (both for kMissingExpectations_ErrorType | 816 // failures (both for kMissingExpectations_ErrorType |
| 823 // and kExpectationsMismatch_ErrorType). | 817 // and kExpectationsMismatch_ErrorType). |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 * hash digest of actualBitmap, which *has* been run through | 883 * hash digest of actualBitmap, which *has* been run through |
| 890 * force_all_opaque(). | 884 * force_all_opaque(). |
| 891 * See comments above complete_bitmap() for more detail. | 885 * See comments above complete_bitmap() for more detail. |
| 892 */ | 886 */ |
| 893 Expectations expectations = expectationsSource->get(nameWithExtensio
n.c_str()); | 887 Expectations expectations = expectationsSource->get(nameWithExtensio
n.c_str()); |
| 894 errors.add(compare_to_expectations(expectations, actualBitmap, | 888 errors.add(compare_to_expectations(expectations, actualBitmap, |
| 895 gm->shortName(), gRec.fName, "",
true)); | 889 gm->shortName(), gRec.fName, "",
true)); |
| 896 } else { | 890 } else { |
| 897 // If we are running without expectations, we still want to | 891 // If we are running without expectations, we still want to |
| 898 // record the actual results. | 892 // record the actual results. |
| 899 SkHashDigest actualBitmapHash; | 893 GmResultDigest actualResultDigest(actualBitmap); |
| 900 // TODO(epoger): Better handling for error returned by ComputeDigest
()? | 894 add_actual_results_to_json_summary(nameWithExtension.c_str(), actual
ResultDigest, |
| 901 // For now, we just report a digest of 0 in error cases, like before
. | |
| 902 if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash))
{ | |
| 903 actualBitmapHash = 0; | |
| 904 } | |
| 905 add_actual_results_to_json_summary(nameWithExtension.c_str(), actual
BitmapHash, | |
| 906 ErrorCombination(kMissingExpectat
ions_ErrorType), | 895 ErrorCombination(kMissingExpectat
ions_ErrorType), |
| 907 false); | 896 false); |
| 908 RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType), | 897 RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType), |
| 909 shortNamePlusConfig, ""); | 898 shortNamePlusConfig, ""); |
| 910 } | 899 } |
| 911 | 900 |
| 912 // TODO: Consider moving this into compare_to_expectations(), | 901 // TODO: Consider moving this into compare_to_expectations(), |
| 913 // similar to fMismatchPath... for now, we don't do that, because | 902 // similar to fMismatchPath... for now, we don't do that, because |
| 914 // we don't want to write out the actual bitmaps for all | 903 // we don't want to write out the actual bitmaps for all |
| 915 // renderModes of all tests! That would be a lot of files. | 904 // renderModes of all tests! That would be a lot of files. |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 if (FLAGS_forceBWtext) { | 2078 if (FLAGS_forceBWtext) { |
| 2090 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2079 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2091 } | 2080 } |
| 2092 } | 2081 } |
| 2093 | 2082 |
| 2094 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2083 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 2095 int main(int argc, char * const argv[]) { | 2084 int main(int argc, char * const argv[]) { |
| 2096 return tool_main(argc, (char**) argv); | 2085 return tool_main(argc, (char**) argv); |
| 2097 } | 2086 } |
| 2098 #endif | 2087 #endif |
| OLD | NEW |