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 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 if (useMPD) { | 648 if (useMPD) { |
649 SkMultiPictureDraw mpd; | 649 SkMultiPictureDraw mpd; |
650 mpd.add(surf->getCanvas(), pict, &matrix, NULL); | 650 mpd.add(surf->getCanvas(), pict, &matrix, NULL); |
651 mpd.draw(); | 651 mpd.draw(); |
652 } else { | 652 } else { |
653 surf->getCanvas()->drawPicture(pict, &matrix, NULL); | 653 surf->getCanvas()->drawPicture(pict, &matrix, NULL); |
654 } | 654 } |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 static void generate_image_from_picture(GM* gm, const ConfigData& config, | 658 static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
659 GrSurface* gpuTarget, | |
660 SkPicture* pict, SkBitmap* bitmap, | 659 SkPicture* pict, SkBitmap* bitmap, |
661 SkScalar scale = SK_Scalar1, | 660 SkScalar scale = SK_Scalar1, |
662 bool tile = false) { | 661 bool tile = false) { |
663 const SkISize size = gm->getISize(); | 662 SkISize size = gm->getISize(); |
| 663 setup_bitmap(gRec, size, bitmap); |
664 | 664 |
665 SkAutoTUnref<SkSurface> surf(CreateSurface(config, size, gpuTarget)); | 665 SkAutoTUnref<SkSurface> surf(SkSurface::NewRasterDirect(bitmap->info(), |
| 666 bitmap->getPixel
s(), |
| 667 bitmap->rowBytes
())); |
666 | 668 |
667 DrawPictureToSurface(surf, pict, scale, tile, false); | 669 DrawPictureToSurface(surf, pict, scale, tile, false); |
668 | |
669 setup_bitmap(config, size, bitmap); | |
670 | |
671 surf->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes()
, 0, 0); | |
672 | |
673 complete_bitmap(bitmap); | 670 complete_bitmap(bitmap); |
674 } | 671 } |
675 | 672 |
676 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { | 673 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
677 #ifdef SK_SUPPORT_PDF | 674 #ifdef SK_SUPPORT_PDF |
678 SkMatrix initialTransform = gm->getInitialTransform(); | 675 SkMatrix initialTransform = gm->getInitialTransform(); |
679 if (FLAGS_useDocumentInsteadOfDevice) { | 676 if (FLAGS_useDocumentInsteadOfDevice) { |
680 SkISize pageISize = gm->getISize(); | 677 SkISize pageISize = gm->getISize(); |
681 SkAutoTUnref<SkDocument> pdfDoc( | 678 SkAutoTUnref<SkDocument> pdfDoc( |
682 SkDocument::CreatePDF(&pdf, NULL, | 679 SkDocument::CreatePDF(&pdf, NULL, |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 } | 1623 } |
1627 } | 1624 } |
1628 | 1625 |
1629 /** | 1626 /** |
1630 * Run this test in a number of different drawing modes (pipe, | 1627 * Run this test in a number of different drawing modes (pipe, |
1631 * deferred, tiled, etc.), confirming that the resulting bitmaps all | 1628 * deferred, tiled, etc.), confirming that the resulting bitmaps all |
1632 * *exactly* match comparisonBitmap. | 1629 * *exactly* match comparisonBitmap. |
1633 * | 1630 * |
1634 * Returns all errors encountered while doing so. | 1631 * Returns all errors encountered while doing so. |
1635 */ | 1632 */ |
1636 ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, | 1633 ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &co
mpareConfig, |
1637 const ConfigData &compareConfig, GrSurface*
gpuTarget, | |
1638 const SkBitmap &comparisonBitmap, | 1634 const SkBitmap &comparisonBitmap, |
1639 const SkTDArray<SkScalar> &tileGridReplaySca
les); | 1635 const SkTDArray<SkScalar> &tileGridReplaySca
les); |
1640 ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, | 1636 ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &co
mpareConfig, |
1641 const ConfigData &compareConfig, GrSurface*
gpuTarget, | |
1642 const SkBitmap &comparisonBitmap, | 1637 const SkBitmap &comparisonBitmap, |
1643 const SkTDArray<SkScalar> &tileGridReplaySca
les) { | 1638 const SkTDArray<SkScalar> &tileGridReplaySca
les) { |
1644 ErrorCombination errorsForAllModes; | 1639 ErrorCombination errorsForAllModes; |
1645 uint32_t gmFlags = gm->getFlags(); | 1640 uint32_t gmFlags = gm->getFlags(); |
1646 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->g
etName(), | 1641 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->g
etName(), |
1647 compa
reConfig.fName); | 1642 compa
reConfig.fName); |
1648 | 1643 |
1649 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); | 1644 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); |
1650 SkAutoTUnref<SkPicture> aur(pict); | 1645 SkAutoTUnref<SkPicture> aur(pict); |
1651 if (FLAGS_replay) { | 1646 if (FLAGS_replay) { |
1652 const char renderModeDescriptor[] = "-replay"; | 1647 const char renderModeDescriptor[] = "-replay"; |
1653 if (gmFlags & GM::kSkipPicture_Flag) { | 1648 if (gmFlags & GM::kSkipPicture_Flag) { |
1654 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNameP
lusConfig, | 1649 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNameP
lusConfig, |
1655 renderModeDescriptor); | 1650 renderModeDescriptor); |
1656 errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 1651 errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
1657 } else { | 1652 } else { |
1658 SkBitmap bitmap; | 1653 SkBitmap bitmap; |
1659 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget, pic
t, &bitmap); | 1654 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap)
; |
1660 | |
1661 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitma
p( | 1655 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitma
p( |
1662 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap
, | 1656 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap
, |
1663 &comparisonBitmap)); | 1657 &comparisonBitmap)); |
1664 } | 1658 } |
1665 } | 1659 } |
1666 | 1660 |
1667 if (FLAGS_serialize) { | 1661 if (FLAGS_serialize) { |
1668 const char renderModeDescriptor[] = "-serialize"; | 1662 const char renderModeDescriptor[] = "-serialize"; |
1669 if (gmFlags & GM::kSkipPicture_Flag) { | 1663 if (gmFlags & GM::kSkipPicture_Flag) { |
1670 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNameP
lusConfig, | 1664 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNameP
lusConfig, |
1671 renderModeDescriptor); | 1665 renderModeDescriptor); |
1672 errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 1666 errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
1673 } else { | 1667 } else { |
1674 SkPicture* repict = gmmain.stream_to_new_picture(*pict); | 1668 SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
1675 SkAutoTUnref<SkPicture> aurr(repict); | 1669 SkAutoTUnref<SkPicture> aurr(repict); |
1676 SkBitmap bitmap; | 1670 SkBitmap bitmap; |
1677 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget, rep
ict, &bitmap); | 1671 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitma
p); |
1678 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitma
p( | 1672 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitma
p( |
1679 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap
, | 1673 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap
, |
1680 &comparisonBitmap)); | 1674 &comparisonBitmap)); |
1681 } | 1675 } |
1682 } | 1676 } |
1683 | 1677 |
1684 if ((1 == FLAGS_writePicturePath.count()) && | 1678 if ((1 == FLAGS_writePicturePath.count()) && |
1685 !(gmFlags & GM::kSkipPicture_Flag)) { | 1679 !(gmFlags & GM::kSkipPicture_Flag)) { |
1686 const char* pictureSuffix = "skp"; | 1680 const char* pictureSuffix = "skp"; |
1687 // TODO(epoger): Make sure this still works even though the | 1681 // TODO(epoger): Make sure this still works even though the |
(...skipping 12 matching lines...) Expand all Loading... |
1700 if (FLAGS_rtree) { | 1694 if (FLAGS_rtree) { |
1701 const char renderModeDescriptor[] = "-rtree"; | 1695 const char renderModeDescriptor[] = "-rtree"; |
1702 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)
) { | 1696 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)
) { |
1703 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNameP
lusConfig, | 1697 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNameP
lusConfig, |
1704 renderModeDescriptor); | 1698 renderModeDescriptor); |
1705 errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 1699 errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
1706 } else { | 1700 } else { |
1707 SkPicture* pict = gmmain.generate_new_picture(gm, kRTree_BbhType, 0)
; | 1701 SkPicture* pict = gmmain.generate_new_picture(gm, kRTree_BbhType, 0)
; |
1708 SkAutoTUnref<SkPicture> aur(pict); | 1702 SkAutoTUnref<SkPicture> aur(pict); |
1709 SkBitmap bitmap; | 1703 SkBitmap bitmap; |
1710 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget, pic
t, &bitmap); | 1704 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap)
; |
1711 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitma
p( | 1705 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitma
p( |
1712 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap
, | 1706 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap
, |
1713 &comparisonBitmap)); | 1707 &comparisonBitmap)); |
1714 } | 1708 } |
1715 } | 1709 } |
1716 | 1710 |
1717 if (FLAGS_tileGrid) { | 1711 if (FLAGS_tileGrid) { |
1718 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++sca
leIndex) { | 1712 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++sca
leIndex) { |
1719 SkScalar replayScale = tileGridReplayScales[scaleIndex]; | 1713 SkScalar replayScale = tileGridReplayScales[scaleIndex]; |
1720 SkString renderModeDescriptor("-tilegrid"); | 1714 SkString renderModeDescriptor("-tilegrid"); |
(...skipping 12 matching lines...) Expand all Loading... |
1733 // We record with the reciprocal scale to obtain a replay | 1727 // We record with the reciprocal scale to obtain a replay |
1734 // result that can be validated against comparisonBitmap. | 1728 // result that can be validated against comparisonBitmap. |
1735 SkScalar recordScale = SkScalarInvert(replayScale); | 1729 SkScalar recordScale = SkScalarInvert(replayScale); |
1736 SkPicture* pict = gmmain.generate_new_picture( | 1730 SkPicture* pict = gmmain.generate_new_picture( |
1737 gm, kTileGrid_BbhType, 0, recordScale); | 1731 gm, kTileGrid_BbhType, 0, recordScale); |
1738 SkAutoTUnref<SkPicture> aur(pict); | 1732 SkAutoTUnref<SkPicture> aur(pict); |
1739 SkBitmap bitmap; | 1733 SkBitmap bitmap; |
1740 // We cannot yet pass 'true' to generate_image_from_picture to | 1734 // We cannot yet pass 'true' to generate_image_from_picture to |
1741 // perform actual tiled rendering (see Issue 1198 - | 1735 // perform actual tiled rendering (see Issue 1198 - |
1742 // https://code.google.com/p/skia/issues/detail?id=1198) | 1736 // https://code.google.com/p/skia/issues/detail?id=1198) |
1743 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget,
pict, &bitmap, | 1737 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bit
map, |
1744 replayScale /*, true */); | 1738 replayScale /*, true */); |
1745 errorsForAllModes.add(gmmain.compare_test_results_to_reference_b
itmap( | 1739 errorsForAllModes.add(gmmain.compare_test_results_to_reference_b
itmap( |
1746 gm->getName(), compareConfig.fName, renderModeDescriptor.c_s
tr(), bitmap, | 1740 gm->getName(), compareConfig.fName, renderModeDescriptor.c_s
tr(), bitmap, |
1747 &comparisonBitmap)); | 1741 &comparisonBitmap)); |
1748 } | 1742 } |
1749 } | 1743 } |
1750 } | 1744 } |
1751 | 1745 |
1752 // run the pipe centric GM steps | 1746 // run the pipe centric GM steps |
1753 if (FLAGS_pipe) { | 1747 if (FLAGS_pipe) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 | 1868 |
1875 if (errorsForThisConfig.isEmpty()) { | 1869 if (errorsForThisConfig.isEmpty()) { |
1876 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterize
rs, | 1870 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterize
rs, |
1877 writePath, gpuTarget, | 1871 writePath, gpuTarget, |
1878 &comparisonBitmap)); | 1872 &comparisonBitmap)); |
1879 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "
"); | 1873 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "
"); |
1880 } | 1874 } |
1881 | 1875 |
1882 // TODO: run only if gmmain.test_drawing succeeded. | 1876 // TODO: run only if gmmain.test_drawing succeeded. |
1883 if (kRaster_Backend == config.fBackend) { | 1877 if (kRaster_Backend == config.fBackend) { |
1884 run_multiple_modes(gmmain, gm, config, gpuTarget, comparisonBitmap,
tileGridReplayScales); | 1878 run_multiple_modes(gmmain, gm, config, comparisonBitmap, tileGridRep
layScales); |
1885 } | 1879 } |
1886 | 1880 |
1887 if (FLAGS_deferred && errorsForThisConfig.isEmpty() && | 1881 if (FLAGS_deferred && errorsForThisConfig.isEmpty() && |
1888 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBacke
nd)) { | 1882 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBacke
nd)) { |
1889 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, com
parisonBitmap, | 1883 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, com
parisonBitmap, |
1890 gpuTarget)); | 1884 gpuTarget)); |
1891 } | 1885 } |
1892 | 1886 |
1893 if (FLAGS_mpd && (kGPU_Backend == config.fBackend || kRaster_Backend ==
config.fBackend)) { | 1887 if (FLAGS_mpd && (kGPU_Backend == config.fBackend || kRaster_Backend ==
config.fBackend)) { |
1894 | 1888 |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2570 if (FLAGS_forceBWtext) { | 2564 if (FLAGS_forceBWtext) { |
2571 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2565 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
2572 } | 2566 } |
2573 } | 2567 } |
2574 | 2568 |
2575 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2569 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
2576 int main(int argc, char * const argv[]) { | 2570 int main(int argc, char * const argv[]) { |
2577 return tool_main(argc, (char**) argv); | 2571 return tool_main(argc, (char**) argv); |
2578 } | 2572 } |
2579 #endif | 2573 #endif |
OLD | NEW |