OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "CopyTilesRenderer.h" | 8 #include "CopyTilesRenderer.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapFactory.h" | |
11 #include "SkCanvas.h" | |
12 #include "SkDevice.h" | 10 #include "SkDevice.h" |
13 #include "SkFlags.h" | 11 #include "SkFlags.h" |
14 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
15 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
16 #include "SkImageEncoder.h" | 14 #include "SkImageEncoder.h" |
17 #include "SkMath.h" | 15 #include "SkMath.h" |
18 #include "SkOSFile.h" | 16 #include "SkOSFile.h" |
19 #include "SkPicture.h" | 17 #include "SkPicture.h" |
20 #include "SkStream.h" | 18 #include "SkStream.h" |
21 #include "SkString.h" | 19 #include "SkString.h" |
22 #include "SkTArray.h" | |
23 #include "PictureRenderer.h" | 20 #include "PictureRenderer.h" |
24 #include "PictureRenderingFlags.h" | 21 #include "PictureRenderingFlags.h" |
25 #include "picture_utils.h" | 22 #include "picture_utils.h" |
26 | 23 |
27 // Flags used by this file, alphabetically: | 24 // Flags used by this file, alphabetically: |
28 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); | 25 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); |
29 DECLARE_bool(deferImageDecoding); | 26 DECLARE_bool(deferImageDecoding); |
30 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo
nents that differ " | 27 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo
nents that differ " |
31 "by more than this amount are considered errors, though all diffs a
re reported. " | 28 "by more than this amount are considered errors, though all diffs a
re reported. " |
32 "Requires --validate."); | 29 "Requires --validate."); |
33 DECLARE_string(r); | 30 DECLARE_string(r); |
34 DEFINE_string(w, "", "Directory to write the rendered images."); | 31 DEFINE_string(w, "", "Directory to write the rendered images."); |
35 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima
ge to a " | 32 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima
ge to a " |
36 "file, instead of an image for each tile."); | 33 "file, instead of an image for each tile."); |
37 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p
ixels as " | 34 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p
ixels as " |
38 "the picture rendered in simple mode."); | 35 "the picture rendered in simple mode."); |
39 | 36 |
40 static void make_output_filepath(SkString* path, const SkString& dir, | 37 static void make_output_filepath(SkString* path, const SkString& dir, |
41 const SkString& name) { | 38 const SkString& name) { |
42 sk_tools::make_filepath(path, dir, name); | 39 sk_tools::make_filepath(path, dir, name); |
43 // Remove ".skp" | 40 // Remove ".skp" |
44 path->remove(path->size() - 4, 4); | 41 path->remove(path->size() - 4, 4); |
45 } | 42 } |
46 | 43 |
47 #include "SkData.h" | 44 // Defined in PictureRenderingFlags.cpp |
48 #include "SkLruImageCache.h" | 45 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap
); |
49 | |
50 static SkLruImageCache gLruImageCache(1024*1024); | |
51 | |
52 #ifdef SK_BUILD_FOR_ANDROID | |
53 #include "SkAshmemImageCache.h" | |
54 #include "SkImage.h" | |
55 | |
56 static SkImageCache* cache_selector(const SkImage::Info& info) { | |
57 if (info.fWidth * info.fHeight > 32 * 1024) { | |
58 return SkAshmemImageCache::GetAshmemImageCache(); | |
59 } | |
60 return &gLruImageCache; | |
61 } | |
62 | |
63 #endif | |
64 | |
65 static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap
) { | |
66 void* copiedBuffer = sk_malloc_throw(size); | |
67 memcpy(copiedBuffer, buffer, size); | |
68 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size)); | |
69 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); | |
70 #ifdef SK_BUILD_FOR_ANDROID | |
71 factory.setCacheSelector(&cache_selector); | |
72 #else | |
73 factory.setImageCache(&gLruImageCache); | |
74 #endif | |
75 return factory.installPixelRef(data, bitmap); | |
76 } | |
77 | 46 |
78 static bool render_picture(const SkString& inputPath, const SkString* outputDir, | 47 static bool render_picture(const SkString& inputPath, const SkString* outputDir, |
79 sk_tools::PictureRenderer& renderer, | 48 sk_tools::PictureRenderer& renderer, |
80 SkBitmap** out) { | 49 SkBitmap** out) { |
81 SkString inputFilename; | 50 SkString inputFilename; |
82 sk_tools::get_basename(&inputFilename, inputPath); | 51 sk_tools::get_basename(&inputFilename, inputPath); |
83 | 52 |
84 SkFILEStream inputStream; | 53 SkFILEStream inputStream; |
85 inputStream.setPath(inputPath.c_str()); | 54 inputStream.setPath(inputPath.c_str()); |
86 if (!inputStream.isValid()) { | 55 if (!inputStream.isValid()) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 #endif | 292 #endif |
324 #endif | 293 #endif |
325 return 0; | 294 return 0; |
326 } | 295 } |
327 | 296 |
328 #if !defined SK_BUILD_FOR_IOS | 297 #if !defined SK_BUILD_FOR_IOS |
329 int main(int argc, char * const argv[]) { | 298 int main(int argc, char * const argv[]) { |
330 return tool_main(argc, (char**) argv); | 299 return tool_main(argc, (char**) argv); |
331 } | 300 } |
332 #endif | 301 #endif |
OLD | NEW |