Index: samplecode/SamplePathFuzz.cpp |
diff --git a/samplecode/SamplePathFuzz.cpp b/samplecode/SamplePathFuzz.cpp |
index 4920e37708bd506e00fc67c949f149772c0b5be3..d6b11c5971012ad51158ab21e6c896a2ba4677e1 100644 |
--- a/samplecode/SamplePathFuzz.cpp |
+++ b/samplecode/SamplePathFuzz.cpp |
@@ -131,12 +131,11 @@ |
class FuzzPath { |
public: |
- FuzzPath() |
+ FuzzPath() |
: fFloatMin(0) |
, fFloatMax(800) |
, fAddCount(0) |
, fPrintName(false) |
- , fStrokeOnly(false) |
, fValidate(false) |
{ |
fTab = " "; |
@@ -173,14 +172,6 @@ |
return fPath; |
} |
- void setSeed(int seed) { |
- fRand.setSeed(seed); |
- } |
- |
- void setStrokeOnly() { |
- fStrokeOnly = true; |
- } |
- |
private: |
SkPath::AddPathMode makeAddPathMode() { |
@@ -274,14 +265,14 @@ |
SkPaint paint; |
bool antiAlias = fRand.nextBool(); |
paint.setAntiAlias(antiAlias); |
- SkPaint::Style style = fStrokeOnly ? SkPaint::kStroke_Style : |
- (SkPaint::Style) fRand.nextRangeU(SkPaint::kFill_Style, SkPaint::kStrokeAndFill_Style); |
+ SkPaint::Style style = (SkPaint::Style) fRand.nextRangeU(SkPaint::kFill_Style, |
+ SkPaint::kStrokeAndFill_Style); |
paint.setStyle(style); |
SkColor color = (SkColor) fRand.nextU(); |
paint.setColor(color); |
- SkScalar width = fRand.nextRangeF(0, 10); |
+ SkScalar width = fRand.nextF(); |
paint.setStrokeWidth(width); |
- SkScalar miter = makeScalar(); |
+ SkScalar miter = fRand.nextF(); |
paint.setStrokeMiter(miter); |
SkPaint::Cap cap = (SkPaint::Cap) fRand.nextRangeU(SkPaint::kButt_Cap, SkPaint::kSquare_Cap); |
paint.setStrokeCap(cap); |
@@ -417,7 +408,7 @@ |
path.addPath(src, dx, dy, mode); |
--fPathDepth; |
validate(path); |
- } |
+ } |
break; |
case kAddPath2: |
if (fPathDepth < fPathDepthLimit) { |
@@ -590,11 +581,11 @@ |
uint32_t fPathSegmentLimit; |
int fAddCount; |
bool fPrintName; |
-bool fStrokeOnly; |
bool fValidate; |
const char* fTab; |
}; |
+////////////////////////////////////////////////////////////////////////////// |
static bool contains_only_moveTo(const SkPath& path) { |
int verbCount = path.countVerbs(); |
if (verbCount == 0) { |
@@ -612,54 +603,10 @@ |
return true; |
} |
-#include "SkGraphics.h" |
-#include "SkSurface.h" |
-#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 + i; |
- states[i].fBitmap = bitmap; |
- } |
- SkTaskGroup tg; |
- tg.batch(test_fuzz, states, SK_ARRAY_COUNT(states)); |
-} |
- |
class PathFuzzView : public SampleView { |
public: |
- PathFuzzView() |
- : fOneDraw(false) |
- { |
+ PathFuzzView() { |
+ fDots = 0; |
} |
protected: |
// overrides from SkEventSink |
@@ -671,42 +618,34 @@ |
return this->INHERITED::onQuery(evt); |
} |
- void onOnceBeforeDraw() SK_OVERRIDE { |
- fIndex = 0; |
- SkImageInfo info(SkImageInfo::MakeN32Premul(SkScalarRoundToInt(width()), |
- SkScalarRoundToInt(height()))); |
- offscreen.allocPixels(info); |
- path_fuzz_stroker(&offscreen, fIndex); |
- } |
- |
virtual void onDrawContent(SkCanvas* canvas) { |
- if (fOneDraw) { |
- fuzzPath.randomize(); |
- const SkPath& path = fuzzPath.getPath(); |
- const SkPaint& paint = fuzzPath.getPaint(); |
- const SkPath& clip = fuzzPath.getClip(); |
- const SkMatrix& matrix = fuzzPath.getMatrix(); |
- if (!contains_only_moveTo(clip)) { |
- canvas->clipPath(clip); |
- } |
- canvas->setMatrix(matrix); |
- canvas->drawPath(path, paint); |
- } else { |
- path_fuzz_stroker(&offscreen, fIndex += 100); |
- canvas->drawBitmap(offscreen, 0, 0); |
+ fuzzPath.randomize(); |
+ const SkPath& path = fuzzPath.getPath(); |
+ const SkPaint& paint = fuzzPath.getPaint(); |
+ const SkPath& clip = fuzzPath.getClip(); |
+ const SkMatrix& matrix = fuzzPath.getMatrix(); |
+ if (!contains_only_moveTo(clip)) { |
+ canvas->clipPath(clip); |
} |
+ canvas->setMatrix(matrix); |
+ canvas->drawPath(path, paint); |
this->inval(NULL); |
+ if (++fDots == 8000) { |
+ SkDebugf("\n"); |
+ fDots = 0; |
+ } |
+ if ((fDots % 100) == 99) { |
+ SkDebugf("."); |
+ } |
} |
private: |
- int fIndex; |
- SkBitmap offscreen; |
FuzzPath fuzzPath; |
- bool fOneDraw; |
+ int fDots; |
typedef SkView INHERITED; |
}; |
+ |
+////////////////////////////////////////////////////////////////////////////// |
static SkView* MyFactory() { return new PathFuzzView; } |
static SkViewRegister reg(MyFactory); |
- |
- |