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