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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/core/SkMultiPictureDraw.h ('k') | src/core/SkMultiPictureDraw.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 2015 Google Inc. 2 * Copyright 2015 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 610 }
611 } 611 }
612 return true; 612 return true;
613 } 613 }
614 614
615 #include "SkGraphics.h" 615 #include "SkGraphics.h"
616 #include "SkSurface.h" 616 #include "SkSurface.h"
617 #include "SkTaskGroup.h" 617 #include "SkTaskGroup.h"
618 #include "SkTDArray.h" 618 #include "SkTDArray.h"
619 619
620 struct ThreadState { 620 static void path_fuzz_stroker(SkBitmap* bitmap, int seed) {
621 int fSeed; 621 sk_parallel_for(100, [&](int i) {
622 const SkBitmap* fBitmap; 622 int localSeed = seed + i;
623 };
624 623
625 static void test_fuzz(ThreadState* data) { 624 FuzzPath fuzzPath;
626 FuzzPath fuzzPath; 625 fuzzPath.setStrokeOnly();
627 fuzzPath.setStrokeOnly(); 626 fuzzPath.setSeed(localSeed);
628 fuzzPath.setSeed(data->fSeed); 627 fuzzPath.randomize();
629 fuzzPath.randomize(); 628 const SkPath& path = fuzzPath.getPath();
630 const SkPath& path = fuzzPath.getPath(); 629 const SkPaint& paint = fuzzPath.getPaint();
631 const SkPaint& paint = fuzzPath.getPaint(); 630 const SkImageInfo& info = bitmap->info();
632 const SkImageInfo& info = data->fBitmap->info(); 631 SkCanvas* canvas(
633 SkCanvas* canvas(SkCanvas::NewRasterDirect(info, data->fBitmap->getPixels(), 632 SkCanvas::NewRasterDirect(info, bitmap->getPixels(), bitmap->rowByte s()));
634 data->fBitmap->rowBytes())); 633 int w = info.width() / 4;
635 int w = info.width() / 4; 634 int h = info.height() / 4;
636 int h = info.height() / 4; 635 int x = localSeed / 4 % 4;
637 int x = data->fSeed / 4 % 4; 636 int y = localSeed % 4;
638 int y = data->fSeed % 4; 637 SkRect clipBounds = SkRect::MakeXYWH(SkIntToScalar(x) * w, SkIntToScalar (y) * h,
639 SkRect clipBounds = SkRect::MakeXYWH(SkIntToScalar(x) * w, SkIntToScalar(y) * h, 638 SkIntToScalar(w), SkIntToScalar(h));
640 SkIntToScalar(w), SkIntToScalar(h)); 639 canvas->save();
641 canvas->save(); 640 canvas->clipRect(clipBounds);
642 canvas->clipRect(clipBounds); 641 canvas->translate(SkIntToScalar(x) * w, SkIntToScalar(y) * h);
643 canvas->translate(SkIntToScalar(x) * w, SkIntToScalar(y) * h); 642 canvas->drawPath(path, paint);
644 canvas->drawPath(path, paint); 643 canvas->restore();
645 canvas->restore(); 644 });
646 }
647
648 static void path_fuzz_stroker(SkBitmap* bitmap, int seed) {
649 ThreadState states[100];
650 for (size_t i = 0; i < SK_ARRAY_COUNT(states); i++) {
651 states[i].fSeed = seed + (int) i;
652 states[i].fBitmap = bitmap;
653 }
654 SkTaskGroup tg;
655 tg.batch(test_fuzz, states, SK_ARRAY_COUNT(states));
656 } 645 }
657 646
658 class PathFuzzView : public SampleView { 647 class PathFuzzView : public SampleView {
659 public: 648 public:
660 PathFuzzView() 649 PathFuzzView()
661 : fOneDraw(false) 650 : fOneDraw(false)
662 { 651 {
663 } 652 }
664 protected: 653 protected:
665 // overrides from SkEventSink 654 // overrides from SkEventSink
666 virtual bool onQuery(SkEvent* evt) { 655 virtual bool onQuery(SkEvent* evt) {
667 if (SampleCode::TitleQ(*evt)) { 656 if (SampleCode::TitleQ(*evt)) {
668 SampleCode::TitleR(evt, "PathFuzzer"); 657 SampleCode::TitleR(evt, "PathFuzzer");
669 return true; 658 return true;
670 } 659 }
671 return this->INHERITED::onQuery(evt); 660 return this->INHERITED::onQuery(evt);
672 } 661 }
673 662
674 void onOnceBeforeDraw() override { 663 void onOnceBeforeDraw() override {
675 fIndex = 0; 664 fIndex = 0;
676 SkImageInfo info(SkImageInfo::MakeN32Premul(SkScalarRoundToInt(width()), 665 SkImageInfo info(SkImageInfo::MakeN32Premul(SkScalarRoundToInt(width()),
677 SkScalarRoundToInt(height()))); 666 SkScalarRoundToInt(height())));
678 offscreen.allocPixels(info); 667 offscreen.allocPixels(info);
679 path_fuzz_stroker(&offscreen, fIndex); 668 path_fuzz_stroker(&offscreen, fIndex);
680 } 669 }
681 670
682 virtual void onDrawContent(SkCanvas* canvas) { 671 virtual void onDrawContent(SkCanvas* canvas) {
683 if (fOneDraw) { 672 if (fOneDraw) {
684 fuzzPath.randomize(); 673 fuzzPath.randomize();
685 const SkPath& path = fuzzPath.getPath(); 674 const SkPath& path = fuzzPath.getPath();
686 const SkPaint& paint = fuzzPath.getPaint(); 675 const SkPaint& paint = fuzzPath.getPaint();
(...skipping 16 matching lines...) Expand all
703 SkBitmap offscreen; 692 SkBitmap offscreen;
704 FuzzPath fuzzPath; 693 FuzzPath fuzzPath;
705 bool fOneDraw; 694 bool fOneDraw;
706 typedef SkView INHERITED; 695 typedef SkView INHERITED;
707 }; 696 };
708 697
709 static SkView* MyFactory() { return new PathFuzzView; } 698 static SkView* MyFactory() { return new PathFuzzView; }
710 static SkViewRegister reg(MyFactory); 699 static SkViewRegister reg(MyFactory);
711 700
712 701
OLDNEW
« 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