| 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" |
| 11 #include "SkRunnable.h" | 11 #include "SkRunnable.h" |
| 12 #include "SkSize.h" | 12 #include "SkSize.h" |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "SkTDict.h" | 14 #include "SkTDict.h" |
| 15 #include "SkThreadPool.h" | 15 #include "SkTaskGroup.h" |
| 16 | 16 |
| 17 // from the tools directory for replace_char(...) | 17 // from the tools directory for replace_char(...) |
| 18 #include "picture_utils.h" | 18 #include "picture_utils.h" |
| 19 | 19 |
| 20 #include "SkDiffContext.h" | 20 #include "SkDiffContext.h" |
| 21 #include "SkImageDiffer.h" | 21 #include "SkImageDiffer.h" |
| 22 #include "skpdiff_util.h" | 22 #include "skpdiff_util.h" |
| 23 | 23 |
| 24 SkDiffContext::SkDiffContext() { | 24 SkDiffContext::SkDiffContext() { |
| 25 fDiffers = NULL; | 25 fDiffers = NULL; |
| 26 fDifferCount = 0; | 26 fDifferCount = 0; |
| 27 fThreadCount = SkThreadPool::kThreadPerCore; | |
| 28 } | 27 } |
| 29 | 28 |
| 30 SkDiffContext::~SkDiffContext() { | 29 SkDiffContext::~SkDiffContext() { |
| 31 if (NULL != fDiffers) { | 30 if (NULL != fDiffers) { |
| 32 SkDELETE_ARRAY(fDiffers); | 31 SkDELETE_ARRAY(fDiffers); |
| 33 } | 32 } |
| 34 } | 33 } |
| 35 | 34 |
| 36 void SkDiffContext::setAlphaMaskDir(const SkString& path) { | 35 void SkDiffContext::setAlphaMaskDir(const SkString& path) { |
| 37 if (!path.isEmpty() && sk_mkdir(path.c_str())) { | 36 if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 79 } |
| 81 } | 80 } |
| 82 if (a.size() > b.size()) { | 81 if (a.size() > b.size()) { |
| 83 return b; | 82 return b; |
| 84 } else { | 83 } else { |
| 85 return a; | 84 return a; |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 89 static SkString get_combined_name(const SkString& a, const SkString& b) { | 88 static SkString get_combined_name(const SkString& a, const SkString& b) { |
| 90 // Note (stephana): We must keep this function in sync with | 89 // Note (stephana): We must keep this function in sync with |
| 91 // getImageDiffRelativeUrl() in static/loader.js (under rebaseline_server). | 90 // getImageDiffRelativeUrl() in static/loader.js (under rebaseline_server). |
| 92 SkString result = a; | 91 SkString result = a; |
| 93 result.append("-vs-"); | 92 result.append("-vs-"); |
| 94 result.append(b); | 93 result.append(b); |
| 95 sk_tools::replace_char(&result, '.', '_'); | 94 sk_tools::replace_char(&result, '.', '_'); |
| 96 return result; | 95 return result; |
| 97 } | 96 } |
| 98 | 97 |
| 99 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { | 98 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
| 100 // Load the images at the paths | 99 // Load the images at the paths |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 }; | 230 }; |
| 232 | 231 |
| 233 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa
th[]) { | 232 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa
th[]) { |
| 234 // Get the files in the baseline, we will then look for those inside the tes
t path | 233 // Get the files in the baseline, we will then look for those inside the tes
t path |
| 235 SkTArray<SkString> baselineEntries; | 234 SkTArray<SkString> baselineEntries; |
| 236 if (!get_directory(baselinePath, &baselineEntries)) { | 235 if (!get_directory(baselinePath, &baselineEntries)) { |
| 237 SkDebugf("Unable to open path \"%s\"\n", baselinePath); | 236 SkDebugf("Unable to open path \"%s\"\n", baselinePath); |
| 238 return; | 237 return; |
| 239 } | 238 } |
| 240 | 239 |
| 241 SkThreadPool threadPool(fThreadCount); | 240 SkTaskGroup tg; |
| 242 SkTArray<SkThreadedDiff> runnableDiffs; | 241 SkTArray<SkThreadedDiff> runnableDiffs; |
| 243 runnableDiffs.reset(baselineEntries.count()); | 242 runnableDiffs.reset(baselineEntries.count()); |
| 244 | 243 |
| 245 for (int x = 0; x < baselineEntries.count(); x++) { | 244 for (int x = 0; x < baselineEntries.count(); x++) { |
| 246 const char* baseFilename = baselineEntries[x].c_str(); | 245 const char* baseFilename = baselineEntries[x].c_str(); |
| 247 | 246 |
| 248 // Find the real location of each file to compare | 247 // Find the real location of each file to compare |
| 249 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename); | 248 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename); |
| 250 SkString testFile = SkOSPath::Join(testPath, baseFilename); | 249 SkString testFile = SkOSPath::Join(testPath, baseFilename); |
| 251 | 250 |
| 252 // Check that the test file exists and is a file | 251 // Check that the test file exists and is a file |
| 253 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { | 252 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { |
| 254 // Queue up the comparison with the differ | 253 // Queue up the comparison with the differ |
| 255 runnableDiffs[x].setup(this, baselineFile, testFile); | 254 runnableDiffs[x].setup(this, baselineFile, testFile); |
| 256 threadPool.add(&runnableDiffs[x]); | 255 tg.add(&runnableDiffs[x]); |
| 257 } else { | 256 } else { |
| 258 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba
selineFile.c_str()); | 257 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba
selineFile.c_str()); |
| 259 } | 258 } |
| 260 } | 259 } |
| 261 | |
| 262 threadPool.wait(); | |
| 263 } | 260 } |
| 264 | 261 |
| 265 | 262 |
| 266 void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa
ttern[]) { | 263 void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa
ttern[]) { |
| 267 // Get the files in the baseline and test patterns. Because they are in sort
ed order, it's easy | 264 // Get the files in the baseline and test patterns. Because they are in sort
ed order, it's easy |
| 268 // to find corresponding images by matching entry indices. | 265 // to find corresponding images by matching entry indices. |
| 269 | 266 |
| 270 SkTArray<SkString> baselineEntries; | 267 SkTArray<SkString> baselineEntries; |
| 271 if (!glob_files(baselinePattern, &baselineEntries)) { | 268 if (!glob_files(baselinePattern, &baselineEntries)) { |
| 272 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); | 269 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); |
| 273 return; | 270 return; |
| 274 } | 271 } |
| 275 | 272 |
| 276 SkTArray<SkString> testEntries; | 273 SkTArray<SkString> testEntries; |
| 277 if (!glob_files(testPattern, &testEntries)) { | 274 if (!glob_files(testPattern, &testEntries)) { |
| 278 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); | 275 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); |
| 279 return; | 276 return; |
| 280 } | 277 } |
| 281 | 278 |
| 282 if (baselineEntries.count() != testEntries.count()) { | 279 if (baselineEntries.count() != testEntries.count()) { |
| 283 SkDebugf("Baseline and test patterns do not yield corresponding number o
f files\n"); | 280 SkDebugf("Baseline and test patterns do not yield corresponding number o
f files\n"); |
| 284 return; | 281 return; |
| 285 } | 282 } |
| 286 | 283 |
| 287 SkThreadPool threadPool(fThreadCount); | 284 SkTaskGroup tg; |
| 288 SkTArray<SkThreadedDiff> runnableDiffs; | 285 SkTArray<SkThreadedDiff> runnableDiffs; |
| 289 runnableDiffs.reset(baselineEntries.count()); | 286 runnableDiffs.reset(baselineEntries.count()); |
| 290 | 287 |
| 291 for (int x = 0; x < baselineEntries.count(); x++) { | 288 for (int x = 0; x < baselineEntries.count(); x++) { |
| 292 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]); | 289 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]); |
| 293 threadPool.add(&runnableDiffs[x]); | 290 tg.add(&runnableDiffs[x]); |
| 294 } | 291 } |
| 295 | |
| 296 threadPool.wait(); | |
| 297 } | 292 } |
| 298 | 293 |
| 299 void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { | 294 void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { |
| 300 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_
IterStart); | 295 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_
IterStart); |
| 301 DiffRecord* currentRecord = iter.get(); | 296 DiffRecord* currentRecord = iter.get(); |
| 302 | 297 |
| 303 if (useJSONP) { | 298 if (useJSONP) { |
| 304 stream.writeText("var SkPDiffRecords = {\n"); | 299 stream.writeText("var SkPDiffRecords = {\n"); |
| 305 } else { | 300 } else { |
| 306 stream.writeText("{\n"); | 301 stream.writeText("{\n"); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 for (int i = 0; i < cntColumns; i++) { | 451 for (int i = 0; i < cntColumns; i++) { |
| 457 SkString str; | 452 SkString str; |
| 458 str.printf(", %f", values[i]); | 453 str.printf(", %f", values[i]); |
| 459 stream.writeText(str.c_str()); | 454 stream.writeText(str.c_str()); |
| 460 } | 455 } |
| 461 stream.writeText("\n"); | 456 stream.writeText("\n"); |
| 462 | 457 |
| 463 currentRecord = iter2.next(); | 458 currentRecord = iter2.next(); |
| 464 } | 459 } |
| 465 } | 460 } |
| OLD | NEW |