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 * "baselinePath": "queue.png", |
mtklein
2013/11/08 15:06:13
maybe add a commonName to the example?
djsollen
2013/11/12 16:40:43
Done.
| |
82 * "testPath": "queue.png", | 90 * "testPath": "queue.png", |
83 * "diffs": [ | 91 * "diffs": [ |
84 * { | 92 * { |
85 * "differName": "different_pixels", | 93 * "differName": "different_pixels", |
86 * "result": 1, | 94 * "result": 1, |
87 * "pointsOfInterest": [ | |
88 * [285,279], | |
89 * ] | |
90 * } | 95 * } |
91 * ] | 96 * ] |
92 * } | 97 * } |
93 * ] | 98 * ] |
94 * } | 99 * } |
95 * | 100 * |
96 * @param stream The stream to output the diff to | 101 * @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. | 102 * @param useJSONP True to adding padding to the JSON output to make it cros s-site requestable. |
98 */ | 103 */ |
99 void outputRecords(SkWStream& stream, bool useJSONP); | 104 void outputRecords(SkWStream& stream, bool useJSONP); |
100 | 105 |
101 /** | 106 /** |
102 * Output the records score in csv format. | 107 * Output the records score in csv format. |
103 */ | 108 */ |
104 void outputCsv(SkWStream& stream); | 109 void outputCsv(SkWStream& stream); |
105 | 110 |
106 | 111 |
107 private: | 112 private: |
108 struct DiffData { | 113 struct DiffData { |
109 const char* fDiffName; | 114 const char* fDiffName; |
110 double fResult; | 115 SkImageDiffer::Result fResult; |
111 SkTDArray<SkIPoint> fPointsOfInterest; | |
112 }; | 116 }; |
113 | 117 |
114 struct DiffRecord { | 118 struct DiffRecord { |
115 SkString fCommonName; | 119 SkString fCommonName; |
116 SkString fDifferencePath; | 120 SkString fDifferencePath; |
117 SkString fBaselinePath; | 121 SkString fBaselinePath; |
118 SkString fTestPath; | 122 SkString fTestPath; |
119 SkTArray<DiffData> fDiffs; | 123 SkTArray<DiffData> fDiffs; |
120 DiffRecord* fNext; | |
121 }; | 124 }; |
122 | 125 |
126 // This is needed to work around a bug in the multithreaded case where the | |
127 // image decoders are crashing when large numbers of threads are invoking | |
128 // the decoder at the same time. | |
129 // see https://code.google.com/p/skia/issues/detail?id=1803 | |
130 SkMutex fImageMutex; | |
131 | |
132 // Used to protect access to fRecords and ensure only one thread is | |
133 // adding new entries at a time. | |
134 SkMutex fRecordMutex; | |
135 | |
123 // We use linked list for the records so that their pointers remain stable. A resizable array | 136 // 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 | 137 // might change its pointers, which would make it harder for async diffs to record their |
125 // results. | 138 // results. |
126 DiffRecord * fRecords; | 139 SkTLList<DiffRecord> fRecords; |
127 | 140 |
128 SkImageDiffer** fDiffers; | 141 SkImageDiffer** fDiffers; |
129 int fDifferCount; | 142 int fDifferCount; |
130 int fThreadCount; | 143 int fThreadCount; |
131 | 144 |
132 SkString fDifferenceDir; | 145 SkString fDifferenceDir; |
133 }; | 146 }; |
134 | 147 |
135 #endif | 148 #endif |
OLD | NEW |