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

Side by Side Diff: dm/DM.cpp

Issue 1059513002: Update DM to allow Src's to have optional options. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: accept command line input Created 5 years, 8 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
« no previous file with comments | « no previous file | dm/DMJsonWriter.h » ('j') | 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 "CrashHandler.h" 8 #include "CrashHandler.h"
9 #include "DMJsonWriter.h" 9 #include "DMJsonWriter.h"
10 #include "DMSrcSink.h" 10 #include "DMSrcSink.h"
11 #include "DMSrcSinkAndroid.h" 11 #include "DMSrcSinkAndroid.h"
12 #include "OverwriteLine.h" 12 #include "OverwriteLine.h"
13 #include "ProcStats.h" 13 #include "ProcStats.h"
14 #include "SkBBHFactory.h" 14 #include "SkBBHFactory.h"
15 #include "SkChecksum.h" 15 #include "SkChecksum.h"
16 #include "SkCommonFlags.h" 16 #include "SkCommonFlags.h"
17 #include "SkForceLinking.h" 17 #include "SkForceLinking.h"
18 #include "SkGraphics.h" 18 #include "SkGraphics.h"
19 #include "SkInstCnt.h" 19 #include "SkInstCnt.h"
20 #include "SkMD5.h" 20 #include "SkMD5.h"
21 #include "SkOSFile.h" 21 #include "SkOSFile.h"
22 #include "SkTHash.h" 22 #include "SkTHash.h"
23 #include "SkTaskGroup.h" 23 #include "SkTaskGroup.h"
24 #include "SkThreadUtils.h" 24 #include "SkThreadUtils.h"
25 #include "Test.h" 25 #include "Test.h"
26 #include "Timer.h" 26 #include "Timer.h"
27 27
28 DEFINE_string(src, "tests gm skp image subset codec scanline", "Source types to test."); 28 DEFINE_string(src, "tests gm skp image", "Source types to test.");
29 DEFINE_string(srcOptions, "decode subset codec scanline",
mtklein 2015/04/02 20:11:58 Seems like we could skip this. You're not plannin
djsollen 2015/04/02 20:24:15 Done.
30 "Options to be applied to the any source types that accepts option s. The\n"
31 "only source type that currently accepts option is image E.g.\n"
32 "'--srcOptions codec scanline' will only execute the codec and sca nline "
33 "variations of the image src.");
29 DEFINE_bool(nameByHash, false, 34 DEFINE_bool(nameByHash, false,
30 "If true, write to FLAGS_writePath[0]/<hash>.png instead of " 35 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
31 "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png"); 36 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>. png");
32 DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); 37 DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
33 DEFINE_string(matrix, "1 0 0 1", 38 DEFINE_string(matrix, "1 0 0 1",
34 "2x2 scale+skew matrix to apply or upright when using " 39 "2x2 scale+skew matrix to apply or upright when using "
35 "'matrix' or 'upright' in config."); 40 "'matrix' or 'upright' in config.");
36 DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); 41 DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
37 42
38 DEFINE_string(blacklist, "", 43 DEFINE_string(blacklist, "",
39 "Space-separated config/src/name triples to blacklist. '_' matches anyt hing. E.g. \n" 44 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_ ' matches anything. E.g. \n"
40 "'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu conf ig.\n" 45 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu co nfig.\n"
41 "'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888."); 46 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aar ects GM on 8888.");
42 47
43 DEFINE_string2(readPath, r, "", "If set check for equality with golden results i n this directory."); 48 DEFINE_string2(readPath, r, "", "If set check for equality with golden results i n this directory.");
44 49
45 __SK_FORCE_IMAGE_DECODER_LINKING; 50 __SK_FORCE_IMAGE_DECODER_LINKING;
46 using namespace DM; 51 using namespace DM;
47 52
48 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 53 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
49 54
50 SK_DECLARE_STATIC_MUTEX(gFailuresMutex); 55 SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
51 static SkTArray<SkString> gFailures; 56 static SkTArray<SkString> gFailures;
52 57
53 static void fail(ImplicitString err) { 58 static void fail(ImplicitString err) {
54 SkAutoMutexAcquire lock(gFailuresMutex); 59 SkAutoMutexAcquire lock(gFailuresMutex);
55 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); 60 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
56 gFailures.push_back(err); 61 gFailures.push_back(err);
57 } 62 }
58 63
59 static int32_t gPending = 0; // Atomic. Total number of running and queued tas ks. 64 static int32_t gPending = 0; // Atomic. Total number of running and queued tas ks.
60 65
61 SK_DECLARE_STATIC_MUTEX(gRunningMutex); 66 SK_DECLARE_STATIC_MUTEX(gRunningMutex);
62 static SkTArray<SkString> gRunning; 67 static SkTArray<SkString> gRunning;
63 68
64 static void done(double ms, 69 static void done(double ms,
65 ImplicitString config, ImplicitString src, ImplicitString name, 70 ImplicitString config, ImplicitString src, ImplicitString srcOp tions,
66 ImplicitString note, ImplicitString log) { 71 ImplicitString name, ImplicitString note, ImplicitString log) {
67 SkString id = SkStringPrintf("%s %s %s", config.c_str(), src.c_str(), name.c _str()); 72 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
73 srcOptions.c_str(), name.c_str() );
68 { 74 {
69 SkAutoMutexAcquire lock(gRunningMutex); 75 SkAutoMutexAcquire lock(gRunningMutex);
70 for (int i = 0; i < gRunning.count(); i++) { 76 for (int i = 0; i < gRunning.count(); i++) {
71 if (gRunning[i] == id) { 77 if (gRunning[i] == id) {
72 gRunning.removeShuffle(i); 78 gRunning.removeShuffle(i);
73 break; 79 break;
74 } 80 }
75 } 81 }
76 } 82 }
77 if (!FLAGS_verbose) { 83 if (!FLAGS_verbose) {
(...skipping 10 matching lines...) Expand all
88 , id.c_str() 94 , id.c_str()
89 , note.c_str() 95 , note.c_str()
90 , log.c_str()); 96 , log.c_str());
91 // We write our dm.json file every once in a while in case we crash. 97 // We write our dm.json file every once in a while in case we crash.
92 // Notice this also handles the final dm.json when pending == 0. 98 // Notice this also handles the final dm.json when pending == 0.
93 if (pending % 500 == 0) { 99 if (pending % 500 == 0) {
94 JsonWriter::DumpJson(); 100 JsonWriter::DumpJson();
95 } 101 }
96 } 102 }
97 103
98 static void start(ImplicitString config, ImplicitString src, ImplicitString name ) { 104 static void start(ImplicitString config, ImplicitString src,
99 SkString id = SkStringPrintf("%s %s %s", config.c_str(), src.c_str(), name.c _str()); 105 ImplicitString srcOptions, ImplicitString name) {
106 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
107 srcOptions.c_str(), name.c_str() );
100 SkAutoMutexAcquire lock(gRunningMutex); 108 SkAutoMutexAcquire lock(gRunningMutex);
101 gRunning.push_back(id); 109 gRunning.push_back(id);
102 } 110 }
103 111
104 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 112 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
105 113
106 struct Gold : public SkString { 114 struct Gold : public SkString {
107 Gold() : SkString("") {} 115 Gold() : SkString("") {}
108 Gold(ImplicitString sink, ImplicitString src, ImplicitString name, ImplicitS tring md5) 116 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
117 ImplicitString name, ImplicitString md5)
109 : SkString("") { 118 : SkString("") {
110 this->append(sink); 119 this->append(sink);
111 this->append(src); 120 this->append(src);
121 this->append(srcOptions);
112 this->append(name); 122 this->append(name);
113 this->append(md5); 123 this->append(md5);
114 } 124 }
115 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); } 125 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); }
116 }; 126 };
117 static SkTHashSet<Gold, Gold::Hash> gGold; 127 static SkTHashSet<Gold, Gold::Hash> gGold;
118 128
119 static void add_gold(JsonWriter::BitmapResult r) { 129 static void add_gold(JsonWriter::BitmapResult r) {
120 gGold.add(Gold(r.config, r.sourceType, r.name, r.md5)); 130 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
121 } 131 }
122 132
123 static void gather_gold() { 133 static void gather_gold() {
124 if (!FLAGS_readPath.isEmpty()) { 134 if (!FLAGS_readPath.isEmpty()) {
125 SkString path(FLAGS_readPath[0]); 135 SkString path(FLAGS_readPath[0]);
126 path.append("/dm.json"); 136 path.append("/dm.json");
127 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { 137 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
128 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_s tr())); 138 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_s tr()));
129 } 139 }
130 } 140 }
131 } 141 }
132 142
133 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 143 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
134 144
135 template <typename T> 145 template <typename T>
136 struct Tagged : public SkAutoTDelete<T> { const char* tag; }; 146 struct Tagged : public SkAutoTDelete<T> {
147 const char* tag;
148 const char* options;
149 };
137 150
138 static const bool kMemcpyOK = true; 151 static const bool kMemcpyOK = true;
139 152
140 static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; 153 static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
141 static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; 154 static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
142 155
143 static void push_src(const char* tag, Src* s) { 156 static void push_src(const char* tag, const char* options, Src* s) {
144 SkAutoTDelete<Src> src(s); 157 SkAutoTDelete<Src> src(s);
145 if (FLAGS_src.contains(tag) && 158 if (FLAGS_src.contains(tag) &&
159 (strcmp(options, "") == 0 || FLAGS_srcOptions.contains(options)) &&
146 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { 160 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
147 Tagged<Src>& s = gSrcs.push_back(); 161 Tagged<Src>& s = gSrcs.push_back();
148 s.reset(src.detach()); 162 s.reset(src.detach());
149 s.tag = tag; 163 s.tag = tag;
164 s.options = options;
150 } 165 }
151 } 166 }
152 167
153 static bool codec_supported(const char* ext) { 168 static bool codec_supported(const char* ext) {
154 // FIXME: Once other versions of SkCodec are available, we can add them to t his 169 // FIXME: Once other versions of SkCodec are available, we can add them to t his
155 // list (and eventually we can remove this check once they are all supported ). 170 // list (and eventually we can remove this check once they are all supported ).
156 static const char* const exts[] = { 171 static const char* const exts[] = {
157 "bmp", "gif", "png", "ico", "wbmp", 172 "bmp", "gif", "png", "ico", "wbmp",
158 "BMP", "GIF", "PNG", "ICO", "WBMP" 173 "BMP", "GIF", "PNG", "ICO", "WBMP"
159 }; 174 };
160 175
161 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { 176 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
162 if (0 == strcmp(exts[i], ext)) { 177 if (0 == strcmp(exts[i], ext)) {
163 return true; 178 return true;
164 } 179 }
165 } 180 }
166 return false; 181 return false;
167 } 182 }
168 183
169 static void gather_srcs() { 184 static void gather_srcs() {
170 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->nex t()) { 185 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->nex t()) {
171 push_src("gm", new GMSrc(r->factory())); 186 push_src("gm", "", new GMSrc(r->factory()));
172 } 187 }
173 for (int i = 0; i < FLAGS_skps.count(); i++) { 188 for (int i = 0; i < FLAGS_skps.count(); i++) {
174 const char* path = FLAGS_skps[i]; 189 const char* path = FLAGS_skps[i];
175 if (sk_isdir(path)) { 190 if (sk_isdir(path)) {
176 SkOSFile::Iter it(path, "skp"); 191 SkOSFile::Iter it(path, "skp");
177 for (SkString file; it.next(&file); ) { 192 for (SkString file; it.next(&file); ) {
178 push_src("skp", new SKPSrc(SkOSPath::Join(path, file.c_str()))); 193 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str() )));
179 } 194 }
180 } else { 195 } else {
181 push_src("skp", new SKPSrc(path)); 196 push_src("skp", "", new SKPSrc(path));
182 } 197 }
183 } 198 }
184 static const char* const exts[] = { 199 static const char* const exts[] = {
185 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico" , 200 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico" ,
186 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO" , 201 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO" ,
187 }; 202 };
188 for (int i = 0; i < FLAGS_images.count(); i++) { 203 for (int i = 0; i < FLAGS_images.count(); i++) {
189 const char* flag = FLAGS_images[i]; 204 const char* flag = FLAGS_images[i];
190 if (sk_isdir(flag)) { 205 if (sk_isdir(flag)) {
191 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) { 206 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
192 SkOSFile::Iter it(flag, exts[j]); 207 SkOSFile::Iter it(flag, exts[j]);
193 for (SkString file; it.next(&file); ) { 208 for (SkString file; it.next(&file); ) {
194 SkString path = SkOSPath::Join(flag, file.c_str()); 209 SkString path = SkOSPath::Join(flag, file.c_str());
195 push_src("image", new ImageSrc(path)); // Decode entire image. 210 push_src("image", "decode", new ImageSrc(path)); // Decode e ntire image
196 push_src("subset", new ImageSrc(path, 2)); // Decode into 2 x 2 subsets 211 push_src("image", "subset", new ImageSrc(path, 2)); // Decod e into 2x2 subsets
197 if (codec_supported(exts[j])) { 212 if (codec_supported(exts[j])) {
198 push_src("codec", new CodecSrc(path, CodecSrc::kNormal_M ode)); 213 push_src("image", "codec", new CodecSrc(path, CodecSrc:: kNormal_Mode));
199 push_src("scanline", new CodecSrc(path, CodecSrc::kScanl ine_Mode)); 214 push_src("image", "scanline", new CodecSrc(path, CodecSr c::kScanline_Mode));
200 } 215 }
201 } 216 }
202 } 217 }
203 } else if (sk_exists(flag)) { 218 } else if (sk_exists(flag)) {
204 // assume that FLAGS_images[i] is a valid image if it is a file. 219 // assume that FLAGS_images[i] is a valid image if it is a file.
205 push_src("image", new ImageSrc(flag)); // Decode entire image. 220 push_src("image", "decode", new ImageSrc(flag)); // Decode entire im age.
206 push_src("subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subs ets 221 push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets
207 push_src("codec", new CodecSrc(flag, CodecSrc::kNormal_Mode)); 222 push_src("image", "codec", new CodecSrc(flag, CodecSrc::kNormal_Mode ));
208 push_src("scanline", new CodecSrc(flag, CodecSrc::kScanline_Mode)); 223 push_src("image", "scanline", new CodecSrc(flag, CodecSrc::kScanline _Mode));
209 } 224 }
210 } 225 }
211 } 226 }
212 227
213 static GrGLStandard get_gpu_api() { 228 static GrGLStandard get_gpu_api() {
214 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } 229 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
215 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } 230 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
216 return kNone_GrGLStandard; 231 return kNone_GrGLStandard;
217 } 232 }
218 233
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (sink) { 350 if (sink) {
336 push_sink(config, sink); 351 push_sink(config, sink);
337 } 352 }
338 } 353 }
339 } 354 }
340 355
341 static bool match(const char* needle, const char* haystack) { 356 static bool match(const char* needle, const char* haystack) {
342 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); 357 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
343 } 358 }
344 359
345 static ImplicitString is_blacklisted(const char* sink, const char* src, const ch ar* name) { 360 static ImplicitString is_blacklisted(const char* sink, const char* src,
361 const char* srcOptions, const char* name) {
346 for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) { 362 for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) {
347 if (match(FLAGS_blacklist[i+0], sink) && 363 if (match(FLAGS_blacklist[i+0], sink) &&
348 match(FLAGS_blacklist[i+1], src) && 364 match(FLAGS_blacklist[i+1], src) &&
349 match(FLAGS_blacklist[i+2], name)) { 365 match(FLAGS_blacklist[i+2], srcOptions) &&
350 return SkStringPrintf("%s %s %s", 366 match(FLAGS_blacklist[i+3], name)) {
351 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FL AGS_blacklist[i+2]); 367 return SkStringPrintf("%s %s %s %s",
368 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
369 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
352 } 370 }
353 } 371 }
354 return ""; 372 return "";
355 } 373 }
356 374
357 // The finest-grained unit of work we can run: draw a single Src into a single S ink, 375 // The finest-grained unit of work we can run: draw a single Src into a single S ink,
358 // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. 376 // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
359 struct Task { 377 struct Task {
360 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink ) {} 378 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink ) {}
361 const Tagged<Src>& src; 379 const Tagged<Src>& src;
362 const Tagged<Sink>& sink; 380 const Tagged<Sink>& sink;
363 381
364 static void Run(Task* task) { 382 static void Run(Task* task) {
365 SkString name = task->src->name(); 383 SkString name = task->src->name();
366 SkString note; 384 SkString note;
367 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str()); 385 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
386 task->src.options, name.c_str() );
368 if (!whyBlacklisted.isEmpty()) { 387 if (!whyBlacklisted.isEmpty()) {
369 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); 388 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
370 } 389 }
371 SkString log; 390 SkString log;
372 WallTimer timer; 391 WallTimer timer;
373 timer.start(); 392 timer.start();
374 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { 393 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
375 SkBitmap bitmap; 394 SkBitmap bitmap;
376 SkDynamicMemoryWStream stream; 395 SkDynamicMemoryWStream stream;
377 start(task->sink.tag, task->src.tag, name.c_str()); 396 start(task->sink.tag, task->src.tag, task->src.options, name.c_str() );
378 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log); 397 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
379 if (!err.isEmpty()) { 398 if (!err.isEmpty()) {
380 timer.end(); 399 timer.end();
381 if (err.isFatal()) { 400 if (err.isFatal()) {
382 fail(SkStringPrintf("%s %s %s: %s", 401 fail(SkStringPrintf("%s %s %s %s: %s",
383 task->sink.tag, 402 task->sink.tag,
384 task->src.tag, 403 task->src.tag,
404 task->src.options,
385 name.c_str(), 405 name.c_str(),
386 err.c_str())); 406 err.c_str()));
387 } else { 407 } else {
388 note.appendf(" (skipped: %s)", err.c_str()); 408 note.appendf(" (skipped: %s)", err.c_str());
389 } 409 }
390 done(timer.fWall, task->sink.tag, task->src.tag, name, note, log ); 410 done(timer.fWall, task->sink.tag, task->src.tag, task->src.optio ns,
411 name, note, log);
391 return; 412 return;
392 } 413 }
393 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); 414 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
394 415
395 SkString md5; 416 SkString md5;
396 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { 417 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
397 SkMD5 hash; 418 SkMD5 hash;
398 if (data->getLength()) { 419 if (data->getLength()) {
399 hash.writeStream(data, data->getLength()); 420 hash.writeStream(data, data->getLength());
400 data->rewind(); 421 data->rewind();
401 } else { 422 } else {
402 hash.write(bitmap.getPixels(), bitmap.getSize()); 423 hash.write(bitmap.getPixels(), bitmap.getSize());
403 } 424 }
404 SkMD5::Digest digest; 425 SkMD5::Digest digest;
405 hash.finish(digest); 426 hash.finish(digest);
406 for (int i = 0; i < 16; i++) { 427 for (int i = 0; i < 16; i++) {
407 md5.appendf("%02x", digest.data[i]); 428 md5.appendf("%02x", digest.data[i]);
408 } 429 }
409 } 430 }
410 431
411 if (!FLAGS_readPath.isEmpty() && 432 if (!FLAGS_readPath.isEmpty() &&
412 !gGold.contains(Gold(task->sink.tag, task->src.tag, name, md5))) { 433 !gGold.contains(Gold(task->sink.tag, task->src.tag,
413 fail(SkStringPrintf("%s not found for %s %s %s in %s", 434 task->src.options, name, md5))) {
435 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
414 md5.c_str(), 436 md5.c_str(),
415 task->sink.tag, 437 task->sink.tag,
416 task->src.tag, 438 task->src.tag,
439 task->src.options,
417 name.c_str(), 440 name.c_str(),
418 FLAGS_readPath[0])); 441 FLAGS_readPath[0]));
419 } 442 }
420 443
421 if (!FLAGS_writePath.isEmpty()) { 444 if (!FLAGS_writePath.isEmpty()) {
422 const char* ext = task->sink->fileExtension(); 445 const char* ext = task->sink->fileExtension();
423 if (data->getLength()) { 446 if (data->getLength()) {
424 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL); 447 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
425 SkASSERT(bitmap.drawsNothing()); 448 SkASSERT(bitmap.drawsNothing());
426 } else if (!bitmap.drawsNothing()) { 449 } else if (!bitmap.drawsNothing()) {
427 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap); 450 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
428 } 451 }
429 } 452 }
430 } 453 }
431 timer.end(); 454 timer.end();
432 done(timer.fWall, task->sink.tag, task->src.tag, name, note, log); 455 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name , note, log);
433 } 456 }
434 457
435 static void WriteToDisk(const Task& task, 458 static void WriteToDisk(const Task& task,
436 SkString md5, 459 SkString md5,
437 const char* ext, 460 const char* ext,
438 SkStream* data, size_t len, 461 SkStream* data, size_t len,
439 const SkBitmap* bitmap) { 462 const SkBitmap* bitmap) {
440 JsonWriter::BitmapResult result; 463 JsonWriter::BitmapResult result;
441 result.name = task.src->name(); 464 result.name = task.src->name();
442 result.config = task.sink.tag; 465 result.config = task.sink.tag;
443 result.sourceType = task.src.tag; 466 result.sourceType = task.src.tag;
444 result.ext = ext; 467 result.sourceOptions = task.src.options;
445 result.md5 = md5; 468 result.ext = ext;
469 result.md5 = md5;
446 JsonWriter::AddBitmapResult(result); 470 JsonWriter::AddBitmapResult(result);
447 471
448 const char* dir = FLAGS_writePath[0]; 472 const char* dir = FLAGS_writePath[0];
449 if (0 == strcmp(dir, "@")) { // Needed for iOS. 473 if (0 == strcmp(dir, "@")) { // Needed for iOS.
450 dir = FLAGS_resourcePath[0]; 474 dir = FLAGS_resourcePath[0];
451 } 475 }
452 sk_mkdir(dir); 476 sk_mkdir(dir);
453 477
454 SkString path; 478 SkString path;
455 if (FLAGS_nameByHash) { 479 if (FLAGS_nameByHash) {
456 path = SkOSPath::Join(dir, result.md5.c_str()); 480 path = SkOSPath::Join(dir, result.md5.c_str());
457 path.append("."); 481 path.append(".");
458 path.append(ext); 482 path.append(ext);
459 if (sk_exists(path.c_str())) { 483 if (sk_exists(path.c_str())) {
460 return; // Content-addressed. If it exists already, we're done . 484 return; // Content-addressed. If it exists already, we're done .
461 } 485 }
462 } else { 486 } else {
463 path = SkOSPath::Join(dir, task.sink.tag); 487 path = SkOSPath::Join(dir, task.sink.tag);
464 sk_mkdir(path.c_str()); 488 sk_mkdir(path.c_str());
465 path = SkOSPath::Join(path.c_str(), task.src.tag); 489 path = SkOSPath::Join(path.c_str(), task.src.tag);
466 sk_mkdir(path.c_str()); 490 sk_mkdir(path.c_str());
491 if (strcmp(task.src.options, "") == 0) {
mtklein 2015/04/02 20:11:58 != ?
djsollen 2015/04/02 20:24:15 Done.
492 path = SkOSPath::Join(path.c_str(), task.src.options);
493 sk_mkdir(path.c_str());
494 }
467 path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); 495 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
468 path.append("."); 496 path.append(".");
469 path.append(ext); 497 path.append(ext);
470 } 498 }
471 499
472 SkFILEWStream file(path.c_str()); 500 SkFILEWStream file(path.c_str());
473 if (!file.isValid()) { 501 if (!file.isValid()) {
474 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); 502 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
475 return; 503 return;
476 } 504 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 JsonWriter::AddTestFailure(failure); 567 JsonWriter::AddTestFailure(failure);
540 } 568 }
541 bool allowExtendedTest() const override { 569 bool allowExtendedTest() const override {
542 return FLAGS_pathOpsExtended; 570 return FLAGS_pathOpsExtended;
543 } 571 }
544 bool verbose() const override { return FLAGS_veryVerbose; } 572 bool verbose() const override { return FLAGS_veryVerbose; }
545 } reporter; 573 } reporter;
546 WallTimer timer; 574 WallTimer timer;
547 timer.start(); 575 timer.start();
548 if (!FLAGS_dryRun) { 576 if (!FLAGS_dryRun) {
549 start("unit", "test", test->name); 577 start("unit", "test", "", test->name);
550 GrContextFactory factory; 578 GrContextFactory factory;
551 test->proc(&reporter, &factory); 579 test->proc(&reporter, &factory);
552 } 580 }
553 timer.end(); 581 timer.end();
554 done(timer.fWall, "unit", "test", test->name, "", ""); 582 done(timer.fWall, "unit", "test", "", test->name, "", "");
555 } 583 }
556 584
557 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 585 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
558 586
559 // If we're isolating all GPU-bound work to one thread (the default), this funct ion runs all that. 587 // If we're isolating all GPU-bound work to one thread (the default), this funct ion runs all that.
560 static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) { 588 static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
561 run_enclave(tasks); 589 run_enclave(tasks);
562 for (int i = 0; i < gGPUTests.count(); i++) { 590 for (int i = 0; i < gGPUTests.count(); i++) {
563 run_test(&gGPUTests[i]); 591 run_test(&gGPUTests[i]);
564 } 592 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 684 }
657 return 0; 685 return 0;
658 } 686 }
659 687
660 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 688 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
661 int main(int argc, char** argv) { 689 int main(int argc, char** argv) {
662 SkCommandLineFlags::Parse(argc, argv); 690 SkCommandLineFlags::Parse(argc, argv);
663 return dm_main(); 691 return dm_main();
664 } 692 }
665 #endif 693 #endif
OLDNEW
« no previous file with comments | « no previous file | dm/DMJsonWriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698