blob: 42d20de19da7b831dd66c16bca4a0535caf6417a [file] [log] [blame]
zachr@google.com945708a2013-07-02 19:55:32 +00001/*
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.comcbbf1ca2013-10-16 18:36:49 +000011#include "SkRunnable.h"
epoger54f1ad82014-07-02 07:43:04 -070012#include "SkSize.h"
zachr@google.com945708a2013-07-02 19:55:32 +000013#include "SkStream.h"
edisonn@google.comc93c8ac2013-07-22 15:24:26 +000014#include "SkTDict.h"
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +000015#include "SkThreadPool.h"
zachr@google.com945708a2013-07-02 19:55:32 +000016
stephana21b342d2014-08-13 10:36:06 -070017// from the tools directory for replace_char(...)
18#include "picture_utils.h"
19
zachr@google.com945708a2013-07-02 19:55:32 +000020#include "SkDiffContext.h"
epoger54f1ad82014-07-02 07:43:04 -070021#include "SkImageDiffer.h"
zachr@google.com945708a2013-07-02 19:55:32 +000022#include "skpdiff_util.h"
23
24SkDiffContext::SkDiffContext() {
zachr@google.com945708a2013-07-02 19:55:32 +000025 fDiffers = NULL;
26 fDifferCount = 0;
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +000027 fThreadCount = SkThreadPool::kThreadPerCore;
zachr@google.com945708a2013-07-02 19:55:32 +000028}
29
30SkDiffContext::~SkDiffContext() {
zachr@google.com945708a2013-07-02 19:55:32 +000031 if (NULL != fDiffers) {
32 SkDELETE_ARRAY(fDiffers);
33 }
34}
35
epoger54f1ad82014-07-02 07:43:04 -070036void SkDiffContext::setAlphaMaskDir(const SkString& path) {
djsollen@google.com513a7bf2013-11-07 19:24:06 +000037 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
epoger54f1ad82014-07-02 07:43:04 -070038 fAlphaMaskDir = path;
39 }
40}
41
42void SkDiffContext::setRgbDiffDir(const SkString& path) {
43 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
44 fRgbDiffDir = path;
45 }
46}
47
48void SkDiffContext::setWhiteDiffDir(const SkString& path) {
49 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
50 fWhiteDiffDir = path;
djsollen@google.com513a7bf2013-11-07 19:24:06 +000051 }
52}
53
stephana21b342d2014-08-13 10:36:06 -070054void SkDiffContext::setLongNames(const bool useLongNames) {
55 longNames = useLongNames;
56}
57
zachr@google.com945708a2013-07-02 19:55:32 +000058void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) {
59 // Delete whatever the last array of differs was
60 if (NULL != fDiffers) {
61 SkDELETE_ARRAY(fDiffers);
62 fDiffers = NULL;
63 fDifferCount = 0;
64 }
65
66 // Copy over the new differs
67 fDifferCount = differs.count();
68 fDiffers = SkNEW_ARRAY(SkImageDiffer*, fDifferCount);
69 differs.copy(fDiffers);
70}
71
djsollen@google.com513a7bf2013-11-07 19:24:06 +000072static SkString get_common_prefix(const SkString& a, const SkString& b) {
73 const size_t maxPrefixLength = SkTMin(a.size(), b.size());
74 SkASSERT(maxPrefixLength > 0);
75 for (size_t x = 0; x < maxPrefixLength; ++x) {
76 if (a[x] != b[x]) {
77 SkString result;
78 result.set(a.c_str(), x);
79 return result;
80 }
81 }
82 if (a.size() > b.size()) {
83 return b;
84 } else {
85 return a;
86 }
87}
88
stephana21b342d2014-08-13 10:36:06 -070089static SkString get_combined_name(const SkString& a, const SkString& b) {
90 // Note (stephana): We must keep this function in sync with
91 // getImageDiffRelativeUrl() in static/loader.js (under rebaseline_server).
92 SkString result = a;
93 result.append("-vs-");
94 result.append(b);
95 sk_tools::replace_char(&result, '.', '_');
96 return result;
97}
98
zachr@google.com945708a2013-07-02 19:55:32 +000099void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) {
100 // Load the images at the paths
101 SkBitmap baselineBitmap;
102 SkBitmap testBitmap;
103 if (!SkImageDecoder::DecodeFile(baselinePath, &baselineBitmap)) {
104 SkDebugf("Failed to load bitmap \"%s\"\n", baselinePath);
105 return;
106 }
107 if (!SkImageDecoder::DecodeFile(testPath, &testBitmap)) {
108 SkDebugf("Failed to load bitmap \"%s\"\n", testPath);
109 return;
110 }
111
112 // Setup a record for this diff
djsollen@google.comefc51b72013-11-12 18:29:17 +0000113 fRecordMutex.acquire();
114 DiffRecord* newRecord = fRecords.addToHead(DiffRecord());
115 fRecordMutex.release();
zachr@google.com945708a2013-07-02 19:55:32 +0000116
djsollen@google.com513a7bf2013-11-07 19:24:06 +0000117 // compute the common name
tfarinaa8e2e152014-07-28 19:26:58 -0700118 SkString baseName = SkOSPath::Basename(baselinePath);
119 SkString testName = SkOSPath::Basename(testPath);
stephana21b342d2014-08-13 10:36:06 -0700120
121 if (longNames) {
122 newRecord->fCommonName = get_combined_name(baseName, testName);
123 } else {
124 newRecord->fCommonName = get_common_prefix(baseName, testName);
125 }
126 newRecord->fCommonName.append(".png");
djsollen@google.com513a7bf2013-11-07 19:24:06 +0000127
djsollen@google.comefc51b72013-11-12 18:29:17 +0000128 newRecord->fBaselinePath = baselinePath;
129 newRecord->fTestPath = testPath;
epoger54f1ad82014-07-02 07:43:04 -0700130 newRecord->fSize = SkISize::Make(baselineBitmap.width(), baselineBitmap.height());
djsollen@google.comefc51b72013-11-12 18:29:17 +0000131
epoger54f1ad82014-07-02 07:43:04 -0700132 // only generate diff images if we have a place to store them
133 SkImageDiffer::BitmapsToCreate bitmapsToCreate;
134 bitmapsToCreate.alphaMask = !fAlphaMaskDir.isEmpty();
135 bitmapsToCreate.rgbDiff = !fRgbDiffDir.isEmpty();
136 bitmapsToCreate.whiteDiff = !fWhiteDiffDir.isEmpty();
djsollen@google.com513a7bf2013-11-07 19:24:06 +0000137
zachr@google.com945708a2013-07-02 19:55:32 +0000138 // Perform each diff
139 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) {
140 SkImageDiffer* differ = fDiffers[differIndex];
djsollen@google.comefc51b72013-11-12 18:29:17 +0000141
142 // Copy the results into data for this record
143 DiffData& diffData = newRecord->fDiffs.push_back();
144 diffData.fDiffName = differ->getName();
145
epoger54f1ad82014-07-02 07:43:04 -0700146 if (!differ->diff(&baselineBitmap, &testBitmap, bitmapsToCreate, &diffData.fResult)) {
147 // if the diff failed, record -1 as the result
148 // TODO(djsollen): Record more detailed information about exactly what failed.
149 // (Image dimension mismatch? etc.) See http://skbug.com/2710 ('make skpdiff
150 // report more detail when it fails to compare two images')
djsollen@google.com27d7ede2014-02-11 16:29:39 +0000151 diffData.fResult.result = -1;
djsollen@google.comefc51b72013-11-12 18:29:17 +0000152 continue;
djsollen@google.com513a7bf2013-11-07 19:24:06 +0000153 }
zachr@google.com945708a2013-07-02 19:55:32 +0000154
epoger54f1ad82014-07-02 07:43:04 -0700155 if (bitmapsToCreate.alphaMask
djsollen@google.comefc51b72013-11-12 18:29:17 +0000156 && SkImageDiffer::RESULT_CORRECT != diffData.fResult.result
157 && !diffData.fResult.poiAlphaMask.empty()
158 && !newRecord->fCommonName.isEmpty()) {
zachr@google.com945708a2013-07-02 19:55:32 +0000159
tfarinaa8e2e152014-07-28 19:26:58 -0700160 newRecord->fAlphaMaskPath = SkOSPath::Join(fAlphaMaskDir.c_str(),
161 newRecord->fCommonName.c_str());
zachr@google.com945708a2013-07-02 19:55:32 +0000162
djsollen@google.comefc51b72013-11-12 18:29:17 +0000163 // compute the image diff and output it
164 SkBitmap copy;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000165 diffData.fResult.poiAlphaMask.copyTo(&copy, kN32_SkColorType);
epoger54f1ad82014-07-02 07:43:04 -0700166 SkImageEncoder::EncodeFile(newRecord->fAlphaMaskPath.c_str(), copy,
djsollen@google.comefc51b72013-11-12 18:29:17 +0000167 SkImageEncoder::kPNG_Type, 100);
zachr@google.com945708a2013-07-02 19:55:32 +0000168
djsollen@google.comefc51b72013-11-12 18:29:17 +0000169 // cleanup the existing bitmap to free up resources;
170 diffData.fResult.poiAlphaMask.reset();
djsollen@google.com513a7bf2013-11-07 19:24:06 +0000171
epoger54f1ad82014-07-02 07:43:04 -0700172 bitmapsToCreate.alphaMask = false;
173 }
174
175 if (bitmapsToCreate.rgbDiff
176 && SkImageDiffer::RESULT_CORRECT != diffData.fResult.result
177 && !diffData.fResult.rgbDiffBitmap.empty()
178 && !newRecord->fCommonName.isEmpty()) {
179 // TODO(djsollen): Rather than taking the max r/g/b diffs that come back from
180 // a particular differ and storing them as toplevel fields within
181 // newRecord, we should extend outputRecords() to report optional
182 // fields for each differ (not just "result" and "pointsOfInterest").
183 // See http://skbug.com/2712 ('allow skpdiff to report different sets
184 // of result fields for different comparison algorithms')
185 newRecord->fMaxRedDiff = diffData.fResult.maxRedDiff;
186 newRecord->fMaxGreenDiff = diffData.fResult.maxGreenDiff;
187 newRecord->fMaxBlueDiff = diffData.fResult.maxBlueDiff;
188
tfarinaa8e2e152014-07-28 19:26:58 -0700189 newRecord->fRgbDiffPath = SkOSPath::Join(fRgbDiffDir.c_str(),
190 newRecord->fCommonName.c_str());
epoger54f1ad82014-07-02 07:43:04 -0700191 SkImageEncoder::EncodeFile(newRecord->fRgbDiffPath.c_str(),
192 diffData.fResult.rgbDiffBitmap,
193 SkImageEncoder::kPNG_Type, 100);
194 diffData.fResult.rgbDiffBitmap.reset();
195 bitmapsToCreate.rgbDiff = false;
196 }
197
198 if (bitmapsToCreate.whiteDiff
199 && SkImageDiffer::RESULT_CORRECT != diffData.fResult.result
200 && !diffData.fResult.whiteDiffBitmap.empty()
201 && !newRecord->fCommonName.isEmpty()) {
tfarinaa8e2e152014-07-28 19:26:58 -0700202 newRecord->fWhiteDiffPath = SkOSPath::Join(fWhiteDiffDir.c_str(),
203 newRecord->fCommonName.c_str());
epoger54f1ad82014-07-02 07:43:04 -0700204 SkImageEncoder::EncodeFile(newRecord->fWhiteDiffPath.c_str(),
205 diffData.fResult.whiteDiffBitmap,
206 SkImageEncoder::kPNG_Type, 100);
207 diffData.fResult.whiteDiffBitmap.reset();
208 bitmapsToCreate.whiteDiff = false;
zachr@google.com945708a2013-07-02 19:55:32 +0000209 }
210 }
211}
212
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000213class SkThreadedDiff : public SkRunnable {
214public:
215 SkThreadedDiff() : fDiffContext(NULL) { }
216
217 void setup(SkDiffContext* diffContext, const SkString& baselinePath, const SkString& testPath) {
218 fDiffContext = diffContext;
219 fBaselinePath = baselinePath;
220 fTestPath = testPath;
221 }
222
223 virtual void run() SK_OVERRIDE {
224 fDiffContext->addDiff(fBaselinePath.c_str(), fTestPath.c_str());
225 }
226
227private:
228 SkDiffContext* fDiffContext;
229 SkString fBaselinePath;
230 SkString fTestPath;
231};
zachr@google.com945708a2013-07-02 19:55:32 +0000232
233void SkDiffContext::diffDirectories(const char baselinePath[], const char testPath[]) {
234 // Get the files in the baseline, we will then look for those inside the test path
235 SkTArray<SkString> baselineEntries;
236 if (!get_directory(baselinePath, &baselineEntries)) {
237 SkDebugf("Unable to open path \"%s\"\n", baselinePath);
238 return;
239 }
240
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000241 SkThreadPool threadPool(fThreadCount);
242 SkTArray<SkThreadedDiff> runnableDiffs;
243 runnableDiffs.reset(baselineEntries.count());
244
245 for (int x = 0; x < baselineEntries.count(); x++) {
246 const char* baseFilename = baselineEntries[x].c_str();
zachr@google.com945708a2013-07-02 19:55:32 +0000247
248 // Find the real location of each file to compare
tfarinaa8e2e152014-07-28 19:26:58 -0700249 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename);
250 SkString testFile = SkOSPath::Join(testPath, baseFilename);
zachr@google.com945708a2013-07-02 19:55:32 +0000251
252 // Check that the test file exists and is a file
253 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) {
254 // Queue up the comparison with the differ
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000255 runnableDiffs[x].setup(this, baselineFile, testFile);
256 threadPool.add(&runnableDiffs[x]);
zachr@google.com945708a2013-07-02 19:55:32 +0000257 } else {
258 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", baselineFile.c_str());
259 }
260 }
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000261
262 threadPool.wait();
zachr@google.com945708a2013-07-02 19:55:32 +0000263}
264
265
266void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPattern[]) {
267 // Get the files in the baseline and test patterns. Because they are in sorted order, it's easy
268 // to find corresponding images by matching entry indices.
269
270 SkTArray<SkString> baselineEntries;
271 if (!glob_files(baselinePattern, &baselineEntries)) {
272 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern);
273 return;
274 }
275
276 SkTArray<SkString> testEntries;
277 if (!glob_files(testPattern, &testEntries)) {
278 SkDebugf("Unable to get pattern \"%s\"\n", testPattern);
279 return;
280 }
281
282 if (baselineEntries.count() != testEntries.count()) {
283 SkDebugf("Baseline and test patterns do not yield corresponding number of files\n");
284 return;
285 }
286
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000287 SkThreadPool threadPool(fThreadCount);
288 SkTArray<SkThreadedDiff> runnableDiffs;
289 runnableDiffs.reset(baselineEntries.count());
zachr@google.com945708a2013-07-02 19:55:32 +0000290
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000291 for (int x = 0; x < baselineEntries.count(); x++) {
292 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]);
293 threadPool.add(&runnableDiffs[x]);
zachr@google.com945708a2013-07-02 19:55:32 +0000294 }
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000295
296 threadPool.wait();
zachr@google.com945708a2013-07-02 19:55:32 +0000297}
298
zachr@google.coma95959c2013-07-08 15:04:45 +0000299void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) {
djsollen@google.comefc51b72013-11-12 18:29:17 +0000300 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_IterStart);
301 DiffRecord* currentRecord = iter.get();
302
zachr@google.coma95959c2013-07-08 15:04:45 +0000303 if (useJSONP) {
304 stream.writeText("var SkPDiffRecords = {\n");
zachr@google.com55173f22013-07-25 17:22:58 +0000305 } else {
zachr@google.coma95959c2013-07-08 15:04:45 +0000306 stream.writeText("{\n");
307 }
epoger54f1ad82014-07-02 07:43:04 -0700308
309 // TODO(djsollen): Would it be better to use the jsoncpp library to write out the JSON?
310 // This manual approach is probably more efficient, but it sure is ugly.
311 // See http://skbug.com/2713 ('make skpdiff use jsoncpp library to write out
312 // JSON output, instead of manual writeText() calls?')
zachr@google.com945708a2013-07-02 19:55:32 +0000313 stream.writeText(" \"records\": [\n");
314 while (NULL != currentRecord) {
315 stream.writeText(" {\n");
316
zachr@google.coma479aa12013-08-02 15:54:30 +0000317 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselinePath);
318 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath);
319
djsollen@google.com1e391b52013-10-16 15:00:11 +0000320 stream.writeText(" \"commonName\": \"");
djsollen@google.com513a7bf2013-11-07 19:24:06 +0000321 stream.writeText(currentRecord->fCommonName.c_str());
djsollen@google.com1e391b52013-10-16 15:00:11 +0000322 stream.writeText("\",\n");
323
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000324 stream.writeText(" \"differencePath\": \"");
epoger54f1ad82014-07-02 07:43:04 -0700325 stream.writeText(get_absolute_path(currentRecord->fAlphaMaskPath).c_str());
326 stream.writeText("\",\n");
327
328 stream.writeText(" \"rgbDiffPath\": \"");
329 stream.writeText(get_absolute_path(currentRecord->fRgbDiffPath).c_str());
330 stream.writeText("\",\n");
331
332 stream.writeText(" \"whiteDiffPath\": \"");
333 stream.writeText(get_absolute_path(currentRecord->fWhiteDiffPath).c_str());
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000334 stream.writeText("\",\n");
335
zachr@google.com945708a2013-07-02 19:55:32 +0000336 stream.writeText(" \"baselinePath\": \"");
zachr@google.coma479aa12013-08-02 15:54:30 +0000337 stream.writeText(baselineAbsPath.c_str());
zachr@google.com945708a2013-07-02 19:55:32 +0000338 stream.writeText("\",\n");
339
340 stream.writeText(" \"testPath\": \"");
zachr@google.coma479aa12013-08-02 15:54:30 +0000341 stream.writeText(testAbsPath.c_str());
zachr@google.com945708a2013-07-02 19:55:32 +0000342 stream.writeText("\",\n");
343
epoger54f1ad82014-07-02 07:43:04 -0700344 stream.writeText(" \"width\": ");
345 stream.writeDecAsText(currentRecord->fSize.width());
346 stream.writeText(",\n");
347 stream.writeText(" \"height\": ");
348 stream.writeDecAsText(currentRecord->fSize.height());
349 stream.writeText(",\n");
350
351 stream.writeText(" \"maxRedDiff\": ");
352 stream.writeDecAsText(currentRecord->fMaxRedDiff);
353 stream.writeText(",\n");
354 stream.writeText(" \"maxGreenDiff\": ");
355 stream.writeDecAsText(currentRecord->fMaxGreenDiff);
356 stream.writeText(",\n");
357 stream.writeText(" \"maxBlueDiff\": ");
358 stream.writeDecAsText(currentRecord->fMaxBlueDiff);
359 stream.writeText(",\n");
360
zachr@google.com945708a2013-07-02 19:55:32 +0000361 stream.writeText(" \"diffs\": [\n");
362 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) {
363 DiffData& data = currentRecord->fDiffs[diffIndex];
364 stream.writeText(" {\n");
365
366 stream.writeText(" \"differName\": \"");
367 stream.writeText(data.fDiffName);
368 stream.writeText("\",\n");
369
370 stream.writeText(" \"result\": ");
djsollen@google.comefc51b72013-11-12 18:29:17 +0000371 stream.writeScalarAsText((SkScalar)data.fResult.result);
zachr@google.com945708a2013-07-02 19:55:32 +0000372 stream.writeText(",\n");
373
djsollen@google.comefc51b72013-11-12 18:29:17 +0000374 stream.writeText(" \"pointsOfInterest\": ");
375 stream.writeDecAsText(data.fResult.poiCount);
376 stream.writeText("\n");
zachr@google.com945708a2013-07-02 19:55:32 +0000377
zachr@google.com945708a2013-07-02 19:55:32 +0000378 stream.writeText(" }");
379
380 // JSON does not allow trailing commas
zachr@google.com55173f22013-07-25 17:22:58 +0000381 if (diffIndex + 1 < currentRecord->fDiffs.count()) {
zachr@google.com945708a2013-07-02 19:55:32 +0000382 stream.writeText(",");
383 }
384 stream.writeText(" \n");
385 }
386 stream.writeText(" ]\n");
387
388 stream.writeText(" }");
389
djsollen@google.comefc51b72013-11-12 18:29:17 +0000390 currentRecord = iter.next();
391
zachr@google.com945708a2013-07-02 19:55:32 +0000392 // JSON does not allow trailing commas
djsollen@google.comefc51b72013-11-12 18:29:17 +0000393 if (NULL != currentRecord) {
zachr@google.com945708a2013-07-02 19:55:32 +0000394 stream.writeText(",");
395 }
396 stream.writeText("\n");
zachr@google.com945708a2013-07-02 19:55:32 +0000397 }
398 stream.writeText(" ]\n");
zachr@google.coma95959c2013-07-08 15:04:45 +0000399 if (useJSONP) {
400 stream.writeText("};\n");
zachr@google.com55173f22013-07-25 17:22:58 +0000401 } else {
zachr@google.coma95959c2013-07-08 15:04:45 +0000402 stream.writeText("}\n");
403 }
zachr@google.com945708a2013-07-02 19:55:32 +0000404}
edisonn@google.comc93c8ac2013-07-22 15:24:26 +0000405
406void SkDiffContext::outputCsv(SkWStream& stream) {
407 SkTDict<int> columns(2);
408 int cntColumns = 0;
409
410 stream.writeText("key");
411
djsollen@google.comefc51b72013-11-12 18:29:17 +0000412 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_IterStart);
413 DiffRecord* currentRecord = iter.get();
edisonn@google.comc93c8ac2013-07-22 15:24:26 +0000414
415 // Write CSV header and create a dictionary of all columns.
416 while (NULL != currentRecord) {
417 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) {
418 DiffData& data = currentRecord->fDiffs[diffIndex];
419 if (!columns.find(data.fDiffName)) {
420 columns.set(data.fDiffName, cntColumns);
421 stream.writeText(", ");
422 stream.writeText(data.fDiffName);
423 cntColumns++;
424 }
425 }
djsollen@google.comefc51b72013-11-12 18:29:17 +0000426 currentRecord = iter.next();
edisonn@google.comc93c8ac2013-07-22 15:24:26 +0000427 }
428 stream.writeText("\n");
429
430 double values[100];
431 SkASSERT(cntColumns < 100); // Make the array larger, if we ever have so many diff types.
432
djsollen@google.comefc51b72013-11-12 18:29:17 +0000433 SkTLList<DiffRecord>::Iter iter2(fRecords, SkTLList<DiffRecord>::Iter::kHead_IterStart);
434 currentRecord = iter2.get();
edisonn@google.comc93c8ac2013-07-22 15:24:26 +0000435 while (NULL != currentRecord) {
436 for (int i = 0; i < cntColumns; i++) {
437 values[i] = -1;
438 }
439
440 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) {
441 DiffData& data = currentRecord->fDiffs[diffIndex];
442 int index = -1;
443 SkAssertResult(columns.find(data.fDiffName, &index));
444 SkASSERT(index >= 0 && index < cntColumns);
djsollen@google.comefc51b72013-11-12 18:29:17 +0000445 values[index] = data.fResult.result;
edisonn@google.comc93c8ac2013-07-22 15:24:26 +0000446 }
447
448 const char* filename = currentRecord->fBaselinePath.c_str() +
449 strlen(currentRecord->fBaselinePath.c_str()) - 1;
450 while (filename > currentRecord->fBaselinePath.c_str() && *(filename - 1) != '/') {
451 filename--;
452 }
453
454 stream.writeText(filename);
455
456 for (int i = 0; i < cntColumns; i++) {
457 SkString str;
458 str.printf(", %f", values[i]);
459 stream.writeText(str.c_str());
460 }
461 stream.writeText("\n");
462
djsollen@google.comefc51b72013-11-12 18:29:17 +0000463 currentRecord = iter2.next();
edisonn@google.comc93c8ac2013-07-22 15:24:26 +0000464 }
465}