| 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 "LazyDecodeBitmap.h" | 8 #include "LazyDecodeBitmap.h" |
| 9 #include "SkLua.h" | 9 #include "SkLua.h" |
| 10 #include "SkLuaCanvas.h" | 10 #include "SkLuaCanvas.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 static const char gSummarizeFunc[] = "sk_scrape_summarize"; | 29 static const char gSummarizeFunc[] = "sk_scrape_summarize"; |
| 30 | 30 |
| 31 // Example usage for the modulo flag: | 31 // Example usage for the modulo flag: |
| 32 // for i in {0..5}; do lua_pictures --skpPath SKP_PATH -l YOUR_SCRIPT --modulo $
i 6 &; done | 32 // for i in {0..5}; do lua_pictures --skpPath SKP_PATH -l YOUR_SCRIPT --modulo $
i 6 &; done |
| 33 DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for
which " | 33 DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for
which " |
| 34 "testIndex %% divisor == remainder."); | 34 "testIndex %% divisor == remainder."); |
| 35 DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir"
); | 35 DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir"
); |
| 36 DEFINE_string2(luaFile, l, "", "File containing lua script to run"); | 36 DEFINE_string2(luaFile, l, "", "File containing lua script to run"); |
| 37 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning"); | 37 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning"); |
| 38 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); | 38 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); |
| 39 DEFINE_bool2(quiet, q, false, "Silence all non-error related output"); |
| 39 | 40 |
| 40 static SkPicture* load_picture(const char path[]) { | 41 static SkPicture* load_picture(const char path[]) { |
| 41 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 42 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 42 SkPicture* pic = NULL; | 43 SkPicture* pic = NULL; |
| 43 if (stream.get()) { | 44 if (stream.get()) { |
| 44 pic = SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBit
map); | 45 pic = SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBit
map); |
| 45 } | 46 } |
| 46 return pic; | 47 return pic; |
| 47 } | 48 } |
| 48 | 49 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const char* summary = gSummarizeFunc; | 91 const char* summary = gSummarizeFunc; |
| 91 if (!FLAGS_tailFunc.isEmpty()) { | 92 if (!FLAGS_tailFunc.isEmpty()) { |
| 92 summary = FLAGS_tailFunc[0]; | 93 summary = FLAGS_tailFunc[0]; |
| 93 } | 94 } |
| 94 | 95 |
| 95 SkAutoGraphics ag; | 96 SkAutoGraphics ag; |
| 96 SkLua L(summary); | 97 SkLua L(summary); |
| 97 | 98 |
| 98 for (int i = 0; i < FLAGS_luaFile.count(); ++i) { | 99 for (int i = 0; i < FLAGS_luaFile.count(); ++i) { |
| 99 SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i])); | 100 SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i])); |
| 100 SkDebugf("loading %s...\n", FLAGS_luaFile[i]); | 101 if (!FLAGS_quiet) { |
| 102 SkDebugf("loading %s...\n", FLAGS_luaFile[i]); |
| 103 } |
| 101 if (!L.runCode(data->data(), data->size())) { | 104 if (!L.runCode(data->data(), data->size())) { |
| 102 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); | 105 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); |
| 103 exit(-1); | 106 exit(-1); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 if (!FLAGS_headCode.isEmpty()) { | 110 if (!FLAGS_headCode.isEmpty()) { |
| 108 L.runCode(FLAGS_headCode[0]); | 111 L.runCode(FLAGS_headCode[0]); |
| 109 } | 112 } |
| 110 | 113 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 137 } | 140 } |
| 138 | 141 |
| 139 for (int i = 0; i < paths.count(); i++) { | 142 for (int i = 0; i < paths.count(); i++) { |
| 140 if (moduloRemainder >= 0) { | 143 if (moduloRemainder >= 0) { |
| 141 if ((i % moduloDivisor) != moduloRemainder) { | 144 if ((i % moduloDivisor) != moduloRemainder) { |
| 142 continue; | 145 continue; |
| 143 } | 146 } |
| 144 moduloStr.printf("[%d.%d] ", i, moduloDivisor); | 147 moduloStr.printf("[%d.%d] ", i, moduloDivisor); |
| 145 } | 148 } |
| 146 const char* path = paths[i].c_str(); | 149 const char* path = paths[i].c_str(); |
| 147 SkDebugf("scraping %s %s\n", path, moduloStr.c_str()); | 150 if (!FLAGS_quiet) { |
| 151 SkDebugf("scraping %s %s\n", path, moduloStr.c_str()); |
| 152 } |
| 148 | 153 |
| 149 SkAutoTUnref<SkPicture> pic(load_picture(path)); | 154 SkAutoTUnref<SkPicture> pic(load_picture(path)); |
| 150 if (pic.get()) { | 155 if (pic.get()) { |
| 151 SkAutoTUnref<SkLuaCanvas> canvas( | 156 SkAutoTUnref<SkLuaCanvas> canvas( |
| 152 new SkLuaCanvas(pic->width(), pic->height(), | 157 new SkLuaCanvas(pic->width(), pic->height(), |
| 153 L.get(), gAccumulateFunc)); | 158 L.get(), gAccumulateFunc)); |
| 154 | 159 |
| 155 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc); | 160 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc); |
| 156 canvas->drawPicture(*pic); | 161 canvas->drawPicture(*pic); |
| 157 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc); | 162 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc); |
| 158 | 163 |
| 159 } else { | 164 } else { |
| 160 SkDebugf("failed to load\n"); | 165 SkDebugf("failed to load\n"); |
| 161 } | 166 } |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 return 0; | 169 return 0; |
| 165 } | 170 } |
| 166 | 171 |
| 167 #if !defined SK_BUILD_FOR_IOS | 172 #if !defined SK_BUILD_FOR_IOS |
| 168 int main(int argc, char * const argv[]) { | 173 int main(int argc, char * const argv[]) { |
| 169 return tool_main(argc, (char**) argv); | 174 return tool_main(argc, (char**) argv); |
| 170 } | 175 } |
| 171 #endif | 176 #endif |
| OLD | NEW |