| OLD | NEW |
| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 "\tminimal parsing to ensure correctness. Default 0 (disabled)."); | 42 "\tminimal parsing to ensure correctness. Default 0 (disabled)."); |
| 43 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable
d)"); | 43 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable
d)"); |
| 44 DEFINE_string2(config, c, "8888", "Canvas to render:\n" | 44 DEFINE_string2(config, c, "8888", "Canvas to render:\n" |
| 45 "\t8888 - argb\n" | 45 "\t8888 - argb\n" |
| 46 | 46 |
| 47 #if SK_SUPPORT_GPU | 47 #if SK_SUPPORT_GPU |
| 48 "\tgpu: use the gpu\n" | 48 "\tgpu: use the gpu\n" |
| 49 #endif | 49 #endif |
| 50 "\tnul - render in null canvas, any draw will
just return.\n" | 50 "\tnul - render in null canvas, any draw will
just return.\n" |
| 51 ); | 51 ); |
| 52 DEFINE_bool2(transparentBackground, t, false, "Make background transparent inste
ad of white."); |
| 52 | 53 |
| 53 | 54 |
| 54 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not
to render at all | 55 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not
to render at all |
| 55 | 56 |
| 56 /** | 57 /** |
| 57 * Given list of directories and files to use as input, expects to find .pdf | 58 * Given list of directories and files to use as input, expects to find .pdf |
| 58 * files and it will convert them to .png files writing them in the same directo
ry | 59 * files and it will convert them to .png files writing them in the same directo
ry |
| 59 * one file for each page. | 60 * one file for each page. |
| 60 * | 61 * |
| 61 * Returns zero exit code if all .pdf files were converted successfully, | 62 * Returns zero exit code if all .pdf files were converted successfully, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 */ | 150 */ |
| 150 static bool make_output_filepath(SkString* path, const SkString& dir, | 151 static bool make_output_filepath(SkString* path, const SkString& dir, |
| 151 const SkString& name, | 152 const SkString& name, |
| 152 int page) { | 153 int page) { |
| 153 make_filepath(path, dir, name); | 154 make_filepath(path, dir, name); |
| 154 return add_page_and_replace_filename_extension(path, page, | 155 return add_page_and_replace_filename_extension(path, page, |
| 155 PDF_FILE_EXTENSION, | 156 PDF_FILE_EXTENSION, |
| 156 PNG_FILE_EXTENSION); | 157 PNG_FILE_EXTENSION); |
| 157 } | 158 } |
| 158 | 159 |
| 159 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color
= SK_ColorTRANSPARENT) { | 160 static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color)
{ |
| 160 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 161 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 161 | 162 |
| 162 bitmap->allocPixels(); | 163 bitmap->allocPixels(); |
| 163 bitmap->eraseColor(color); | 164 bitmap->eraseColor(color); |
| 164 } | 165 } |
| 165 | 166 |
| 166 /** Write the output of pdf renderer to a file. | 167 /** Write the output of pdf renderer to a file. |
| 167 * @param outputDir Output dir. | 168 * @param outputDir Output dir. |
| 168 * @param inputFilename The skp file that was read. | 169 * @param inputFilename The skp file that was read. |
| 169 * @param renderer The object responsible to write the pdf file. | 170 * @param renderer The object responsible to write the pdf file. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 } else { | 193 } else { |
| 193 // 8888 | 194 // 8888 |
| 194 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); | 195 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); |
| 195 | 196 |
| 196 SkBitmap bitmap; | 197 SkBitmap bitmap; |
| 197 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_
DPI / 72.0))); | 198 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_
DPI / 72.0))); |
| 198 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAG
S_DPI / 72.0))); | 199 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAG
S_DPI / 72.0))); |
| 199 | 200 |
| 200 rect = SkRect::MakeWH(width, height); | 201 rect = SkRect::MakeWH(width, height); |
| 201 | 202 |
| 203 SkColor background = FLAGS_transparentBackground ? SK_ColorTRANSPARENT :
SK_ColorWHITE; |
| 204 |
| 202 #ifdef PDF_DEBUG_3X | 205 #ifdef PDF_DEBUG_3X |
| 203 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala
rToDouble(height)); | 206 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScala
rToDouble(height), background); |
| 204 #else | 207 #else |
| 205 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl
e(height)); | 208 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDoubl
e(height), background); |
| 206 #endif | 209 #endif |
| 207 SkAutoTUnref<SkBaseDevice> device; | 210 SkAutoTUnref<SkBaseDevice> device; |
| 208 if (strcmp(FLAGS_config[0], "8888") == 0) { | 211 if (strcmp(FLAGS_config[0], "8888") == 0) { |
| 209 device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap))); | 212 device.reset(SkNEW_ARGS(SkBitmapDevice, (bitmap))); |
| 210 } | 213 } |
| 211 #if SK_SUPPORT_GPU | 214 #if SK_SUPPORT_GPU |
| 212 else if (strcmp(FLAGS_config[0], "gpu") == 0) { | 215 else if (strcmp(FLAGS_config[0], "gpu") == 0) { |
| 213 SkAutoTUnref<GrSurface> target; | 216 SkAutoTUnref<GrSurface> target; |
| 214 GrContext* gr = gContextFactory.get(GrContextFactory::kNative_GLCont
extType); | 217 GrContext* gr = gContextFactory.get(GrContextFactory::kNative_GLCont
extType); |
| 215 if (gr) { | 218 if (gr) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 382 } |
| 380 | 383 |
| 381 return 0; | 384 return 0; |
| 382 } | 385 } |
| 383 | 386 |
| 384 #if !defined SK_BUILD_FOR_IOS | 387 #if !defined SK_BUILD_FOR_IOS |
| 385 int main(int argc, char * const argv[]) { | 388 int main(int argc, char * const argv[]) { |
| 386 return tool_main(argc, (char**) argv); | 389 return tool_main(argc, (char**) argv); |
| 387 } | 390 } |
| 388 #endif | 391 #endif |
| OLD | NEW |