| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 newRecord->fCommonName.c_
str()); | 202 newRecord->fCommonName.c_
str()); |
| 203 SkImageEncoder::EncodeFile(newRecord->fWhiteDiffPath.c_str(), | 203 SkImageEncoder::EncodeFile(newRecord->fWhiteDiffPath.c_str(), |
| 204 diffData.fResult.whiteDiffBitmap, | 204 diffData.fResult.whiteDiffBitmap, |
| 205 SkImageEncoder::kPNG_Type, 100); | 205 SkImageEncoder::kPNG_Type, 100); |
| 206 diffData.fResult.whiteDiffBitmap.reset(); | 206 diffData.fResult.whiteDiffBitmap.reset(); |
| 207 bitmapsToCreate.whiteDiff = false; | 207 bitmapsToCreate.whiteDiff = false; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 class SkThreadedDiff : public SkRunnable { | |
| 213 public: | |
| 214 SkThreadedDiff() : fDiffContext(NULL) { } | |
| 215 | |
| 216 void setup(SkDiffContext* diffContext, const SkString& baselinePath, const S
kString& testPath) { | |
| 217 fDiffContext = diffContext; | |
| 218 fBaselinePath = baselinePath; | |
| 219 fTestPath = testPath; | |
| 220 } | |
| 221 | |
| 222 void run() override { | |
| 223 fDiffContext->addDiff(fBaselinePath.c_str(), fTestPath.c_str()); | |
| 224 } | |
| 225 | |
| 226 private: | |
| 227 SkDiffContext* fDiffContext; | |
| 228 SkString fBaselinePath; | |
| 229 SkString fTestPath; | |
| 230 }; | |
| 231 | |
| 232 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa
th[]) { | 212 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa
th[]) { |
| 233 // Get the files in the baseline, we will then look for those inside the tes
t path | 213 // Get the files in the baseline, we will then look for those inside the tes
t path |
| 234 SkTArray<SkString> baselineEntries; | 214 SkTArray<SkString> baselineEntries; |
| 235 if (!get_directory(baselinePath, &baselineEntries)) { | 215 if (!get_directory(baselinePath, &baselineEntries)) { |
| 236 SkDebugf("Unable to open path \"%s\"\n", baselinePath); | 216 SkDebugf("Unable to open path \"%s\"\n", baselinePath); |
| 237 return; | 217 return; |
| 238 } | 218 } |
| 239 | 219 |
| 240 SkTaskGroup tg; | 220 sk_parallel_for(baselineEntries.count(), [&](int i) { |
| 241 SkTArray<SkThreadedDiff> runnableDiffs; | 221 const char* baseFilename = baselineEntries[i].c_str(); |
| 242 runnableDiffs.reset(baselineEntries.count()); | |
| 243 | |
| 244 for (int x = 0; x < baselineEntries.count(); x++) { | |
| 245 const char* baseFilename = baselineEntries[x].c_str(); | |
| 246 | 222 |
| 247 // Find the real location of each file to compare | 223 // Find the real location of each file to compare |
| 248 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename); | 224 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename); |
| 249 SkString testFile = SkOSPath::Join(testPath, baseFilename); | 225 SkString testFile = SkOSPath::Join(testPath, baseFilename); |
| 250 | 226 |
| 251 // Check that the test file exists and is a file | 227 // Check that the test file exists and is a file |
| 252 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { | 228 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { |
| 253 // Queue up the comparison with the differ | 229 this->addDiff(baselineFile.c_str(), testFile.c_str()); |
| 254 runnableDiffs[x].setup(this, baselineFile, testFile); | |
| 255 tg.add(&runnableDiffs[x]); | |
| 256 } else { | 230 } else { |
| 257 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba
selineFile.c_str()); | 231 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba
selineFile.c_str()); |
| 258 } | 232 } |
| 259 } | 233 }); |
| 260 } | 234 } |
| 261 | 235 |
| 262 | 236 |
| 263 void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa
ttern[]) { | 237 void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa
ttern[]) { |
| 264 // Get the files in the baseline and test patterns. Because they are in sort
ed order, it's easy | 238 // Get the files in the baseline and test patterns. Because they are in sort
ed order, it's easy |
| 265 // to find corresponding images by matching entry indices. | 239 // to find corresponding images by matching entry indices. |
| 266 | 240 |
| 267 SkTArray<SkString> baselineEntries; | 241 SkTArray<SkString> baselineEntries; |
| 268 if (!glob_files(baselinePattern, &baselineEntries)) { | 242 if (!glob_files(baselinePattern, &baselineEntries)) { |
| 269 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); | 243 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); |
| 270 return; | 244 return; |
| 271 } | 245 } |
| 272 | 246 |
| 273 SkTArray<SkString> testEntries; | 247 SkTArray<SkString> testEntries; |
| 274 if (!glob_files(testPattern, &testEntries)) { | 248 if (!glob_files(testPattern, &testEntries)) { |
| 275 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); | 249 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); |
| 276 return; | 250 return; |
| 277 } | 251 } |
| 278 | 252 |
| 279 if (baselineEntries.count() != testEntries.count()) { | 253 if (baselineEntries.count() != testEntries.count()) { |
| 280 SkDebugf("Baseline and test patterns do not yield corresponding number o
f files\n"); | 254 SkDebugf("Baseline and test patterns do not yield corresponding number o
f files\n"); |
| 281 return; | 255 return; |
| 282 } | 256 } |
| 283 | 257 |
| 284 SkTaskGroup tg; | 258 sk_parallel_for(baselineEntries.count(), [&](int i) { |
| 285 SkTArray<SkThreadedDiff> runnableDiffs; | 259 this->addDiff(baselineEntries[i].c_str(), testEntries[i].c_str()); |
| 286 runnableDiffs.reset(baselineEntries.count()); | 260 }); |
| 287 | |
| 288 for (int x = 0; x < baselineEntries.count(); x++) { | |
| 289 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]); | |
| 290 tg.add(&runnableDiffs[x]); | |
| 291 } | |
| 292 tg.wait(); | |
| 293 } | 261 } |
| 294 | 262 |
| 295 void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { | 263 void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { |
| 296 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_
IterStart); | 264 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_
IterStart); |
| 297 DiffRecord* currentRecord = iter.get(); | 265 DiffRecord* currentRecord = iter.get(); |
| 298 | 266 |
| 299 if (useJSONP) { | 267 if (useJSONP) { |
| 300 stream.writeText("var SkPDiffRecords = {\n"); | 268 stream.writeText("var SkPDiffRecords = {\n"); |
| 301 } else { | 269 } else { |
| 302 stream.writeText("{\n"); | 270 stream.writeText("{\n"); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 for (int i = 0; i < cntColumns; i++) { | 420 for (int i = 0; i < cntColumns; i++) { |
| 453 SkString str; | 421 SkString str; |
| 454 str.printf(", %f", values[i]); | 422 str.printf(", %f", values[i]); |
| 455 stream.writeText(str.c_str()); | 423 stream.writeText(str.c_str()); |
| 456 } | 424 } |
| 457 stream.writeText("\n"); | 425 stream.writeText("\n"); |
| 458 | 426 |
| 459 currentRecord = iter2.next(); | 427 currentRecord = iter2.next(); |
| 460 } | 428 } |
| 461 } | 429 } |
| OLD | NEW |