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

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

Issue 540013002: Revert of SkThreadPool ~~> SkTaskGroup (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 | « tools/iOSShell.cpp ('k') | tools/skpdiff/skpdiff_main.cpp » ('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 "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 "SkTaskGroup.h" 15 #include "SkThreadPool.h"
16 16
17 // from the tools directory for replace_char(...) 17 // from the tools directory for replace_char(...)
18 #include "picture_utils.h" 18 #include "picture_utils.h"
19 19
20 #include "SkDiffContext.h" 20 #include "SkDiffContext.h"
21 #include "SkImageDiffer.h" 21 #include "SkImageDiffer.h"
22 #include "skpdiff_util.h" 22 #include "skpdiff_util.h"
23 23
24 SkDiffContext::SkDiffContext() { 24 SkDiffContext::SkDiffContext() {
25 fDiffers = NULL; 25 fDiffers = NULL;
26 fDifferCount = 0; 26 fDifferCount = 0;
27 fThreadCount = SkThreadPool::kThreadPerCore;
27 } 28 }
28 29
29 SkDiffContext::~SkDiffContext() { 30 SkDiffContext::~SkDiffContext() {
30 if (NULL != fDiffers) { 31 if (NULL != fDiffers) {
31 SkDELETE_ARRAY(fDiffers); 32 SkDELETE_ARRAY(fDiffers);
32 } 33 }
33 } 34 }
34 35
35 void SkDiffContext::setAlphaMaskDir(const SkString& path) { 36 void SkDiffContext::setAlphaMaskDir(const SkString& path) {
36 if (!path.isEmpty() && sk_mkdir(path.c_str())) { 37 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 80 }
80 } 81 }
81 if (a.size() > b.size()) { 82 if (a.size() > b.size()) {
82 return b; 83 return b;
83 } else { 84 } else {
84 return a; 85 return a;
85 } 86 }
86 } 87 }
87 88
88 static SkString get_combined_name(const SkString& a, const SkString& b) { 89 static SkString get_combined_name(const SkString& a, const SkString& b) {
89 // Note (stephana): We must keep this function in sync with 90 // Note (stephana): We must keep this function in sync with
90 // getImageDiffRelativeUrl() in static/loader.js (under rebaseline_server). 91 // getImageDiffRelativeUrl() in static/loader.js (under rebaseline_server).
91 SkString result = a; 92 SkString result = a;
92 result.append("-vs-"); 93 result.append("-vs-");
93 result.append(b); 94 result.append(b);
94 sk_tools::replace_char(&result, '.', '_'); 95 sk_tools::replace_char(&result, '.', '_');
95 return result; 96 return result;
96 } 97 }
97 98
98 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { 99 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) {
99 // Load the images at the paths 100 // Load the images at the paths
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 }; 231 };
231 232
232 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa th[]) { 233 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa th[]) {
233 // Get the files in the baseline, we will then look for those inside the tes t path 234 // Get the files in the baseline, we will then look for those inside the tes t path
234 SkTArray<SkString> baselineEntries; 235 SkTArray<SkString> baselineEntries;
235 if (!get_directory(baselinePath, &baselineEntries)) { 236 if (!get_directory(baselinePath, &baselineEntries)) {
236 SkDebugf("Unable to open path \"%s\"\n", baselinePath); 237 SkDebugf("Unable to open path \"%s\"\n", baselinePath);
237 return; 238 return;
238 } 239 }
239 240
240 SkTaskGroup tg; 241 SkThreadPool threadPool(fThreadCount);
241 SkTArray<SkThreadedDiff> runnableDiffs; 242 SkTArray<SkThreadedDiff> runnableDiffs;
242 runnableDiffs.reset(baselineEntries.count()); 243 runnableDiffs.reset(baselineEntries.count());
243 244
244 for (int x = 0; x < baselineEntries.count(); x++) { 245 for (int x = 0; x < baselineEntries.count(); x++) {
245 const char* baseFilename = baselineEntries[x].c_str(); 246 const char* baseFilename = baselineEntries[x].c_str();
246 247
247 // Find the real location of each file to compare 248 // Find the real location of each file to compare
248 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename); 249 SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename);
249 SkString testFile = SkOSPath::Join(testPath, baseFilename); 250 SkString testFile = SkOSPath::Join(testPath, baseFilename);
250 251
251 // Check that the test file exists and is a file 252 // Check that the test file exists and is a file
252 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { 253 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) {
253 // Queue up the comparison with the differ 254 // Queue up the comparison with the differ
254 runnableDiffs[x].setup(this, baselineFile, testFile); 255 runnableDiffs[x].setup(this, baselineFile, testFile);
255 tg.add(&runnableDiffs[x]); 256 threadPool.add(&runnableDiffs[x]);
256 } else { 257 } else {
257 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba selineFile.c_str()); 258 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba selineFile.c_str());
258 } 259 }
259 } 260 }
261
262 threadPool.wait();
260 } 263 }
261 264
262 265
263 void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa ttern[]) { 266 void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa ttern[]) {
264 // Get the files in the baseline and test patterns. Because they are in sort ed order, it's easy 267 // Get the files in the baseline and test patterns. Because they are in sort ed order, it's easy
265 // to find corresponding images by matching entry indices. 268 // to find corresponding images by matching entry indices.
266 269
267 SkTArray<SkString> baselineEntries; 270 SkTArray<SkString> baselineEntries;
268 if (!glob_files(baselinePattern, &baselineEntries)) { 271 if (!glob_files(baselinePattern, &baselineEntries)) {
269 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); 272 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern);
270 return; 273 return;
271 } 274 }
272 275
273 SkTArray<SkString> testEntries; 276 SkTArray<SkString> testEntries;
274 if (!glob_files(testPattern, &testEntries)) { 277 if (!glob_files(testPattern, &testEntries)) {
275 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); 278 SkDebugf("Unable to get pattern \"%s\"\n", testPattern);
276 return; 279 return;
277 } 280 }
278 281
279 if (baselineEntries.count() != testEntries.count()) { 282 if (baselineEntries.count() != testEntries.count()) {
280 SkDebugf("Baseline and test patterns do not yield corresponding number o f files\n"); 283 SkDebugf("Baseline and test patterns do not yield corresponding number o f files\n");
281 return; 284 return;
282 } 285 }
283 286
284 SkTaskGroup tg; 287 SkThreadPool threadPool(fThreadCount);
285 SkTArray<SkThreadedDiff> runnableDiffs; 288 SkTArray<SkThreadedDiff> runnableDiffs;
286 runnableDiffs.reset(baselineEntries.count()); 289 runnableDiffs.reset(baselineEntries.count());
287 290
288 for (int x = 0; x < baselineEntries.count(); x++) { 291 for (int x = 0; x < baselineEntries.count(); x++) {
289 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]); 292 runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]);
290 tg.add(&runnableDiffs[x]); 293 threadPool.add(&runnableDiffs[x]);
291 } 294 }
295
296 threadPool.wait();
292 } 297 }
293 298
294 void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { 299 void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) {
295 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_ IterStart); 300 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_ IterStart);
296 DiffRecord* currentRecord = iter.get(); 301 DiffRecord* currentRecord = iter.get();
297 302
298 if (useJSONP) { 303 if (useJSONP) {
299 stream.writeText("var SkPDiffRecords = {\n"); 304 stream.writeText("var SkPDiffRecords = {\n");
300 } else { 305 } else {
301 stream.writeText("{\n"); 306 stream.writeText("{\n");
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 for (int i = 0; i < cntColumns; i++) { 456 for (int i = 0; i < cntColumns; i++) {
452 SkString str; 457 SkString str;
453 str.printf(", %f", values[i]); 458 str.printf(", %f", values[i]);
454 stream.writeText(str.c_str()); 459 stream.writeText(str.c_str());
455 } 460 }
456 stream.writeText("\n"); 461 stream.writeText("\n");
457 462
458 currentRecord = iter2.next(); 463 currentRecord = iter2.next();
459 } 464 }
460 } 465 }
OLDNEW
« no previous file with comments | « tools/iOSShell.cpp ('k') | tools/skpdiff/skpdiff_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698