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

Side by Side Diff: experimental/PdfViewer/pdf_viewer_main.cpp

Issue 19793006: pdfviewer: All NulCanvas (does not draw operations), TrackDevice (trackes what pixels have been cha… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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 | « experimental/PdfViewer/SkTracker.cpp ('k') | gyp/pdfviewer.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "SkCanvas.h" 1 #include "SkCanvas.h"
2 #include "SkCommandLineFlags.h" 2 #include "SkCommandLineFlags.h"
3 #include "SkDevice.h" 3 #include "SkDevice.h"
4 #include "SkGraphics.h" 4 #include "SkGraphics.h"
5 #include "SkImageDecoder.h" 5 #include "SkImageDecoder.h"
6 #include "SkImageEncoder.h" 6 #include "SkImageEncoder.h"
7 #include "SkOSFile.h" 7 #include "SkOSFile.h"
8 #include "SkPicture.h" 8 #include "SkPicture.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 #include "SkTypeface.h" 10 #include "SkTypeface.h"
11 #include "SkTArray.h" 11 #include "SkTArray.h"
12 #include "picture_utils.h" 12 #include "picture_utils.h"
13 #include "SkNulCanvas.h"
13 14
14 #include "SkPdfRenderer.h" 15 #include "SkPdfRenderer.h"
15 16
16 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s."); 17 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s.");
17 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages."); 18 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages.");
18 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page."); 19 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page.");
19 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); 20 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage.");
20 DEFINE_string2(pages, p, "all", "What pages to render and how:\n" 21 DEFINE_string2(pages, p, "all", "What pages to render and how:\n"
21 "\tall - all pages\n" 22 "\tall - all pages\n"
22 "\treverse - all pages, in reverse order\n" 23 "\treverse - all pages, in reverse order\n"
23 "\tfirst - first page\n" 24 "\tfirst - first page\n"
24 "\tlast - last page\n" 25 "\tlast - last page\n"
25 "\tnumber - a specific page number\n" 26 "\tnumber - a specific page number\n"
26 ); 27 );
27 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); 28 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale).");
28 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren dering and \n" 29 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren dering and \n"
29 "\tminimal parsing to ensure correctness. Default 0 (disabled)."); 30 "\tminimal parsing to ensure correctness. Default 0 (disabled).");
30 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)"); 31 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)");
32 DEFINE_string2(config, c, "8888", "Canvas to render:\n"
33 "\t8888 - all pages\n"
34 "\tnul - all pages, in reverse order\n"
35 );
31 36
32 37
33 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all 38 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all
34 39
35 /** 40 /**
36 * Given list of directories and files to use as input, expects to find .pdf 41 * Given list of directories and files to use as input, expects to find .pdf
37 * files and it will convert them to .png files writing them in the same directo ry 42 * files and it will convert them to .png files writing them in the same directo ry
38 * one file for each page. 43 * one file for each page.
39 * 44 *
40 * Returns zero exit code if all .pdf files were converted successfully, 45 * Returns zero exit code if all .pdf files were converted successfully,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 108
104 extern "C" SkBitmap* gDumpBitmap; 109 extern "C" SkBitmap* gDumpBitmap;
105 extern "C" SkCanvas* gDumpCanvas; 110 extern "C" SkCanvas* gDumpCanvas;
106 111
107 static bool render_page(const SkString& outputDir, 112 static bool render_page(const SkString& outputDir,
108 const SkString& inputFilename, 113 const SkString& inputFilename,
109 const SkPdfRenderer& renderer, 114 const SkPdfRenderer& renderer,
110 int page) { 115 int page) {
111 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); 116 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
112 117
113 SkBitmap bitmap; 118 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed.
114 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_DPI / 72.0))); 119 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) {
115 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAGS_DP I / 72.0))); 120 SkBitmap bitmap;
121 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
122 SkNulCanvas canvas(device);
123 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
124 } else {
125 // 8888
126 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
116 127
117 rect = SkRect::MakeWH(width, height); 128 SkBitmap bitmap;
129 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_ DPI / 72.0)));
130 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAG S_DPI / 72.0)));
131
132 rect = SkRect::MakeWH(width, height);
118 133
119 #ifdef PDF_DEBUG_3X 134 #ifdef PDF_DEBUG_3X
120 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScalarToD ouble(height)); 135 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height));
121 #else 136 #else
122 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(he ight)); 137 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height));
123 #endif 138 #endif
124 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); 139 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
125 SkCanvas canvas(device); 140 SkCanvas canvas(device);
126 141
127 gDumpBitmap = &bitmap; 142 gDumpBitmap = &bitmap;
128 143
129 gDumpCanvas = &canvas; 144 gDumpCanvas = &canvas;
130 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); 145 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
131 146
132 SkString outputPath; 147 SkString outputPath;
133 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) { 148 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) {
134 return false; 149 return false;
150 }
151 SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::k PNG_Type, 100);
152
153 if (FLAGS_showMemoryUsage) {
154 SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : page, (unsigned int)renderer.bytesUsed());
155 }
135 } 156 }
136 SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_ Type, 100);
137
138 if (FLAGS_showMemoryUsage) {
139 SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : pag e, (unsigned int)renderer.bytesUsed());
140 }
141
142 return true; 157 return true;
143 } 158 }
144 159
145 /** Reads an skp file, renders it to pdf and writes the output to a pdf file 160 /** Reads an skp file, renders it to pdf and writes the output to a pdf file
146 * @param inputPath The skp file to be read. 161 * @param inputPath The skp file to be read.
147 * @param outputDir Output dir. 162 * @param outputDir Output dir.
148 * @param renderer The object responsible to render the skp object into pdf. 163 * @param renderer The object responsible to render the skp object into pdf.
149 */ 164 */
150 static bool process_pdf(const SkString& inputPath, const SkString& outputDir, 165 static bool process_pdf(const SkString& inputPath, const SkString& outputDir,
151 SkPdfRenderer& renderer) { 166 SkPdfRenderer& renderer) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 285 }
271 286
272 return 0; 287 return 0;
273 } 288 }
274 289
275 #if !defined SK_BUILD_FOR_IOS 290 #if !defined SK_BUILD_FOR_IOS
276 int main(int argc, char * const argv[]) { 291 int main(int argc, char * const argv[]) {
277 return tool_main(argc, (char**) argv); 292 return tool_main(argc, (char**) argv);
278 } 293 }
279 #endif 294 #endif
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkTracker.cpp ('k') | gyp/pdfviewer.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698