2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-03-19 21:52:42 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
|
|
|
|
static void set2x3(SkMatrix* m, float a, float b, float c, float d, float e, float f) {
|
|
|
|
m->reset();
|
|
|
|
m->set(0, a);
|
|
|
|
m->set(1, b);
|
|
|
|
m->set(2, c);
|
|
|
|
m->set(3, d);
|
|
|
|
m->set(4, e);
|
|
|
|
m->set(5, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkRandom gRand;
|
|
|
|
static bool return_large;
|
|
|
|
static bool return_undef;
|
|
|
|
static bool quick;
|
|
|
|
static bool scale_large;
|
|
|
|
static int scval = 1;
|
|
|
|
static float transval = 0;
|
|
|
|
|
|
|
|
static int R(float x) {
|
|
|
|
return (int)floor(SkScalarToFloat(gRand.nextUScalar1()) * x);
|
|
|
|
}
|
|
|
|
|
2012-05-14 17:51:23 +00:00
|
|
|
#if defined _WIN32
|
|
|
|
#pragma warning ( push )
|
|
|
|
// we are intentionally causing an overflow here
|
|
|
|
// (warning C4756: overflow in constant arithmetic)
|
|
|
|
#pragma warning ( disable : 4756 )
|
|
|
|
#endif
|
|
|
|
|
2011-04-14 17:53:24 +00:00
|
|
|
static float huge() {
|
|
|
|
double d = 1e100;
|
|
|
|
float f = (float)d;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2012-05-14 17:51:23 +00:00
|
|
|
#if defined _WIN32
|
|
|
|
#pragma warning ( pop )
|
|
|
|
#endif
|
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
static float make_number() {
|
2011-07-29 13:44:30 +00:00
|
|
|
float v = 0;
|
2009-03-19 21:52:42 +00:00
|
|
|
int sel;
|
|
|
|
|
2013-09-06 14:16:12 +00:00
|
|
|
if (return_large == true && R(3) == 1) {
|
2013-09-07 07:01:16 +00:00
|
|
|
sel = R(6);
|
2013-09-06 14:16:12 +00:00
|
|
|
} else {
|
|
|
|
sel = R(4);
|
|
|
|
}
|
2009-03-19 21:52:42 +00:00
|
|
|
|
2013-09-06 14:16:12 +00:00
|
|
|
if (return_undef == false && sel == 0) {
|
|
|
|
sel = 1;
|
|
|
|
}
|
2009-03-19 21:52:42 +00:00
|
|
|
|
2013-09-06 14:16:12 +00:00
|
|
|
if (R(2) == 1) {
|
2013-09-07 07:01:16 +00:00
|
|
|
v = (float)R(100);
|
2013-09-06 14:16:12 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
switch (sel) {
|
|
|
|
case 0: break;
|
|
|
|
case 1: v = 0; break;
|
|
|
|
case 2: v = 0.000001f; break;
|
|
|
|
case 3: v = 10000; break;
|
|
|
|
case 4: v = 2000000000; break;
|
|
|
|
case 5: v = huge(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-07 07:01:16 +00:00
|
|
|
if (R(4) == 1) {
|
2013-09-06 14:16:12 +00:00
|
|
|
v = -v;
|
2009-03-19 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkColor make_color() {
|
|
|
|
if (R(2) == 1) return 0xFFC0F0A0; else return 0xFF000090;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SkColor make_fill() {
|
|
|
|
#if 0
|
|
|
|
int sel;
|
|
|
|
|
|
|
|
if (quick == true) sel = 0; else sel = R(6);
|
|
|
|
|
|
|
|
switch (sel) {
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
return make_color();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
var r = ctx.createLinearGradient(make_number(),make_number(),make_number(),make_number());
|
|
|
|
for (i=0;i<4;i++)
|
|
|
|
r.addColorStop(make_number(),make_color());
|
|
|
|
return r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
var r = ctx.createRadialGradient(make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
|
|
|
|
for (i=0;i<4;i++)
|
|
|
|
r.addColorStop(make_number(),make_color());
|
|
|
|
return r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
var r = ctx.createPattern(imgObj,"repeat");
|
|
|
|
if (R(6) == 0)
|
|
|
|
r.addColorStop(make_number(),make_color());
|
|
|
|
return r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return make_color();
|
|
|
|
#endif
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
|
|
|
|
static void do_fuzz(SkCanvas* canvas) {
|
|
|
|
SkPath path;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
for (int i=0;i<100;i++) {
|
|
|
|
switch (R(33)) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
paint.setColor(make_fill());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
paint.setAlpha(gRand.nextU() & 0xFF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: {
|
2009-06-23 12:19:41 +00:00
|
|
|
SkXfermode::Mode mode;
|
|
|
|
switch (R(3)) {
|
2011-10-27 15:27:51 +00:00
|
|
|
case 0: mode = SkXfermode::kSrc_Mode; break;
|
2009-06-23 12:19:41 +00:00
|
|
|
case 1: mode = SkXfermode::kXor_Mode; break;
|
2011-10-27 15:27:51 +00:00
|
|
|
case 2:
|
|
|
|
default: // silence warning
|
|
|
|
mode = SkXfermode::kSrcOver_Mode; break;
|
2009-06-23 12:19:41 +00:00
|
|
|
}
|
2009-11-05 21:04:00 +00:00
|
|
|
paint.setXfermodeMode(mode);
|
2009-03-19 21:52:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
switch (R(2)) {
|
|
|
|
case 0: paint.setStrokeCap(SkPaint::kRound_Cap); break;
|
|
|
|
case 1: paint.setStrokeCap(SkPaint::kButt_Cap); break;
|
2012-08-23 18:19:56 +00:00
|
|
|
}
|
2009-03-19 21:52:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
switch (R(2)) {
|
|
|
|
case 0: paint.setStrokeJoin(SkPaint::kRound_Join); break;
|
|
|
|
case 1: paint.setStrokeJoin(SkPaint::kMiter_Join); break;
|
2012-08-23 18:19:56 +00:00
|
|
|
}
|
2009-03-19 21:52:42 +00:00
|
|
|
break;
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
case 5:
|
|
|
|
paint.setStrokeWidth(make_number());
|
2009-03-19 21:52:42 +00:00
|
|
|
break;
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
case 6:
|
2009-03-19 21:52:42 +00:00
|
|
|
paint.setStrokeMiter(make_number());
|
|
|
|
break;
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
case 7:
|
2009-03-19 21:52:42 +00:00
|
|
|
if (quick == true) break;
|
2013-09-06 14:16:12 +00:00
|
|
|
SkSafeUnref(paint.setMaskFilter(SkBlurMaskFilter::Create(
|
|
|
|
SkBlurMaskFilter::kNormal_BlurStyle,
|
|
|
|
make_number())));
|
2009-03-19 21:52:42 +00:00
|
|
|
break;
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
case 8:
|
2009-03-19 21:52:42 +00:00
|
|
|
if (quick == true) break;
|
2012-08-23 18:19:56 +00:00
|
|
|
//ctx.shadowColor = make_fill();
|
2009-03-19 21:52:42 +00:00
|
|
|
break;
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
case 9:
|
2009-03-19 21:52:42 +00:00
|
|
|
if (quick == true) break;
|
|
|
|
//ctx.shadowOffsetX = make_number();
|
|
|
|
//ctx.shadowOffsetY = make_number();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
canvas->restore();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
canvas->rotate(make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
canvas->save();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
canvas->scale(-1,-1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
|
|
|
|
|
|
|
if (quick == true) break;
|
|
|
|
|
|
|
|
if (transval == 0) {
|
|
|
|
transval = make_number();
|
|
|
|
canvas->translate(transval,0);
|
|
|
|
} else {
|
|
|
|
canvas->translate(-transval,0);
|
|
|
|
transval = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15: {
|
|
|
|
SkRect r;
|
|
|
|
r.set(make_number(),make_number(),make_number(),make_number());
|
|
|
|
SkPaint::Style s = paint.getStyle();
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
paint.setStyle(s);
|
|
|
|
// clearrect
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
if (quick == true) break;
|
|
|
|
// ctx.drawImage(imgObj,make_number(),make_number(),make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 17: {
|
|
|
|
SkRect r;
|
|
|
|
r.set(make_number(),make_number(),make_number(),make_number());
|
|
|
|
SkPaint::Style s = paint.getStyle();
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
paint.setStyle(s);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
path.reset();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 19:
|
|
|
|
// ctx.clip() is evil.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 20:
|
|
|
|
path.close();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 21: {
|
|
|
|
SkPaint::Style s = paint.getStyle();
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
paint.setStyle(s);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 22: {
|
|
|
|
SkPaint::Style s = paint.getStyle();
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
paint.setStyle(s);
|
|
|
|
} break;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
case 23: {
|
|
|
|
SkRect r;
|
|
|
|
r.set(make_number(),make_number(),make_number(),make_number());
|
|
|
|
SkPaint::Style s = paint.getStyle();
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
paint.setStyle(s);
|
|
|
|
} break;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
case 24:
|
|
|
|
if (quick == true) break;
|
|
|
|
//ctx.arc(make_number(),make_number(),make_number(),make_number(),make_number(),true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 25:
|
|
|
|
if (quick == true) break;
|
|
|
|
//ctx.arcTo(make_number(),make_number(),make_number(),make_number(),make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 26:
|
|
|
|
if (quick == true) break;
|
|
|
|
//ctx.bezierCurveTo(make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 27:
|
|
|
|
path.lineTo(make_number(),make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 28:
|
|
|
|
path.moveTo(make_number(),make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 29:
|
|
|
|
if (quick == true) break;
|
|
|
|
path.quadTo(make_number(),make_number(),make_number(),make_number());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 30: {
|
|
|
|
if (quick == true) break;
|
|
|
|
SkMatrix matrix;
|
|
|
|
set2x3(&matrix, make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
|
|
|
|
canvas->concat(matrix);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 31: {
|
|
|
|
if (quick == true) break;
|
|
|
|
SkMatrix matrix;
|
|
|
|
set2x3(&matrix, make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
|
|
|
|
canvas->setMatrix(matrix);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 32:
|
|
|
|
|
|
|
|
if (scale_large == true) {
|
|
|
|
|
|
|
|
switch (scval) {
|
2012-08-23 18:19:56 +00:00
|
|
|
case 0: canvas->scale(-1000000000,1);
|
2009-03-19 21:52:42 +00:00
|
|
|
canvas->scale(-1000000000,1);
|
|
|
|
scval = 1; break;
|
2011-04-14 17:53:24 +00:00
|
|
|
case 1: canvas->scale(-.000000001f,1); scval = 2; break;
|
|
|
|
case 2: canvas->scale(-.000000001f,1); scval = 0; break;
|
2009-03-19 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
class FuzzView : public SampleView {
|
2009-03-19 21:52:42 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
FuzzView() {
|
2011-05-05 01:59:48 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "Fuzzer");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
void drawBG(SkCanvas* canvas) {
|
|
|
|
canvas->drawColor(0xFFDDDDDD);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2009-03-19 21:52:42 +00:00
|
|
|
do_fuzz(canvas);
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-03-19 21:52:42 +00:00
|
|
|
private:
|
|
|
|
typedef SkView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new FuzzView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|