| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 114             count += 1; | 114             count += 1; | 
| 115             reg = reg->next(); | 115             reg = reg->next(); | 
| 116         } | 116         } | 
| 117         return count; | 117         return count; | 
| 118     } | 118     } | 
| 119 | 119 | 
| 120 private: | 120 private: | 
| 121     const GMRegistry* fReg; | 121     const GMRegistry* fReg; | 
| 122 }; | 122 }; | 
| 123 | 123 | 
|  | 124 // TODO(epoger): Right now, various places in this code assume that all the | 
|  | 125 // image files read/written by GM use this file extension. | 
|  | 126 // Search for references to this constant to find these assumptions. | 
|  | 127 const static char kPNG_FileExtension[] = "png"; | 
|  | 128 | 
| 124 enum Backend { | 129 enum Backend { | 
| 125     kRaster_Backend, | 130     kRaster_Backend, | 
| 126     kGPU_Backend, | 131     kGPU_Backend, | 
| 127     kPDF_Backend, | 132     kPDF_Backend, | 
| 128     kXPS_Backend, | 133     kXPS_Backend, | 
| 129 }; | 134 }; | 
| 130 | 135 | 
| 131 enum BbhType { | 136 enum BbhType { | 
| 132     kNone_BbhType, | 137     kNone_BbhType, | 
| 133     kRTree_BbhType, | 138     kRTree_BbhType, | 
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 600     ErrorCombination write_reference_image(const ConfigData& gRec, const char wr
      itePath [], | 605     ErrorCombination write_reference_image(const ConfigData& gRec, const char wr
      itePath [], | 
| 601                                            const char renderModeDescriptor [], c
      onst SkString& name, | 606                                            const char renderModeDescriptor [], c
      onst SkString& name, | 
| 602                                            SkBitmap& bitmap, SkDynamicMemoryWStr
      eam* document) { | 607                                            SkBitmap& bitmap, SkDynamicMemoryWStr
      eam* document) { | 
| 603         SkString path; | 608         SkString path; | 
| 604         bool success = false; | 609         bool success = false; | 
| 605         if (gRec.fBackend == kRaster_Backend || | 610         if (gRec.fBackend == kRaster_Backend || | 
| 606             gRec.fBackend == kGPU_Backend || | 611             gRec.fBackend == kGPU_Backend || | 
| 607             (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { | 612             (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { | 
| 608 | 613 | 
| 609             path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 614             path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 
| 610                                  "png"); | 615                                  kPNG_FileExtension); | 
| 611             success = write_bitmap(path, bitmap); | 616             success = write_bitmap(path, bitmap); | 
| 612         } | 617         } | 
| 613         if (kPDF_Backend == gRec.fBackend) { | 618         if (kPDF_Backend == gRec.fBackend) { | 
| 614             path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 619             path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 
| 615                                  "pdf"); | 620                                  "pdf"); | 
| 616             success = write_document(path, *document); | 621             success = write_document(path, *document); | 
| 617         } | 622         } | 
| 618         if (kXPS_Backend == gRec.fBackend) { | 623         if (kXPS_Backend == gRec.fBackend) { | 
| 619             path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 624             path = make_filename(writePath, renderModeDescriptor, name.c_str(), | 
| 620                                  "xps"); | 625                                  "xps"); | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 720                                              bool addToJsonSummary) { | 725                                              bool addToJsonSummary) { | 
| 721         ErrorCombination errors; | 726         ErrorCombination errors; | 
| 722         SkHashDigest actualBitmapHash; | 727         SkHashDigest actualBitmapHash; | 
| 723         // TODO(epoger): Better handling for error returned by ComputeDigest()? | 728         // TODO(epoger): Better handling for error returned by ComputeDigest()? | 
| 724         // For now, we just report a digest of 0 in error cases, like before. | 729         // For now, we just report a digest of 0 in error cases, like before. | 
| 725         if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { | 730         if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { | 
| 726             actualBitmapHash = 0; | 731             actualBitmapHash = 0; | 
| 727         } | 732         } | 
| 728         SkString completeNameString = baseNameString; | 733         SkString completeNameString = baseNameString; | 
| 729         completeNameString.append(renderModeDescriptor); | 734         completeNameString.append(renderModeDescriptor); | 
|  | 735         completeNameString.append("."); | 
|  | 736         completeNameString.append(kPNG_FileExtension); | 
| 730         const char* completeName = completeNameString.c_str(); | 737         const char* completeName = completeNameString.c_str(); | 
| 731 | 738 | 
| 732         if (expectations.empty()) { | 739         if (expectations.empty()) { | 
| 733             errors.add(kMissingExpectations_ErrorType); | 740             errors.add(kMissingExpectations_ErrorType); | 
| 734         } else if (!expectations.match(actualBitmapHash)) { | 741         } else if (!expectations.match(actualBitmapHash)) { | 
| 735             addToJsonSummary = true; | 742             addToJsonSummary = true; | 
| 736             // The error mode we record depends on whether this was running | 743             // The error mode we record depends on whether this was running | 
| 737             // in a non-standard renderMode. | 744             // in a non-standard renderMode. | 
| 738             if ('\0' == *renderModeDescriptor) { | 745             if ('\0' == *renderModeDescriptor) { | 
| 739                 errors.add(kExpectationsMismatch_ErrorType); | 746                 errors.add(kExpectationsMismatch_ErrorType); | 
| 740             } else { | 747             } else { | 
| 741                 errors.add(kRenderModeMismatch_ErrorType); | 748                 errors.add(kRenderModeMismatch_ErrorType); | 
| 742             } | 749             } | 
| 743 | 750 | 
| 744             // Write out the "actuals" for any mismatches, if we have | 751             // Write out the "actuals" for any mismatches, if we have | 
| 745             // been directed to do so. | 752             // been directed to do so. | 
| 746             if (fMismatchPath) { | 753             if (fMismatchPath) { | 
| 747                 SkString path = | 754                 SkString path = | 
| 748                     make_filename(fMismatchPath, renderModeDescriptor, | 755                     make_filename(fMismatchPath, renderModeDescriptor, | 
| 749                                   baseNameString.c_str(), "png"); | 756                                   baseNameString.c_str(), kPNG_FileExtension); | 
| 750                 write_bitmap(path, actualBitmap); | 757                 write_bitmap(path, actualBitmap); | 
| 751             } | 758             } | 
| 752 | 759 | 
| 753             // If we have access to a single expected bitmap, log more | 760             // If we have access to a single expected bitmap, log more | 
| 754             // detail about the mismatch. | 761             // detail about the mismatch. | 
| 755             const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); | 762             const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); | 
| 756             if (NULL != expectedBitmapPtr) { | 763             if (NULL != expectedBitmapPtr) { | 
| 757                 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeNa
      me); | 764                 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeNa
      me); | 
| 758             } | 765             } | 
| 759         } | 766         } | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 846              * get this by computing the hash digest of a single PNG file on dis
      k. | 853              * get this by computing the hash digest of a single PNG file on dis
      k. | 
| 847              * | 854              * | 
| 848              * TODO(epoger): This relies on the fact that | 855              * TODO(epoger): This relies on the fact that | 
| 849              * force_all_opaque() was called on the bitmap before it | 856              * force_all_opaque() was called on the bitmap before it | 
| 850              * was written to disk as a PNG in the first place. If | 857              * was written to disk as a PNG in the first place. If | 
| 851              * not, the hash digest returned here may not match the | 858              * not, the hash digest returned here may not match the | 
| 852              * hash digest of actualBitmap, which *has* been run through | 859              * hash digest of actualBitmap, which *has* been run through | 
| 853              * force_all_opaque(). | 860              * force_all_opaque(). | 
| 854              * See comments above complete_bitmap() for more detail. | 861              * See comments above complete_bitmap() for more detail. | 
| 855              */ | 862              */ | 
| 856             Expectations expectations = expectationsSource->get(name.c_str()); | 863             SkString nameWithExtension(name); | 
|  | 864             nameWithExtension.append("."); | 
|  | 865             nameWithExtension.append(kPNG_FileExtension); | 
|  | 866             Expectations expectations = expectationsSource->get(nameWithExtensio
      n.c_str()); | 
| 857             errors.add(compare_to_expectations(expectations, actualBitmap, | 867             errors.add(compare_to_expectations(expectations, actualBitmap, | 
| 858                                                name, "", true)); | 868                                                name, "", true)); | 
| 859         } else { | 869         } else { | 
| 860             // If we are running without expectations, we still want to | 870             // If we are running without expectations, we still want to | 
| 861             // record the actual results. | 871             // record the actual results. | 
| 862             SkHashDigest actualBitmapHash; | 872             SkHashDigest actualBitmapHash; | 
| 863             // TODO(epoger): Better handling for error returned by ComputeDigest
      ()? | 873             // TODO(epoger): Better handling for error returned by ComputeDigest
      ()? | 
| 864             // For now, we just report a digest of 0 in error cases, like before
      . | 874             // For now, we just report a digest of 0 in error cases, like before
      . | 
| 865             if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash))
       { | 875             if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash))
       { | 
| 866                 actualBitmapHash = 0; | 876                 actualBitmapHash = 0; | 
| 867             } | 877             } | 
| 868             add_actual_results_to_json_summary(name.c_str(), actualBitmapHash, | 878             SkString nameWithExtension(name); | 
|  | 879             nameWithExtension.append("."); | 
|  | 880             nameWithExtension.append(kPNG_FileExtension); | 
|  | 881             add_actual_results_to_json_summary(nameWithExtension.c_str(), actual
      BitmapHash, | 
| 869                                                ErrorCombination(kMissingExpectat
      ions_ErrorType), | 882                                                ErrorCombination(kMissingExpectat
      ions_ErrorType), | 
| 870                                                false); | 883                                                false); | 
| 871             RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType), 
      name, ""); | 884             RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType), 
      name, ""); | 
| 872         } | 885         } | 
| 873 | 886 | 
| 874         // TODO: Consider moving this into compare_to_expectations(), | 887         // TODO: Consider moving this into compare_to_expectations(), | 
| 875         // similar to fMismatchPath... for now, we don't do that, because | 888         // similar to fMismatchPath... for now, we don't do that, because | 
| 876         // we don't want to write out the actual bitmaps for all | 889         // we don't want to write out the actual bitmaps for all | 
| 877         // renderModes of all tests!  That would be a lot of files. | 890         // renderModes of all tests!  That would be a lot of files. | 
| 878         if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | 891         if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | 
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2032     if (FLAGS_forceBWtext) { | 2045     if (FLAGS_forceBWtext) { | 
| 2033         canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2046         canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 
| 2034     } | 2047     } | 
| 2035 } | 2048 } | 
| 2036 | 2049 | 
| 2037 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2050 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 
| 2038 int main(int argc, char * const argv[]) { | 2051 int main(int argc, char * const argv[]) { | 
| 2039     return tool_main(argc, (char**) argv); | 2052     return tool_main(argc, (char**) argv); | 
| 2040 } | 2053 } | 
| 2041 #endif | 2054 #endif | 
| OLD | NEW | 
|---|