blob: 20193b38514248e77ba6e7a34752cf299a413d14 [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#ifndef SkDiffContext_DEFINED
9#define SkDiffContext_DEFINED
10
11#include "SkString.h"
12#include "SkTArray.h"
13#include "SkTDArray.h"
14
15class SkWStream;
16class SkImageDiffer;
17
18/**
19 * Collects records of diffs and outputs them as JSON.
20 */
21class SkDiffContext {
22public:
23 SkDiffContext();
24 ~SkDiffContext();
25
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +000026 void setThreadCount(int threadCount) { fThreadCount = threadCount; }
27
zachr@google.com945708a2013-07-02 19:55:32 +000028 /**
29 * Sets the differs to be used in each diff. Already started diffs will not retroactively use
30 * these.
31 * @param differs An array of differs to use. The array is copied, but not the differs
32 * themselves.
33 */
34 void setDiffers(const SkTDArray<SkImageDiffer*>& differs);
35
36 /**
37 * Compares two directories of images with the given differ
38 * @param baselinePath The baseline directory's path
39 * @param testPath The test directory's path
40 */
41 void diffDirectories(const char baselinePath[], const char testPath[]);
42
43 /**
44 * Compares two sets of images identified by glob style patterns with the given differ
45 * @param baselinePattern A pattern for baseline files
46 * @param testPattern A pattern for test files that matches each file of the baseline file
47 */
48 void diffPatterns(const char baselinePattern[], const char testPattern[]);
49
50 /**
51 * Compares the images at the given paths
52 * @param baselinePath The baseline file path
53 * @param testPath The matching test file path
54 */
55 void addDiff(const char* baselinePath, const char* testPath);
56
57 /**
58 * Output the records of each diff in JSON.
59 *
60 * The format of the JSON document is one top level array named "records".
61 * Each record in the array is an object with both a "baselinePath" and "testPath" string field.
62 * They also have an array named "diffs" with each element being one diff record for the two
63 * images indicated in the above field.
64 * A diff record includes:
65 * "differName" : string name of the diff metric used
66 * "result" : numerical result of the diff
67 * "pointsOfInterest" : an array of coordinates (stored as a 2-array of ints) of interesting
68 * points
69 *
70 * Here is an example:
71 *
72 * {
73 * "records": [
74 * {
75 * "baselinePath": "queue.png",
76 * "testPath": "queue.png",
77 * "diffs": [
78 * {
79 * "differName": "different_pixels",
80 * "result": 1,
81 * "pointsOfInterest": [
82 * [285,279],
83 * ]
84 * }
85 * ]
86 * }
87 * ]
88 * }
89 *
zachr@google.coma95959c2013-07-08 15:04:45 +000090 * @param stream The stream to output the diff to
91 * @param useJSONP True to adding padding to the JSON output to make it cross-site requestable.
zachr@google.com945708a2013-07-02 19:55:32 +000092 */
zachr@google.coma95959c2013-07-08 15:04:45 +000093 void outputRecords(SkWStream& stream, bool useJSONP);
zachr@google.com945708a2013-07-02 19:55:32 +000094
edisonn@google.comc93c8ac2013-07-22 15:24:26 +000095 /**
96 * Output the records score in csv format.
97 */
98 void outputCsv(SkWStream& stream);
99
100
zachr@google.com945708a2013-07-02 19:55:32 +0000101private:
102 struct DiffData {
103 const char* fDiffName;
104 double fResult;
105 SkTDArray<SkIPoint> fPointsOfInterest;
106 };
107
108 struct DiffRecord {
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000109 SkString fDifferencePath;
zachr@google.com945708a2013-07-02 19:55:32 +0000110 SkString fBaselinePath;
111 SkString fTestPath;
112 SkTArray<DiffData> fDiffs;
113 DiffRecord* fNext;
114 };
115
116 // We use linked list for the records so that their pointers remain stable. A resizable array
117 // might change its pointers, which would make it harder for async diffs to record their
118 // results.
119 DiffRecord * fRecords;
120
121 SkImageDiffer** fDiffers;
122 int fDifferCount;
djsollen@google.comcbbf1ca2013-10-16 18:36:49 +0000123 int fThreadCount;
zachr@google.com945708a2013-07-02 19:55:32 +0000124};
125
126#endif