| 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 * |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 ErrorCombination write_reference_image(const ConfigData& gRec, const char wr
itePath [], | 600 ErrorCombination write_reference_image(const ConfigData& gRec, const char wr
itePath [], |
| 601 const char renderModeDescriptor [], c
onst SkString& name, | 601 const char renderModeDescriptor [], c
onst SkString& name, |
| 602 SkBitmap& bitmap, SkDynamicMemoryWStr
eam* document) { | 602 SkBitmap& bitmap, SkDynamicMemoryWStr
eam* document) { |
| 603 SkString path; | 603 SkString path; |
| 604 bool success = false; | 604 bool success = false; |
| 605 if (gRec.fBackend == kRaster_Backend || | 605 if (gRec.fBackend == kRaster_Backend || |
| 606 gRec.fBackend == kGPU_Backend || | 606 gRec.fBackend == kGPU_Backend || |
| 607 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { | 607 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { |
| 608 | 608 |
| 609 path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 609 path = make_filename(writePath, renderModeDescriptor, name.c_str(), |
| 610 "png"); | 610 kPNG_FileExtension); |
| 611 success = write_bitmap(path, bitmap); | 611 success = write_bitmap(path, bitmap); |
| 612 } | 612 } |
| 613 if (kPDF_Backend == gRec.fBackend) { | 613 if (kPDF_Backend == gRec.fBackend) { |
| 614 path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 614 path = make_filename(writePath, renderModeDescriptor, name.c_str(), |
| 615 "pdf"); | 615 "pdf"); |
| 616 success = write_document(path, *document); | 616 success = write_document(path, *document); |
| 617 } | 617 } |
| 618 if (kXPS_Backend == gRec.fBackend) { | 618 if (kXPS_Backend == gRec.fBackend) { |
| 619 path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 619 path = make_filename(writePath, renderModeDescriptor, name.c_str(), |
| 620 "xps"); | 620 "xps"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 bool addToJsonSummary) { | 720 bool addToJsonSummary) { |
| 721 ErrorCombination errors; | 721 ErrorCombination errors; |
| 722 SkHashDigest actualBitmapHash; | 722 SkHashDigest actualBitmapHash; |
| 723 // TODO(epoger): Better handling for error returned by ComputeDigest()? | 723 // TODO(epoger): Better handling for error returned by ComputeDigest()? |
| 724 // For now, we just report a digest of 0 in error cases, like before. | 724 // For now, we just report a digest of 0 in error cases, like before. |
| 725 if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { | 725 if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { |
| 726 actualBitmapHash = 0; | 726 actualBitmapHash = 0; |
| 727 } | 727 } |
| 728 SkString completeNameString = baseNameString; | 728 SkString completeNameString = baseNameString; |
| 729 completeNameString.append(renderModeDescriptor); | 729 completeNameString.append(renderModeDescriptor); |
| 730 completeNameString.append("."); |
| 731 completeNameString.append(kPNG_FileExtension); |
| 730 const char* completeName = completeNameString.c_str(); | 732 const char* completeName = completeNameString.c_str(); |
| 731 | 733 |
| 732 if (expectations.empty()) { | 734 if (expectations.empty()) { |
| 733 errors.add(kMissingExpectations_ErrorType); | 735 errors.add(kMissingExpectations_ErrorType); |
| 734 } else if (!expectations.match(actualBitmapHash)) { | 736 } else if (!expectations.match(actualBitmapHash)) { |
| 735 addToJsonSummary = true; | 737 addToJsonSummary = true; |
| 736 // The error mode we record depends on whether this was running | 738 // The error mode we record depends on whether this was running |
| 737 // in a non-standard renderMode. | 739 // in a non-standard renderMode. |
| 738 if ('\0' == *renderModeDescriptor) { | 740 if ('\0' == *renderModeDescriptor) { |
| 739 errors.add(kExpectationsMismatch_ErrorType); | 741 errors.add(kExpectationsMismatch_ErrorType); |
| 740 } else { | 742 } else { |
| 741 errors.add(kRenderModeMismatch_ErrorType); | 743 errors.add(kRenderModeMismatch_ErrorType); |
| 742 } | 744 } |
| 743 | 745 |
| 744 // Write out the "actuals" for any mismatches, if we have | 746 // Write out the "actuals" for any mismatches, if we have |
| 745 // been directed to do so. | 747 // been directed to do so. |
| 746 if (fMismatchPath) { | 748 if (fMismatchPath) { |
| 747 SkString path = | 749 SkString path = |
| 748 make_filename(fMismatchPath, renderModeDescriptor, | 750 make_filename(fMismatchPath, renderModeDescriptor, |
| 749 baseNameString.c_str(), "png"); | 751 baseNameString.c_str(), kPNG_FileExtension); |
| 750 write_bitmap(path, actualBitmap); | 752 write_bitmap(path, actualBitmap); |
| 751 } | 753 } |
| 752 | 754 |
| 753 // If we have access to a single expected bitmap, log more | 755 // If we have access to a single expected bitmap, log more |
| 754 // detail about the mismatch. | 756 // detail about the mismatch. |
| 755 const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); | 757 const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); |
| 756 if (NULL != expectedBitmapPtr) { | 758 if (NULL != expectedBitmapPtr) { |
| 757 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeNa
me); | 759 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeNa
me); |
| 758 } | 760 } |
| 759 } | 761 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 name, "", true)); | 860 name, "", true)); |
| 859 } else { | 861 } else { |
| 860 // If we are running without expectations, we still want to | 862 // If we are running without expectations, we still want to |
| 861 // record the actual results. | 863 // record the actual results. |
| 862 SkHashDigest actualBitmapHash; | 864 SkHashDigest actualBitmapHash; |
| 863 // TODO(epoger): Better handling for error returned by ComputeDigest
()? | 865 // TODO(epoger): Better handling for error returned by ComputeDigest
()? |
| 864 // For now, we just report a digest of 0 in error cases, like before
. | 866 // For now, we just report a digest of 0 in error cases, like before
. |
| 865 if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash))
{ | 867 if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash))
{ |
| 866 actualBitmapHash = 0; | 868 actualBitmapHash = 0; |
| 867 } | 869 } |
| 868 add_actual_results_to_json_summary(name.c_str(), actualBitmapHash, | 870 SkString nameWithExtension(name); |
| 871 nameWithExtension.append("."); |
| 872 nameWithExtension.append(kPNG_FileExtension); |
| 873 add_actual_results_to_json_summary(nameWithExtension.c_str(), actual
BitmapHash, |
| 869 ErrorCombination(kMissingExpectat
ions_ErrorType), | 874 ErrorCombination(kMissingExpectat
ions_ErrorType), |
| 870 false); | 875 false); |
| 871 RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType),
name, ""); | 876 RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType),
name, ""); |
| 872 } | 877 } |
| 873 | 878 |
| 874 // TODO: Consider moving this into compare_to_expectations(), | 879 // TODO: Consider moving this into compare_to_expectations(), |
| 875 // similar to fMismatchPath... for now, we don't do that, because | 880 // similar to fMismatchPath... for now, we don't do that, because |
| 876 // we don't want to write out the actual bitmaps for all | 881 // we don't want to write out the actual bitmaps for all |
| 877 // renderModes of all tests! That would be a lot of files. | 882 // renderModes of all tests! That would be a lot of files. |
| 878 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | 883 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2008 if (FLAGS_forceBWtext) { | 2013 if (FLAGS_forceBWtext) { |
| 2009 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2014 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2010 } | 2015 } |
| 2011 } | 2016 } |
| 2012 | 2017 |
| 2013 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2018 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 2014 int main(int argc, char * const argv[]) { | 2019 int main(int argc, char * const argv[]) { |
| 2015 return tool_main(argc, (char**) argv); | 2020 return tool_main(argc, (char**) argv); |
| 2016 } | 2021 } |
| 2017 #endif | 2022 #endif |
| OLD | NEW |