OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkDiffContext_DEFINED | 8 #ifndef SkDiffContext_DEFINED |
9 #define SkDiffContext_DEFINED | 9 #define SkDiffContext_DEFINED |
10 | 10 |
| 11 #include "SkImageDiffer.h" |
11 #include "SkString.h" | 12 #include "SkString.h" |
12 #include "SkTArray.h" | 13 #include "SkTArray.h" |
13 #include "SkTDArray.h" | 14 #include "SkTDArray.h" |
| 15 #include "SkTLList.h" |
| 16 #include "SkThread.h" |
14 | 17 |
15 class SkWStream; | 18 class SkWStream; |
16 class SkImageDiffer; | |
17 | 19 |
18 /** | 20 /** |
19 * Collects records of diffs and outputs them as JSON. | 21 * Collects records of diffs and outputs them as JSON. |
20 */ | 22 */ |
21 class SkDiffContext { | 23 class SkDiffContext { |
22 public: | 24 public: |
23 SkDiffContext(); | 25 SkDiffContext(); |
24 ~SkDiffContext(); | 26 ~SkDiffContext(); |
25 | 27 |
26 void setThreadCount(int threadCount) { fThreadCount = threadCount; } | 28 void setThreadCount(int threadCount) { fThreadCount = threadCount; } |
(...skipping 30 matching lines...) Expand all Loading... |
57 * Compares the images at the given paths | 59 * Compares the images at the given paths |
58 * @param baselinePath The baseline file path | 60 * @param baselinePath The baseline file path |
59 * @param testPath The matching test file path | 61 * @param testPath The matching test file path |
60 */ | 62 */ |
61 void addDiff(const char* baselinePath, const char* testPath); | 63 void addDiff(const char* baselinePath, const char* testPath); |
62 | 64 |
63 /** | 65 /** |
64 * Output the records of each diff in JSON. | 66 * Output the records of each diff in JSON. |
65 * | 67 * |
66 * The format of the JSON document is one top level array named "records". | 68 * The format of the JSON document is one top level array named "records". |
67 * Each record in the array is an object with both a "baselinePath" and "tes
tPath" string field. | 69 * Each record in the array is an object with the following values: |
| 70 * "commonName" : string containing the common prefix of the baseline
Path |
| 71 * and testPath filenames |
| 72 * "baselinePath" : string containing the path to the baseline image |
| 73 * "testPath" : string containing the path to the test image |
| 74 * "differencePath" : (optional) string containing the path to an alpha |
| 75 * mask of the pixel difference between the baseline |
| 76 * and test images |
| 77 * |
68 * They also have an array named "diffs" with each element being one diff re
cord for the two | 78 * They also have an array named "diffs" with each element being one diff re
cord for the two |
69 * images indicated in the above field. | 79 * images indicated in the above field. |
70 * A diff record includes: | 80 * A diff record includes: |
71 * "differName" : string name of the diff metric used | 81 * "differName" : string name of the diff metric used |
72 * "result" : numerical result of the diff | 82 * "result" : numerical result of the diff |
73 * "pointsOfInterest" : an array of coordinates (stored as a 2-array of i
nts) of interesting | |
74 * points | |
75 * | 83 * |
76 * Here is an example: | 84 * Here is an example: |
77 * | 85 * |
78 * { | 86 * { |
79 * "records": [ | 87 * "records": [ |
80 * { | 88 * { |
81 * "baselinePath": "queue.png", | 89 * "commonName": "queue.png", |
82 * "testPath": "queue.png", | 90 * "baselinePath": "/a/queue.png", |
| 91 * "testPath": "/b/queue.png", |
83 * "diffs": [ | 92 * "diffs": [ |
84 * { | 93 * { |
85 * "differName": "different_pixels", | 94 * "differName": "different_pixels", |
86 * "result": 1, | 95 * "result": 1, |
87 * "pointsOfInterest": [ | |
88 * [285,279], | |
89 * ] | |
90 * } | 96 * } |
91 * ] | 97 * ] |
92 * } | 98 * } |
93 * ] | 99 * ] |
94 * } | 100 * } |
95 * | 101 * |
96 * @param stream The stream to output the diff to | 102 * @param stream The stream to output the diff to |
97 * @param useJSONP True to adding padding to the JSON output to make it cros
s-site requestable. | 103 * @param useJSONP True to adding padding to the JSON output to make it cros
s-site requestable. |
98 */ | 104 */ |
99 void outputRecords(SkWStream& stream, bool useJSONP); | 105 void outputRecords(SkWStream& stream, bool useJSONP); |
100 | 106 |
101 /** | 107 /** |
102 * Output the records score in csv format. | 108 * Output the records score in csv format. |
103 */ | 109 */ |
104 void outputCsv(SkWStream& stream); | 110 void outputCsv(SkWStream& stream); |
105 | 111 |
106 | 112 |
107 private: | 113 private: |
108 struct DiffData { | 114 struct DiffData { |
109 const char* fDiffName; | 115 const char* fDiffName; |
110 double fResult; | 116 SkImageDiffer::Result fResult; |
111 SkTDArray<SkIPoint> fPointsOfInterest; | |
112 }; | 117 }; |
113 | 118 |
114 struct DiffRecord { | 119 struct DiffRecord { |
115 SkString fCommonName; | 120 SkString fCommonName; |
116 SkString fDifferencePath; | 121 SkString fDifferencePath; |
117 SkString fBaselinePath; | 122 SkString fBaselinePath; |
118 SkString fTestPath; | 123 SkString fTestPath; |
119 SkTArray<DiffData> fDiffs; | 124 SkTArray<DiffData> fDiffs; |
120 DiffRecord* fNext; | |
121 }; | 125 }; |
122 | 126 |
| 127 // This is needed to work around a bug in the multithreaded case where the |
| 128 // image decoders are crashing when large numbers of threads are invoking |
| 129 // the decoder at the same time. |
| 130 // see https://code.google.com/p/skia/issues/detail?id=1803 |
| 131 SkMutex fImageMutex; |
| 132 |
| 133 // Used to protect access to fRecords and ensure only one thread is |
| 134 // adding new entries at a time. |
| 135 SkMutex fRecordMutex; |
| 136 |
123 // We use linked list for the records so that their pointers remain stable.
A resizable array | 137 // We use linked list for the records so that their pointers remain stable.
A resizable array |
124 // might change its pointers, which would make it harder for async diffs to
record their | 138 // might change its pointers, which would make it harder for async diffs to
record their |
125 // results. | 139 // results. |
126 DiffRecord * fRecords; | 140 SkTLList<DiffRecord> fRecords; |
127 | 141 |
128 SkImageDiffer** fDiffers; | 142 SkImageDiffer** fDiffers; |
129 int fDifferCount; | 143 int fDifferCount; |
130 int fThreadCount; | 144 int fThreadCount; |
131 | 145 |
132 SkString fDifferenceDir; | 146 SkString fDifferenceDir; |
133 }; | 147 }; |
134 | 148 |
135 #endif | 149 #endif |
OLD | NEW |