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

Side by Side Diff: gm/gmmain.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Treat SkFontMgr::createFromStream as taking ownership of the stream (is this correct?) Created 5 years, 11 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
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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 SkPictureRecorder recorder; 1044 SkPictureRecorder recorder;
1045 SkCanvas* cv = recorder.beginRecording(width, height, factory.get(), rec ordFlags); 1045 SkCanvas* cv = recorder.beginRecording(width, height, factory.get(), rec ordFlags);
1046 cv->scale(scale, scale); 1046 cv->scale(scale, scale);
1047 invokeGM(gm, cv, false, false); 1047 invokeGM(gm, cv, false, false);
1048 return recorder.endRecording(); 1048 return recorder.endRecording();
1049 } 1049 }
1050 1050
1051 static SkPicture* stream_to_new_picture(const SkPicture& src) { 1051 static SkPicture* stream_to_new_picture(const SkPicture& src) {
1052 SkDynamicMemoryWStream storage; 1052 SkDynamicMemoryWStream storage;
1053 src.serialize(&storage); 1053 src.serialize(&storage);
1054 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream()); 1054 SkAutoTDelete<SkStreamAsset> pictReadback(storage.detachAsStream());
1055 SkPicture* retval = SkPicture::CreateFromStream(pictReadback, 1055 SkPicture* retval = SkPicture::CreateFromStream(pictReadback,
1056 &SkImageDecoder::DecodeM emory); 1056 &SkImageDecoder::DecodeM emory);
1057 return retval; 1057 return retval;
1058 } 1058 }
1059 1059
1060 // Test: draw into a bitmap or pdf. 1060 // Test: draw into a bitmap or pdf.
1061 // Depending on flags, possibly compare to an expected image. 1061 // Depending on flags, possibly compare to an expected image.
1062 // If writePath is not NULL, also write images (or documents) to the specifi ed path. 1062 // If writePath is not NULL, also write images (or documents) to the specifi ed path.
1063 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec, 1063 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec,
1064 const SkTDArray<const PDFRasterizerData*> &pdf Rasterizers, 1064 const SkTDArray<const PDFRasterizerData*> &pdf Rasterizers,
(...skipping 12 matching lines...) Expand all
1077 // JSON look like if we get an "early error" while 1077 // JSON look like if we get an "early error" while
1078 // trying to generate the image. 1078 // trying to generate the image.
1079 return errors; 1079 return errors;
1080 } 1080 }
1081 1081
1082 errors.add(this->writeBitmap(gm, gRec, gRec.fName, writePath, *bitma p)); 1082 errors.add(this->writeBitmap(gm, gRec, gRec.fName, writePath, *bitma p));
1083 } else if (gRec.fBackend == kPDF_Backend) { 1083 } else if (gRec.fBackend == kPDF_Backend) {
1084 if (!generate_pdf(gm, document)) { 1084 if (!generate_pdf(gm, document)) {
1085 errors.add(kGeneratePdfFailed_ErrorType); 1085 errors.add(kGeneratePdfFailed_ErrorType);
1086 } else { 1086 } else {
1087 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStre am()); 1087 SkAutoTDelete<SkStreamAsset> documentStream(document.detachAsStr eam());
1088 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { 1088 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
1089 SkString path = make_filename(writePath, gm->getName(), gRec .fName, "", "pdf"); 1089 SkString path = make_filename(writePath, gm->getName(), gRec .fName, "", "pdf");
1090 errors.add(write_document(path, documentStream)); 1090 errors.add(write_document(path, documentStream));
1091 } 1091 }
1092 1092
1093 if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) { 1093 if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) {
1094 for (int i = 0; i < pdfRasterizers.count(); i++) { 1094 for (int i = 0; i < pdfRasterizers.count(); i++) {
1095 SkBitmap pdfBitmap; 1095 SkBitmap pdfBitmap;
1096 documentStream->rewind();
1097 bool success = (*pdfRasterizers[i]->fRasterizerFunction) ( 1096 bool success = (*pdfRasterizers[i]->fRasterizerFunction) (
1098 documentStream.get(), &pdfBitmap); 1097 documentStream->duplicate(), &pdfBitmap);
bungeman-skia 2015/01/15 22:44:55 I think you can just rewind and detach here, since
scroggo 2015/01/16 19:13:37 Actually, that won't work. This loops through the
1099 if (!success) { 1098 if (!success) {
1100 SkDebugf("FAILED to render PDF for %s using renderer %s\n", 1099 SkDebugf("FAILED to render PDF for %s using renderer %s\n",
1101 gm->getName(), 1100 gm->getName(),
1102 pdfRasterizers[i]->fName); 1101 pdfRasterizers[i]->fName);
1103 continue; 1102 continue;
1104 } 1103 }
1105 1104
1106 SkString configName(gRec.fName); 1105 SkString configName(gRec.fName);
1107 configName.append("-"); 1106 configName.append("-");
1108 configName.append(pdfRasterizers[i]->fName); 1107 configName.append(pdfRasterizers[i]->fName);
1109 1108
1110 errors.add(this->writeBitmap(gm, gRec, configName.c_str( ), 1109 errors.add(this->writeBitmap(gm, gRec, configName.c_str( ),
1111 writePath, pdfBitmap)); 1110 writePath, pdfBitmap));
1112 } 1111 }
1113 } else { 1112 } else {
1114 errors.add(kIntentionallySkipped_ErrorType); 1113 errors.add(kIntentionallySkipped_ErrorType);
1115 } 1114 }
1116 } 1115 }
1117 } else if (gRec.fBackend == kXPS_Backend) { 1116 } else if (gRec.fBackend == kXPS_Backend) {
1118 generate_xps(gm, document); 1117 generate_xps(gm, document);
1119 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream() ); 1118 SkAutoTDelete<SkStreamAsset> documentStream(document.detachAsStream( ));
1120 1119
1121 errors.add(this->compareTestResultsToStoredExpectations( 1120 errors.add(this->compareTestResultsToStoredExpectations(
1122 gm, gRec, gRec.fName, NULL)); 1121 gm, gRec, gRec.fName, NULL));
1123 1122
1124 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { 1123 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
1125 SkString path = make_filename(writePath, gm->getName(), gRec.fNa me, "", "xps"); 1124 SkString path = make_filename(writePath, gm->getName(), gRec.fNa me, "", "xps");
1126 errors.add(write_document(path, documentStream)); 1125 errors.add(write_document(path, documentStream));
1127 } 1126 }
1128 } else { 1127 } else {
1129 SkASSERT(false); 1128 SkASSERT(false);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 #endif // SK_SUPPORT_GPU 1382 #endif // SK_SUPPORT_GPU
1384 #ifdef SK_SUPPORT_XPS 1383 #ifdef SK_SUPPORT_XPS
1385 /* At present we have no way of comparing XPS files (either natively or by c onverting to PNG). */ 1384 /* At present we have no way of comparing XPS files (either natively or by c onverting to PNG). */
1386 { kN32_SkColorType, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true }, 1385 { kN32_SkColorType, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
1387 #endif // SK_SUPPORT_XPS 1386 #endif // SK_SUPPORT_XPS
1388 #ifdef SK_SUPPORT_PDF 1387 #ifdef SK_SUPPORT_PDF
1389 { kN32_SkColorType, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true }, 1388 { kN32_SkColorType, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
1390 #endif // SK_SUPPORT_PDF 1389 #endif // SK_SUPPORT_PDF
1391 }; 1390 };
1392 1391
1393 static bool SkNoRasterizePDF(SkStream*, SkBitmap*) { return false; } 1392 // Deletes SkStream, like other rasterizers.
1393 static bool SkNoRasterizePDF(SkStream* stream, SkBitmap*) {
1394 SkDELETE(stream);
1395 return false;
1396 }
1394 1397
1395 static const PDFRasterizerData kPDFRasterizers[] = { 1398 static const PDFRasterizerData kPDFRasterizers[] = {
1396 #ifdef SK_BUILD_FOR_MAC 1399 #ifdef SK_BUILD_FOR_MAC
1397 { &SkPDFDocumentToBitmap, "mac", true }, 1400 { &SkPDFDocumentToBitmap, "mac", true },
1398 #endif 1401 #endif
1399 #ifdef SK_BUILD_POPPLER 1402 #ifdef SK_BUILD_POPPLER
1400 { &SkPopplerRasterizePDF, "poppler", true }, 1403 { &SkPopplerRasterizePDF, "poppler", true },
1401 #endif 1404 #endif
1402 #ifdef SK_BUILD_NATIVE_PDF_RENDERER 1405 #ifdef SK_BUILD_NATIVE_PDF_RENDERER
1403 { &SkNativeRasterizePDF, "native", true }, 1406 { &SkNativeRasterizePDF, "native", true },
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 1883
1881 1884
1882 /** 1885 /**
1883 * Read individual lines from a file, pushing them into the given array. 1886 * Read individual lines from a file, pushing them into the given array.
1884 * 1887 *
1885 * @param filename path to the file to read 1888 * @param filename path to the file to read
1886 * @param lines array of strings to add the lines to 1889 * @param lines array of strings to add the lines to
1887 * @returns true if able to read lines from the file 1890 * @returns true if able to read lines from the file
1888 */ 1891 */
1889 static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines ) { 1892 static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines ) {
1890 SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename)); 1893 SkAutoTDelete<SkStream> streamWrapper(SkStream::NewFromFile(filename));
1891 SkStream *stream = streamWrapper.get(); 1894 SkStream *stream = streamWrapper.get();
1892 if (!stream) { 1895 if (!stream) {
1893 SkDebugf("unable to read file '%s'\n", filename); 1896 SkDebugf("unable to read file '%s'\n", filename);
1894 return false; 1897 return false;
1895 } 1898 }
1896 1899
1897 char c; 1900 char c;
1898 SkString line; 1901 SkString line;
1899 while (1 == stream->read(&c, 1)) { 1902 while (1 == stream->read(&c, 1)) {
1900 // If we hit either CR or LF, we've completed a line. 1903 // If we hit either CR or LF, we've completed a line.
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 if (FLAGS_forceBWtext) { 2543 if (FLAGS_forceBWtext) {
2541 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); 2544 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2542 } 2545 }
2543 } 2546 }
2544 2547
2545 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 2548 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
2546 int main(int argc, char * const argv[]) { 2549 int main(int argc, char * const argv[]) {
2547 return tool_main(argc, (char**) argv); 2550 return tool_main(argc, (char**) argv);
2548 } 2551 }
2549 #endif 2552 #endif
OLDNEW
« no previous file with comments | « gm/dftext.cpp ('k') | include/core/SkImageDecoder.h » ('j') | include/core/SkStream.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698