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 */ |
| 90 void outputRecords(SkWStream& stream); |
| 91 |
| 92 private: |
| 93 struct DiffData { |
| 94 const char* fDiffName; |
| 95 double fResult; |
| 96 SkTDArray<SkIPoint> fPointsOfInterest; |
| 97 }; |
| 98 |
| 99 struct DiffRecord { |
| 100 SkString fBaselinePath; |
| 101 SkString fTestPath; |
| 102 SkTArray<DiffData> fDiffs; |
| 103 DiffRecord* fNext; |
| 104 }; |
| 105 |
| 106 // We use linked list for the records so that their pointers remain stable.
A resizable array |
| 107 // might change its pointers, which would make it harder for async diffs to
record their |
| 108 // results. |
| 109 DiffRecord * fRecords; |
| 110 |
| 111 SkImageDiffer** fDiffers; |
| 112 int fDifferCount; |
| 113 }; |
| 114 |
| 115 #endif |
OLD | NEW |