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