zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkBitmap.h" |
| 9 | #include "SkImageDecoder.h" |
| 10 | #include "SkOSFile.h" |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 11 | #include "SkRunnable.h" |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 12 | #include "SkStream.h" |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 13 | #include "SkTDict.h" |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 14 | #include "SkThreadPool.h" |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 15 | |
| 16 | #include "SkDiffContext.h" |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 17 | #include "skpdiff_util.h" |
| 18 | |
| 19 | SkDiffContext::SkDiffContext() { |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 20 | fDiffers = NULL; |
| 21 | fDifferCount = 0; |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 22 | fThreadCount = SkThreadPool::kThreadPerCore; |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | SkDiffContext::~SkDiffContext() { |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 26 | if (NULL != fDiffers) { |
| 27 | SkDELETE_ARRAY(fDiffers); |
| 28 | } |
| 29 | } |
| 30 | |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 31 | void SkDiffContext::setDifferenceDir(const SkString& path) { |
| 32 | if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
| 33 | fDifferenceDir = path; |
| 34 | } |
| 35 | } |
| 36 | |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 37 | void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { |
| 38 | // Delete whatever the last array of differs was |
| 39 | if (NULL != fDiffers) { |
| 40 | SkDELETE_ARRAY(fDiffers); |
| 41 | fDiffers = NULL; |
| 42 | fDifferCount = 0; |
| 43 | } |
| 44 | |
| 45 | // Copy over the new differs |
| 46 | fDifferCount = differs.count(); |
| 47 | fDiffers = SkNEW_ARRAY(SkImageDiffer*, fDifferCount); |
| 48 | differs.copy(fDiffers); |
| 49 | } |
| 50 | |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 51 | static SkString get_common_prefix(const SkString& a, const SkString& b) { |
| 52 | const size_t maxPrefixLength = SkTMin(a.size(), b.size()); |
| 53 | SkASSERT(maxPrefixLength > 0); |
| 54 | for (size_t x = 0; x < maxPrefixLength; ++x) { |
| 55 | if (a[x] != b[x]) { |
| 56 | SkString result; |
| 57 | result.set(a.c_str(), x); |
| 58 | return result; |
| 59 | } |
| 60 | } |
| 61 | if (a.size() > b.size()) { |
| 62 | return b; |
| 63 | } else { |
| 64 | return a; |
| 65 | } |
| 66 | } |
| 67 | |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 68 | void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
| 69 | // Load the images at the paths |
| 70 | SkBitmap baselineBitmap; |
| 71 | SkBitmap testBitmap; |
| 72 | if (!SkImageDecoder::DecodeFile(baselinePath, &baselineBitmap)) { |
| 73 | SkDebugf("Failed to load bitmap \"%s\"\n", baselinePath); |
| 74 | return; |
| 75 | } |
| 76 | if (!SkImageDecoder::DecodeFile(testPath, &testBitmap)) { |
| 77 | SkDebugf("Failed to load bitmap \"%s\"\n", testPath); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | // Setup a record for this diff |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 82 | fRecordMutex.acquire(); |
| 83 | DiffRecord* newRecord = fRecords.addToHead(DiffRecord()); |
| 84 | fRecordMutex.release(); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 85 | |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 86 | // compute the common name |
| 87 | SkString baseName = SkOSPath::SkBasename(baselinePath); |
| 88 | SkString testName = SkOSPath::SkBasename(testPath); |
| 89 | newRecord->fCommonName = get_common_prefix(baseName, testName); |
| 90 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 91 | newRecord->fBaselinePath = baselinePath; |
| 92 | newRecord->fTestPath = testPath; |
| 93 | |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 94 | bool alphaMaskPending = false; |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 95 | |
| 96 | // only enable alpha masks if a difference dir has been provided |
| 97 | if (!fDifferenceDir.isEmpty()) { |
| 98 | alphaMaskPending = true; |
| 99 | } |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 100 | |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 101 | // Perform each diff |
| 102 | for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { |
| 103 | SkImageDiffer* differ = fDiffers[differIndex]; |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 104 | |
| 105 | // Copy the results into data for this record |
| 106 | DiffData& diffData = newRecord->fDiffs.push_back(); |
| 107 | diffData.fDiffName = differ->getName(); |
| 108 | |
| 109 | if (!differ->diff(&baselineBitmap, &testBitmap, alphaMaskPending, &diffData.fResult)) { |
djsollen@google.com | 60bce6c | 2014-02-11 16:22:58 +0000 | [diff] [blame] | 110 | // if the diff failed record -1 as the result |
djsollen@google.com | 27d7ede | 2014-02-11 16:29:39 +0000 | [diff] [blame^] | 111 | diffData.fResult.result = -1; |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 112 | continue; |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 113 | } |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 114 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 115 | if (alphaMaskPending |
| 116 | && SkImageDiffer::RESULT_CORRECT != diffData.fResult.result |
| 117 | && !diffData.fResult.poiAlphaMask.empty() |
| 118 | && !newRecord->fCommonName.isEmpty()) { |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 119 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 120 | newRecord->fDifferencePath = SkOSPath::SkPathJoin(fDifferenceDir.c_str(), |
| 121 | newRecord->fCommonName.c_str()); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 122 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 123 | // compute the image diff and output it |
| 124 | SkBitmap copy; |
| 125 | diffData.fResult.poiAlphaMask.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 126 | SkImageEncoder::EncodeFile(newRecord->fDifferencePath.c_str(), copy, |
| 127 | SkImageEncoder::kPNG_Type, 100); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 128 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 129 | // cleanup the existing bitmap to free up resources; |
| 130 | diffData.fResult.poiAlphaMask.reset(); |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 131 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 132 | alphaMaskPending = false; |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 137 | class SkThreadedDiff : public SkRunnable { |
| 138 | public: |
| 139 | SkThreadedDiff() : fDiffContext(NULL) { } |
| 140 | |
| 141 | void setup(SkDiffContext* diffContext, const SkString& baselinePath, const SkString& testPath) { |
| 142 | fDiffContext = diffContext; |
| 143 | fBaselinePath = baselinePath; |
| 144 | fTestPath = testPath; |
| 145 | } |
| 146 | |
| 147 | virtual void run() SK_OVERRIDE { |
| 148 | fDiffContext->addDiff(fBaselinePath.c_str(), fTestPath.c_str()); |
| 149 | } |
| 150 | |
| 151 | private: |
| 152 | SkDiffContext* fDiffContext; |
| 153 | SkString fBaselinePath; |
| 154 | SkString fTestPath; |
| 155 | }; |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 156 | |
| 157 | void SkDiffContext::diffDirectories(const char baselinePath[], const char testPath[]) { |
| 158 | // Get the files in the baseline, we will then look for those inside the test path |
| 159 | SkTArray<SkString> baselineEntries; |
| 160 | if (!get_directory(baselinePath, &baselineEntries)) { |
| 161 | SkDebugf("Unable to open path \"%s\"\n", baselinePath); |
| 162 | return; |
| 163 | } |
| 164 | |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 165 | SkThreadPool threadPool(fThreadCount); |
| 166 | SkTArray<SkThreadedDiff> runnableDiffs; |
| 167 | runnableDiffs.reset(baselineEntries.count()); |
| 168 | |
| 169 | for (int x = 0; x < baselineEntries.count(); x++) { |
| 170 | const char* baseFilename = baselineEntries[x].c_str(); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 171 | |
| 172 | // Find the real location of each file to compare |
| 173 | SkString baselineFile = SkOSPath::SkPathJoin(baselinePath, baseFilename); |
| 174 | SkString testFile = SkOSPath::SkPathJoin(testPath, baseFilename); |
| 175 | |
| 176 | // Check that the test file exists and is a file |
| 177 | if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { |
| 178 | // Queue up the comparison with the differ |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 179 | runnableDiffs[x].setup(this, baselineFile, testFile); |
| 180 | threadPool.add(&runnableDiffs[x]); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 181 | } else { |
| 182 | SkDebugf("Baseline file \"%s\" has no corresponding test file\n", baselineFile.c_str()); |
| 183 | } |
| 184 | } |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 185 | |
| 186 | threadPool.wait(); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | |
| 190 | void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPattern[]) { |
| 191 | // Get the files in the baseline and test patterns. Because they are in sorted order, it's easy |
| 192 | // to find corresponding images by matching entry indices. |
| 193 | |
| 194 | SkTArray<SkString> baselineEntries; |
| 195 | if (!glob_files(baselinePattern, &baselineEntries)) { |
| 196 | SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | SkTArray<SkString> testEntries; |
| 201 | if (!glob_files(testPattern, &testEntries)) { |
| 202 | SkDebugf("Unable to get pattern \"%s\"\n", testPattern); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | if (baselineEntries.count() != testEntries.count()) { |
| 207 | SkDebugf("Baseline and test patterns do not yield corresponding number of files\n"); |
| 208 | return; |
| 209 | } |
| 210 | |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 211 | SkThreadPool threadPool(fThreadCount); |
| 212 | SkTArray<SkThreadedDiff> runnableDiffs; |
| 213 | runnableDiffs.reset(baselineEntries.count()); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 214 | |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 215 | for (int x = 0; x < baselineEntries.count(); x++) { |
| 216 | runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]); |
| 217 | threadPool.add(&runnableDiffs[x]); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 218 | } |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 219 | |
| 220 | threadPool.wait(); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 221 | } |
| 222 | |
zachr@google.com | a95959c | 2013-07-08 15:04:45 +0000 | [diff] [blame] | 223 | void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 224 | SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_IterStart); |
| 225 | DiffRecord* currentRecord = iter.get(); |
| 226 | |
zachr@google.com | a95959c | 2013-07-08 15:04:45 +0000 | [diff] [blame] | 227 | if (useJSONP) { |
| 228 | stream.writeText("var SkPDiffRecords = {\n"); |
zachr@google.com | 55173f2 | 2013-07-25 17:22:58 +0000 | [diff] [blame] | 229 | } else { |
zachr@google.com | a95959c | 2013-07-08 15:04:45 +0000 | [diff] [blame] | 230 | stream.writeText("{\n"); |
| 231 | } |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 232 | stream.writeText(" \"records\": [\n"); |
| 233 | while (NULL != currentRecord) { |
| 234 | stream.writeText(" {\n"); |
| 235 | |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 236 | SkString differenceAbsPath = get_absolute_path(currentRecord->fDifferencePath); |
zachr@google.com | a479aa1 | 2013-08-02 15:54:30 +0000 | [diff] [blame] | 237 | SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselinePath); |
| 238 | SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); |
| 239 | |
djsollen@google.com | 1e391b5 | 2013-10-16 15:00:11 +0000 | [diff] [blame] | 240 | stream.writeText(" \"commonName\": \""); |
djsollen@google.com | 513a7bf | 2013-11-07 19:24:06 +0000 | [diff] [blame] | 241 | stream.writeText(currentRecord->fCommonName.c_str()); |
djsollen@google.com | 1e391b5 | 2013-10-16 15:00:11 +0000 | [diff] [blame] | 242 | stream.writeText("\",\n"); |
| 243 | |
djsollen@google.com | cbbf1ca | 2013-10-16 18:36:49 +0000 | [diff] [blame] | 244 | stream.writeText(" \"differencePath\": \""); |
| 245 | stream.writeText(differenceAbsPath.c_str()); |
| 246 | stream.writeText("\",\n"); |
| 247 | |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 248 | stream.writeText(" \"baselinePath\": \""); |
zachr@google.com | a479aa1 | 2013-08-02 15:54:30 +0000 | [diff] [blame] | 249 | stream.writeText(baselineAbsPath.c_str()); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 250 | stream.writeText("\",\n"); |
| 251 | |
| 252 | stream.writeText(" \"testPath\": \""); |
zachr@google.com | a479aa1 | 2013-08-02 15:54:30 +0000 | [diff] [blame] | 253 | stream.writeText(testAbsPath.c_str()); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 254 | stream.writeText("\",\n"); |
| 255 | |
| 256 | stream.writeText(" \"diffs\": [\n"); |
| 257 | for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) { |
| 258 | DiffData& data = currentRecord->fDiffs[diffIndex]; |
| 259 | stream.writeText(" {\n"); |
| 260 | |
| 261 | stream.writeText(" \"differName\": \""); |
| 262 | stream.writeText(data.fDiffName); |
| 263 | stream.writeText("\",\n"); |
| 264 | |
| 265 | stream.writeText(" \"result\": "); |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 266 | stream.writeScalarAsText((SkScalar)data.fResult.result); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 267 | stream.writeText(",\n"); |
| 268 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 269 | stream.writeText(" \"pointsOfInterest\": "); |
| 270 | stream.writeDecAsText(data.fResult.poiCount); |
| 271 | stream.writeText("\n"); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 272 | |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 273 | stream.writeText(" }"); |
| 274 | |
| 275 | // JSON does not allow trailing commas |
zachr@google.com | 55173f2 | 2013-07-25 17:22:58 +0000 | [diff] [blame] | 276 | if (diffIndex + 1 < currentRecord->fDiffs.count()) { |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 277 | stream.writeText(","); |
| 278 | } |
| 279 | stream.writeText(" \n"); |
| 280 | } |
| 281 | stream.writeText(" ]\n"); |
| 282 | |
| 283 | stream.writeText(" }"); |
| 284 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 285 | currentRecord = iter.next(); |
| 286 | |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 287 | // JSON does not allow trailing commas |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 288 | if (NULL != currentRecord) { |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 289 | stream.writeText(","); |
| 290 | } |
| 291 | stream.writeText("\n"); |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 292 | } |
| 293 | stream.writeText(" ]\n"); |
zachr@google.com | a95959c | 2013-07-08 15:04:45 +0000 | [diff] [blame] | 294 | if (useJSONP) { |
| 295 | stream.writeText("};\n"); |
zachr@google.com | 55173f2 | 2013-07-25 17:22:58 +0000 | [diff] [blame] | 296 | } else { |
zachr@google.com | a95959c | 2013-07-08 15:04:45 +0000 | [diff] [blame] | 297 | stream.writeText("}\n"); |
| 298 | } |
zachr@google.com | 945708a | 2013-07-02 19:55:32 +0000 | [diff] [blame] | 299 | } |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 300 | |
| 301 | void SkDiffContext::outputCsv(SkWStream& stream) { |
| 302 | SkTDict<int> columns(2); |
| 303 | int cntColumns = 0; |
| 304 | |
| 305 | stream.writeText("key"); |
| 306 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 307 | SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_IterStart); |
| 308 | DiffRecord* currentRecord = iter.get(); |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 309 | |
| 310 | // Write CSV header and create a dictionary of all columns. |
| 311 | while (NULL != currentRecord) { |
| 312 | for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) { |
| 313 | DiffData& data = currentRecord->fDiffs[diffIndex]; |
| 314 | if (!columns.find(data.fDiffName)) { |
| 315 | columns.set(data.fDiffName, cntColumns); |
| 316 | stream.writeText(", "); |
| 317 | stream.writeText(data.fDiffName); |
| 318 | cntColumns++; |
| 319 | } |
| 320 | } |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 321 | currentRecord = iter.next(); |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 322 | } |
| 323 | stream.writeText("\n"); |
| 324 | |
| 325 | double values[100]; |
| 326 | SkASSERT(cntColumns < 100); // Make the array larger, if we ever have so many diff types. |
| 327 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 328 | SkTLList<DiffRecord>::Iter iter2(fRecords, SkTLList<DiffRecord>::Iter::kHead_IterStart); |
| 329 | currentRecord = iter2.get(); |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 330 | while (NULL != currentRecord) { |
| 331 | for (int i = 0; i < cntColumns; i++) { |
| 332 | values[i] = -1; |
| 333 | } |
| 334 | |
| 335 | for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) { |
| 336 | DiffData& data = currentRecord->fDiffs[diffIndex]; |
| 337 | int index = -1; |
| 338 | SkAssertResult(columns.find(data.fDiffName, &index)); |
| 339 | SkASSERT(index >= 0 && index < cntColumns); |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 340 | values[index] = data.fResult.result; |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | const char* filename = currentRecord->fBaselinePath.c_str() + |
| 344 | strlen(currentRecord->fBaselinePath.c_str()) - 1; |
| 345 | while (filename > currentRecord->fBaselinePath.c_str() && *(filename - 1) != '/') { |
| 346 | filename--; |
| 347 | } |
| 348 | |
| 349 | stream.writeText(filename); |
| 350 | |
| 351 | for (int i = 0; i < cntColumns; i++) { |
| 352 | SkString str; |
| 353 | str.printf(", %f", values[i]); |
| 354 | stream.writeText(str.c_str()); |
| 355 | } |
| 356 | stream.writeText("\n"); |
| 357 | |
djsollen@google.com | efc51b7 | 2013-11-12 18:29:17 +0000 | [diff] [blame] | 358 | currentRecord = iter2.next(); |
edisonn@google.com | c93c8ac | 2013-07-22 15:24:26 +0000 | [diff] [blame] | 359 | } |
| 360 | } |