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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 uint32_t flags; | 186 uint32_t flags; |
187 }; | 187 }; |
188 | 188 |
189 static PipeFlagComboData gPipeWritingFlagCombos[] = { | 189 static PipeFlagComboData gPipeWritingFlagCombos[] = { |
190 { "", 0 }, | 190 { "", 0 }, |
191 { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, | 191 { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
192 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag | 192 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
193 | SkGPipeWriter::kSharedAddressSpace_Flag } | 193 | SkGPipeWriter::kSharedAddressSpace_Flag } |
194 }; | 194 }; |
195 | 195 |
196 static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, cons
t SkIRect& rect); | 196 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap
); |
197 | 197 |
198 const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() | 198 const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() |
199 .plus(kMissingExpectations_ErrorType) | 199 .plus(kMissingExpectations_ErrorType) |
200 .plus(kIntentionallySkipped_ErrorType); | 200 .plus(kIntentionallySkipped_ErrorType); |
201 | 201 |
202 class GMMain { | 202 class GMMain { |
203 public: | 203 public: |
204 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), | 204 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), |
205 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), | 205 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), |
206 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0)
, | 206 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0)
, |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), | 626 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
627 SkIntToScalar(pageSize.height())); | 627 SkIntToScalar(pageSize.height())); |
628 initialTransform.mapRect(&content); | 628 initialTransform.mapRect(&content); |
629 content.intersect(0, 0, SkIntToScalar(pageSize.width()), | 629 content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
630 SkIntToScalar(pageSize.height())); | 630 SkIntToScalar(pageSize.height())); |
631 SkISize contentSize = | 631 SkISize contentSize = |
632 SkISize::Make(SkScalarRoundToInt(content.width()), | 632 SkISize::Make(SkScalarRoundToInt(content.width()), |
633 SkScalarRoundToInt(content.height())); | 633 SkScalarRoundToInt(content.height())); |
634 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); | 634 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
635 } | 635 } |
636 dev->setDCTEncoder(encode_to_dct_stream); | 636 dev->setDCTEncoder(encode_to_dct_data); |
637 SkAutoUnref aur(dev); | 637 SkAutoUnref aur(dev); |
638 | 638 |
639 SkCanvas c(dev); | 639 SkCanvas c(dev); |
640 invokeGM(gm, &c, true, false); | 640 invokeGM(gm, &c, true, false); |
641 | 641 |
642 SkPDFDocument doc; | 642 SkPDFDocument doc; |
643 doc.appendPage(dev); | 643 doc.appendPage(dev); |
644 doc.emitPDF(&pdf); | 644 doc.emitPDF(&pdf); |
645 #endif | 645 #endif |
646 } | 646 } |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 "each test)."); | 1416 "each test)."); |
1417 DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images,
use checksum-" | 1417 DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images,
use checksum-" |
1418 "based filenames, as rebaseline.py will use when downloading them fr
om Google Storage"); | 1418 "based filenames, as rebaseline.py will use when downloading them fr
om Google Storage"); |
1419 DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary t
o this file."); | 1419 DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary t
o this file."); |
1420 DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); | 1420 DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); |
1421 DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.")
; | 1421 DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.")
; |
1422 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " | 1422 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " |
1423 "which can be in range 0-100). N = -1 will disable JPEG compression
. " | 1423 "which can be in range 0-100). N = -1 will disable JPEG compression
. " |
1424 "Default is N = 100, maximum quality."); | 1424 "Default is N = 100, maximum quality."); |
1425 | 1425 |
1426 static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, cons
t SkIRect& rect) { | 1426 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap
) { |
1427 // Filter output of warnings that JPEG is not available for the image. | 1427 // Filter output of warnings that JPEG is not available for the image. |
1428 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return false; | 1428 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return false; |
1429 if (FLAGS_pdfJpegQuality == -1) return false; | 1429 if (FLAGS_pdfJpegQuality == -1) return false; |
1430 | 1430 |
1431 SkIRect bitmapBounds; | 1431 SkBitmap bm = bitmap; |
1432 SkBitmap subset; | |
1433 const SkBitmap* bitmapToUse = &bitmap; | |
1434 bitmap.getBounds(&bitmapBounds); | |
1435 if (rect != bitmapBounds) { | |
1436 SkAssertResult(bitmap.extractSubset(&subset, rect)); | |
1437 bitmapToUse = ⊂ | |
1438 } | |
1439 | |
1440 #if defined(SK_BUILD_FOR_MAC) | 1432 #if defined(SK_BUILD_FOR_MAC) |
1441 // Workaround bug #1043 where bitmaps with referenced pixels cause | 1433 // Workaround bug #1043 where bitmaps with referenced pixels cause |
1442 // CGImageDestinationFinalize to crash | 1434 // CGImageDestinationFinalize to crash |
1443 SkBitmap copy; | 1435 SkBitmap copy; |
1444 bitmapToUse->deepCopyTo(©, bitmapToUse->config()); | 1436 bitmapToUse->deepCopyTo(©, bitmapToUse->config()); |
1445 bitmapToUse = © | 1437 bm = © |
1446 #endif | 1438 #endif |
1447 | 1439 |
1448 return SkImageEncoder::EncodeStream(stream, | 1440 SkPixelRef* pr = bm.pixelRef(); |
1449 *bitmapToUse, | 1441 if (pr != NULL) { |
1450 SkImageEncoder::kJPEG_Type, | 1442 SkData* data = pr->refEncodedData(); |
1451 FLAGS_pdfJpegQuality); | 1443 if (data != NULL) { |
| 1444 *pixelRefOffset = bm.pixelRefOffset(); |
| 1445 return data; |
| 1446 } |
| 1447 } |
| 1448 |
| 1449 *pixelRefOffset = 0; |
| 1450 return SkImageEncoder::EncodeData(bm, |
| 1451 SkImageEncoder::kJPEG_Type, |
| 1452 FLAGS_pdfJpegQuality); |
1452 } | 1453 } |
1453 | 1454 |
1454 static int findConfig(const char config[]) { | 1455 static int findConfig(const char config[]) { |
1455 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { | 1456 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
1456 if (!strcmp(config, gRec[i].fName)) { | 1457 if (!strcmp(config, gRec[i].fName)) { |
1457 return (int) i; | 1458 return (int) i; |
1458 } | 1459 } |
1459 } | 1460 } |
1460 return -1; | 1461 return -1; |
1461 } | 1462 } |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2254 if (FLAGS_forceBWtext) { | 2255 if (FLAGS_forceBWtext) { |
2255 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2256 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
2256 } | 2257 } |
2257 } | 2258 } |
2258 | 2259 |
2259 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2260 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
2260 int main(int argc, char * const argv[]) { | 2261 int main(int argc, char * const argv[]) { |
2261 return tool_main(argc, (char**) argv); | 2262 return tool_main(argc, (char**) argv); |
2262 } | 2263 } |
2263 #endif | 2264 #endif |
OLD | NEW |