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

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

Issue 579733003: Revert "Move SkGpuDevice.h to src/gpu" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
24 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s."); 30 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces s.");
25 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages."); 31 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages.");
26 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page."); 32 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page.");
27 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); 33 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage.");
28 DEFINE_string2(pages, p, "all", "What pages to render and how:\n" 34 DEFINE_string2(pages, p, "all", "What pages to render and how:\n"
29 "\tall - all pages\n" 35 "\tall - all pages\n"
30 "\treverse - all pages, in reverse order\n" 36 "\treverse - all pages, in reverse order\n"
31 "\tfirst - first page\n" 37 "\tfirst - first page\n"
32 "\tlast - last page\n" 38 "\tlast - last page\n"
33 "\tnumber - a specific page number\n" 39 "\tnumber - a specific page number\n"
34 ); 40 );
35 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); 41 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale).");
36 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren dering and \n" 42 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren dering and \n"
37 "\tminimal parsing to ensure correctness. Default 0 (disabled)."); 43 "\tminimal parsing to ensure correctness. Default 0 (disabled).");
38 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable d)"); 44 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
39 DEFINE_string2(config, c, "8888", "Canvas to render:\n" 52 DEFINE_string2(config, c, "8888", "Canvas to render:\n"
40 "\t8888 - argb\n" 53 "\t8888 - argb\n"
41 "\tnul - render in null canvas, any draw will just return.\n" 54 "\tnul - render in null canvas, any draw will just return.\n"
42 ); 55 );
56 #endif
43 DEFINE_bool2(transparentBackground, t, false, "Make background transparent inste ad of white."); 57 DEFINE_bool2(transparentBackground, t, false, "Make background transparent inste ad of white.");
44 58
45 /** 59 /**
46 * Given list of directories and files to use as input, expects to find .pdf 60 * Given list of directories and files to use as input, expects to find .pdf
47 * files and it will convert them to .png files writing them in the same directo ry 61 * files and it will convert them to .png files writing them in the same directo ry
48 * one file for each page. 62 * one file for each page.
49 * 63 *
50 * Returns zero exit code if all .pdf files were converted successfully, 64 * Returns zero exit code if all .pdf files were converted successfully,
51 * otherwise returns error code 1. 65 * otherwise returns error code 1.
52 */ 66 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 * @param inputFilename The skp file that was read. 119 * @param inputFilename The skp file that was read.
106 * @param renderer The object responsible to write the pdf file. 120 * @param renderer The object responsible to write the pdf file.
107 * @param page -1 means there is only one page (0), and render in a file without page extension 121 * @param page -1 means there is only one page (0), and render in a file without page extension
108 */ 122 */
109 123
110 #ifdef PDF_TRACE_DIFF_IN_PNG 124 #ifdef PDF_TRACE_DIFF_IN_PNG
111 extern "C" SkBitmap* gDumpBitmap; 125 extern "C" SkBitmap* gDumpBitmap;
112 extern "C" SkCanvas* gDumpCanvas; 126 extern "C" SkCanvas* gDumpCanvas;
113 #endif 127 #endif
114 128
129 #if SK_SUPPORT_GPU
130 GrContextFactory gContextFactory;
131 #endif
132
115 static bool render_page(const SkString& outputDir, 133 static bool render_page(const SkString& outputDir,
116 const SkString& inputFilename, 134 const SkString& inputFilename,
117 const SkPdfRenderer& renderer, 135 const SkPdfRenderer& renderer,
118 int page) { 136 int page) {
119 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); 137 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
120 138
121 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed. 139 // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed.
122 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) { 140 if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) {
123 SkBitmap bitmap; 141 SkBitmap bitmap;
124 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 142 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
(...skipping 14 matching lines...) Expand all
139 #ifdef PDF_DEBUG_3X 157 #ifdef PDF_DEBUG_3X
140 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height), 158 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala rToDouble(height),
141 background); 159 background);
142 #else 160 #else
143 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height), 161 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl e(height),
144 background); 162 background);
145 #endif 163 #endif
146 SkAutoTUnref<SkBaseDevice> device; 164 SkAutoTUnref<SkBaseDevice> device;
147 if (strcmp(FLAGS_config[0], "8888") == 0) { 165 if (strcmp(FLAGS_config[0], "8888") == 0) {
148 device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap))); 166 device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap)));
149 } else { 167 }
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 {
150 SkDebugf("unknown --config: %s\n", FLAGS_config[0]); 192 SkDebugf("unknown --config: %s\n", FLAGS_config[0]);
151 return false; 193 return false;
152 } 194 }
153 SkCanvas canvas(device); 195 SkCanvas canvas(device);
154 196
155 #ifdef PDF_TRACE_DIFF_IN_PNG 197 #ifdef PDF_TRACE_DIFF_IN_PNG
156 gDumpBitmap = &bitmap; 198 gDumpBitmap = &bitmap;
157 gDumpCanvas = &canvas; 199 gDumpCanvas = &canvas;
158 #endif 200 #endif
159 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); 201 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 341 }
300 342
301 return 0; 343 return 0;
302 } 344 }
303 345
304 #if !defined SK_BUILD_FOR_IOS 346 #if !defined SK_BUILD_FOR_IOS
305 int main(int argc, char * const argv[]) { 347 int main(int argc, char * const argv[]) {
306 return tool_main(argc, (char**) argv); 348 return tool_main(argc, (char**) argv);
307 } 349 }
308 #endif 350 #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