aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@google.com>2015-03-04 11:46:27 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-04 11:46:27 -0800
commita84cff9b994fd53ce2a23069db4282589983fde6 (patch)
tree1b08acba30d02f770ccd2a3a0008c062ea0c389e /samplecode
parent4e644f5d5020a6ec904734a3f521bfad173cb450 (diff)
Revert of fix casts (patchset #1 id:1 of https://codereview.chromium.org/979453004/)
Reason for revert: 64-bit windows build warnings-as-errors Original issue's description: > (starting with mtklein's 966503002 mod to 963593003) > fix casts > > Committed: https://skia.googlesource.com/skia/+/9e73a84deb5e6c201081b1d30175863898543e8d TBR=caryclark@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/977583007
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SamplePathFuzz.cpp117
1 files changed, 28 insertions, 89 deletions
diff --git a/samplecode/SamplePathFuzz.cpp b/samplecode/SamplePathFuzz.cpp
index 4920e37708..d6b11c5971 100644
--- a/samplecode/SamplePathFuzz.cpp
+++ b/samplecode/SamplePathFuzz.cpp
@@ -131,12 +131,11 @@ const char* gRandomSetMatrixNames[] = {
class FuzzPath {
public:
- FuzzPath()
+ FuzzPath()
: fFloatMin(0)
, fFloatMax(800)
, fAddCount(0)
, fPrintName(false)
- , fStrokeOnly(false)
, fValidate(false)
{
fTab = " ";
@@ -173,14 +172,6 @@ public:
return fPath;
}
- void setSeed(int seed) {
- fRand.setSeed(seed);
- }
-
- void setStrokeOnly() {
- fStrokeOnly = true;
- }
-
private:
SkPath::AddPathMode makeAddPathMode() {
@@ -274,14 +265,14 @@ SkPaint makePaint() {
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 @@ SkPath makePath() {
path.addPath(src, dx, dy, mode);
--fPathDepth;
validate(path);
- }
+ }
break;
case kAddPath2:
if (fPathDepth < fPathDepthLimit) {
@@ -590,11 +581,11 @@ int fPathDepthLimit;
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 @@ static bool contains_only_moveTo(const SkPath& path) {
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 @@ protected:
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);
-
-