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

Unified Diff: samplecode/SamplePathFuzz.cpp

Issue 1184373003: Add sk_parallel_for() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkMultiPictureDraw.h ('k') | src/core/SkMultiPictureDraw.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SamplePathFuzz.cpp
diff --git a/samplecode/SamplePathFuzz.cpp b/samplecode/SamplePathFuzz.cpp
index f2595c59ea2b3ff817fe1a3d156168f30065b9f4..55f7f4129d12b31087a90324785decf93d03c54a 100644
--- a/samplecode/SamplePathFuzz.cpp
+++ b/samplecode/SamplePathFuzz.cpp
@@ -617,42 +617,31 @@ static bool contains_only_moveTo(const SkPath& path) {
#include "SkTaskGroup.h"
#include "SkTDArray.h"
-struct ThreadState {
- int fSeed;
- const SkBitmap* fBitmap;
-};
-
-static void test_fuzz(ThreadState* data) {
- FuzzPath fuzzPath;
- fuzzPath.setStrokeOnly();
- fuzzPath.setSeed(data->fSeed);
- fuzzPath.randomize();
- const SkPath& path = fuzzPath.getPath();
- const SkPaint& paint = fuzzPath.getPaint();
- const SkImageInfo& info = data->fBitmap->info();
- SkCanvas* canvas(SkCanvas::NewRasterDirect(info, data->fBitmap->getPixels(),
- data->fBitmap->rowBytes()));
- int w = info.width() / 4;
- int h = info.height() / 4;
- int x = data->fSeed / 4 % 4;
- int y = data->fSeed % 4;
- SkRect clipBounds = SkRect::MakeXYWH(SkIntToScalar(x) * w, SkIntToScalar(y) * h,
- SkIntToScalar(w), SkIntToScalar(h));
- canvas->save();
- canvas->clipRect(clipBounds);
- canvas->translate(SkIntToScalar(x) * w, SkIntToScalar(y) * h);
- canvas->drawPath(path, paint);
- canvas->restore();
-}
-
static void path_fuzz_stroker(SkBitmap* bitmap, int seed) {
- ThreadState states[100];
- for (size_t i = 0; i < SK_ARRAY_COUNT(states); i++) {
- states[i].fSeed = seed + (int) i;
- states[i].fBitmap = bitmap;
- }
- SkTaskGroup tg;
- tg.batch(test_fuzz, states, SK_ARRAY_COUNT(states));
+ sk_parallel_for(100, [&](int i) {
+ int localSeed = seed + i;
+
+ FuzzPath fuzzPath;
+ fuzzPath.setStrokeOnly();
+ fuzzPath.setSeed(localSeed);
+ fuzzPath.randomize();
+ const SkPath& path = fuzzPath.getPath();
+ const SkPaint& paint = fuzzPath.getPaint();
+ const SkImageInfo& info = bitmap->info();
+ SkCanvas* canvas(
+ SkCanvas::NewRasterDirect(info, bitmap->getPixels(), bitmap->rowBytes()));
+ int w = info.width() / 4;
+ int h = info.height() / 4;
+ int x = localSeed / 4 % 4;
+ int y = localSeed % 4;
+ SkRect clipBounds = SkRect::MakeXYWH(SkIntToScalar(x) * w, SkIntToScalar(y) * h,
+ SkIntToScalar(w), SkIntToScalar(h));
+ canvas->save();
+ canvas->clipRect(clipBounds);
+ canvas->translate(SkIntToScalar(x) * w, SkIntToScalar(y) * h);
+ canvas->drawPath(path, paint);
+ canvas->restore();
+ });
}
class PathFuzzView : public SampleView {
@@ -673,7 +662,7 @@ protected:
void onOnceBeforeDraw() override {
fIndex = 0;
- SkImageInfo info(SkImageInfo::MakeN32Premul(SkScalarRoundToInt(width()),
+ SkImageInfo info(SkImageInfo::MakeN32Premul(SkScalarRoundToInt(width()),
SkScalarRoundToInt(height())));
offscreen.allocPixels(info);
path_fuzz_stroker(&offscreen, fIndex);
« no previous file with comments | « include/core/SkMultiPictureDraw.h ('k') | src/core/SkMultiPictureDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698