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 "SkLua.h" | 8 #include "SkLua.h" |
9 #include "SkLuaCanvas.h" | 9 #include "SkLuaCanvas.h" |
10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 static const char gStartCanvasFunc[] = "sk_scrape_startcanvas"; | 28 static const char gStartCanvasFunc[] = "sk_scrape_startcanvas"; |
29 static const char gEndCanvasFunc[] = "sk_scrape_endcanvas"; | 29 static const char gEndCanvasFunc[] = "sk_scrape_endcanvas"; |
30 static const char gAccumulateFunc[] = "sk_scrape_accumulate"; | 30 static const char gAccumulateFunc[] = "sk_scrape_accumulate"; |
31 static const char gSummarizeFunc[] = "sk_scrape_summarize"; | 31 static const char gSummarizeFunc[] = "sk_scrape_summarize"; |
32 | 32 |
33 // PictureRenderingFlags.cpp | 33 // PictureRenderingFlags.cpp |
34 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap*); | 34 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap*); |
35 | 35 |
36 DEFINE_string2(skpPath, r, "", "Read .skp files from this dir"); | 36 DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir"
); |
37 DEFINE_string2(luaFile, l, "", "File containing lua script to run"); | 37 DEFINE_string2(luaFile, l, "", "File containing lua script to run"); |
38 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning"); | 38 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning"); |
39 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); | 39 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); |
40 | 40 |
41 static SkPicture* load_picture(const char path[]) { | 41 static SkPicture* load_picture(const char path[]) { |
42 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 42 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
43 SkPicture* pic = NULL; | 43 SkPicture* pic = NULL; |
44 if (stream.get()) { | 44 if (stream.get()) { |
45 bool success; | 45 bool success; |
46 pic = SkNEW_ARGS(SkPicture, (stream.get(), &success, | 46 pic = SkNEW_ARGS(SkPicture, (stream.get(), &success, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); | 109 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); |
110 exit(-1); | 110 exit(-1); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 if (!FLAGS_headCode.isEmpty()) { | 114 if (!FLAGS_headCode.isEmpty()) { |
115 L.runCode(FLAGS_headCode[0]); | 115 L.runCode(FLAGS_headCode[0]); |
116 } | 116 } |
117 | 117 |
118 for (int i = 0; i < FLAGS_skpPath.count(); i ++) { | 118 for (int i = 0; i < FLAGS_skpPath.count(); i ++) { |
119 SkOSFile::Iter iter(FLAGS_skpPath[i], "skp"); | 119 SkTArray<SkString> paths; |
120 SkString inputFilename; | 120 if (sk_isdir(FLAGS_skpPath[i])) { |
| 121 // Add all .skp in this directory. |
| 122 const SkString directory(FLAGS_skpPath[i]); |
| 123 SkString filename; |
| 124 SkOSFile::Iter iter(FLAGS_skpPath[i], "skp"); |
| 125 while(iter.next(&filename)) { |
| 126 sk_tools::make_filepath(&paths.push_back(), directory, filename)
; |
| 127 } |
| 128 } else { |
| 129 // Add this as an .skp itself. |
| 130 paths.push_back() = FLAGS_skpPath[i]; |
| 131 } |
121 | 132 |
122 while (iter.next(&inputFilename)) { | 133 for (int i = 0; i < paths.count(); i++) { |
123 SkString inputPath; | 134 const char* path = paths[i].c_str(); |
124 SkString inputAsSkString(FLAGS_skpPath[i]); | |
125 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename); | |
126 | |
127 const char* path = inputPath.c_str(); | |
128 SkDebugf("scraping %s\n", path); | 135 SkDebugf("scraping %s\n", path); |
129 | 136 |
130 SkAutoTUnref<SkPicture> pic(load_picture(path)); | 137 SkAutoTUnref<SkPicture> pic(load_picture(path)); |
131 if (pic.get()) { | 138 if (pic.get()) { |
132 SkAutoTUnref<SkLuaCanvas> canvas( | 139 SkAutoTUnref<SkLuaCanvas> canvas( |
133 new SkLuaCanvas(pic->width(), pic->height(), | 140 new SkLuaCanvas(pic->width(), pic->height(), |
134 L.get(), gAccumulateFunc)); | 141 L.get(), gAccumulateFunc)); |
135 | 142 |
136 call_canvas(L.get(), canvas.get(), inputFilename.c_str(), gStart
CanvasFunc); | 143 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc); |
137 canvas->drawPicture(*pic); | 144 canvas->drawPicture(*pic); |
138 call_canvas(L.get(), canvas.get(), inputFilename.c_str(), gEndCa
nvasFunc); | 145 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc); |
139 | 146 |
140 } else { | 147 } else { |
141 SkDebugf("failed to load\n"); | 148 SkDebugf("failed to load\n"); |
142 } | 149 } |
143 } | 150 } |
144 } | 151 } |
145 return 0; | 152 return 0; |
146 } | 153 } |
147 | 154 |
148 #if !defined SK_BUILD_FOR_IOS | 155 #if !defined SK_BUILD_FOR_IOS |
149 int main(int argc, char * const argv[]) { | 156 int main(int argc, char * const argv[]) { |
150 return tool_main(argc, (char**) argv); | 157 return tool_main(argc, (char**) argv); |
151 } | 158 } |
152 #endif | 159 #endif |
OLD | NEW |