| OLD | NEW |
| 1 #include "SampleCode.h" | 1 #include "SampleCode.h" |
| 2 #include "SkView.h" | 2 #include "SkView.h" |
| 3 #include "SkCanvas.h" | 3 #include "SkCanvas.h" |
| 4 #include "SkBlurMaskFilter.h" | 4 #include "SkBlurMaskFilter.h" |
| 5 #include "SkPaint.h" | 5 #include "SkPaint.h" |
| 6 #include "SkPath.h" | 6 #include "SkPath.h" |
| 7 #include "SkXfermode.h" | 7 #include "SkXfermode.h" |
| 8 #include "SkMatrix.h" | 8 #include "SkMatrix.h" |
| 9 #include "SkColor.h" | 9 #include "SkColor.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 static float make_number() { | 34 static float make_number() { |
| 35 float v; | 35 float v; |
| 36 int sel; | 36 int sel; |
| 37 | 37 |
| 38 if (return_large == true && R(3) == 1) sel = R(6); else sel = R(4); | 38 if (return_large == true && R(3) == 1) sel = R(6); else sel = R(4); |
| 39 if (return_undef == false && sel == 0) sel = 1; | 39 if (return_undef == false && sel == 0) sel = 1; |
| 40 | 40 |
| 41 if (R(2) == 1) v = R(100); else | 41 if (R(2) == 1) v = R(100); else |
| 42 | 42 |
| 43 switch (sel) { | 43 switch (sel) { |
| 44 case 0: break; | 44 case 0: break; |
| 45 case 1: v = 0; break; | 45 case 1: v = 0; break; |
| 46 case 2: v = 0.000001; break; | 46 case 2: v = 0.000001; break; |
| 47 case 3: v = 10000; break; | 47 case 3: v = 10000; break; |
| 48 case 4: v = 2000000000; break; | 48 case 4: v = 2000000000; break; |
| 49 case 5: v = 1e100; break; | 49 case 5: v = 1e100; break; |
| 50 } | 50 } |
| 51 | 51 |
| 52 if (R(4) == 1) v = -v; | 52 if (R(4) == 1) v = -v; |
| 53 return v; | 53 return v; |
| 54 } | 54 } |
| 55 | 55 |
| 56 static SkColor make_color() { | 56 static SkColor make_color() { |
| 57 if (R(2) == 1) return 0xFFC0F0A0; else return 0xFF000090; | 57 if (R(2) == 1) return 0xFFC0F0A0; else return 0xFF000090; |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 static SkColor make_fill() { | 61 static SkColor make_fill() { |
| 62 #if 0 | 62 #if 0 |
| 63 int sel; | 63 int sel; |
| 64 | 64 |
| 65 if (quick == true) sel = 0; else sel = R(6); | 65 if (quick == true) sel = 0; else sel = R(6); |
| 66 | 66 |
| 67 switch (sel) { | 67 switch (sel) { |
| 68 | 68 |
| 69 case 0: | 69 case 0: |
| 70 case 1: | 70 case 1: |
| 71 case 2: | 71 case 2: |
| 72 return make_color(); | 72 return make_color(); |
| 73 break; | 73 break; |
| 74 | 74 |
| 75 case 3: | 75 case 3: |
| 76 var r = ctx.createLinearGradient(make_number(),make_number(),make_number()
,make_number()); | 76 var r = ctx.createLinearGradient(make_number(),make_number(),make_number()
,make_number()); |
| 77 for (i=0;i<4;i++) | 77 for (i=0;i<4;i++) |
| 78 r.addColorStop(make_number(),make_color()); | 78 r.addColorStop(make_number(),make_color()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 var r = ctx.createPattern(imgObj,"repeat"); | 90 var r = ctx.createPattern(imgObj,"repeat"); |
| 91 if (R(6) == 0) | 91 if (R(6) == 0) |
| 92 r.addColorStop(make_number(),make_color()); | 92 r.addColorStop(make_number(),make_color()); |
| 93 return r; | 93 return r; |
| 94 break; | 94 break; |
| 95 } | 95 } |
| 96 #else | 96 #else |
| 97 return make_color(); | 97 return make_color(); |
| 98 #endif | 98 #endif |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 static void do_fuzz(SkCanvas* canvas) { | 102 static void do_fuzz(SkCanvas* canvas) { |
| 103 SkPath path; | 103 SkPath path; |
| 104 SkPaint paint; | 104 SkPaint paint; |
| 105 paint.setAntiAlias(true); | 105 paint.setAntiAlias(true); |
| 106 | 106 |
| 107 for (int i=0;i<100;i++) { | 107 for (int i=0;i<100;i++) { |
| 108 switch (R(33)) { | 108 switch (R(33)) { |
| 109 | 109 |
| 110 case 0: | 110 case 0: |
| 111 paint.setColor(make_fill()); | 111 paint.setColor(make_fill()); |
| 112 break; | 112 break; |
| 113 | 113 |
| 114 case 1: | 114 case 1: |
| 115 paint.setAlpha(gRand.nextU() & 0xFF); | 115 paint.setAlpha(gRand.nextU() & 0xFF); |
| 116 break; | 116 break; |
| 117 | 117 |
| 118 case 2: { | 118 case 2: { |
| 119 SkXfermode::Mode mode; | 119 SkXfermode::Mode mode; |
| 120 switch (R(3)) { | 120 switch (R(3)) { |
| 121 case 0: mode = SkXfermode::kSrc_Mode; break; | 121 case 0: mode = SkXfermode::kSrc_Mode; break; |
| 122 case 1: mode = SkXfermode::kXor_Mode; break; | 122 case 1: mode = SkXfermode::kXor_Mode; break; |
| 123 case 2: mode = SkXfermode::kSrcOver_Mode; break; | 123 case 2: mode = SkXfermode::kSrcOver_Mode; break; |
| 124 } | 124 } |
| 125 paint.setXfermode(mode); | 125 paint.setXfermode(mode); |
| 126 } | 126 } |
| 127 break; | 127 break; |
| 128 | 128 |
| 129 case 3: | 129 case 3: |
| 130 switch (R(2)) { | 130 switch (R(2)) { |
| 131 case 0: paint.setStrokeCap(SkPaint::kRound_Cap); break; | 131 case 0: paint.setStrokeCap(SkPaint::kRound_Cap); break; |
| 132 case 1: paint.setStrokeCap(SkPaint::kButt_Cap); break; | 132 case 1: paint.setStrokeCap(SkPaint::kButt_Cap); break; |
| 133 } | 133 } |
| 134 break; | 134 break; |
| 135 | 135 |
| 136 case 4: | 136 case 4: |
| 137 switch (R(2)) { | 137 switch (R(2)) { |
| 138 case 0: paint.setStrokeJoin(SkPaint::kRound_Join); break; | 138 case 0: paint.setStrokeJoin(SkPaint::kRound_Join); break; |
| 139 case 1: paint.setStrokeJoin(SkPaint::kMiter_Join); break; | 139 case 1: paint.setStrokeJoin(SkPaint::kMiter_Join); break; |
| 140 } | 140 } |
| 141 break; | 141 break; |
| 142 | 142 |
| 143 case 5: | 143 case 5: |
| 144 paint.setStrokeWidth(make_number()); | 144 paint.setStrokeWidth(make_number()); |
| 145 break; | 145 break; |
| 146 | 146 |
| 147 case 6: | 147 case 6: |
| 148 paint.setStrokeMiter(make_number()); | 148 paint.setStrokeMiter(make_number()); |
| 149 break; | 149 break; |
| 150 | 150 |
| 151 case 7: | 151 case 7: |
| 152 if (quick == true) break; | 152 if (quick == true) break; |
| 153 paint.setMaskFilter(SkBlurMaskFilter::Create(make_number(), SkBlurMask
Filter::kNormal_BlurStyle))->safeUnref(); | 153 paint.setMaskFilter(SkBlurMaskFilter::Create(make_number(), SkBlurMask
Filter::kNormal_BlurStyle))->safeUnref(); |
| 154 break; | 154 break; |
| 155 | 155 |
| 156 case 8: | 156 case 8: |
| 157 if (quick == true) break; | 157 if (quick == true) break; |
| 158 //ctx.shadowColor = make_fill(); | 158 //ctx.shadowColor = make_fill(); |
| 159 break; | 159 break; |
| 160 | 160 |
| 161 case 9: | 161 case 9: |
| 162 if (quick == true) break; | 162 if (quick == true) break; |
| 163 //ctx.shadowOffsetX = make_number(); | 163 //ctx.shadowOffsetX = make_number(); |
| 164 //ctx.shadowOffsetY = make_number(); | 164 //ctx.shadowOffsetY = make_number(); |
| 165 break; | 165 break; |
| 166 | 166 |
| 167 case 10: | 167 case 10: |
| 168 canvas->restore(); | 168 canvas->restore(); |
| 169 break; | 169 break; |
| 170 | 170 |
| 171 case 11: | 171 case 11: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 canvas->drawPath(path, paint); | 236 canvas->drawPath(path, paint); |
| 237 paint.setStyle(s); | 237 paint.setStyle(s); |
| 238 } break; | 238 } break; |
| 239 | 239 |
| 240 case 22: { | 240 case 22: { |
| 241 SkPaint::Style s = paint.getStyle(); | 241 SkPaint::Style s = paint.getStyle(); |
| 242 paint.setStyle(SkPaint::kFill_Style); | 242 paint.setStyle(SkPaint::kFill_Style); |
| 243 canvas->drawPath(path, paint); | 243 canvas->drawPath(path, paint); |
| 244 paint.setStyle(s); | 244 paint.setStyle(s); |
| 245 } break; | 245 } break; |
| 246 | 246 |
| 247 case 23: { | 247 case 23: { |
| 248 SkRect r; | 248 SkRect r; |
| 249 r.set(make_number(),make_number(),make_number(),make_number()); | 249 r.set(make_number(),make_number(),make_number(),make_number()); |
| 250 SkPaint::Style s = paint.getStyle(); | 250 SkPaint::Style s = paint.getStyle(); |
| 251 paint.setStyle(SkPaint::kStroke_Style); | 251 paint.setStyle(SkPaint::kStroke_Style); |
| 252 canvas->drawRect(r, paint); | 252 canvas->drawRect(r, paint); |
| 253 paint.setStyle(s); | 253 paint.setStyle(s); |
| 254 } break; | 254 } break; |
| 255 | 255 |
| 256 case 24: | 256 case 24: |
| 257 if (quick == true) break; | 257 if (quick == true) break; |
| 258 //ctx.arc(make_number(),make_number(),make_number(),make_number(),make_num
ber(),true); | 258 //ctx.arc(make_number(),make_number(),make_number(),make_number(),make_num
ber(),true); |
| 259 break; | 259 break; |
| 260 | 260 |
| 261 case 25: | 261 case 25: |
| 262 if (quick == true) break; | 262 if (quick == true) break; |
| 263 //ctx.arcTo(make_number(),make_number(),make_number(),make_number(),make_n
umber()); | 263 //ctx.arcTo(make_number(),make_number(),make_number(),make_number(),make_n
umber()); |
| 264 break; | 264 break; |
| 265 | 265 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 293 SkMatrix matrix; | 293 SkMatrix matrix; |
| 294 set2x3(&matrix, make_number(),make_number(),make_number(),make_number(
),make_number(),make_number()); | 294 set2x3(&matrix, make_number(),make_number(),make_number(),make_number(
),make_number(),make_number()); |
| 295 canvas->setMatrix(matrix); | 295 canvas->setMatrix(matrix); |
| 296 } break; | 296 } break; |
| 297 | 297 |
| 298 case 32: | 298 case 32: |
| 299 | 299 |
| 300 if (scale_large == true) { | 300 if (scale_large == true) { |
| 301 | 301 |
| 302 switch (scval) { | 302 switch (scval) { |
| 303 case 0: canvas->scale(-1000000000,1); | 303 case 0: canvas->scale(-1000000000,1); |
| 304 canvas->scale(-1000000000,1); | 304 canvas->scale(-1000000000,1); |
| 305 scval = 1; break; | 305 scval = 1; break; |
| 306 case 1: canvas->scale(-.000000001,1); scval = 2; break; | 306 case 1: canvas->scale(-.000000001,1); scval = 2; break; |
| 307 case 2: canvas->scale(-.000000001,1); scval = 0; break; | 307 case 2: canvas->scale(-.000000001,1); scval = 0; break; |
| 308 } | 308 } |
| 309 | 309 |
| 310 } | 310 } |
| 311 | 311 |
| 312 break; | 312 break; |
| 313 | 313 |
| 314 | 314 |
| 315 | 315 |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 } | 319 } |
| 320 | 320 |
| 321 ////////////////////////////////////////////////////////////////////////////// | 321 ////////////////////////////////////////////////////////////////////////////// |
| 322 | 322 |
| 323 class FuzzView : public SkView { | 323 class FuzzView : public SkView { |
| 324 public: | 324 public: |
| 325 FuzzView() {} | 325 FuzzView() {} |
| 326 | 326 |
| 327 protected: | 327 protected: |
| 328 // overrides from SkEventSink | 328 // overrides from SkEventSink |
| 329 virtual bool onQuery(SkEvent* evt) { | 329 virtual bool onQuery(SkEvent* evt) { |
| 330 if (SampleCode::TitleQ(*evt)) { | 330 if (SampleCode::TitleQ(*evt)) { |
| 331 SampleCode::TitleR(evt, "Fuzzer"); | 331 SampleCode::TitleR(evt, "Fuzzer"); |
| 332 return true; | 332 return true; |
| 333 } | 333 } |
| 334 return this->INHERITED::onQuery(evt); | 334 return this->INHERITED::onQuery(evt); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void drawBG(SkCanvas* canvas) { | 337 void drawBG(SkCanvas* canvas) { |
| 338 canvas->drawColor(0xFFDDDDDD); | 338 canvas->drawColor(0xFFDDDDDD); |
| 339 } | 339 } |
| 340 | 340 |
| 341 virtual void onDraw(SkCanvas* canvas) { | 341 virtual void onDraw(SkCanvas* canvas) { |
| 342 this->drawBG(canvas); | 342 this->drawBG(canvas); |
| 343 do_fuzz(canvas); | 343 do_fuzz(canvas); |
| 344 this->inval(NULL); | 344 this->inval(NULL); |
| 345 } | 345 } |
| 346 | 346 |
| 347 private: | 347 private: |
| 348 typedef SkView INHERITED; | 348 typedef SkView INHERITED; |
| 349 }; | 349 }; |
| 350 | 350 |
| 351 ////////////////////////////////////////////////////////////////////////////// | 351 ////////////////////////////////////////////////////////////////////////////// |
| 352 | 352 |
| 353 static SkView* MyFactory() { return new FuzzView; } | 353 static SkView* MyFactory() { return new FuzzView; } |
| 354 static SkViewRegister reg(MyFactory); | 354 static SkViewRegister reg(MyFactory); |
| 355 | 355 |
| OLD | NEW |