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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #else | 67 #else |
68 class GrContextFactory; | 68 class GrContextFactory; |
69 class GrContext; | 69 class GrContext; |
70 class GrSurface; | 70 class GrSurface; |
71 typedef int GLContextType; | 71 typedef int GLContextType; |
72 typedef int GrGLStandard; | 72 typedef int GrGLStandard; |
73 #endif | 73 #endif |
74 | 74 |
75 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") | 75 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") |
76 | 76 |
77 DECLARE_bool(useDocumentInsteadOfDevice); | |
78 | |
79 #ifdef SK_SUPPORT_PDF | |
80 #include "SkPDFDevice.h" | |
81 #include "SkPDFDocument.h" | |
82 #endif | |
83 | |
84 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , | 77 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
85 // stop writing out XPS-format image baselines in gm. | 78 // stop writing out XPS-format image baselines in gm. |
86 #undef SK_SUPPORT_XPS | 79 #undef SK_SUPPORT_XPS |
87 #ifdef SK_SUPPORT_XPS | 80 #ifdef SK_SUPPORT_XPS |
88 #include "SkXPSDevice.h" | 81 #include "SkXPSDevice.h" |
89 #endif | 82 #endif |
90 | 83 |
91 #ifdef SK_BUILD_FOR_MAC | 84 #ifdef SK_BUILD_FOR_MAC |
92 #include "SkCGUtils.h" | 85 #include "SkCGUtils.h" |
93 #endif | 86 #endif |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 661 |
669 setup_bitmap(config, size, bitmap); | 662 setup_bitmap(config, size, bitmap); |
670 | 663 |
671 surf->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes()
, 0, 0); | 664 surf->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes()
, 0, 0); |
672 | 665 |
673 complete_bitmap(bitmap); | 666 complete_bitmap(bitmap); |
674 } | 667 } |
675 | 668 |
676 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { | 669 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
677 #ifdef SK_SUPPORT_PDF | 670 #ifdef SK_SUPPORT_PDF |
678 SkMatrix initialTransform = gm->getInitialTransform(); | 671 SkAutoTUnref<SkDocument> pdfDoc( |
679 if (FLAGS_useDocumentInsteadOfDevice) { | 672 SkDocument::CreatePDF(&pdf, NULL, encode_to_dct_data, |
680 SkISize pageISize = gm->getISize(); | 673 SkIntToScalar(FLAGS_pdfRasterDpi))); |
681 SkAutoTUnref<SkDocument> pdfDoc( | 674 if (!pdfDoc) { |
682 SkDocument::CreatePDF(&pdf, NULL, | 675 return false; |
683 encode_to_dct_data, | 676 } |
684 SkIntToScalar(FLAGS_pdfRasterDpi))); | |
685 | 677 |
686 if (!pdfDoc.get()) { | 678 SkCanvas* canvas = NULL; |
687 return false; | 679 canvas = pdfDoc->beginPage(gm->width(), gm->height()); |
688 } | 680 canvas->concat(gm->getInitialTransform()); |
689 | 681 |
690 SkCanvas* canvas = NULL; | 682 invokeGM(gm, canvas, true, false); |
691 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), | |
692 SkIntToScalar(pageISize.height())); | |
693 canvas->concat(initialTransform); | |
694 | 683 |
695 invokeGM(gm, canvas, true, false); | 684 return pdfDoc->close(); |
696 | 685 |
697 return pdfDoc->close(); | 686 #else // SK_SUPPORT_PDF |
698 } else { | 687 return true; // Do not report failure if pdf is not supported. |
699 SkISize pageSize = gm->getISize(); | |
700 SkPDFDevice* dev = NULL; | |
701 if (initialTransform.isIdentity()) { | |
702 dev = new SkPDFDevice(pageSize, pageSize, initialTransform); | |
703 } else { | |
704 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), | |
705 SkIntToScalar(pageSize.height())
); | |
706 initialTransform.mapRect(&content); | |
707 content.intersect(0, 0, SkIntToScalar(pageSize.width()), | |
708 SkIntToScalar(pageSize.height())); | |
709 SkISize contentSize = | |
710 SkISize::Make(SkScalarRoundToInt(content.width()), | |
711 SkScalarRoundToInt(content.height())); | |
712 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); | |
713 } | |
714 dev->setDCTEncoder(encode_to_dct_data); | |
715 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi)); | |
716 SkAutoUnref aur(dev); | |
717 SkCanvas c(dev); | |
718 invokeGM(gm, &c, true, false); | |
719 SkPDFDocument doc; | |
720 doc.appendPage(dev); | |
721 doc.emitPDF(&pdf); | |
722 } | |
723 #endif // SK_SUPPORT_PDF | 688 #endif // SK_SUPPORT_PDF |
724 return true; // Do not report failure if pdf is not supported. | |
725 } | 689 } |
726 | 690 |
727 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { | 691 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
728 #ifdef SK_SUPPORT_XPS | 692 #ifdef SK_SUPPORT_XPS |
729 SkISize size = gm->getISize(); | 693 SkISize size = gm->getISize(); |
730 | 694 |
731 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), | 695 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
732 SkIntToScalar(size.height())); | 696 SkIntToScalar(size.height())); |
733 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); | 697 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
734 static const SkScalar upm = 72 * inchesPerMeter; | 698 static const SkScalar upm = 72 * inchesPerMeter; |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " | 1535 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " |
1572 "which can be in range 0-100). N = -1 will disable JPEG compression
. " | 1536 "which can be in range 0-100). N = -1 will disable JPEG compression
. " |
1573 "Default is N = 100, maximum quality."); | 1537 "Default is N = 100, maximum quality."); |
1574 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix | 1538 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix |
1575 // Either the 9 numbers defining the matrix | 1539 // Either the 9 numbers defining the matrix |
1576 // or probably more readable would be to replace it with a set of a few predicat
es | 1540 // or probably more readable would be to replace it with a set of a few predicat
es |
1577 // Like --prerotate 100 200 10 --posttranslate 10, 10 | 1541 // Like --prerotate 100 200 10 --posttranslate 10, 10 |
1578 // Probably define spacial names like centerx, centery, top, bottom, left, right | 1542 // Probably define spacial names like centerx, centery, top, bottom, left, right |
1579 // then we can write something reabable like --rotate centerx centery 90 | 1543 // then we can write something reabable like --rotate centerx centery 90 |
1580 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); | 1544 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); |
1581 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea
d of SkFooDevice."); | |
1582 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " | 1545 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " |
1583 "features in PDF are rasterized. Must be be in range 0-10000. " | 1546 "features in PDF are rasterized. Must be be in range 0-10000. " |
1584 "Default is 72. N = 0 will disable rasterizing features like " | 1547 "Default is 72. N = 0 will disable rasterizing features like " |
1585 "text shadows or perspective bitmaps."); | 1548 "text shadows or perspective bitmaps."); |
1586 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { | 1549 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { |
1587 // Filter output of warnings that JPEG is not available for the image. | 1550 // Filter output of warnings that JPEG is not available for the image. |
1588 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; | 1551 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; |
1589 if (FLAGS_pdfJpegQuality == -1) return NULL; | 1552 if (FLAGS_pdfJpegQuality == -1) return NULL; |
1590 | 1553 |
1591 SkBitmap bm = bitmap; | 1554 SkBitmap bm = bitmap; |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2580 if (FLAGS_forceBWtext) { | 2543 if (FLAGS_forceBWtext) { |
2581 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2544 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
2582 } | 2545 } |
2583 } | 2546 } |
2584 | 2547 |
2585 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2548 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
2586 int main(int argc, char * const argv[]) { | 2549 int main(int argc, char * const argv[]) { |
2587 return tool_main(argc, (char**) argv); | 2550 return tool_main(argc, (char**) argv); |
2588 } | 2551 } |
2589 #endif | 2552 #endif |
OLD | NEW |