Chromium Code Reviews| 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 |
|
epoger
2013/08/13 18:06:54
Make sure that the self-tests still pass after you
ducky
2013/08/14 00:37:11
Done.
| |
| 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 "SkColorPriv.h" | 21 #include "SkColorPriv.h" |
| 22 #include "SkCommandLineFlags.h" | 22 #include "SkCommandLineFlags.h" |
| 23 #include "SkData.h" | 23 #include "SkData.h" |
| 24 #include "SkDeferredCanvas.h" | 24 #include "SkDeferredCanvas.h" |
| 25 #include "SkDevice.h" | 25 #include "SkDevice.h" |
| 26 #include "SkDrawFilter.h" | 26 #include "SkDrawFilter.h" |
| 27 #include "SkForceLinking.h" | 27 #include "SkForceLinking.h" |
| 28 #include "SkGPipe.h" | 28 #include "SkGPipe.h" |
| 29 #include "SkGraphics.h" | 29 #include "SkGraphics.h" |
| 30 #include "SkImageDecoder.h" | 30 #include "SkImageDecoder.h" |
| 31 #include "SkImageEncoder.h" | 31 #include "SkImageEncoder.h" |
| 32 #include "SkOSFile.h" | 32 #include "SkOSFile.h" |
| 33 #include "SkPDFRasterizer.h" | |
| 33 #include "SkPicture.h" | 34 #include "SkPicture.h" |
| 34 #include "SkRefCnt.h" | 35 #include "SkRefCnt.h" |
| 35 #include "SkStream.h" | 36 #include "SkStream.h" |
| 36 #include "SkTArray.h" | 37 #include "SkTArray.h" |
| 37 #include "SkTDict.h" | 38 #include "SkTDict.h" |
| 38 #include "SkTileGridPicture.h" | 39 #include "SkTileGridPicture.h" |
| 39 #include "SamplePipeControllers.h" | 40 #include "SamplePipeControllers.h" |
| 40 | 41 |
| 41 __SK_FORCE_IMAGE_DECODER_LINKING; | 42 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 42 | 43 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 | 77 |
| 77 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , | 78 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 78 // stop writing out XPS-format image baselines in gm. | 79 // stop writing out XPS-format image baselines in gm. |
| 79 #undef SK_SUPPORT_XPS | 80 #undef SK_SUPPORT_XPS |
| 80 #ifdef SK_SUPPORT_XPS | 81 #ifdef SK_SUPPORT_XPS |
| 81 #include "SkXPSDevice.h" | 82 #include "SkXPSDevice.h" |
| 82 #endif | 83 #endif |
| 83 | 84 |
| 84 #ifdef SK_BUILD_FOR_MAC | 85 #ifdef SK_BUILD_FOR_MAC |
| 85 #include "SkCGUtils.h" | 86 #include "SkCGUtils.h" |
| 86 #define CAN_IMAGE_PDF 1 | |
| 87 #else | |
| 88 #define CAN_IMAGE_PDF 0 | |
| 89 #endif | 87 #endif |
| 90 | 88 |
| 91 using namespace skiagm; | 89 using namespace skiagm; |
| 92 | 90 |
| 93 class Iter { | 91 class Iter { |
| 94 public: | 92 public: |
| 95 Iter() { | 93 Iter() { |
| 96 this->reset(); | 94 this->reset(); |
| 97 } | 95 } |
| 98 | 96 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 struct ConfigData { | 151 struct ConfigData { |
| 154 SkBitmap::Config fConfig; | 152 SkBitmap::Config fConfig; |
| 155 Backend fBackend; | 153 Backend fBackend; |
| 156 GLContextType fGLContextType; // GPU backend only | 154 GLContextType fGLContextType; // GPU backend only |
| 157 int fSampleCnt; // GPU backend only | 155 int fSampleCnt; // GPU backend only |
| 158 ConfigFlags fFlags; | 156 ConfigFlags fFlags; |
| 159 const char* fName; | 157 const char* fName; |
| 160 bool fRunByDefault; | 158 bool fRunByDefault; |
| 161 }; | 159 }; |
| 162 | 160 |
| 161 struct PDFRasterizerData { | |
| 162 bool (*fRasterizerFunction)(SkStream*, SkBitmap*); | |
| 163 const char* fName; | |
| 164 bool fRunByDefault; | |
| 165 }; | |
| 166 | |
| 163 class BWTextDrawFilter : public SkDrawFilter { | 167 class BWTextDrawFilter : public SkDrawFilter { |
| 164 public: | 168 public: |
| 165 virtual bool filter(SkPaint*, Type) SK_OVERRIDE; | 169 virtual bool filter(SkPaint*, Type) SK_OVERRIDE; |
| 166 }; | 170 }; |
| 167 bool BWTextDrawFilter::filter(SkPaint* p, Type t) { | 171 bool BWTextDrawFilter::filter(SkPaint* p, Type t) { |
| 168 if (kText_Type == t) { | 172 if (kText_Type == t) { |
| 169 p->setAntiAlias(false); | 173 p->setAntiAlias(false); |
| 170 } | 174 } |
| 171 return true; | 175 return true; |
| 172 } | 176 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 | 279 |
| 276 static void force_all_opaque_8888(const SkBitmap& bitmap) { | 280 static void force_all_opaque_8888(const SkBitmap& bitmap) { |
| 277 SkAutoLockPixels lock(bitmap); | 281 SkAutoLockPixels lock(bitmap); |
| 278 for (int y = 0; y < bitmap.height(); y++) { | 282 for (int y = 0; y < bitmap.height(); y++) { |
| 279 for (int x = 0; x < bitmap.width(); x++) { | 283 for (int x = 0; x < bitmap.width(); x++) { |
| 280 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); | 284 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 281 } | 285 } |
| 282 } | 286 } |
| 283 } | 287 } |
| 284 | 288 |
| 285 static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { | 289 static ErrorCombination write_bitmap(const SkString& path, const SkBitmap& b itmap) { |
| 286 // TODO(epoger): Now that we have removed force_all_opaque() | 290 // TODO(epoger): Now that we have removed force_all_opaque() |
| 287 // from this method, we should be able to get rid of the | 291 // from this method, we should be able to get rid of the |
| 288 // transformation to 8888 format also. | 292 // transformation to 8888 format also. |
| 289 SkBitmap copy; | 293 SkBitmap copy; |
| 290 bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); | 294 bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 291 return SkImageEncoder::EncodeFile(path.c_str(), copy, | 295 if (!SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 292 SkImageEncoder::kPNG_Type, 100); | 296 SkImageEncoder::kPNG_Type, |
| 297 100)) { | |
| 298 gm_fprintf(stderr, "FAILED to write bitmap: %s\n", path.c_str()); | |
| 299 return ErrorCombination(kWritingReferenceImage_ErrorType); | |
| 300 } | |
| 301 return kEmpty_ErrorCombination; | |
| 293 } | 302 } |
| 294 | 303 |
| 295 /** | 304 /** |
| 296 * Add all render modes encountered thus far to the "modes" array. | 305 * Add all render modes encountered thus far to the "modes" array. |
| 297 */ | 306 */ |
| 298 void GetRenderModesEncountered(SkTArray<SkString> &modes) { | 307 void GetRenderModesEncountered(SkTArray<SkString> &modes) { |
| 299 SkTDict<int>::Iter iter(this->fRenderModesEncountered); | 308 SkTDict<int>::Iter iter(this->fRenderModesEncountered); |
| 300 const char* mode; | 309 const char* mode; |
| 301 while ((mode = iter.next(NULL)) != NULL) { | 310 while ((mode = iter.next(NULL)) != NULL) { |
| 302 SkString modeAsString = SkString(mode); | 311 SkString modeAsString = SkString(mode); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 } | 412 } |
| 404 gm_fprintf(stdout, "%s\n", summary.c_str()); | 413 gm_fprintf(stdout, "%s\n", summary.c_str()); |
| 405 | 414 |
| 406 // Now, for each failure type, list the tests that failed that way. | 415 // Now, for each failure type, list the tests that failed that way. |
| 407 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { | 416 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 408 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verb ose); | 417 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verb ose); |
| 409 } | 418 } |
| 410 gm_fprintf(stdout, "(results marked with [*] will cause nonzero return v alue)\n"); | 419 gm_fprintf(stdout, "(results marked with [*] will cause nonzero return v alue)\n"); |
| 411 } | 420 } |
| 412 | 421 |
| 413 static bool write_document(const SkString& path, SkStreamAsset* asset) { | 422 static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) { |
| 414 SkFILEWStream stream(path.c_str()); | 423 SkFILEWStream stream(path.c_str()); |
| 415 return stream.writeStream(asset, asset->getLength()); | 424 if (!stream.writeStream(asset, asset->getLength())) { |
| 425 gm_fprintf(stderr, "FAILED to write document: %s\n", path.c_str()); | |
| 426 return ErrorCombination(kWritingReferenceImage_ErrorType); | |
| 427 } | |
| 428 return kEmpty_ErrorCombination; | |
| 416 } | 429 } |
| 417 | 430 |
| 418 /** | 431 /** |
| 419 * Prepare an SkBitmap to render a GM into. | 432 * Prepare an SkBitmap to render a GM into. |
| 420 * | 433 * |
| 421 * After you've rendered the GM into the SkBitmap, you must call | 434 * After you've rendered the GM into the SkBitmap, you must call |
| 422 * complete_bitmap()! | 435 * complete_bitmap()! |
| 423 * | 436 * |
| 424 * @todo thudson 22 April 2011 - could refactor this to take in | 437 * @todo thudson 22 April 2011 - could refactor this to take in |
| 425 * a factory to generate the context, always call readPixels() | 438 * a factory to generate the context, always call readPixels() |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 SkCanvas c(dev); | 665 SkCanvas c(dev); |
| 653 dev->beginPortfolio(&xps); | 666 dev->beginPortfolio(&xps); |
| 654 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); | 667 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
| 655 invokeGM(gm, &c, false, false); | 668 invokeGM(gm, &c, false, false); |
| 656 dev->endSheet(); | 669 dev->endSheet(); |
| 657 dev->endPortfolio(); | 670 dev->endPortfolio(); |
| 658 | 671 |
| 659 #endif | 672 #endif |
| 660 } | 673 } |
| 661 | 674 |
| 662 ErrorCombination write_reference_image(const ConfigData& gRec, const char wr itePath [], | |
| 663 const char renderModeDescriptor [], | |
| 664 const char *shortName, | |
| 665 const BitmapAndDigest* bitmapAndDiges t, | |
| 666 SkStreamAsset* document) { | |
| 667 SkString path; | |
| 668 bool success = false; | |
| 669 if (gRec.fBackend == kRaster_Backend || | |
| 670 gRec.fBackend == kGPU_Backend || | |
| 671 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { | |
| 672 | |
| 673 path = make_bitmap_filename(writePath, shortName, gRec.fName, render ModeDescriptor, | |
| 674 bitmapAndDigest->fDigest); | |
| 675 success = write_bitmap(path, bitmapAndDigest->fBitmap); | |
| 676 } | |
| 677 if (kPDF_Backend == gRec.fBackend) { | |
| 678 path = make_filename(writePath, shortName, gRec.fName, renderModeDes criptor, | |
| 679 "pdf"); | |
| 680 success = write_document(path, document); | |
| 681 } | |
| 682 if (kXPS_Backend == gRec.fBackend) { | |
| 683 path = make_filename(writePath, shortName, gRec.fName, renderModeDes criptor, | |
| 684 "xps"); | |
| 685 success = write_document(path, document); | |
| 686 } | |
| 687 if (success) { | |
| 688 return kEmpty_ErrorCombination; | |
| 689 } else { | |
| 690 gm_fprintf(stderr, "FAILED to write %s\n", path.c_str()); | |
| 691 ErrorCombination errors(kWritingReferenceImage_ErrorType); | |
| 692 // TODO(epoger): Don't call RecordTestResults() here... | |
| 693 // Instead, we should make sure to call RecordTestResults | |
| 694 // exactly ONCE per test. (Otherwise, gmmain.fTestsRun | |
| 695 // will be incremented twice for this test: once in | |
| 696 // compare_test_results_to_stored_expectations() before | |
| 697 // that method calls this one, and again here.) | |
| 698 // | |
| 699 // When we make that change, we should probably add a | |
| 700 // WritingReferenceImage test to the gm self-tests.) | |
| 701 RecordTestResults(errors, make_shortname_plus_config(shortName, gRec .fName), | |
| 702 renderModeDescriptor); | |
| 703 return errors; | |
| 704 } | |
| 705 } | |
| 706 | |
| 707 /** | 675 /** |
| 708 * Log more detail about the mistmatch between expectedBitmap and | 676 * Log more detail about the mistmatch between expectedBitmap and |
| 709 * actualBitmap. | 677 * actualBitmap. |
| 710 */ | 678 */ |
| 711 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& act ualBitmap, | 679 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& act ualBitmap, |
| 712 const char *testName) { | 680 const char *testName) { |
| 713 const int expectedWidth = expectedBitmap.width(); | 681 const int expectedWidth = expectedBitmap.width(); |
| 714 const int expectedHeight = expectedBitmap.height(); | 682 const int expectedHeight = expectedBitmap.height(); |
| 715 const int width = actualBitmap.width(); | 683 const int width = actualBitmap.width(); |
| 716 const int height = actualBitmap.height(); | 684 const int height = actualBitmap.height(); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 void add_expected_results_to_json_summary(const char testName[], | 862 void add_expected_results_to_json_summary(const char testName[], |
| 895 Expectations expectations) { | 863 Expectations expectations) { |
| 896 this->fJsonExpectedResults[testName] = expectations.asJsonValue(); | 864 this->fJsonExpectedResults[testName] = expectations.asJsonValue(); |
| 897 } | 865 } |
| 898 | 866 |
| 899 /** | 867 /** |
| 900 * Compare actualBitmap to expectations stored in this->fExpectationsSource. | 868 * Compare actualBitmap to expectations stored in this->fExpectationsSource. |
| 901 * | 869 * |
| 902 * @param gm which test generated the actualBitmap | 870 * @param gm which test generated the actualBitmap |
| 903 * @param gRec | 871 * @param gRec |
| 904 * @param writePath unless this is NULL, write out actual images into this | 872 * @param writePath unless this is NULL, write out actual images into this |
|
epoger
2013/08/13 18:06:54
Please update the doc to reflect the removed param
ducky
2013/08/14 00:37:11
Done.
| |
| 905 * directory | 873 * directory |
| 906 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL | 874 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL |
| 907 * if we don't have a usable bitmap representation | 875 * if we don't have a usable bitmap representation |
| 908 * @param document pdf or xps representation, if appropriate | 876 * @param document pdf or xps representation, if appropriate |
| 909 */ | 877 */ |
| 910 ErrorCombination compare_test_results_to_stored_expectations( | 878 ErrorCombination compare_test_results_to_stored_expectations( |
| 911 GM* gm, const ConfigData& gRec, const char writePath[], | 879 GM* gm, const ConfigData& gRec, |
| 912 const BitmapAndDigest* actualBitmapAndDigest, SkStreamAsset* document) { | 880 const BitmapAndDigest* actualBitmapAndDigest) { |
| 913 | 881 |
| 914 SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName( ), gRec.fName); | 882 SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName( ), gRec.fName); |
| 915 SkString nameWithExtension(shortNamePlusConfig); | |
| 916 nameWithExtension.append("."); | |
| 917 nameWithExtension.append(kPNG_FileExtension); | |
| 918 | 883 |
| 919 ErrorCombination errors; | 884 ErrorCombination errors; |
| 920 | 885 |
| 921 if (NULL == actualBitmapAndDigest) { | 886 if (NULL == actualBitmapAndDigest) { |
| 922 // Note that we intentionally skipped validating the results for | 887 // Note that we intentionally skipped validating the results for |
| 923 // this test, because we don't know how to generate an SkBitmap | 888 // this test, because we don't know how to generate an SkBitmap |
| 924 // version of the output. | 889 // version of the output. |
| 925 RecordTestResults(ErrorCombination(kIntentionallySkipped_ErrorType), | 890 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType)); |
| 926 shortNamePlusConfig, ""); | |
| 927 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) { | 891 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) { |
| 928 // We don't record the results for this test or compare them | 892 // We don't record the results for this test or compare them |
| 929 // against any expectations, because the output image isn't | 893 // against any expectations, because the output image isn't |
| 930 // meaningful. | 894 // meaningful. |
| 931 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some | 895 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some |
| 932 // GM result images not available for download from Google Storage') | 896 // GM result images not available for download from Google Storage') |
| 933 RecordTestResults(ErrorCombination(kIntentionallySkipped_ErrorType), | 897 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType)); |
| 934 shortNamePlusConfig, ""); | |
| 935 } else { | 898 } else { |
| 936 ExpectationsSource *expectationsSource = this->fExpectationsSource.g et(); | 899 ExpectationsSource *expectationsSource = this->fExpectationsSource.g et(); |
| 900 SkString nameWithExtension(shortNamePlusConfig); | |
| 901 nameWithExtension.append("."); | |
| 902 nameWithExtension.append(kPNG_FileExtension); | |
| 903 | |
| 937 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) { | 904 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) { |
| 938 /* | 905 /* |
| 939 * Get the expected results for this test, as one or more allowe d | 906 * Get the expected results for this test, as one or more allowe d |
| 940 * hash digests. The current implementation of expectationsSourc e | 907 * hash digests. The current implementation of expectationsSourc e |
| 941 * get this by computing the hash digest of a single PNG file on disk. | 908 * get this by computing the hash digest of a single PNG file on disk. |
| 942 * | 909 * |
| 943 * TODO(epoger): This relies on the fact that | 910 * TODO(epoger): This relies on the fact that |
| 944 * force_all_opaque() was called on the bitmap before it | 911 * force_all_opaque() was called on the bitmap before it |
| 945 * was written to disk as a PNG in the first place. If | 912 * was written to disk as a PNG in the first place. If |
| 946 * not, the hash digest returned here may not match the | 913 * not, the hash digest returned here may not match the |
| 947 * hash digest of actualBitmap, which *has* been run through | 914 * hash digest of actualBitmap, which *has* been run through |
| 948 * force_all_opaque(). | 915 * force_all_opaque(). |
| 949 * See comments above complete_bitmap() for more detail. | 916 * See comments above complete_bitmap() for more detail. |
| 950 */ | 917 */ |
| 951 Expectations expectations = expectationsSource->get(nameWithExte nsion.c_str()); | 918 Expectations expectations = expectationsSource->get(nameWithExte nsion.c_str()); |
| 952 errors.add(compare_to_expectations(expectations, *actualBitmapAn dDigest, | 919 errors.add(compare_to_expectations(expectations, *actualBitmapAn dDigest, |
| 953 gm->shortName(), gRec.fName, "", true)); | 920 gm->shortName(), gRec.fName, "", true)); |
| 954 } else { | 921 } else { |
| 955 // If we are running without expectations, we still want to | 922 // If we are running without expectations, we still want to |
| 956 // record the actual results. | 923 // record the actual results. |
| 957 add_actual_results_to_json_summary(nameWithExtension.c_str(), | 924 add_actual_results_to_json_summary(nameWithExtension.c_str(), |
| 958 actualBitmapAndDigest->fDiges t, | 925 actualBitmapAndDigest->fDiges t, |
| 959 ErrorCombination(kMissingExpe ctations_ErrorType), | 926 ErrorCombination(kMissingExpe ctations_ErrorType), |
| 960 false); | 927 false); |
| 961 RecordTestResults(ErrorCombination(kMissingExpectations_ErrorTyp e), | 928 errors.add(ErrorCombination(kMissingExpectations_ErrorType)); |
| 962 shortNamePlusConfig, ""); | |
| 963 } | 929 } |
| 964 } | 930 } |
| 965 | |
| 966 // TODO: Consider moving this into compare_to_expectations(), | |
| 967 // similar to fMismatchPath... for now, we don't do that, because | |
| 968 // we don't want to write out the actual bitmaps for all | |
| 969 // renderModes of all tests! That would be a lot of files. | |
| 970 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | |
| 971 errors.add(write_reference_image(gRec, writePath, "", gm->shortName( ), | |
| 972 actualBitmapAndDigest, document)); | |
| 973 } | |
| 974 | |
| 975 return errors; | 931 return errors; |
| 976 } | 932 } |
| 977 | 933 |
| 978 /** | 934 /** |
| 979 * Compare actualBitmap to referenceBitmap. | 935 * Compare actualBitmap to referenceBitmap. |
| 980 * | 936 * |
| 981 * @param shortName test name, e.g. "selftest1" | 937 * @param shortName test name, e.g. "selftest1" |
| 982 * @param configName configuration name, e.g. "8888" | 938 * @param configName configuration name, e.g. "8888" |
| 983 * @param renderModeDescriptor | 939 * @param renderModeDescriptor |
| 984 * @param actualBitmap actual bitmap generated by this run | 940 * @param actualBitmap actual bitmap generated by this run |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 static SkPicture* stream_to_new_picture(const SkPicture& src) { | 981 static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 1026 SkDynamicMemoryWStream storage; | 982 SkDynamicMemoryWStream storage; |
| 1027 src.serialize(&storage); | 983 src.serialize(&storage); |
| 1028 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream()); | 984 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream()); |
| 1029 SkPicture* retval = SkPicture::CreateFromStream(pictReadback); | 985 SkPicture* retval = SkPicture::CreateFromStream(pictReadback); |
| 1030 return retval; | 986 return retval; |
| 1031 } | 987 } |
| 1032 | 988 |
| 1033 // Test: draw into a bitmap or pdf. | 989 // Test: draw into a bitmap or pdf. |
| 1034 // Depending on flags, possibly compare to an expected image. | 990 // Depending on flags, possibly compare to an expected image. |
| 1035 ErrorCombination test_drawing(GM* gm, | 991 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec, |
| 1036 const ConfigData& gRec, | 992 const SkTDArray<const PDFRasterizerData*> &pdf Rasterizers, |
| 1037 const char writePath [], | 993 const char writePath [], |
| 1038 GrSurface* gpuTarget, | 994 GrSurface* gpuTarget, |
| 1039 SkBitmap* bitmap) { | 995 SkBitmap* bitmap) { |
| 996 ErrorCombination errors; | |
| 1040 SkDynamicMemoryWStream document; | 997 SkDynamicMemoryWStream document; |
| 998 SkString path; | |
| 1041 | 999 |
| 1042 if (gRec.fBackend == kRaster_Backend || | 1000 if (gRec.fBackend == kRaster_Backend || |
| 1043 gRec.fBackend == kGPU_Backend) { | 1001 gRec.fBackend == kGPU_Backend) { |
| 1044 // Early exit if we can't generate the image. | 1002 // Early exit if we can't generate the image. |
| 1045 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, bitmap , false); | 1003 errors.add(generate_image(gm, gRec, gpuTarget, bitmap, false)); |
| 1046 if (!errors.isEmpty()) { | 1004 if (!errors.isEmpty()) { |
| 1047 // TODO: Add a test to exercise what the stdout and | 1005 // TODO: Add a test to exercise what the stdout and |
| 1048 // JSON look like if we get an "early error" while | 1006 // JSON look like if we get an "early error" while |
| 1049 // trying to generate the image. | 1007 // trying to generate the image. |
| 1050 return errors; | 1008 return errors; |
| 1051 } | 1009 } |
| 1010 BitmapAndDigest bitmapAndDigest(*bitmap); | |
| 1011 errors.add(compare_test_results_to_stored_expectations( | |
| 1012 gm, gRec, &bitmapAndDigest)); | |
| 1013 | |
| 1014 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | |
| 1015 path = make_bitmap_filename(writePath, gm->shortName(), gRec.fNa me, | |
| 1016 "", bitmapAndDigest.fDigest); | |
| 1017 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap)); | |
| 1018 } | |
| 1052 } else if (gRec.fBackend == kPDF_Backend) { | 1019 } else if (gRec.fBackend == kPDF_Backend) { |
| 1053 generate_pdf(gm, document); | 1020 generate_pdf(gm, document); |
| 1054 #if CAN_IMAGE_PDF | 1021 |
| 1055 SkAutoDataUnref data(document.copyToData()); | 1022 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream() ); |
| 1056 SkMemoryStream stream(data->data(), data->size()); | 1023 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| 1057 SkPDFDocumentToBitmap(&stream, bitmap); | 1024 path = make_filename(writePath, gm->shortName(), gRec.fName, "", "pdf"); |
| 1058 #else | 1025 errors.add(write_document(path, documentStream)); |
| 1059 bitmap = NULL; // we don't generate a bitmap rendering of the PDF f ile | 1026 } |
| 1060 #endif | 1027 |
| 1028 for (int i = 0; i < pdfRasterizers.count(); i++) { | |
| 1029 SkBitmap pdfBitmap; | |
| 1030 SkASSERT(documentStream->rewind()); | |
| 1031 bool success = (*pdfRasterizers[i]->fRasterizerFunction)( | |
| 1032 documentStream.get(), &pdfBitmap); | |
| 1033 if (!success) { | |
| 1034 gm_fprintf(stderr, "FAILED to render PDF for %s using render er %s\n", | |
| 1035 gm->shortName(), | |
| 1036 pdfRasterizers[i]->fName); | |
| 1037 continue; | |
| 1038 } | |
| 1039 | |
| 1040 BitmapAndDigest bitmapAndDigest(pdfBitmap); | |
| 1041 errors.add(compare_test_results_to_stored_expectations( | |
| 1042 gm, gRec, &bitmapAndDigest)); | |
| 1043 | |
| 1044 SkString configName(gRec.fName); | |
| 1045 configName.append("_"); | |
| 1046 configName.append(pdfRasterizers[i]->fName); | |
| 1047 | |
| 1048 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | |
| 1049 path = make_bitmap_filename(writePath, gm->shortName(), conf igName.c_str(), | |
| 1050 "", bitmapAndDigest.fDigest); | |
| 1051 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap)); | |
| 1052 } | |
| 1053 } | |
| 1061 } else if (gRec.fBackend == kXPS_Backend) { | 1054 } else if (gRec.fBackend == kXPS_Backend) { |
| 1062 generate_xps(gm, document); | 1055 generate_xps(gm, document); |
| 1063 bitmap = NULL; // we don't generate a bitmap rendering of the XPS f ile | 1056 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream() ); |
| 1057 | |
| 1058 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | |
| 1059 path = make_filename(writePath, gm->shortName(), gRec.fName, "", "xps"); | |
| 1060 errors.add(write_document(path, documentStream)); | |
| 1061 } | |
| 1062 } else { | |
| 1063 SkASSERT(false); | |
| 1064 } | 1064 } |
| 1065 | 1065 return errors; |
| 1066 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream()); | |
| 1067 if (NULL == bitmap) { | |
| 1068 return compare_test_results_to_stored_expectations( | |
| 1069 gm, gRec, writePath, NULL, documentStream); | |
| 1070 } else { | |
| 1071 BitmapAndDigest bitmapAndDigest(*bitmap); | |
| 1072 return compare_test_results_to_stored_expectations( | |
| 1073 gm, gRec, writePath, &bitmapAndDigest, documentStream); | |
| 1074 } | |
| 1075 } | 1066 } |
| 1076 | 1067 |
| 1077 ErrorCombination test_deferred_drawing(GM* gm, | 1068 ErrorCombination test_deferred_drawing(GM* gm, |
| 1078 const ConfigData& gRec, | 1069 const ConfigData& gRec, |
| 1079 const SkBitmap& referenceBitmap, | 1070 const SkBitmap& referenceBitmap, |
| 1080 GrSurface* gpuTarget) { | 1071 GrSurface* gpuTarget) { |
| 1081 if (gRec.fBackend == kRaster_Backend || | 1072 if (gRec.fBackend == kRaster_Backend || |
| 1082 gRec.fBackend == kGPU_Backend) { | 1073 gRec.fBackend == kGPU_Backend) { |
| 1083 const char renderModeDescriptor[] = "-deferred"; | 1074 const char renderModeDescriptor[] = "-deferred"; |
| 1084 SkBitmap bitmap; | 1075 SkBitmap bitmap; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1216 Json::Value fJsonActualResults_Succeeded; | 1207 Json::Value fJsonActualResults_Succeeded; |
| 1217 | 1208 |
| 1218 }; // end of GMMain class definition | 1209 }; // end of GMMain class definition |
| 1219 | 1210 |
| 1220 #if SK_SUPPORT_GPU | 1211 #if SK_SUPPORT_GPU |
| 1221 static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_G LContextType; | 1212 static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_G LContextType; |
| 1222 #else | 1213 #else |
| 1223 static const GLContextType kDontCare_GLContextType = 0; | 1214 static const GLContextType kDontCare_GLContextType = 0; |
| 1224 #endif | 1215 #endif |
| 1225 | 1216 |
| 1226 // If the platform does not support writing PNGs of PDFs then there will be no | |
| 1227 // reference images to read. However, we can always write the .pdf files | |
| 1228 static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : | |
| 1229 kWrite_ConfigFlag; | |
| 1230 | |
| 1231 static const ConfigData gRec[] = { | 1217 static const ConfigData gRec[] = { |
| 1232 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true }, | 1218 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true }, |
| 1233 #if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!) | 1219 #if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!) |
| 1234 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true }, | 1220 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true }, |
| 1235 #endif | 1221 #endif |
| 1236 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true }, | 1222 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true }, |
| 1237 #if SK_SUPPORT_GPU | 1223 #if SK_SUPPORT_GPU |
| 1238 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GL ContextType, 0, kRW_ConfigFlag, "gpu", true }, | 1224 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GL ContextType, 0, kRW_ConfigFlag, "gpu", true }, |
| 1239 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GL ContextType, 16, kRW_ConfigFlag, "msaa16", false}, | 1225 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GL ContextType, 16, kRW_ConfigFlag, "msaa16", false}, |
| 1240 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GL ContextType, 4, kRW_ConfigFlag, "msaa4", false}, | 1226 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GL ContextType, 4, kRW_ConfigFlag, "msaa4", false}, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1252 #endif // SK_ANGLE | 1238 #endif // SK_ANGLE |
| 1253 #ifdef SK_MESA | 1239 #ifdef SK_MESA |
| 1254 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLCo ntextType, 0, kRW_ConfigFlag, "mesa", true }, | 1240 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLCo ntextType, 0, kRW_ConfigFlag, "mesa", true }, |
| 1255 #endif // SK_MESA | 1241 #endif // SK_MESA |
| 1256 #endif // SK_SUPPORT_GPU | 1242 #endif // SK_SUPPORT_GPU |
| 1257 #ifdef SK_SUPPORT_XPS | 1243 #ifdef SK_SUPPORT_XPS |
| 1258 /* At present we have no way of comparing XPS files (either natively or by c onverting to PNG). */ | 1244 /* At present we have no way of comparing XPS files (either natively or by c onverting to PNG). */ |
| 1259 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true }, | 1245 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true }, |
| 1260 #endif // SK_SUPPORT_XPS | 1246 #endif // SK_SUPPORT_XPS |
| 1261 #ifdef SK_SUPPORT_PDF | 1247 #ifdef SK_SUPPORT_PDF |
| 1262 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf", true }, | 1248 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true }, |
| 1263 #endif // SK_SUPPORT_PDF | 1249 #endif // SK_SUPPORT_PDF |
| 1264 }; | 1250 }; |
| 1265 | 1251 |
| 1252 static const PDFRasterizerData kPDFRasterizers[] = { | |
| 1253 #ifdef SK_BUILD_FOR_MAC | |
| 1254 { &SkPDFDocumentToBitmap, "mac", true }, | |
| 1255 #endif | |
| 1256 #ifdef SK_BUILD_POPPLER | |
| 1257 { &SkPopplerRasterizePDF, "poppler", true }, | |
|
vandebo (ex-Chrome)
2013/08/13 17:48:00
nit: remove the extra whitespace from these declar
ducky
2013/08/14 00:37:11
Done.
| |
| 1258 #endif | |
| 1259 }; | |
| 1260 | |
| 1266 static const char kDefaultsConfigStr[] = "defaults"; | 1261 static const char kDefaultsConfigStr[] = "defaults"; |
| 1267 static const char kExcludeConfigChar = '~'; | 1262 static const char kExcludeConfigChar = '~'; |
| 1268 | 1263 |
| 1269 static SkString configUsage() { | 1264 static SkString configUsage() { |
| 1270 SkString result; | 1265 SkString result; |
| 1271 result.appendf("Space delimited list of which configs to run. Possible optio ns: ["); | 1266 result.appendf("Space delimited list of which configs to run. Possible optio ns: ["); |
| 1272 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 1267 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1273 SkASSERT(gRec[i].fName != kDefaultsConfigStr); | 1268 SkASSERT(gRec[i].fName != kDefaultsConfigStr); |
| 1274 if (i > 0) { | 1269 if (i > 0) { |
| 1275 result.append("|"); | 1270 result.append("|"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s % s", | 1302 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s % s", |
| 1308 kDefaultsConfigStr, | 1303 kDefaultsConfigStr, |
| 1309 kExcludeConfigChar, | 1304 kExcludeConfigChar, |
| 1310 firstDefault.c_str(), | 1305 firstDefault.c_str(), |
| 1311 nonDefault.c_str(), | 1306 nonDefault.c_str(), |
| 1312 allButFirstDefaults.c_str(), | 1307 allButFirstDefaults.c_str(), |
| 1313 nonDefault.c_str()); | 1308 nonDefault.c_str()); |
| 1314 return result; | 1309 return result; |
| 1315 } | 1310 } |
| 1316 | 1311 |
| 1312 static SkString pdfRasterizerUsage() { | |
| 1313 SkString result; | |
| 1314 result.appendf("Space delimited list of which PDF rasterizers to run. Possib le options: ["); | |
| 1315 for (size_t i = 0; i < SK_ARRAY_COUNT(kPDFRasterizers); ++i) { | |
| 1316 if (i > 0) { | |
| 1317 result.append(", "); | |
|
vandebo (ex-Chrome)
2013/08/13 17:48:00
Oops, if the input should be space delimited, then
ducky
2013/08/14 00:37:11
Done.
| |
| 1318 } | |
| 1319 result.append(kPDFRasterizers[i].fName); | |
| 1320 } | |
| 1321 result.append("]\n"); | |
| 1322 result.append("The default value is: \""); | |
| 1323 for (size_t i = 0; i < SK_ARRAY_COUNT(kPDFRasterizers); ++i) { | |
| 1324 if (kPDFRasterizers[i].fRunByDefault) { | |
| 1325 if (i > 0) { | |
| 1326 result.append(" "); | |
| 1327 } | |
| 1328 result.append(kPDFRasterizers[i].fName); | |
| 1329 } | |
| 1330 } | |
| 1331 result.append("\""); | |
| 1332 return result; | |
| 1333 } | |
| 1334 | |
| 1317 // Macro magic to convert a numeric preprocessor token into a string. | 1335 // Macro magic to convert a numeric preprocessor token into a string. |
| 1318 // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor -token-to-a-string | 1336 // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor -token-to-a-string |
| 1319 // This should probably be moved into one of our common headers... | 1337 // This should probably be moved into one of our common headers... |
| 1320 #define TOSTRING_INTERNAL(x) #x | 1338 #define TOSTRING_INTERNAL(x) #x |
| 1321 #define TOSTRING(x) TOSTRING_INTERNAL(x) | 1339 #define TOSTRING(x) TOSTRING_INTERNAL(x) |
| 1322 | 1340 |
| 1323 // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). | 1341 // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). |
| 1324 DEFINE_string(config, "", configUsage().c_str()); | 1342 DEFINE_string(config, "", configUsage().c_str()); |
| 1343 DEFINE_string(pdfRasterizers, "", pdfRasterizerUsage().c_str()); | |
| 1325 DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass."); | 1344 DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass."); |
| 1326 DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); | 1345 DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); |
| 1327 DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); | 1346 DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); |
| 1328 #if SK_SUPPORT_GPU | 1347 #if SK_SUPPORT_GPU |
| 1329 DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte si ze or " | 1348 DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte si ze or " |
| 1330 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " | 1349 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " |
| 1331 "use the default. 0 for either disables the cache."); | 1350 "use the default. 0 for either disables the cache."); |
| 1332 #endif | 1351 #endif |
| 1333 DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " | 1352 DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " |
| 1334 "when reading/writing files."); | 1353 "when reading/writing files."); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1403 | 1422 |
| 1404 static int findConfig(const char config[]) { | 1423 static int findConfig(const char config[]) { |
| 1405 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { | 1424 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 1406 if (!strcmp(config, gRec[i].fName)) { | 1425 if (!strcmp(config, gRec[i].fName)) { |
| 1407 return (int) i; | 1426 return (int) i; |
| 1408 } | 1427 } |
| 1409 } | 1428 } |
| 1410 return -1; | 1429 return -1; |
| 1411 } | 1430 } |
| 1412 | 1431 |
| 1432 static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) { | |
| 1433 for (size_t i = 0; i < SK_ARRAY_COUNT(kPDFRasterizers); i++) { | |
| 1434 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) { | |
| 1435 return &kPDFRasterizers[i]; | |
| 1436 } | |
| 1437 } | |
| 1438 return NULL; | |
| 1439 } | |
| 1440 | |
| 1413 namespace skiagm { | 1441 namespace skiagm { |
| 1414 #if SK_SUPPORT_GPU | 1442 #if SK_SUPPORT_GPU |
| 1415 SkAutoTUnref<GrContext> gGrContext; | 1443 SkAutoTUnref<GrContext> gGrContext; |
| 1416 /** | 1444 /** |
| 1417 * Sets the global GrContext, accessible by individual GMs | 1445 * Sets the global GrContext, accessible by individual GMs |
| 1418 */ | 1446 */ |
| 1419 static void SetGr(GrContext* grContext) { | 1447 static void SetGr(GrContext* grContext) { |
| 1420 SkSafeRef(grContext); | 1448 SkSafeRef(grContext); |
| 1421 gGrContext.reset(grContext); | 1449 gGrContext.reset(grContext); |
| 1422 } | 1450 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1459 } | 1487 } |
| 1460 } | 1488 } |
| 1461 | 1489 |
| 1462 /** | 1490 /** |
| 1463 * Run this test in a number of different configs (8888, 565, PDF, | 1491 * Run this test in a number of different configs (8888, 565, PDF, |
| 1464 * etc.), confirming that the resulting bitmaps match expectations | 1492 * etc.), confirming that the resulting bitmaps match expectations |
| 1465 * (which may be different for each config). | 1493 * (which may be different for each config). |
| 1466 * | 1494 * |
| 1467 * Returns all errors encountered while doing so. | 1495 * Returns all errors encountered while doing so. |
| 1468 */ | 1496 */ |
| 1469 ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<si ze_t> &configs, | 1497 ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, |
| 1498 const SkTDArray<size_t> &configs, | |
| 1499 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, | |
| 1470 GrContextFactory *grFactory); | 1500 GrContextFactory *grFactory); |
| 1471 ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<si ze_t> &configs, | 1501 ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, |
| 1502 const SkTDArray<size_t> &configs, | |
| 1503 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, | |
| 1472 GrContextFactory *grFactory) { | 1504 GrContextFactory *grFactory) { |
| 1473 const char renderModeDescriptor[] = ""; | 1505 const char renderModeDescriptor[] = ""; |
| 1474 ErrorCombination errorsForAllConfigs; | 1506 ErrorCombination errorsForAllConfigs; |
| 1475 uint32_t gmFlags = gm->getFlags(); | 1507 uint32_t gmFlags = gm->getFlags(); |
| 1476 | 1508 |
| 1477 for (int i = 0; i < configs.count(); i++) { | 1509 for (int i = 0; i < configs.count(); i++) { |
| 1478 ConfigData config = gRec[configs[i]]; | 1510 ConfigData config = gRec[configs[i]]; |
| 1479 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(g m->shortName(), | 1511 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(g m->shortName(), |
| 1480 c onfig.fName); | 1512 c onfig.fName); |
| 1481 | 1513 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1552 #endif | 1584 #endif |
| 1553 | 1585 |
| 1554 SkBitmap comparisonBitmap; | 1586 SkBitmap comparisonBitmap; |
| 1555 | 1587 |
| 1556 const char* writePath; | 1588 const char* writePath; |
| 1557 if (FLAGS_writePath.count() == 1) { | 1589 if (FLAGS_writePath.count() == 1) { |
| 1558 writePath = FLAGS_writePath[0]; | 1590 writePath = FLAGS_writePath[0]; |
| 1559 } else { | 1591 } else { |
| 1560 writePath = NULL; | 1592 writePath = NULL; |
| 1561 } | 1593 } |
| 1594 | |
| 1562 if (errorsForThisConfig.isEmpty()) { | 1595 if (errorsForThisConfig.isEmpty()) { |
| 1563 errorsForThisConfig.add(gmmain.test_drawing(gm,config, writePath, gp uTarget, | 1596 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterize rs, |
| 1597 writePath, gpuTarget, | |
| 1564 &comparisonBitmap)); | 1598 &comparisonBitmap)); |
| 1599 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, " "); | |
| 1565 } | 1600 } |
| 1566 | 1601 |
| 1567 if (FLAGS_deferred && errorsForThisConfig.isEmpty() && | 1602 if (FLAGS_deferred && errorsForThisConfig.isEmpty() && |
| 1568 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBacke nd)) { | 1603 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBacke nd)) { |
| 1569 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, com parisonBitmap, | 1604 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, com parisonBitmap, |
| 1570 gpuTarget)); | 1605 gpuTarget)); |
| 1571 } | 1606 } |
| 1572 | 1607 |
| 1573 errorsForAllConfigs.add(errorsForThisConfig); | 1608 errorsForAllConfigs.add(errorsForThisConfig); |
| 1574 } | 1609 } |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1863 SkString configStr("These configs will be run: "); | 1898 SkString configStr("These configs will be run: "); |
| 1864 // show the user the config that will run. | 1899 // show the user the config that will run. |
| 1865 for (int i = 0; i < outConfigs->count(); ++i) { | 1900 for (int i = 0; i < outConfigs->count(); ++i) { |
| 1866 configStr.appendf("%s ", gRec[(*outConfigs)[i]].fName); | 1901 configStr.appendf("%s ", gRec[(*outConfigs)[i]].fName); |
| 1867 } | 1902 } |
| 1868 gm_fprintf(stdout, "%s\n", configStr.c_str()); | 1903 gm_fprintf(stdout, "%s\n", configStr.c_str()); |
| 1869 | 1904 |
| 1870 return true; | 1905 return true; |
| 1871 } | 1906 } |
| 1872 | 1907 |
| 1908 static bool parse_flags_pdf_rasterizers(SkTDArray<const PDFRasterizerData*>* out Rasterizers) { | |
| 1909 for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) { | |
| 1910 const char* rasterizer = FLAGS_pdfRasterizers[i]; | |
| 1911 const PDFRasterizerData* rasterizerPtr = findPDFRasterizer(rasterizer); | |
| 1912 | |
| 1913 if (rasterizerPtr == NULL) { | |
| 1914 gm_fprintf(stderr, "unrecognized rasterizer %s\n", rasterizer); | |
| 1915 return false; | |
| 1916 } | |
| 1917 appendUnique<const PDFRasterizerData*>(outRasterizers, | |
| 1918 rasterizerPtr); | |
| 1919 } | |
| 1920 | |
| 1921 if (outRasterizers->count() == 0) { | |
| 1922 // if no config is specified by user, add the defaults | |
| 1923 for (size_t i = 0; i < SK_ARRAY_COUNT(kPDFRasterizers); ++i) { | |
| 1924 if (kPDFRasterizers[i].fRunByDefault) { | |
| 1925 *outRasterizers->append() = &kPDFRasterizers[i]; | |
| 1926 } | |
| 1927 } | |
| 1928 } | |
| 1929 | |
| 1930 // now show the user the set of configs that will be run. | |
| 1931 SkString configStr("These PDF rasterizers will be run: "); | |
| 1932 // show the user the config that will run. | |
| 1933 for (int i = 0; i < outRasterizers->count(); ++i) { | |
| 1934 configStr.appendf("%s ", (*outRasterizers)[i]->fName); | |
| 1935 } | |
| 1936 gm_fprintf(stdout, "%s\n", configStr.c_str()); | |
| 1937 | |
| 1938 return true; | |
| 1939 } | |
| 1940 | |
| 1873 static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) { | 1941 static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) { |
| 1874 if (FLAGS_ignoreErrorTypes.count() > 0) { | 1942 if (FLAGS_ignoreErrorTypes.count() > 0) { |
| 1875 *outErrorTypes = ErrorCombination(); | 1943 *outErrorTypes = ErrorCombination(); |
| 1876 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { | 1944 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { |
| 1877 ErrorType type; | 1945 ErrorType type; |
| 1878 const char *name = FLAGS_ignoreErrorTypes[i]; | 1946 const char *name = FLAGS_ignoreErrorTypes[i]; |
| 1879 if (!getErrorTypeByName(name, &type)) { | 1947 if (!getErrorTypeByName(name, &type)) { |
| 1880 gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", nam e); | 1948 gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", nam e); |
| 1881 return false; | 1949 return false; |
| 1882 } else { | 1950 } else { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2005 | 2073 |
| 2006 setSystemPreferences(); | 2074 setSystemPreferences(); |
| 2007 GMMain gmmain; | 2075 GMMain gmmain; |
| 2008 | 2076 |
| 2009 SkString usage; | 2077 SkString usage; |
| 2010 usage.printf("Run the golden master tests.\n"); | 2078 usage.printf("Run the golden master tests.\n"); |
| 2011 SkCommandLineFlags::SetUsage(usage.c_str()); | 2079 SkCommandLineFlags::SetUsage(usage.c_str()); |
| 2012 SkCommandLineFlags::Parse(argc, argv); | 2080 SkCommandLineFlags::Parse(argc, argv); |
| 2013 | 2081 |
| 2014 SkTDArray<size_t> configs; | 2082 SkTDArray<size_t> configs; |
| 2083 | |
| 2015 int moduloRemainder = -1; | 2084 int moduloRemainder = -1; |
| 2016 int moduloDivisor = -1; | 2085 int moduloDivisor = -1; |
| 2086 SkTDArray<const PDFRasterizerData*> pdfRasterizers; | |
| 2017 SkTDArray<SkScalar> tileGridReplayScales; | 2087 SkTDArray<SkScalar> tileGridReplayScales; |
| 2018 #if SK_SUPPORT_GPU | 2088 #if SK_SUPPORT_GPU |
| 2019 GrContextFactory* grFactory = new GrContextFactory; | 2089 GrContextFactory* grFactory = new GrContextFactory; |
| 2020 #else | 2090 #else |
| 2021 GrContextFactory* grFactory = NULL; | 2091 GrContextFactory* grFactory = NULL; |
| 2022 #endif | 2092 #endif |
| 2023 SkTDArray<const char*> matchStrs; | 2093 SkTDArray<const char*> matchStrs; |
| 2024 | 2094 |
| 2025 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) || | 2095 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) || |
| 2026 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) || | 2096 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) || |
| 2027 #if SK_SUPPORT_GPU | 2097 #if SK_SUPPORT_GPU |
| 2028 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) || | 2098 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) || |
| 2029 #endif | 2099 #endif |
| 2030 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) || | 2100 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) || |
| 2031 !parse_flags_gmmain_paths(&gmmain) || | 2101 !parse_flags_gmmain_paths(&gmmain) || |
| 2032 !parse_flags_resource_path() || | 2102 !parse_flags_resource_path() || |
| 2033 !parse_flags_match_strs(&matchStrs) || | 2103 !parse_flags_match_strs(&matchStrs) || |
| 2034 !parse_flags_jpeg_quality() || | 2104 !parse_flags_jpeg_quality() || |
| 2035 !parse_flags_configs(&configs, grFactory)) { | 2105 !parse_flags_configs(&configs, grFactory) || |
| 2106 !parse_flags_pdf_rasterizers(&pdfRasterizers)) { | |
| 2036 return -1; | 2107 return -1; |
| 2037 } | 2108 } |
| 2038 | 2109 |
| 2039 if (FLAGS_verbose) { | 2110 if (FLAGS_verbose) { |
| 2040 if (FLAGS_writePath.count() == 1) { | 2111 if (FLAGS_writePath.count() == 1) { |
| 2041 gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); | 2112 gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); |
| 2042 } | 2113 } |
| 2043 if (NULL != gmmain.fMismatchPath) { | 2114 if (NULL != gmmain.fMismatchPath) { |
| 2044 gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPat h); | 2115 gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPat h); |
| 2045 } | 2116 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2093 | 2164 |
| 2094 if (SkCommandLineFlags::ShouldSkip(matchStrs, shortName)) { | 2165 if (SkCommandLineFlags::ShouldSkip(matchStrs, shortName)) { |
| 2095 continue; | 2166 continue; |
| 2096 } | 2167 } |
| 2097 | 2168 |
| 2098 gmsRun++; | 2169 gmsRun++; |
| 2099 SkISize size = gm->getISize(); | 2170 SkISize size = gm->getISize(); |
| 2100 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), short Name, | 2171 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), short Name, |
| 2101 size.width(), size.height()); | 2172 size.width(), size.height()); |
| 2102 | 2173 |
| 2103 run_multiple_configs(gmmain, gm, configs, grFactory); | 2174 run_multiple_configs(gmmain, gm, configs, pdfRasterizers, grFactory); |
| 2104 | 2175 |
| 2105 SkBitmap comparisonBitmap; | 2176 SkBitmap comparisonBitmap; |
| 2106 const ConfigData compareConfig = | 2177 const ConfigData compareConfig = |
| 2107 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextT ype, 0, kRW_ConfigFlag, "comparison", false }; | 2178 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextT ype, 0, kRW_ConfigFlag, "comparison", false }; |
| 2108 gmmain.generate_image(gm, compareConfig, NULL, &comparisonBitmap, false) ; | 2179 gmmain.generate_image(gm, compareConfig, NULL, &comparisonBitmap, false) ; |
| 2109 | 2180 |
| 2110 // TODO(epoger): only run this if gmmain.generate_image() succeeded? | 2181 // TODO(epoger): only run this if gmmain.generate_image() succeeded? |
| 2111 // Otherwise, what are we comparing against? | 2182 // Otherwise, what are we comparing against? |
| 2112 run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap, tileGrid ReplayScales); | 2183 run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap, tileGrid ReplayScales); |
| 2113 } | 2184 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2177 if (FLAGS_forceBWtext) { | 2248 if (FLAGS_forceBWtext) { |
| 2178 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2249 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2179 } | 2250 } |
| 2180 } | 2251 } |
| 2181 | 2252 |
| 2182 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2253 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 2183 int main(int argc, char * const argv[]) { | 2254 int main(int argc, char * const argv[]) { |
| 2184 return tool_main(argc, (char**) argv); | 2255 return tool_main(argc, (char**) argv); |
| 2185 } | 2256 } |
| 2186 #endif | 2257 #endif |
| OLD | NEW |