| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #else | 66 #else |
| 67 class GrContextFactory; | 67 class GrContextFactory; |
| 68 class GrContext; | 68 class GrContext; |
| 69 class GrSurface; | 69 class GrSurface; |
| 70 typedef int GLContextType; | 70 typedef int GLContextType; |
| 71 typedef int GrGLStandard; | 71 typedef int GrGLStandard; |
| 72 #endif | 72 #endif |
| 73 | 73 |
| 74 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") | 74 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") |
| 75 | 75 |
| 76 DECLARE_bool(useDocumentInsteadOfDevice); |
| 77 |
| 78 #ifdef SK_SUPPORT_PDF |
| 79 #include "SkPDFDevice.h" |
| 80 #include "SkPDFDocument.h" |
| 81 #endif |
| 82 |
| 76 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , | 83 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 77 // stop writing out XPS-format image baselines in gm. | 84 // stop writing out XPS-format image baselines in gm. |
| 78 #undef SK_SUPPORT_XPS | 85 #undef SK_SUPPORT_XPS |
| 79 #ifdef SK_SUPPORT_XPS | 86 #ifdef SK_SUPPORT_XPS |
| 80 #include "SkXPSDevice.h" | 87 #include "SkXPSDevice.h" |
| 81 #endif | 88 #endif |
| 82 | 89 |
| 83 #ifdef SK_BUILD_FOR_MAC | 90 #ifdef SK_BUILD_FOR_MAC |
| 84 #include "SkCGUtils.h" | 91 #include "SkCGUtils.h" |
| 85 #endif | 92 #endif |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 SkCanvas canvas(*bitmap); | 652 SkCanvas canvas(*bitmap); |
| 646 installFilter(&canvas); | 653 installFilter(&canvas); |
| 647 canvas.scale(scale, scale); | 654 canvas.scale(scale, scale); |
| 648 canvas.drawPicture(pict); | 655 canvas.drawPicture(pict); |
| 649 complete_bitmap(bitmap); | 656 complete_bitmap(bitmap); |
| 650 } | 657 } |
| 651 } | 658 } |
| 652 | 659 |
| 653 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { | 660 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 654 #ifdef SK_SUPPORT_PDF | 661 #ifdef SK_SUPPORT_PDF |
| 655 SkAutoTUnref<SkDocument> pdfDoc( | 662 SkMatrix initialTransform = gm->getInitialTransform(); |
| 656 SkDocument::CreatePDF(&pdf, NULL, encode_to_dct_data, | 663 if (FLAGS_useDocumentInsteadOfDevice) { |
| 657 SkIntToScalar(FLAGS_pdfRasterDpi))); | 664 SkISize pageISize = gm->getISize(); |
| 658 if (!pdfDoc) { | 665 SkAutoTUnref<SkDocument> pdfDoc( |
| 659 return false; | 666 SkDocument::CreatePDF(&pdf, NULL, |
| 667 encode_to_dct_data, |
| 668 SkIntToScalar(FLAGS_pdfRasterDpi))); |
| 669 |
| 670 if (!pdfDoc.get()) { |
| 671 return false; |
| 672 } |
| 673 |
| 674 SkCanvas* canvas = NULL; |
| 675 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), |
| 676 SkIntToScalar(pageISize.height())); |
| 677 canvas->concat(initialTransform); |
| 678 |
| 679 invokeGM(gm, canvas, true, false); |
| 680 |
| 681 return pdfDoc->close(); |
| 682 } else { |
| 683 SkISize pageSize = gm->getISize(); |
| 684 SkPDFDevice* dev = NULL; |
| 685 if (initialTransform.isIdentity()) { |
| 686 dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 687 } else { |
| 688 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 689 SkIntToScalar(pageSize.height())
); |
| 690 initialTransform.mapRect(&content); |
| 691 content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 692 SkIntToScalar(pageSize.height())); |
| 693 SkISize contentSize = |
| 694 SkISize::Make(SkScalarRoundToInt(content.width()), |
| 695 SkScalarRoundToInt(content.height())); |
| 696 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 697 } |
| 698 dev->setDCTEncoder(encode_to_dct_data); |
| 699 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi)); |
| 700 SkAutoUnref aur(dev); |
| 701 SkCanvas c(dev); |
| 702 invokeGM(gm, &c, true, false); |
| 703 SkPDFDocument doc; |
| 704 doc.appendPage(dev); |
| 705 doc.emitPDF(&pdf); |
| 660 } | 706 } |
| 661 | |
| 662 SkISize pageISize = gm->getISize(); | |
| 663 SkCanvas* canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), | |
| 664 SkIntToScalar(pageISize.height())); | |
| 665 canvas->concat(gm->getInitialTransform()); | |
| 666 | |
| 667 invokeGM(gm, canvas, true, false); | |
| 668 | |
| 669 return pdfDoc->close(); | |
| 670 #endif // SK_SUPPORT_PDF | 707 #endif // SK_SUPPORT_PDF |
| 671 return true; // Do not report failure if pdf is not supported. | 708 return true; // Do not report failure if pdf is not supported. |
| 672 } | 709 } |
| 673 | 710 |
| 674 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { | 711 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 675 #ifdef SK_SUPPORT_XPS | 712 #ifdef SK_SUPPORT_XPS |
| 676 SkISize size = gm->getISize(); | 713 SkISize size = gm->getISize(); |
| 677 | 714 |
| 678 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), | 715 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 679 SkIntToScalar(size.height())); | 716 SkIntToScalar(size.height())); |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " | 1498 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " |
| 1462 "which can be in range 0-100). N = -1 will disable JPEG compression
. " | 1499 "which can be in range 0-100). N = -1 will disable JPEG compression
. " |
| 1463 "Default is N = 100, maximum quality."); | 1500 "Default is N = 100, maximum quality."); |
| 1464 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix | 1501 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix |
| 1465 // Either the 9 numbers defining the matrix | 1502 // Either the 9 numbers defining the matrix |
| 1466 // or probably more readable would be to replace it with a set of a few predicat
es | 1503 // or probably more readable would be to replace it with a set of a few predicat
es |
| 1467 // Like --prerotate 100 200 10 --posttranslate 10, 10 | 1504 // Like --prerotate 100 200 10 --posttranslate 10, 10 |
| 1468 // Probably define spacial names like centerx, centery, top, bottom, left, right | 1505 // Probably define spacial names like centerx, centery, top, bottom, left, right |
| 1469 // then we can write something reabable like --rotate centerx centery 90 | 1506 // then we can write something reabable like --rotate centerx centery 90 |
| 1470 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); | 1507 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); |
| 1508 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea
d of SkFooDevice."); |
| 1471 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " | 1509 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " |
| 1472 "features in PDF are rasterized. Must be be in range 0-10000. " | 1510 "features in PDF are rasterized. Must be be in range 0-10000. " |
| 1473 "Default is 72. N = 0 will disable rasterizing features like " | 1511 "Default is 72. N = 0 will disable rasterizing features like " |
| 1474 "text shadows or perspective bitmaps."); | 1512 "text shadows or perspective bitmaps."); |
| 1475 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { | 1513 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { |
| 1476 // Filter output of warnings that JPEG is not available for the image. | 1514 // Filter output of warnings that JPEG is not available for the image. |
| 1477 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; | 1515 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; |
| 1478 if (FLAGS_pdfJpegQuality == -1) return NULL; | 1516 if (FLAGS_pdfJpegQuality == -1) return NULL; |
| 1479 | 1517 |
| 1480 SkBitmap bm = bitmap; | 1518 SkBitmap bm = bitmap; |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2452 if (FLAGS_forceBWtext) { | 2490 if (FLAGS_forceBWtext) { |
| 2453 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2491 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2454 } | 2492 } |
| 2455 } | 2493 } |
| 2456 | 2494 |
| 2457 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2495 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 2458 int main(int argc, char * const argv[]) { | 2496 int main(int argc, char * const argv[]) { |
| 2459 return tool_main(argc, (char**) argv); | 2497 return tool_main(argc, (char**) argv); |
| 2460 } | 2498 } |
| 2461 #endif | 2499 #endif |
| OLD | NEW |