| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 static PipeFlagComboData gPipeWritingFlagCombos[] = { | 193 static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 194 { "", 0 }, | 194 { "", 0 }, |
| 195 { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, | 195 { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
| 196 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag | 196 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
| 197 | SkGPipeWriter::kSharedAddressSpace_Flag } | 197 | SkGPipeWriter::kSharedAddressSpace_Flag } |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap
); | 200 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap
); |
| 201 DECLARE_int32(pdfRasterDpi); |
| 201 | 202 |
| 202 const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() | 203 const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() |
| 203 .plus(kMissingExpectations_ErrorType) | 204 .plus(kMissingExpectations_ErrorType) |
| 204 .plus(kIntentionallySkipped_ErrorType); | 205 .plus(kIntentionallySkipped_ErrorType); |
| 205 | 206 |
| 206 class GMMain { | 207 class GMMain { |
| 207 public: | 208 public: |
| 208 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), | 209 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), |
| 209 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), | 210 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), |
| 210 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0)
, | 211 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0)
, |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 canvas.drawPicture(*pict); | 630 canvas.drawPicture(*pict); |
| 630 complete_bitmap(bitmap); | 631 complete_bitmap(bitmap); |
| 631 } | 632 } |
| 632 } | 633 } |
| 633 | 634 |
| 634 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { | 635 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 635 #ifdef SK_SUPPORT_PDF | 636 #ifdef SK_SUPPORT_PDF |
| 636 SkMatrix initialTransform = gm->getInitialTransform(); | 637 SkMatrix initialTransform = gm->getInitialTransform(); |
| 637 if (FLAGS_useDocumentInsteadOfDevice) { | 638 if (FLAGS_useDocumentInsteadOfDevice) { |
| 638 SkISize pageISize = gm->getISize(); | 639 SkISize pageISize = gm->getISize(); |
| 639 SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(&pdf, NULL, en
code_to_dct_data)); | 640 SkAutoTUnref<SkDocument> pdfDoc( |
| 641 SkDocument::CreatePDF(&pdf, NULL, |
| 642 encode_to_dct_data, |
| 643 SkIntToScalar(FLAGS_pdfRasterDpi))); |
| 640 | 644 |
| 641 if (!pdfDoc.get()) { | 645 if (!pdfDoc.get()) { |
| 642 return false; | 646 return false; |
| 643 } | 647 } |
| 644 | 648 |
| 645 SkCanvas* canvas = NULL; | 649 SkCanvas* canvas = NULL; |
| 646 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), | 650 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), |
| 647 SkIntToScalar(pageISize.height())); | 651 SkIntToScalar(pageISize.height())); |
| 648 canvas->concat(initialTransform); | 652 canvas->concat(initialTransform); |
| 649 | 653 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 660 SkIntToScalar(pageSize.height())
); | 664 SkIntToScalar(pageSize.height())
); |
| 661 initialTransform.mapRect(&content); | 665 initialTransform.mapRect(&content); |
| 662 content.intersect(0, 0, SkIntToScalar(pageSize.width()), | 666 content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 663 SkIntToScalar(pageSize.height())); | 667 SkIntToScalar(pageSize.height())); |
| 664 SkISize contentSize = | 668 SkISize contentSize = |
| 665 SkISize::Make(SkScalarRoundToInt(content.width()), | 669 SkISize::Make(SkScalarRoundToInt(content.width()), |
| 666 SkScalarRoundToInt(content.height())); | 670 SkScalarRoundToInt(content.height())); |
| 667 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); | 671 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 668 } | 672 } |
| 669 dev->setDCTEncoder(encode_to_dct_data); | 673 dev->setDCTEncoder(encode_to_dct_data); |
| 674 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi)); |
| 670 SkAutoUnref aur(dev); | 675 SkAutoUnref aur(dev); |
| 671 SkCanvas c(dev); | 676 SkCanvas c(dev); |
| 672 invokeGM(gm, &c, true, false); | 677 invokeGM(gm, &c, true, false); |
| 673 SkPDFDocument doc; | 678 SkPDFDocument doc; |
| 674 doc.appendPage(dev); | 679 doc.appendPage(dev); |
| 675 doc.emitPDF(&pdf); | 680 doc.emitPDF(&pdf); |
| 676 } | 681 } |
| 677 #endif // SK_SUPPORT_PDF | 682 #endif // SK_SUPPORT_PDF |
| 678 return true; // Do not report failure if pdf is not supported. | 683 return true; // Do not report failure if pdf is not supported. |
| 679 } | 684 } |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 "which can be in range 0-100). N = -1 will disable JPEG compression
. " | 1473 "which can be in range 0-100). N = -1 will disable JPEG compression
. " |
| 1469 "Default is N = 100, maximum quality."); | 1474 "Default is N = 100, maximum quality."); |
| 1470 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix | 1475 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix |
| 1471 // Either the 9 numbers defining the matrix | 1476 // Either the 9 numbers defining the matrix |
| 1472 // or probably more readable would be to replace it with a set of a few predicat
es | 1477 // or probably more readable would be to replace it with a set of a few predicat
es |
| 1473 // Like --prerotate 100 200 10 --posttranslate 10, 10 | 1478 // Like --prerotate 100 200 10 --posttranslate 10, 10 |
| 1474 // Probably define spacial names like centerx, centery, top, bottom, left, right | 1479 // Probably define spacial names like centerx, centery, top, bottom, left, right |
| 1475 // then we can write something reabable like --rotate centerx centery 90 | 1480 // then we can write something reabable like --rotate centerx centery 90 |
| 1476 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); | 1481 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); |
| 1477 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea
d of SkFooDevice."); | 1482 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea
d of SkFooDevice."); |
| 1478 | 1483 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " |
| 1484 "features in PDF are rasterized. Must be be in range 0-10000. " |
| 1485 "Default is 72. N = 0 will disable rasterizing features like " |
| 1486 "text shadows or perspective bitmaps."); |
| 1479 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap
) { | 1487 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap
) { |
| 1480 // Filter output of warnings that JPEG is not available for the image. | 1488 // Filter output of warnings that JPEG is not available for the image. |
| 1481 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; | 1489 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; |
| 1482 if (FLAGS_pdfJpegQuality == -1) return NULL; | 1490 if (FLAGS_pdfJpegQuality == -1) return NULL; |
| 1483 | 1491 |
| 1484 SkBitmap bm = bitmap; | 1492 SkBitmap bm = bitmap; |
| 1485 #if defined(SK_BUILD_FOR_MAC) | 1493 #if defined(SK_BUILD_FOR_MAC) |
| 1486 // Workaround bug #1043 where bitmaps with referenced pixels cause | 1494 // Workaround bug #1043 where bitmaps with referenced pixels cause |
| 1487 // CGImageDestinationFinalize to crash | 1495 // CGImageDestinationFinalize to crash |
| 1488 SkBitmap copy; | 1496 SkBitmap copy; |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 if (FLAGS_forceBWtext) { | 2386 if (FLAGS_forceBWtext) { |
| 2379 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2387 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2380 } | 2388 } |
| 2381 } | 2389 } |
| 2382 | 2390 |
| 2383 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2391 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 2384 int main(int argc, char * const argv[]) { | 2392 int main(int argc, char * const argv[]) { |
| 2385 return tool_main(argc, (char**) argv); | 2393 return tool_main(argc, (char**) argv); |
| 2386 } | 2394 } |
| 2387 #endif | 2395 #endif |
| OLD | NEW |