Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: tools/lua/lua_pictures.cpp

Issue 16950025: Add modulo flag to lua_pictures. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Example usage for the modulo flag:
37 // for i in {0..5}; do lua_pictures --skpPath SKP_PATH -l YOUR_SCRIPT --modulo $ i 6 &; done
38 DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
39 "testIndex %% divisor == remainder.");
36 DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir" ); 40 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"); 41 DEFINE_string2(luaFile, l, "", "File containing lua script to run");
38 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning"); 42 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning");
39 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); 43 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
40 44
41 static SkPicture* load_picture(const char path[]) { 45 static SkPicture* load_picture(const char path[]) {
42 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 46 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
43 SkPicture* pic = NULL; 47 SkPicture* pic = NULL;
44 if (stream.get()) { 48 if (stream.get()) {
45 bool success; 49 bool success;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (!L.runCode(data->data(), data->size())) { 112 if (!L.runCode(data->data(), data->size())) {
109 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); 113 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]);
110 exit(-1); 114 exit(-1);
111 } 115 }
112 } 116 }
113 117
114 if (!FLAGS_headCode.isEmpty()) { 118 if (!FLAGS_headCode.isEmpty()) {
115 L.runCode(FLAGS_headCode[0]); 119 L.runCode(FLAGS_headCode[0]);
116 } 120 }
117 121
122 int moduloRemainder = -1;
123 int moduloDivisor = -1;
124 SkString moduloStr;
125
126 if (FLAGS_modulo.count() == 2) {
127 moduloRemainder = atoi(FLAGS_modulo[0]);
128 moduloDivisor = atoi(FLAGS_modulo[1]);
129 if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= modu loDivisor) {
130 SkDebugf("invalid modulo values.\n");
131 return -1;
132 }
133 }
134
118 for (int i = 0; i < FLAGS_skpPath.count(); i ++) { 135 for (int i = 0; i < FLAGS_skpPath.count(); i ++) {
119 SkTArray<SkString> paths; 136 SkTArray<SkString> paths;
120 if (sk_isdir(FLAGS_skpPath[i])) { 137 if (sk_isdir(FLAGS_skpPath[i])) {
121 // Add all .skp in this directory. 138 // Add all .skp in this directory.
122 const SkString directory(FLAGS_skpPath[i]); 139 const SkString directory(FLAGS_skpPath[i]);
123 SkString filename; 140 SkString filename;
124 SkOSFile::Iter iter(FLAGS_skpPath[i], "skp"); 141 SkOSFile::Iter iter(FLAGS_skpPath[i], "skp");
125 while(iter.next(&filename)) { 142 while(iter.next(&filename)) {
126 sk_tools::make_filepath(&paths.push_back(), directory, filename) ; 143 sk_tools::make_filepath(&paths.push_back(), directory, filename) ;
127 } 144 }
128 } else { 145 } else {
129 // Add this as an .skp itself. 146 // Add this as an .skp itself.
130 paths.push_back() = FLAGS_skpPath[i]; 147 paths.push_back() = FLAGS_skpPath[i];
131 } 148 }
132 149
133 for (int i = 0; i < paths.count(); i++) { 150 for (int i = 0; i < paths.count(); i++) {
151 if (moduloRemainder >= 0) {
152 if ((i % moduloDivisor) != moduloRemainder) {
153 continue;
154 }
155 moduloStr.printf("[%d.%d] ", i, moduloDivisor);
156 }
134 const char* path = paths[i].c_str(); 157 const char* path = paths[i].c_str();
135 SkDebugf("scraping %s\n", path); 158 SkDebugf("scraping %s %s\n", path, moduloStr.c_str());
136 159
137 SkAutoTUnref<SkPicture> pic(load_picture(path)); 160 SkAutoTUnref<SkPicture> pic(load_picture(path));
138 if (pic.get()) { 161 if (pic.get()) {
139 SkAutoTUnref<SkLuaCanvas> canvas( 162 SkAutoTUnref<SkLuaCanvas> canvas(
140 new SkLuaCanvas(pic->width(), pic->height(), 163 new SkLuaCanvas(pic->width(), pic->height(),
141 L.get(), gAccumulateFunc)); 164 L.get(), gAccumulateFunc));
142 165
143 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc); 166 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc);
144 canvas->drawPicture(*pic); 167 canvas->drawPicture(*pic);
145 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc); 168 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc);
146 169
147 } else { 170 } else {
148 SkDebugf("failed to load\n"); 171 SkDebugf("failed to load\n");
149 } 172 }
150 } 173 }
151 } 174 }
152 return 0; 175 return 0;
153 } 176 }
154 177
155 #if !defined SK_BUILD_FOR_IOS 178 #if !defined SK_BUILD_FOR_IOS
156 int main(int argc, char * const argv[]) { 179 int main(int argc, char * const argv[]) {
157 return tool_main(argc, (char**) argv); 180 return tool_main(argc, (char**) argv);
158 } 181 }
159 #endif 182 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698