Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tools/skpdiff/SkDiffContext.cpp

Issue 371853005: Move threadpool code from include/utils to tools/threadpool. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gyp Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/skia_test.cpp ('k') | tools/threadpool/CondVar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "Runnable.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 "ThreadPool.h"
16 16
17 #include "SkDiffContext.h" 17 #include "SkDiffContext.h"
18 #include "SkImageDiffer.h" 18 #include "SkImageDiffer.h"
19 #include "skpdiff_util.h" 19 #include "skpdiff_util.h"
20 20
21 SkDiffContext::SkDiffContext() { 21 SkDiffContext::SkDiffContext() {
22 fDiffers = NULL; 22 fDiffers = NULL;
23 fDifferCount = 0; 23 fDifferCount = 0;
24 fThreadCount = SkThreadPool::kThreadPerCore; 24 fThreadCount = ThreadPool::kThreadPerCore;
25 } 25 }
26 26
27 SkDiffContext::~SkDiffContext() { 27 SkDiffContext::~SkDiffContext() {
28 if (NULL != fDiffers) { 28 if (NULL != fDiffers) {
29 SkDELETE_ARRAY(fDiffers); 29 SkDELETE_ARRAY(fDiffers);
30 } 30 }
31 } 31 }
32 32
33 void SkDiffContext::setAlphaMaskDir(const SkString& path) { 33 void SkDiffContext::setAlphaMaskDir(const SkString& path) {
34 if (!path.isEmpty() && sk_mkdir(path.c_str())) { 34 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 newRecord->fCommonN ame.c_str()); 180 newRecord->fCommonN ame.c_str());
181 SkImageEncoder::EncodeFile(newRecord->fWhiteDiffPath.c_str(), 181 SkImageEncoder::EncodeFile(newRecord->fWhiteDiffPath.c_str(),
182 diffData.fResult.whiteDiffBitmap, 182 diffData.fResult.whiteDiffBitmap,
183 SkImageEncoder::kPNG_Type, 100); 183 SkImageEncoder::kPNG_Type, 100);
184 diffData.fResult.whiteDiffBitmap.reset(); 184 diffData.fResult.whiteDiffBitmap.reset();
185 bitmapsToCreate.whiteDiff = false; 185 bitmapsToCreate.whiteDiff = false;
186 } 186 }
187 } 187 }
188 } 188 }
189 189
190 class SkThreadedDiff : public SkRunnable { 190 class SkThreadedDiff : public Runnable {
191 public: 191 public:
192 SkThreadedDiff() : fDiffContext(NULL) { } 192 SkThreadedDiff() : fDiffContext(NULL) { }
193 193
194 void setup(SkDiffContext* diffContext, const SkString& baselinePath, const S kString& testPath) { 194 void setup(SkDiffContext* diffContext, const SkString& baselinePath, const S kString& testPath) {
195 fDiffContext = diffContext; 195 fDiffContext = diffContext;
196 fBaselinePath = baselinePath; 196 fBaselinePath = baselinePath;
197 fTestPath = testPath; 197 fTestPath = testPath;
198 } 198 }
199 199
200 virtual void run() SK_OVERRIDE { 200 virtual void run() SK_OVERRIDE {
201 fDiffContext->addDiff(fBaselinePath.c_str(), fTestPath.c_str()); 201 fDiffContext->addDiff(fBaselinePath.c_str(), fTestPath.c_str());
202 } 202 }
203 203
204 private: 204 private:
205 SkDiffContext* fDiffContext; 205 SkDiffContext* fDiffContext;
206 SkString fBaselinePath; 206 SkString fBaselinePath;
207 SkString fTestPath; 207 SkString fTestPath;
208 }; 208 };
209 209
210 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa th[]) { 210 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa th[]) {
211 // Get the files in the baseline, we will then look for those inside the tes t path 211 // Get the files in the baseline, we will then look for those inside the tes t path
212 SkTArray<SkString> baselineEntries; 212 SkTArray<SkString> baselineEntries;
213 if (!get_directory(baselinePath, &baselineEntries)) { 213 if (!get_directory(baselinePath, &baselineEntries)) {
214 SkDebugf("Unable to open path \"%s\"\n", baselinePath); 214 SkDebugf("Unable to open path \"%s\"\n", baselinePath);
215 return; 215 return;
216 } 216 }
217 217
218 SkThreadPool threadPool(fThreadCount); 218 ThreadPool threadPool(fThreadCount);
219 SkTArray<SkThreadedDiff> runnableDiffs; 219 SkTArray<SkThreadedDiff> runnableDiffs;
220 runnableDiffs.reset(baselineEntries.count()); 220 runnableDiffs.reset(baselineEntries.count());
221 221
222 for (int x = 0; x < baselineEntries.count(); x++) { 222 for (int x = 0; x < baselineEntries.count(); x++) {
223 const char* baseFilename = baselineEntries[x].c_str(); 223 const char* baseFilename = baselineEntries[x].c_str();
224 224
225 // Find the real location of each file to compare 225 // Find the real location of each file to compare
226 SkString baselineFile = SkOSPath::SkPathJoin(baselinePath, baseFilename) ; 226 SkString baselineFile = SkOSPath::SkPathJoin(baselinePath, baseFilename) ;
227 SkString testFile = SkOSPath::SkPathJoin(testPath, baseFilename); 227 SkString testFile = SkOSPath::SkPathJoin(testPath, baseFilename);
228 228
(...skipping 25 matching lines...) Expand all
254 if (!glob_files(testPattern, &testEntries)) { 254 if (!glob_files(testPattern, &testEntries)) {
255 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); 255 SkDebugf("Unable to get pattern \"%s\"\n", testPattern);
256 return; 256 return;
257 } 257 }
258 258
259 if (baselineEntries.count() != testEntries.count()) { 259 if (baselineEntries.count() != testEntries.count()) {
260 SkDebugf("Baseline and test patterns do not yield corresponding number o f files\n"); 260 SkDebugf("Baseline and test patterns do not yield corresponding number o f files\n");
261 return; 261 return;
262 } 262 }
263 263
264 SkThreadPool threadPool(fThreadCount); 264 ThreadPool threadPool(fThreadCount);
265 SkTArray<SkThreadedDiff> runnableDiffs; 265 SkTArray<SkThreadedDiff> runnableDiffs;
266 runnableDiffs.reset(baselineEntries.count()); 266 runnableDiffs.reset(baselineEntries.count());
267 267
268 for (int x = 0; x < baselineEntries.count(); x++) { 268 for (int x = 0; x < baselineEntries.count(); x++) {
269 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]); 269 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]);
270 threadPool.add(&runnableDiffs[x]); 270 threadPool.add(&runnableDiffs[x]);
271 } 271 }
272 272
273 threadPool.wait(); 273 threadPool.wait();
274 } 274 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 for (int i = 0; i < cntColumns; i++) { 433 for (int i = 0; i < cntColumns; i++) {
434 SkString str; 434 SkString str;
435 str.printf(", %f", values[i]); 435 str.printf(", %f", values[i]);
436 stream.writeText(str.c_str()); 436 stream.writeText(str.c_str());
437 } 437 }
438 stream.writeText("\n"); 438 stream.writeText("\n");
439 439
440 currentRecord = iter2.next(); 440 currentRecord = iter2.next();
441 } 441 }
442 } 442 }
OLDNEW
« no previous file with comments | « tests/skia_test.cpp ('k') | tools/threadpool/CondVar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698