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 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
11 #include "SkRunnable.h" | 11 #include "SkRunnable.h" |
12 #include "SkSize.h" | 12 #include "SkSize.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTDict.h" | 14 #include "SkTDict.h" |
15 #include "SkThreadPool.h" | 15 #include "SkThreadPool.h" |
16 | 16 |
| 17 // from the tools directory for replace_char(...) |
| 18 #include "picture_utils.h" |
| 19 |
17 #include "SkDiffContext.h" | 20 #include "SkDiffContext.h" |
18 #include "SkImageDiffer.h" | 21 #include "SkImageDiffer.h" |
19 #include "skpdiff_util.h" | 22 #include "skpdiff_util.h" |
20 | 23 |
21 SkDiffContext::SkDiffContext() { | 24 SkDiffContext::SkDiffContext() { |
22 fDiffers = NULL; | 25 fDiffers = NULL; |
23 fDifferCount = 0; | 26 fDifferCount = 0; |
24 fThreadCount = SkThreadPool::kThreadPerCore; | 27 fThreadCount = SkThreadPool::kThreadPerCore; |
25 } | 28 } |
26 | 29 |
(...skipping 14 matching lines...) Expand all Loading... |
41 fRgbDiffDir = path; | 44 fRgbDiffDir = path; |
42 } | 45 } |
43 } | 46 } |
44 | 47 |
45 void SkDiffContext::setWhiteDiffDir(const SkString& path) { | 48 void SkDiffContext::setWhiteDiffDir(const SkString& path) { |
46 if (!path.isEmpty() && sk_mkdir(path.c_str())) { | 49 if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
47 fWhiteDiffDir = path; | 50 fWhiteDiffDir = path; |
48 } | 51 } |
49 } | 52 } |
50 | 53 |
| 54 void SkDiffContext::setLongNames(const bool useLongNames) { |
| 55 longNames = useLongNames; |
| 56 } |
| 57 |
51 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { | 58 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { |
52 // Delete whatever the last array of differs was | 59 // Delete whatever the last array of differs was |
53 if (NULL != fDiffers) { | 60 if (NULL != fDiffers) { |
54 SkDELETE_ARRAY(fDiffers); | 61 SkDELETE_ARRAY(fDiffers); |
55 fDiffers = NULL; | 62 fDiffers = NULL; |
56 fDifferCount = 0; | 63 fDifferCount = 0; |
57 } | 64 } |
58 | 65 |
59 // Copy over the new differs | 66 // Copy over the new differs |
60 fDifferCount = differs.count(); | 67 fDifferCount = differs.count(); |
(...skipping 11 matching lines...) Expand all Loading... |
72 return result; | 79 return result; |
73 } | 80 } |
74 } | 81 } |
75 if (a.size() > b.size()) { | 82 if (a.size() > b.size()) { |
76 return b; | 83 return b; |
77 } else { | 84 } else { |
78 return a; | 85 return a; |
79 } | 86 } |
80 } | 87 } |
81 | 88 |
| 89 static SkString get_combined_name(const SkString& a, const SkString& b) { |
| 90 // Note (stephana): We must keep this function in sync with |
| 91 // getImageDiffRelativeUrl() in static/loader.js (under rebaseline_server). |
| 92 SkString result = a; |
| 93 result.append("-vs-"); |
| 94 result.append(b); |
| 95 sk_tools::replace_char(&result, '.', '_'); |
| 96 return result; |
| 97 } |
| 98 |
82 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { | 99 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
83 // Load the images at the paths | 100 // Load the images at the paths |
84 SkBitmap baselineBitmap; | 101 SkBitmap baselineBitmap; |
85 SkBitmap testBitmap; | 102 SkBitmap testBitmap; |
86 if (!SkImageDecoder::DecodeFile(baselinePath, &baselineBitmap)) { | 103 if (!SkImageDecoder::DecodeFile(baselinePath, &baselineBitmap)) { |
87 SkDebugf("Failed to load bitmap \"%s\"\n", baselinePath); | 104 SkDebugf("Failed to load bitmap \"%s\"\n", baselinePath); |
88 return; | 105 return; |
89 } | 106 } |
90 if (!SkImageDecoder::DecodeFile(testPath, &testBitmap)) { | 107 if (!SkImageDecoder::DecodeFile(testPath, &testBitmap)) { |
91 SkDebugf("Failed to load bitmap \"%s\"\n", testPath); | 108 SkDebugf("Failed to load bitmap \"%s\"\n", testPath); |
92 return; | 109 return; |
93 } | 110 } |
94 | 111 |
95 // Setup a record for this diff | 112 // Setup a record for this diff |
96 fRecordMutex.acquire(); | 113 fRecordMutex.acquire(); |
97 DiffRecord* newRecord = fRecords.addToHead(DiffRecord()); | 114 DiffRecord* newRecord = fRecords.addToHead(DiffRecord()); |
98 fRecordMutex.release(); | 115 fRecordMutex.release(); |
99 | 116 |
100 // compute the common name | 117 // compute the common name |
101 SkString baseName = SkOSPath::Basename(baselinePath); | 118 SkString baseName = SkOSPath::Basename(baselinePath); |
102 SkString testName = SkOSPath::Basename(testPath); | 119 SkString testName = SkOSPath::Basename(testPath); |
103 newRecord->fCommonName = get_common_prefix(baseName, testName); | 120 |
| 121 if (longNames) { |
| 122 newRecord->fCommonName = get_combined_name(baseName, testName); |
| 123 } else { |
| 124 newRecord->fCommonName = get_common_prefix(baseName, testName); |
| 125 } |
| 126 newRecord->fCommonName.append(".png"); |
104 | 127 |
105 newRecord->fBaselinePath = baselinePath; | 128 newRecord->fBaselinePath = baselinePath; |
106 newRecord->fTestPath = testPath; | 129 newRecord->fTestPath = testPath; |
107 newRecord->fSize = SkISize::Make(baselineBitmap.width(), baselineBitmap.heig
ht()); | 130 newRecord->fSize = SkISize::Make(baselineBitmap.width(), baselineBitmap.heig
ht()); |
108 | 131 |
109 // only generate diff images if we have a place to store them | 132 // only generate diff images if we have a place to store them |
110 SkImageDiffer::BitmapsToCreate bitmapsToCreate; | 133 SkImageDiffer::BitmapsToCreate bitmapsToCreate; |
111 bitmapsToCreate.alphaMask = !fAlphaMaskDir.isEmpty(); | 134 bitmapsToCreate.alphaMask = !fAlphaMaskDir.isEmpty(); |
112 bitmapsToCreate.rgbDiff = !fRgbDiffDir.isEmpty(); | 135 bitmapsToCreate.rgbDiff = !fRgbDiffDir.isEmpty(); |
113 bitmapsToCreate.whiteDiff = !fWhiteDiffDir.isEmpty(); | 136 bitmapsToCreate.whiteDiff = !fWhiteDiffDir.isEmpty(); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 for (int i = 0; i < cntColumns; i++) { | 456 for (int i = 0; i < cntColumns; i++) { |
434 SkString str; | 457 SkString str; |
435 str.printf(", %f", values[i]); | 458 str.printf(", %f", values[i]); |
436 stream.writeText(str.c_str()); | 459 stream.writeText(str.c_str()); |
437 } | 460 } |
438 stream.writeText("\n"); | 461 stream.writeText("\n"); |
439 | 462 |
440 currentRecord = iter2.next(); | 463 currentRecord = iter2.next(); |
441 } | 464 } |
442 } | 465 } |
OLD | NEW |