Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2570)

Side by Side Diff: gm/gmmain.cpp

Issue 25054002: Use SkPicture::ExtractBitmap callback in pdf too. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix return on another funtion with signature change Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | include/pdf/SkPDFDevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more i nfo about " 1415 DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more i nfo about "
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
1426 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix 1425 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1427 // Either the 9 numbers defining the matrix 1426 // Either the 9 numbers defining the matrix
1428 // or probably more readable would be to replace it with a set of a few predicat es 1427 // or probably more readable would be to replace it with a set of a few predicat es
1429 // Like --prerotate 100 200 10 --posttranslate 10, 10 1428 // Like --prerotate 100 200 10 --posttranslate 10, 10
1430 // Probably define spacial names like centerx, centery, top, bottom, left, right 1429 // Probably define spacial names like centerx, centery, top, bottom, left, right
1431 // then we can write something reabable like --rotate centerx centery 90 1430 // then we can write something reabable like --rotate centerx centery 90
1432 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); 1431 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
1433 1432
1434 static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, cons t SkIRect& rect) { 1433 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap ) {
1435 // Filter output of warnings that JPEG is not available for the image. 1434 // Filter output of warnings that JPEG is not available for the image.
1436 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return false; 1435 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1437 if (FLAGS_pdfJpegQuality == -1) return false; 1436 if (FLAGS_pdfJpegQuality == -1) return NULL;
1438 1437
1439 SkIRect bitmapBounds; 1438 SkBitmap bm = bitmap;
1440 SkBitmap subset;
1441 const SkBitmap* bitmapToUse = &bitmap;
1442 bitmap.getBounds(&bitmapBounds);
1443 if (rect != bitmapBounds) {
1444 SkAssertResult(bitmap.extractSubset(&subset, rect));
1445 bitmapToUse = ⊂
1446 }
1447
1448 #if defined(SK_BUILD_FOR_MAC) 1439 #if defined(SK_BUILD_FOR_MAC)
1449 // Workaround bug #1043 where bitmaps with referenced pixels cause 1440 // Workaround bug #1043 where bitmaps with referenced pixels cause
1450 // CGImageDestinationFinalize to crash 1441 // CGImageDestinationFinalize to crash
1451 SkBitmap copy; 1442 SkBitmap copy;
1452 bitmapToUse->deepCopyTo(&copy, bitmapToUse->config()); 1443 bitmap.deepCopyTo(&copy, bitmap.config());
1453 bitmapToUse = © 1444 bm = copy;
1454 #endif 1445 #endif
1455 1446
1456 return SkImageEncoder::EncodeStream(stream, 1447 SkPixelRef* pr = bm.pixelRef();
1457 *bitmapToUse, 1448 if (pr != NULL) {
1458 SkImageEncoder::kJPEG_Type, 1449 SkData* data = pr->refEncodedData();
1459 FLAGS_pdfJpegQuality); 1450 if (data != NULL) {
1451 *pixelRefOffset = bm.pixelRefOffset();
1452 return data;
1453 }
1454 }
1455
1456 *pixelRefOffset = 0;
1457 return SkImageEncoder::EncodeData(bm,
1458 SkImageEncoder::kJPEG_Type,
1459 FLAGS_pdfJpegQuality);
1460 } 1460 }
1461 1461
1462 static int findConfig(const char config[]) { 1462 static int findConfig(const char config[]) {
1463 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { 1463 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1464 if (!strcmp(config, gRec[i].fName)) { 1464 if (!strcmp(config, gRec[i].fName)) {
1465 return (int) i; 1465 return (int) i;
1466 } 1466 }
1467 } 1467 }
1468 return -1; 1468 return -1;
1469 } 1469 }
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 if (FLAGS_forceBWtext) { 2271 if (FLAGS_forceBWtext) {
2272 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); 2272 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2273 } 2273 }
2274 } 2274 }
2275 2275
2276 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 2276 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
2277 int main(int argc, char * const argv[]) { 2277 int main(int argc, char * const argv[]) {
2278 return tool_main(argc, (char**) argv); 2278 return tool_main(argc, (char**) argv);
2279 } 2279 }
2280 #endif 2280 #endif
OLDNEW
« no previous file with comments | « no previous file | include/pdf/SkPDFDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698