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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 116773002: Fixed more fuzzer issues (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Changed isAvailable for validateAvailable Created 7 years 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #include "SampleCode.h" 7 #include "SampleCode.h"
8 #include "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 static SkPoint3 make_point() { 105 static SkPoint3 make_point() {
106 return SkPoint3(make_scalar(), make_scalar(), make_scalar(true)); 106 return SkPoint3(make_scalar(), make_scalar(), make_scalar(true));
107 } 107 }
108 108
109 static SkDisplacementMapEffect::ChannelSelectorType make_channel_selector_type() { 109 static SkDisplacementMapEffect::ChannelSelectorType make_channel_selector_type() {
110 return static_cast<SkDisplacementMapEffect::ChannelSelectorType>(R(4)+1); 110 return static_cast<SkDisplacementMapEffect::ChannelSelectorType>(R(4)+1);
111 } 111 }
112 112
113 static void make_g_bitmap(SkBitmap& bitmap) { 113 static void make_g_bitmap(SkBitmap& bitmap) {
114 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); 114 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, k BitmapSize);
115 bitmap.allocPixels(); 115 while (!bitmap.allocPixels()) {
116 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSiz e, kBitmapSize);
117 }
116 SkBitmapDevice device(bitmap); 118 SkBitmapDevice device(bitmap);
117 SkCanvas canvas(&device); 119 SkCanvas canvas(&device);
118 canvas.clear(0x00000000); 120 canvas.clear(0x00000000);
119 SkPaint paint; 121 SkPaint paint;
120 paint.setAntiAlias(true); 122 paint.setAntiAlias(true);
121 paint.setColor(0xFF884422); 123 paint.setColor(0xFF884422);
122 paint.setTextSize(SkIntToScalar(kBitmapSize/2)); 124 paint.setTextSize(SkIntToScalar(kBitmapSize/2));
123 const char* str = "g"; 125 const char* str = "g";
124 canvas.drawText(str, strlen(str), SkIntToScalar(kBitmapSize/8), 126 canvas.drawText(str, strlen(str), SkIntToScalar(kBitmapSize/8),
125 SkIntToScalar(kBitmapSize/4), paint); 127 SkIntToScalar(kBitmapSize/4), paint);
126 } 128 }
127 129
128 static void make_checkerboard_bitmap(SkBitmap& bitmap) { 130 static void make_checkerboard_bitmap(SkBitmap& bitmap) {
129 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); 131 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, k BitmapSize);
130 bitmap.allocPixels(); 132 while (!bitmap.allocPixels()) {
133 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSiz e, kBitmapSize);
134 }
131 SkBitmapDevice device(bitmap); 135 SkBitmapDevice device(bitmap);
132 SkCanvas canvas(&device); 136 SkCanvas canvas(&device);
133 canvas.clear(0x00000000); 137 canvas.clear(0x00000000);
134 SkPaint darkPaint; 138 SkPaint darkPaint;
135 darkPaint.setColor(0xFF804020); 139 darkPaint.setColor(0xFF804020);
136 SkPaint lightPaint; 140 SkPaint lightPaint;
137 lightPaint.setColor(0xFF244484); 141 lightPaint.setColor(0xFF244484);
138 const int i = kBitmapSize / 8; 142 const int i = kBitmapSize / 8;
139 const SkScalar f = SkIntToScalar(i); 143 const SkScalar f = SkIntToScalar(i);
140 for (int y = 0; y < kBitmapSize; y += i) { 144 for (int y = 0; y < kBitmapSize; y += i) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 309
306 static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai nt) { 310 static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai nt) {
307 canvas->save(); 311 canvas->save();
308 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 312 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
309 SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize))); 313 SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)));
310 canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint ); 314 canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint );
311 canvas->restore(); 315 canvas->restore();
312 } 316 }
313 317
314 static void do_fuzz(SkCanvas* canvas) { 318 static void do_fuzz(SkCanvas* canvas) {
319 SkImageFilter* filter = make_serialized_image_filter();
320
315 #ifdef SK_FUZZER_IS_VERBOSE 321 #ifdef SK_FUZZER_IS_VERBOSE
316 static uint32_t filterId = 0; 322 static uint32_t numFilters = 0;
317 if (0 == filterId) { 323 static uint32_t numValidFilters = 0;
324 if (0 == numFilters) {
318 printf("Fuzzing with %u\n", kSeed); 325 printf("Fuzzing with %u\n", kSeed);
319 } 326 }
320 printf("Filter no %u\r", filterId); 327 numFilters++;
328 if (NULL != filter) {
329 numValidFilters++;
330 }
331 printf("Filter no : %u. Valid filters so far : %u\r", numFilters, numValidFi lters);
321 fflush(stdout); 332 fflush(stdout);
322 filterId++;
323 #endif 333 #endif
324 334
325 SkPaint paint; 335 SkPaint paint;
326 SkSafeUnref(paint.setImageFilter(make_serialized_image_filter())); 336 SkSafeUnref(paint.setImageFilter(filter));
327 drawClippedBitmap(canvas, 0, 0, paint); 337 drawClippedBitmap(canvas, 0, 0, paint);
328 } 338 }
329 339
330 ////////////////////////////////////////////////////////////////////////////// 340 //////////////////////////////////////////////////////////////////////////////
331 341
332 class ImageFilterFuzzView : public SampleView { 342 class ImageFilterFuzzView : public SampleView {
333 public: 343 public:
334 ImageFilterFuzzView() { 344 ImageFilterFuzzView() {
335 this->setBGColor(0xFFDDDDDD); 345 this->setBGColor(0xFFDDDDDD);
336 } 346 }
(...skipping 18 matching lines...) Expand all
355 } 365 }
356 366
357 private: 367 private:
358 typedef SkView INHERITED; 368 typedef SkView INHERITED;
359 }; 369 };
360 370
361 ////////////////////////////////////////////////////////////////////////////// 371 //////////////////////////////////////////////////////////////////////////////
362 372
363 static SkView* MyFactory() { return new ImageFilterFuzzView; } 373 static SkView* MyFactory() { return new ImageFilterFuzzView; }
364 static SkViewRegister reg(MyFactory); 374 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698