| 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. When used in conjunction with
--bbh, results " | 35 "the picture rendered in simple mode. When used in conjunction with
--bbh, results " |
| 39 "are validated against the picture rendered in the same mode, but wi
thout the bbh."); | 36 "are validated against the picture rendered in the same mode, but wi
thout the bbh."); |
| 40 | 37 |
| 41 static void make_output_filepath(SkString* path, const SkString& dir, | 38 static void make_output_filepath(SkString* path, const SkString& dir, |
| 42 const SkString& name) { | 39 const SkString& name) { |
| 43 sk_tools::make_filepath(path, dir, name); | 40 sk_tools::make_filepath(path, dir, name); |
| 44 // Remove ".skp" | 41 // Remove ".skp" |
| 45 path->remove(path->size() - 4, 4); | 42 path->remove(path->size() - 4, 4); |
| 46 } | 43 } |
| 47 | 44 |
| 48 #include "SkData.h" | 45 // Defined in PictureRenderingFlags.cpp |
| 49 #include "SkLruImageCache.h" | 46 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap
); |
| 50 | |
| 51 static SkLruImageCache gLruImageCache(1024*1024); | |
| 52 | |
| 53 #ifdef SK_BUILD_FOR_ANDROID | |
| 54 #include "SkAshmemImageCache.h" | |
| 55 #include "SkImage.h" | |
| 56 | |
| 57 static SkImageCache* cache_selector(const SkImage::Info& info) { | |
| 58 if (info.fWidth * info.fHeight > 32 * 1024) { | |
| 59 return SkAshmemImageCache::GetAshmemImageCache(); | |
| 60 } | |
| 61 return &gLruImageCache; | |
| 62 } | |
| 63 | |
| 64 #endif | |
| 65 | |
| 66 static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap
) { | |
| 67 void* copiedBuffer = sk_malloc_throw(size); | |
| 68 memcpy(copiedBuffer, buffer, size); | |
| 69 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size)); | |
| 70 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); | |
| 71 #ifdef SK_BUILD_FOR_ANDROID | |
| 72 factory.setCacheSelector(&cache_selector); | |
| 73 #else | |
| 74 factory.setImageCache(&gLruImageCache); | |
| 75 #endif | |
| 76 return factory.installPixelRef(data, bitmap); | |
| 77 } | |
| 78 | 47 |
| 79 static bool render_picture(const SkString& inputPath, const SkString* outputDir, | 48 static bool render_picture(const SkString& inputPath, const SkString* outputDir, |
| 80 sk_tools::PictureRenderer& renderer, | 49 sk_tools::PictureRenderer& renderer, |
| 81 SkBitmap** out) { | 50 SkBitmap** out) { |
| 82 SkString inputFilename; | 51 SkString inputFilename; |
| 83 sk_tools::get_basename(&inputFilename, inputPath); | 52 sk_tools::get_basename(&inputFilename, inputPath); |
| 84 | 53 |
| 85 SkFILEStream inputStream; | 54 SkFILEStream inputStream; |
| 86 inputStream.setPath(inputPath.c_str()); | 55 inputStream.setPath(inputPath.c_str()); |
| 87 if (!inputStream.isValid()) { | 56 if (!inputStream.isValid()) { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 #endif | 333 #endif |
| 365 #endif | 334 #endif |
| 366 return 0; | 335 return 0; |
| 367 } | 336 } |
| 368 | 337 |
| 369 #if !defined SK_BUILD_FOR_IOS | 338 #if !defined SK_BUILD_FOR_IOS |
| 370 int main(int argc, char * const argv[]) { | 339 int main(int argc, char * const argv[]) { |
| 371 return tool_main(argc, (char**) argv); | 340 return tool_main(argc, (char**) argv); |
| 372 } | 341 } |
| 373 #endif | 342 #endif |
| OLD | NEW |