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

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

Issue 22684002: pdfviewer: add ability to run on gpu (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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 | 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 "SkNulCanvas.h" 12 #include "SkNulCanvas.h"
13 13
14 #if SK_SUPPORT_GPU
15 #include "GrContextFactory.h"
16 #include "GrContext.h"
17 #include "SkGpuDevice.h"
18 #endif
19
14 #include "SkPdfRenderer.h" 20 #include "SkPdfRenderer.h"
15 21
16 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s."); 22 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."); 23 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages.");
18 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page."); 24 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page.");
19 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); 25 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage.");
20 DEFINE_string2(pages, p, "all", "What pages to render and how:\n" 26 DEFINE_string2(pages, p, "all", "What pages to render and how:\n"
21 "\tall - all pages\n" 27 "\tall - all pages\n"
22 "\treverse - all pages, in reverse order\n" 28 "\treverse - all pages, in reverse order\n"
23 "\tfirst - first page\n" 29 "\tfirst - first page\n"
24 "\tlast - last page\n" 30 "\tlast - last page\n"
25 "\tnumber - a specific page number\n" 31 "\tnumber - a specific page number\n"
26 ); 32 );
27 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); 33 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" 34 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)."); 35 "\tminimal parsing to ensure correctness. Default 0 (disabled).");
30 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)"); 36 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)");
31 DEFINE_string2(config, c, "8888", "Canvas to render:\n" 37 DEFINE_string2(config, c, "8888", "Canvas to render:\n"
32 "\t8888 - all pages\n" 38 "\t8888 - argb\n"
33 "\tnul - all pages, in reverse order\n" 39
40 #if SK_SUPPORT_GPU
41 "\tgpu: use the gpu\n"
42 #endif
43 "\tnul - render in null canvas, any draw will just return.\n"
34 ); 44 );
35 45
36 46
37 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all 47 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all
38 48
39 /** 49 /**
40 * Given list of directories and files to use as input, expects to find .pdf 50 * Given list of directories and files to use as input, expects to find .pdf
41 * files and it will convert them to .png files writing them in the same directo ry 51 * files and it will convert them to .png files writing them in the same directo ry
42 * one file for each page. 52 * one file for each page.
43 * 53 *
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 /** Write the output of pdf renderer to a file. 159 /** Write the output of pdf renderer to a file.
150 * @param outputDir Output dir. 160 * @param outputDir Output dir.
151 * @param inputFilename The skp file that was read. 161 * @param inputFilename The skp file that was read.
152 * @param renderer The object responsible to write the pdf file. 162 * @param renderer The object responsible to write the pdf file.
153 * @param page -1 means there is only one page (0), and render in a file without page extension 163 * @param page -1 means there is only one page (0), and render in a file without page extension
154 */ 164 */
155 165
156 extern "C" SkBitmap* gDumpBitmap; 166 extern "C" SkBitmap* gDumpBitmap;
157 extern "C" SkCanvas* gDumpCanvas; 167 extern "C" SkCanvas* gDumpCanvas;
158 168
169 #if SK_SUPPORT_GPU
170 GrContextFactory gContextFactory;
171 #endif
172
159 static bool render_page(const SkString& outputDir, 173 static bool render_page(const SkString& outputDir,
160 const SkString& inputFilename, 174 const SkString& inputFilename,
161 const SkPdfRenderer& renderer, 175 const SkPdfRenderer& renderer,
162 int page) { 176 int page) {
163 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); 177 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
164 178
165 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed. 179 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed.
166 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) { 180 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) {
167 SkBitmap bitmap; 181 SkBitmap bitmap;
168 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); 182 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
169 SkNulCanvas canvas(device); 183 SkNulCanvas canvas(device);
170 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); 184 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
171 } else { 185 } else {
172 // 8888 186 // 8888
173 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); 187 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
174 188
175 SkBitmap bitmap; 189 SkBitmap bitmap;
176 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_ DPI / 72.0))); 190 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_ DPI / 72.0)));
177 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAG S_DPI / 72.0))); 191 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAG S_DPI / 72.0)));
178 192
179 rect = SkRect::MakeWH(width, height); 193 rect = SkRect::MakeWH(width, height);
180 194
181 #ifdef PDF_DEBUG_3X 195 #ifdef PDF_DEBUG_3X
182 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height)); 196 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height));
183 #else 197 #else
184 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height)); 198 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height));
185 #endif 199 #endif
186 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); 200 SkAutoTUnref<SkDevice> device;
201 if (strcmp(FLAGS_config[0], "8888") == 0) {
202 device.reset(SkNEW_ARGS(SkDevice, (bitmap)));
203 }
204 #if SK_SUPPORT_GPU
205 else if (strcmp(FLAGS_config[0], "gpu") == 0) {
206 SkAutoTUnref<GrSurface> target;
207 GrContext* gr = gContextFactory.get(GrContextFactory::kNative_GLCont extType);
208 if (gr) {
209 // create a render target to back the device
210 GrTextureDesc desc;
211 desc.fConfig = kSkia8888_GrPixelConfig;
212 desc.fFlags = kRenderTarget_GrTextureFlagBit;
213 desc.fWidth = width;
214 desc.fHeight = height;
215 desc.fSampleCnt = 0;
216 target.reset(gr->createUncachedTexture(desc, NULL, 0));
217 }
218 if (NULL == target.get()) {
219 SkASSERT(0);
220 return false;
221 }
222
223 device.reset(SkGpuDevice::Create(target));
224 }
225 #endif
226 else {
227 SkDebugf("unknown --config: %s\n", FLAGS_config[0]);
228 return false;
229 }
187 SkCanvas canvas(device); 230 SkCanvas canvas(device);
188 231
189 gDumpBitmap = &bitmap; 232 gDumpBitmap = &bitmap;
190 233
191 gDumpCanvas = &canvas; 234 gDumpCanvas = &canvas;
192 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); 235 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
193 236
194 SkString outputPath; 237 SkString outputPath;
195 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) { 238 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) {
196 return false; 239 return false;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 372 }
330 373
331 return 0; 374 return 0;
332 } 375 }
333 376
334 #if !defined SK_BUILD_FOR_IOS 377 #if !defined SK_BUILD_FOR_IOS
335 int main(int argc, char * const argv[]) { 378 int main(int argc, char * const argv[]) {
336 return tool_main(argc, (char**) argv); 379 return tool_main(argc, (char**) argv);
337 } 380 }
338 #endif 381 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/pdfviewer.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698