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

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

Issue 545193006: Move SkGpuDevice.h to src/gpu (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove gpu support from pdfviewer Created 6 years, 3 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
« no previous file with comments | « no previous file | gyp/gpu.gypi » ('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 2013 Google Inc. 2 * Copyright 2013 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 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCommandLineFlags.h" 10 #include "SkCommandLineFlags.h"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkGraphics.h" 12 #include "SkGraphics.h"
13 #include "SkImageDecoder.h" 13 #include "SkImageDecoder.h"
14 #include "SkImageEncoder.h" 14 #include "SkImageEncoder.h"
15 #include "SkOSFile.h" 15 #include "SkOSFile.h"
16 #include "SkPdfConfig.h" 16 #include "SkPdfConfig.h"
17 #include "SkPdfRenderer.h" 17 #include "SkPdfRenderer.h"
18 #include "SkPicture.h" 18 #include "SkPicture.h"
19 #include "SkStream.h" 19 #include "SkStream.h"
20 #include "SkTypeface.h" 20 #include "SkTypeface.h"
21 #include "SkTArray.h" 21 #include "SkTArray.h"
22 #include "SkNulCanvas.h" 22 #include "SkNulCanvas.h"
23 23
24 #if SK_SUPPORT_GPU
25 #include "GrContextFactory.h"
26 #include "GrContext.h"
27 #include "SkGpuDevice.h"
28 #endif
29
30 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s."); 24 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s.");
31 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages."); 25 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages.");
32 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page."); 26 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page.");
33 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); 27 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage.");
34 DEFINE_string2(pages, p, "all", "What pages to render and how:\n" 28 DEFINE_string2(pages, p, "all", "What pages to render and how:\n"
35 "\tall - all pages\n" 29 "\tall - all pages\n"
36 "\treverse - all pages, in reverse order\n" 30 "\treverse - all pages, in reverse order\n"
37 "\tfirst - first page\n" 31 "\tfirst - first page\n"
38 "\tlast - last page\n" 32 "\tlast - last page\n"
39 "\tnumber - a specific page number\n" 33 "\tnumber - a specific page number\n"
40 ); 34 );
41 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); 35 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale).");
42 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren dering and \n" 36 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren dering and \n"
43 "\tminimal parsing to ensure correctness. Default 0 (disabled)."); 37 "\tminimal parsing to ensure correctness. Default 0 (disabled).");
44 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)"); 38 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)");
45 #if SK_SUPPORT_GPU
46 DEFINE_string2(config, c, "8888", "Canvas to render:\n"
47 "\t8888 - argb\n"
48 "\tgpu: use the gpu\n"
49 "\tnul - render in null canvas, any draw will just return.\n"
50 );
51 #else
52 DEFINE_string2(config, c, "8888", "Canvas to render:\n" 39 DEFINE_string2(config, c, "8888", "Canvas to render:\n"
53 "\t8888 - argb\n" 40 "\t8888 - argb\n"
54 "\tnul - render in null canvas, any draw will just return.\n" 41 "\tnul - render in null canvas, any draw will just return.\n"
55 ); 42 );
56 #endif
57 DEFINE_bool2(transparentBackground, t, false, "Make background transparent inste ad of white."); 43 DEFINE_bool2(transparentBackground, t, false, "Make background transparent inste ad of white.");
58 44
59 /** 45 /**
60 * Given list of directories and files to use as input, expects to find .pdf 46 * Given list of directories and files to use as input, expects to find .pdf
61 * files and it will convert them to .png files writing them in the same directo ry 47 * files and it will convert them to .png files writing them in the same directo ry
62 * one file for each page. 48 * one file for each page.
63 * 49 *
64 * Returns zero exit code if all .pdf files were converted successfully, 50 * Returns zero exit code if all .pdf files were converted successfully,
65 * otherwise returns error code 1. 51 * otherwise returns error code 1.
66 */ 52 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 * @param inputFilename The skp file that was read. 105 * @param inputFilename The skp file that was read.
120 * @param renderer The object responsible to write the pdf file. 106 * @param renderer The object responsible to write the pdf file.
121 * @param page -1 means there is only one page (0), and render in a file without page extension 107 * @param page -1 means there is only one page (0), and render in a file without page extension
122 */ 108 */
123 109
124 #ifdef PDF_TRACE_DIFF_IN_PNG 110 #ifdef PDF_TRACE_DIFF_IN_PNG
125 extern "C" SkBitmap* gDumpBitmap; 111 extern "C" SkBitmap* gDumpBitmap;
126 extern "C" SkCanvas* gDumpCanvas; 112 extern "C" SkCanvas* gDumpCanvas;
127 #endif 113 #endif
128 114
129 #if SK_SUPPORT_GPU
130 GrContextFactory gContextFactory;
131 #endif
132
133 static bool render_page(const SkString& outputDir, 115 static bool render_page(const SkString& outputDir,
134 const SkString& inputFilename, 116 const SkString& inputFilename,
135 const SkPdfRenderer& renderer, 117 const SkPdfRenderer& renderer,
136 int page) { 118 int page) {
137 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); 119 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
138 120
139 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed. 121 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed.
140 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) { 122 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) {
141 SkBitmap bitmap; 123 SkBitmap bitmap;
142 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 124 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
(...skipping 14 matching lines...) Expand all
157 #ifdef PDF_DEBUG_3X 139 #ifdef PDF_DEBUG_3X
158 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height), 140 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height),
159 background); 141 background);
160 #else 142 #else
161 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height), 143 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height),
162 background); 144 background);
163 #endif 145 #endif
164 SkAutoTUnref<SkBaseDevice> device; 146 SkAutoTUnref<SkBaseDevice> device;
165 if (strcmp(FLAGS_config[0], "8888") == 0) { 147 if (strcmp(FLAGS_config[0], "8888") == 0) {
166 device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 148 device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
167 } 149 } else {
168 #if SK_SUPPORT_GPU
169 else if (strcmp(FLAGS_config[0], "gpu") == 0) {
170 SkAutoTUnref<GrSurface> target;
171 GrContext* gr = gContextFactory.get(GrContextFactory::kNative_GLCont extType,
172 kNone_GrGLStandard);
173 if (gr) {
174 // create a render target to back the device
175 GrTextureDesc desc;
176 desc.fConfig = kSkia8888_GrPixelConfig;
177 desc.fFlags = kRenderTarget_GrTextureFlagBit;
178 desc.fWidth = SkScalarCeilToInt(width);
179 desc.fHeight = SkScalarCeilToInt(height);
180 desc.fSampleCnt = 0;
181 target.reset(gr->createUncachedTexture(desc, NULL, 0));
182 }
183 if (NULL == target.get()) {
184 SkASSERT(0);
185 return false;
186 }
187
188 device.reset(SkGpuDevice::Create(target));
189 }
190 #endif
191 else {
192 SkDebugf("unknown --config: %s\n", FLAGS_config[0]); 150 SkDebugf("unknown --config: %s\n", FLAGS_config[0]);
193 return false; 151 return false;
194 } 152 }
195 SkCanvas canvas(device); 153 SkCanvas canvas(device);
196 154
197 #ifdef PDF_TRACE_DIFF_IN_PNG 155 #ifdef PDF_TRACE_DIFF_IN_PNG
198 gDumpBitmap = &bitmap; 156 gDumpBitmap = &bitmap;
199 gDumpCanvas = &canvas; 157 gDumpCanvas = &canvas;
200 #endif 158 #endif
201 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); 159 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 299 }
342 300
343 return 0; 301 return 0;
344 } 302 }
345 303
346 #if !defined SK_BUILD_FOR_IOS 304 #if !defined SK_BUILD_FOR_IOS
347 int main(int argc, char * const argv[]) { 305 int main(int argc, char * const argv[]) {
348 return tool_main(argc, (char**) argv); 306 return tool_main(argc, (char**) argv);
349 } 307 }
350 #endif 308 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/gpu.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698