aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-06-17 15:26:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-17 15:26:15 -0700
commit00b621cfc0dac2a0028757a974de33a78bb8579d (patch)
tree696d1a4560d37af4929a6d0501611ceb88c0b45e /tools
parent5a9e2994c9915f76b1e3720f107e87fc952ffab2 (diff)
Add sk_parallel_for()
This should be a drop-in replacement for most for-loops to make them run in parallel: for (int i = 0; i < N; i++) { code... } ~~~> sk_parallel_for(N, [&](int i) { code... }); This is just syntax sugar over SkTaskGroup to make this use case really easy to write. There's no more overhead that we weren't already forced to add using an interface like batch(), and no extra heap allocations. I've replaced 3 uses of SkTaskGroup with sk_parallel_for: 1) My unit tests for SkOnce. 2) Cary's path fuzzer. 3) SkMultiPictureDraw. Performance should be the same. Please compare left and right for readability. :) BUG=skia: No public API changes. TBR=reed@google.com Review URL: https://codereview.chromium.org/1184373003
Diffstat (limited to 'tools')
-rw-r--r--tools/skpdiff/SkDiffContext.cpp46
1 files changed, 7 insertions, 39 deletions
diff --git a/tools/skpdiff/SkDiffContext.cpp b/tools/skpdiff/SkDiffContext.cpp
index c422636f6e..d14546046c 100644
--- a/tools/skpdiff/SkDiffContext.cpp
+++ b/tools/skpdiff/SkDiffContext.cpp
@@ -209,26 +209,6 @@ void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) {
}
}
-class SkThreadedDiff : public SkRunnable {
-public:
- SkThreadedDiff() : fDiffContext(NULL) { }
-
- void setup(SkDiffContext* diffContext, const SkString& baselinePath, const SkString& testPath) {
- fDiffContext = diffContext;
- fBaselinePath = baselinePath;
- fTestPath = testPath;
- }
-
- void run() override {
- fDiffContext->addDiff(fBaselinePath.c_str(), fTestPath.c_str());
- }
-
-private:
- SkDiffContext* fDiffContext;
- SkString fBaselinePath;
- SkString fTestPath;
-};
-
void SkDiffContext::diffDirectories(const char baselinePath[], const char testPath[]) {
// Get the files in the baseline, we will then look for those inside the test path
SkTArray<SkString> baselineEntries;
@@ -237,12 +217,8 @@ void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa
return;
}
- SkTaskGroup tg;
- SkTArray<SkThreadedDiff> runnableDiffs;
- runnableDiffs.reset(baselineEntries.count());
-
- for (int x = 0; x < baselineEntries.count(); x++) {
- const char* baseFilename = baselineEntries[x].c_str();
+ sk_parallel_for(baselineEntries.count(), [&](int i) {
+ const char* baseFilename = baselineEntries[i].c_str();
// Find the real location of each file to compare
SkString baselineFile = SkOSPath::Join(baselinePath, baseFilename);
@@ -250,13 +226,11 @@ void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa
// Check that the test file exists and is a file
if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) {
- // Queue up the comparison with the differ
- runnableDiffs[x].setup(this, baselineFile, testFile);
- tg.add(&runnableDiffs[x]);
+ this->addDiff(baselineFile.c_str(), testFile.c_str());
} else {
SkDebugf("Baseline file \"%s\" has no corresponding test file\n", baselineFile.c_str());
}
- }
+ });
}
@@ -281,15 +255,9 @@ void SkDiffContext::diffPatterns(const char baselinePattern[], const char testPa
return;
}
- SkTaskGroup tg;
- SkTArray<SkThreadedDiff> runnableDiffs;
- runnableDiffs.reset(baselineEntries.count());
-
- for (int x = 0; x < baselineEntries.count(); x++) {
- runnableDiffs[x].setup(this, baselineEntries[x], testEntries[x]);
- tg.add(&runnableDiffs[x]);
- }
- tg.wait();
+ sk_parallel_for(baselineEntries.count(), [&](int i) {
+ this->addDiff(baselineEntries[i].c_str(), testEntries[i].c_str());
+ });
}
void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) {