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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 44573002: Enabling validation code in serialization and adding serialization to fuzzer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1
2 /* 1 /*
3 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 #include "SampleCode.h" 7 #include "SampleCode.h"
9 #include "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
11 #include "SkBlurImageFilter.h" 11 #include "SkBlurImageFilter.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
14 #include "SkColorFilterImageFilter.h" 14 #include "SkColorFilterImageFilter.h"
15 #include "SkComposeImageFilter.h" 15 #include "SkComposeImageFilter.h"
16 #include "SkBitmapDevice.h" 16 #include "SkData.h"
17 #include "SkDisplacementMapEffect.h" 17 #include "SkDisplacementMapEffect.h"
18 #include "SkDropShadowImageFilter.h" 18 #include "SkDropShadowImageFilter.h"
19 #include "SkFlattenableSerialization.h" 19 #include "SkFlattenableSerialization.h"
20 #include "SkLightingImageFilter.h" 20 #include "SkLightingImageFilter.h"
21 #include "SkMagnifierImageFilter.h" 21 #include "SkMagnifierImageFilter.h"
22 #include "SkMergeImageFilter.h" 22 #include "SkMergeImageFilter.h"
23 #include "SkMorphologyImageFilter.h" 23 #include "SkMorphologyImageFilter.h"
24 #include "SkOffsetImageFilter.h" 24 #include "SkOffsetImageFilter.h"
25 #include "SkPerlinNoiseShader.h" 25 #include "SkPerlinNoiseShader.h"
26 #include "SkRandom.h" 26 #include "SkRandom.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 filter = new SkDisplacementMapEffect(make_channel_selector_type(), 255 filter = new SkDisplacementMapEffect(make_channel_selector_type(),
256 make_channel_selector_type(), make_scalar(), 256 make_channel_selector_type(), make_scalar(),
257 make_image_filter(false), make_image_filter()); 257 make_image_filter(false), make_image_filter());
258 break; 258 break;
259 default: 259 default:
260 break; 260 break;
261 } 261 }
262 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); 262 return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
263 } 263 }
264 264
265 SkImageFilter* make_serialized_image_filter() {
266 SkImageFilter* filter = make_image_filter(false);
mtklein 2013/10/25 16:17:31 Coming new at this, sorry if these are dumb questi
Stephen White 2013/10/25 16:36:21 Oooh, good catch. This probably leaks (Alexis can
sugoi1 2013/10/25 17:15:04 I probably had an initial implementation that gave
267 SkData* data = SkValidatingSerializeFlattenable(filter);
268 unsigned char* ptr = static_cast<unsigned char*>(const_cast<void*>(data->dat a()));
mtklein 2013/10/25 16:17:31 Seems like you don't need the const_cast until you
sugoi1 2013/10/25 17:15:04 Done.
269 size_t len = data->size();
270 #ifdef SK_ADD_RANDOM_BIT_FLIPS
271 unsigned char* p = ptr;
272 for (size_t i = 0; i < len; ++i, ++p) {
273 if ((R(1000) == 1)) { // 0.1% of the time, flip a bit
274 *p ^= (1 << R(8));
275 }
276 }
277 #endif // SK_ADD_RANDOM_BIT_FLIPS
278 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len,
279 SkImageFilter::GetFlattenableType());
280 SkASSERT(NULL != flattenable);
281 return static_cast<SkImageFilter*>(flattenable);
282 }
283
265 static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai nt) { 284 static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai nt) {
266 canvas->save(); 285 canvas->save();
267 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 286 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
268 SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize))); 287 SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)));
269 canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint ); 288 canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint );
270 canvas->restore(); 289 canvas->restore();
271 } 290 }
272 291
273 static void do_fuzz(SkCanvas* canvas) { 292 static void do_fuzz(SkCanvas* canvas) {
274 SkPaint paint; 293 SkPaint paint;
275 paint.setImageFilter(make_image_filter()); 294 paint.setImageFilter(make_serialized_image_filter());
276 drawClippedBitmap(canvas, 0, 0, paint); 295 drawClippedBitmap(canvas, 0, 0, paint);
277 } 296 }
278 297
279 ////////////////////////////////////////////////////////////////////////////// 298 //////////////////////////////////////////////////////////////////////////////
280 299
281 class ImageFilterFuzzView : public SampleView { 300 class ImageFilterFuzzView : public SampleView {
282 public: 301 public:
283 ImageFilterFuzzView() { 302 ImageFilterFuzzView() {
284 this->setBGColor(0xFFDDDDDD); 303 this->setBGColor(0xFFDDDDDD);
285 } 304 }
(...skipping 18 matching lines...) Expand all
304 } 323 }
305 324
306 private: 325 private:
307 typedef SkView INHERITED; 326 typedef SkView INHERITED;
308 }; 327 };
309 328
310 ////////////////////////////////////////////////////////////////////////////// 329 //////////////////////////////////////////////////////////////////////////////
311 330
312 static SkView* MyFactory() { return new ImageFilterFuzzView; } 331 static SkView* MyFactory() { return new ImageFilterFuzzView; }
313 static SkViewRegister reg(MyFactory); 332 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698