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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 1556553002: Implement an SkPaint-based image filter (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: More randomness for paths and for rasterizer's paint Created 4 years, 11 months 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
« no previous file with comments | « include/effects/SkPaintImageFilter.h ('k') | src/core/SkPathEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "Sk1DPathEffect.h"
9 #include "Sk2DPathEffect.h"
8 #include "SkAlphaThresholdFilter.h" 10 #include "SkAlphaThresholdFilter.h"
11 #include "SkArcToPathEffect.h"
12 #include "SkAnnotation.h"
9 #include "SkBlurImageFilter.h" 13 #include "SkBlurImageFilter.h"
14 #include "SkBlurMaskFilter.h"
10 #include "SkCanvas.h" 15 #include "SkCanvas.h"
11 #include "SkColorCubeFilter.h" 16 #include "SkColorCubeFilter.h"
12 #include "SkColorFilter.h" 17 #include "SkColorFilter.h"
13 #include "SkColorFilterImageFilter.h" 18 #include "SkColorFilterImageFilter.h"
19 #include "SkColorMatrixFilter.h"
14 #include "SkComposeImageFilter.h" 20 #include "SkComposeImageFilter.h"
21 #include "SkCornerPathEffect.h"
22 #include "SkDashPathEffect.h"
15 #include "SkData.h" 23 #include "SkData.h"
24 #include "SkDiscretePathEffect.h"
16 #include "SkDisplacementMapEffect.h" 25 #include "SkDisplacementMapEffect.h"
17 #include "SkDropShadowImageFilter.h" 26 #include "SkDropShadowImageFilter.h"
27 #include "SkEmbossMaskFilter.h"
18 #include "SkFlattenableSerialization.h" 28 #include "SkFlattenableSerialization.h"
19 #include "SkImageSource.h" 29 #include "SkImageSource.h"
30 #include "SkLayerRasterizer.h"
20 #include "SkLightingImageFilter.h" 31 #include "SkLightingImageFilter.h"
32 #include "SkLumaColorFilter.h"
21 #include "SkMagnifierImageFilter.h" 33 #include "SkMagnifierImageFilter.h"
22 #include "SkMatrixConvolutionImageFilter.h" 34 #include "SkMatrixConvolutionImageFilter.h"
23 #include "SkMergeImageFilter.h" 35 #include "SkMergeImageFilter.h"
24 #include "SkMorphologyImageFilter.h" 36 #include "SkMorphologyImageFilter.h"
25 #include "SkOffsetImageFilter.h" 37 #include "SkOffsetImageFilter.h"
38 #include "SkPaintImageFilter.h"
26 #include "SkPerlinNoiseShader.h" 39 #include "SkPerlinNoiseShader.h"
27 #include "SkPictureImageFilter.h" 40 #include "SkPictureImageFilter.h"
28 #include "SkPictureRecorder.h" 41 #include "SkPictureRecorder.h"
29 #include "SkPoint3.h" 42 #include "SkPoint3.h"
30 #include "SkRandom.h" 43 #include "SkRandom.h"
31 #include "SkRectShaderImageFilter.h" 44 #include "SkTableColorFilter.h"
32 #include "SkTestImageFilters.h" 45 #include "SkTestImageFilters.h"
33 #include "SkTileImageFilter.h" 46 #include "SkTileImageFilter.h"
47 #include "SkTypeface.h"
34 #include "SkView.h" 48 #include "SkView.h"
35 #include "SkXfermodeImageFilter.h" 49 #include "SkXfermodeImageFilter.h"
36 #include <stdio.h> 50 #include <stdio.h>
37 #include <time.h> 51 #include <time.h>
38 52
39 //#define SK_ADD_RANDOM_BIT_FLIPS 53 //#define SK_ADD_RANDOM_BIT_FLIPS
40 //#define SK_FUZZER_IS_VERBOSE 54 //#define SK_FUZZER_IS_VERBOSE
41 55
42 static const uint32_t kSeed = (uint32_t)(time(nullptr)); 56 static const uint32_t kSeed = (uint32_t)(time(nullptr));
43 static SkRandom gRand(kSeed); 57 static SkRandom gRand(kSeed);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 101 }
88 102
89 if (!positiveOnly && (R(4) == 1)) v = -v; 103 if (!positiveOnly && (R(4) == 1)) v = -v;
90 return v; 104 return v;
91 } 105 }
92 106
93 static SkScalar make_scalar(bool positiveOnly = false) { 107 static SkScalar make_scalar(bool positiveOnly = false) {
94 return make_number(positiveOnly); 108 return make_number(positiveOnly);
95 } 109 }
96 110
111 static SkString make_string() {
112 int length = R(1000);
113 SkString str(length);
114 for (int i = 0; i < length; ++i) {
115 str[i] = static_cast<char>(R(256));
116 }
117 return str;
118 }
119
120 static SkString make_font_name() {
121 int sel = R(8);
122
123 switch(sel) {
124 case 0: return SkString("Courier New");
125 case 1: return SkString("Helvetica");
126 case 2: return SkString("monospace");
127 case 3: return SkString("sans-serif");
128 case 4: return SkString("serif");
129 case 5: return SkString("Times");
130 case 6: return SkString("Times New Roman");
131 case 7:
132 default:
133 return make_string();
134 }
135 }
136
137 static bool make_bool() {
138 return R(2) == 1;
139 }
140
97 static SkRect make_rect() { 141 static SkRect make_rect() {
98 return SkRect::MakeWH(SkIntToScalar(R(static_cast<float>(kBitmapSize))), 142 return SkRect::MakeWH(SkIntToScalar(R(static_cast<float>(kBitmapSize))),
99 SkIntToScalar(R(static_cast<float>(kBitmapSize)))); 143 SkIntToScalar(R(static_cast<float>(kBitmapSize))));
100 } 144 }
101 145
102 static SkRegion make_region() { 146 static SkRegion make_region() {
103 SkIRect iRegion = SkIRect::MakeXYWH(R(static_cast<float>(kBitmapSize)), 147 SkIRect iRegion = SkIRect::MakeXYWH(R(static_cast<float>(kBitmapSize)),
104 R(static_cast<float>(kBitmapSize)), 148 R(static_cast<float>(kBitmapSize)),
105 R(static_cast<float>(kBitmapSize)), 149 R(static_cast<float>(kBitmapSize)),
106 R(static_cast<float>(kBitmapSize))); 150 R(static_cast<float>(kBitmapSize)));
107 return SkRegion(iRegion); 151 return SkRegion(iRegion);
108 } 152 }
109 153
110 static SkMatrix make_matrix() { 154 static SkMatrix make_matrix() {
111 SkMatrix m; 155 SkMatrix m;
112 for (int i = 0; i < 9; ++i) { 156 for (int i = 0; i < 9; ++i) {
113 m[i] = make_scalar(); 157 m[i] = make_scalar();
114 } 158 }
115 return m; 159 return m;
116 } 160 }
117 161
118 static SkXfermode::Mode make_xfermode() { 162 static SkXfermode::Mode make_xfermode() {
119 return static_cast<SkXfermode::Mode>(R(SkXfermode::kLastMode+1)); 163 return static_cast<SkXfermode::Mode>(R(SkXfermode::kLastMode+1));
120 } 164 }
121 165
166 static SkPaint::Align make_paint_align() {
167 return static_cast<SkPaint::Align>(R(SkPaint::kRight_Align+1));
168 }
169
170 static SkPaint::Hinting make_paint_hinting() {
171 return static_cast<SkPaint::Hinting>(R(SkPaint::kFull_Hinting+1));
172 }
173
174 static SkPaint::Style make_paint_style() {
175 return static_cast<SkPaint::Style>(R(SkPaint::kStrokeAndFill_Style+1));
176 }
177
178 static SkPaint::Cap make_paint_cap() {
179 return static_cast<SkPaint::Cap>(R(SkPaint::kDefault_Cap+1));
180 }
181
182 static SkPaint::Join make_paint_join() {
183 return static_cast<SkPaint::Join>(R(SkPaint::kDefault_Join+1));
184 }
185
186 static SkPaint::TextEncoding make_paint_text_encoding() {
187 return static_cast<SkPaint::TextEncoding>(R(SkPaint::kGlyphID_TextEncoding+1 ));
188 }
189
190 static SkBlurStyle make_blur_style() {
191 return static_cast<SkBlurStyle>(R(kLastEnum_SkBlurStyle+1));
192 }
193
194 static SkBlurMaskFilter::BlurFlags make_blur_mask_filter_flag() {
195 return static_cast<SkBlurMaskFilter::BlurFlags>(R(SkBlurMaskFilter::kAll_Blu rFlag+1));
196 }
197
198 static SkFilterQuality make_filter_quality() {
199 return static_cast<SkFilterQuality>(R(kHigh_SkFilterQuality+1));
200 }
201
202 static SkTypeface::Style make_typeface_style() {
203 return static_cast<SkTypeface::Style>(R(SkTypeface::kBoldItalic+1));
204 }
205
206 static SkPath1DPathEffect::Style make_path_1d_path_effect_style() {
207 return static_cast<SkPath1DPathEffect::Style>(R(SkPath1DPathEffect::kStyleCo unt));
208 }
209
122 static SkColor make_color() { 210 static SkColor make_color() {
123 return (R(2) == 1) ? 0xFFC0F0A0 : 0xFF000090; 211 return (R(2) == 1) ? 0xFFC0F0A0 : 0xFF000090;
124 } 212 }
125 213
126 static SkDropShadowImageFilter::ShadowMode make_shadow_mode() { 214 static SkDropShadowImageFilter::ShadowMode make_shadow_mode() {
127 return (R(2) == 1) ? SkDropShadowImageFilter::kDrawShadowAndForeground_Shado wMode : 215 return (R(2) == 1) ? SkDropShadowImageFilter::kDrawShadowAndForeground_Shado wMode :
128 SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode; 216 SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode;
129 } 217 }
130 218
131 static SkPoint3 make_point() { 219 static SkPoint3 make_point() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 338
251 paint.setAntiAlias(true); 339 paint.setAntiAlias(true);
252 340
253 paint.setColor(SK_ColorRED); 341 paint.setColor(SK_ColorRED);
254 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2 ), SkIntToScalar(kBitmapSize/3), paint); 342 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2 ), SkIntToScalar(kBitmapSize/3), paint);
255 paint.setColor(SK_ColorBLACK); 343 paint.setColor(SK_ColorBLACK);
256 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); 344 paint.setTextSize(SkIntToScalar(kBitmapSize/3));
257 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint); 345 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint);
258 } 346 }
259 347
260 static SkImageFilter* make_image_filter(bool canBeNull = true) { 348 static void rand_color_table(uint8_t* table) {
349 for (int i = 0; i < 256; ++i) {
350 table[i] = R(256);
351 }
352 }
353
354 static SkColorFilter* make_color_filter() {
355 SkColorFilter* colorFilter;
356 switch (R(6)) {
357 case 0: {
358 SkScalar array[20];
359 for (int i = 0; i < 20; ++i) {
360 array[i] = make_scalar();
361 }
362 colorFilter = SkColorMatrixFilter::Create(array);
363 break;
364 }
365 case 1:
366 colorFilter = SkLumaColorFilter::Create();
367 break;
368 case 2: {
369 uint8_t tableA[256];
370 uint8_t tableR[256];
371 uint8_t tableG[256];
372 uint8_t tableB[256];
373 rand_color_table(tableA);
374 rand_color_table(tableR);
375 rand_color_table(tableG);
376 rand_color_table(tableB);
377 colorFilter = SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
378 break;
379 }
380 case 3:
381 colorFilter = SkColorFilter::CreateModeFilter(make_color(), make_xfe rmode());
382 break;
383 case 4:
384 colorFilter = SkColorFilter::CreateLightingFilter(make_color(), make _color());
385 break;
386 case 5:
387 default:
388 colorFilter = nullptr;
389 break;
390 }
391 return colorFilter;
392 }
393
394 static SkPath make_path() {
395 SkPath path;
396 int numOps = R(30);
397 for (int i = 0; i < numOps; ++i) {
398 switch (R(6)) {
399 case 0:
400 path.moveTo(make_scalar(), make_scalar());
401 break;
402 case 1:
403 path.lineTo(make_scalar(), make_scalar());
404 break;
405 case 2:
406 path.quadTo(make_scalar(), make_scalar(), make_scalar(), make_sc alar());
407 break;
408 case 3:
409 path.conicTo(make_scalar(), make_scalar(), make_scalar(), make_s calar(), make_scalar());
410 break;
411 case 4:
412 path.cubicTo(make_scalar(), make_scalar(), make_scalar(),
413 make_scalar(), make_scalar(), make_scalar());
414 break;
415 case 5:
416 default:
417 path.arcTo(make_scalar(), make_scalar(), make_scalar(), make_sca lar(), make_scalar());
418 break;
419
420 }
421 }
422 path.close();
423 return path;
424 }
425
426 static SkPathEffect* make_path_effect(bool canBeNull = true) {
427 SkPathEffect* pathEffect = nullptr;
428 if (canBeNull && (R(3) == 1)) { return pathEffect; }
429
430 switch (R(9)) {
431 case 0:
432 pathEffect = SkArcToPathEffect::Create(make_scalar(true));
433 break;
434 case 1: {
435 SkAutoTUnref<SkPathEffect> outer(make_path_effect(false));
436 SkAutoTUnref<SkPathEffect> inner(make_path_effect(false));
437 pathEffect = SkComposePathEffect::Create(outer, inner);
438 break;
439 }
440 case 2:
441 pathEffect = SkCornerPathEffect::Create(make_scalar());
442 break;
443 case 3: {
444 int count = R(10);
445 SkScalar intervals[10];
446 for (int i = 0; i < count; ++i) {
447 intervals[i] = make_scalar();
448 }
449 pathEffect = SkDashPathEffect::Create(intervals, count, make_scalar( ));
450 break;
451 }
452 case 4:
453 pathEffect = SkDiscretePathEffect::Create(make_scalar(), make_scalar ());
454 break;
455 case 5:
456 pathEffect = SkPath1DPathEffect::Create(make_path(),
457 make_scalar(),
458 make_scalar(),
459 make_path_1d_path_effect_sty le());
460 break;
461 case 6:
462 pathEffect = SkLine2DPathEffect::Create(make_scalar(), make_matrix() );
463 break;
464 case 7:
465 pathEffect = SkPath2DPathEffect::Create(make_matrix(), make_path());
466 break;
467 case 8:
468 default:
469 pathEffect = SkSumPathEffect::Create(make_path_effect(false),
470 make_path_effect(false));
471 break;
472 }
473 return pathEffect;
474 }
475
476 static SkMaskFilter* make_mask_filter() {
477 SkMaskFilter* maskFilter;
478 switch (R(3)) {
479 case 0:
480 maskFilter = SkBlurMaskFilter::Create(make_blur_style(),
481 make_scalar(),
482 make_blur_mask_filter_flag());
483 case 1: {
484 SkEmbossMaskFilter::Light light;
485 for (int i = 0; i < 3; ++i) {
486 light.fDirection[i] = make_scalar();
487 }
488 light.fPad = R(65536);
489 light.fAmbient = R(256);
490 light.fSpecular = R(256);
491 maskFilter = SkEmbossMaskFilter::Create(make_scalar(),
492 light);
493 }
494 case 2:
495 default:
496 maskFilter = nullptr;
497 break;
498 }
499 return maskFilter;
500 }
501
502 static SkImageFilter* make_image_filter(bool canBeNull = true);
503
504 static SkPaint make_paint() {
505 SkPaint paint;
506 paint.setHinting(make_paint_hinting());
507 paint.setAntiAlias(make_bool());
508 paint.setDither(make_bool());
509 paint.setLinearText(make_bool());
510 paint.setSubpixelText(make_bool());
511 paint.setLCDRenderText(make_bool());
512 paint.setEmbeddedBitmapText(make_bool());
513 paint.setAutohinted(make_bool());
514 paint.setVerticalText(make_bool());
515 paint.setUnderlineText(make_bool());
516 paint.setStrikeThruText(make_bool());
517 paint.setFakeBoldText(make_bool());
518 paint.setDevKernText(make_bool());
519 paint.setFilterQuality(make_filter_quality());
520 paint.setStyle(make_paint_style());
521 paint.setColor(make_color());
522 paint.setStrokeWidth(make_scalar());
523 paint.setStrokeMiter(make_scalar());
524 paint.setStrokeCap(make_paint_cap());
525 paint.setStrokeJoin(make_paint_join());
526 paint.setColorFilter(make_color_filter());
527 paint.setXfermodeMode(make_xfermode());
528 paint.setPathEffect(make_path_effect());
529 paint.setMaskFilter(make_mask_filter());
530 SkAutoTUnref<SkTypeface> typeface(
531 SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style ()));
532 paint.setTypeface(typeface);
533 SkLayerRasterizer::Builder rasterizerBuilder;
534 SkPaint paintForRasterizer;
535 if (R(2) == 1) {
536 paintForRasterizer = make_paint();
ajuma 2016/01/08 19:09:08 Made this paint random too.
537 }
538 rasterizerBuilder.addLayer(paintForRasterizer);
539 SkAutoTUnref<SkRasterizer> rasterizer(rasterizerBuilder.detachRasterizer());
540 paint.setRasterizer(rasterizer);
541 paint.setImageFilter(make_image_filter());
542 SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool ()));
543 SkAutoTUnref<SkAnnotation> annotation(
544 SkAnnotation::Create(make_string().c_str(), data));
545 paint.setAnnotation(annotation);
546 paint.setTextAlign(make_paint_align());
547 paint.setTextSize(make_scalar());
548 paint.setTextScaleX(make_scalar());
549 paint.setTextSkewX(make_scalar());
550 paint.setTextEncoding(make_paint_text_encoding());
551 return paint;
552 }
553
554 static SkImageFilter* make_image_filter(bool canBeNull) {
261 SkImageFilter* filter = 0; 555 SkImageFilter* filter = 0;
262 556
263 // Add a 1 in 3 chance to get a nullptr input 557 // Add a 1 in 3 chance to get a nullptr input
264 if (canBeNull && (R(3) == 1)) { return filter; } 558 if (canBeNull && (R(3) == 1)) { return filter; }
265 559
266 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, 560 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
267 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, 561 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
268 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, 562 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
269 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; 563 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS };
270 564
271 switch (R(NUM_FILTERS)) { 565 switch (R(NUM_FILTERS)) {
272 case ALPHA_THRESHOLD: 566 case ALPHA_THRESHOLD:
273 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar()); 567 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar());
274 break; 568 break;
275 case MERGE: 569 case MERGE:
276 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); 570 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode());
277 break; 571 break;
278 case COLOR: 572 case COLOR:
279 { 573 {
280 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ? 574 SkAutoTUnref<SkColorFilter> cf(make_color_filter());
281 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) :
282 SkColorFilter::CreateLightingFilter(make_color(), make_color()) );
283 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 575 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
284 } 576 }
285 break; 577 break;
286 case LUT3D: 578 case LUT3D:
287 { 579 {
288 int cubeDimension; 580 int cubeDimension;
289 SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1 ), (R(2) == 1))); 581 SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1 ), (R(2) == 1)));
290 SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDime nsion)); 582 SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDime nsion));
291 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 583 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
292 } 584 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 make_point(), make_scalar(), make_scalar(), make_color(), 657 make_point(), make_scalar(), make_scalar(), make_color(),
366 make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_ filter()); 658 make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_ filter());
367 break; 659 break;
368 case NOISE: 660 case NOISE:
369 { 661 {
370 SkAutoTUnref<SkShader> shader((R(2) == 1) ? 662 SkAutoTUnref<SkShader> shader((R(2) == 1) ?
371 SkPerlinNoiseShader::CreateFractalNoise( 663 SkPerlinNoiseShader::CreateFractalNoise(
372 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : 664 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
373 SkPerlinNoiseShader::CreateTurbulence( 665 SkPerlinNoiseShader::CreateTurbulence(
374 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); 666 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()));
667 SkPaint paint;
668 paint.setShader(shader);
375 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), 669 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
376 SkIntToScalar(kBitmapSize)) ); 670 SkIntToScalar(kBitmapSize)) );
377 filter = SkRectShaderImageFilter::Create(shader, &cropR); 671 filter = SkPaintImageFilter::Create(paint, &cropR);
378 } 672 }
379 break; 673 break;
380 case DROP_SHADOW: 674 case DROP_SHADOW:
381 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m ake_scalar(true), 675 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m ake_scalar(true),
382 make_scalar(true), make_color(), make_shadow_mode(), make_im age_filter(), 676 make_scalar(true), make_color(), make_shadow_mode(), make_im age_filter(),
383 nullptr); 677 nullptr);
384 break; 678 break;
385 case MORPHOLOGY: 679 case MORPHOLOGY:
386 if (R(2) == 1) { 680 if (R(2) == 1) {
387 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz e)), 681 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz e)),
(...skipping 26 matching lines...) Expand all
414 SkRTreeFactory factory; 708 SkRTreeFactory factory;
415 SkPictureRecorder recorder; 709 SkPictureRecorder recorder;
416 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma pSize), 710 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma pSize),
417 SkIntToScalar(kBitma pSize), 711 SkIntToScalar(kBitma pSize),
418 &factory, 0); 712 &factory, 0);
419 drawSomething(recordingCanvas); 713 drawSomething(recordingCanvas);
420 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 714 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
421 filter = SkPictureImageFilter::Create(pict.get(), make_rect()); 715 filter = SkPictureImageFilter::Create(pict.get(), make_rect());
422 } 716 }
423 break; 717 break;
718 case PAINT:
719 {
720 SkImageFilter::CropRect cropR(make_rect());
721 filter = SkPaintImageFilter::Create(make_paint(), &cropR);
722 }
424 default: 723 default:
425 break; 724 break;
426 } 725 }
427 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); 726 return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
428 } 727 }
429 728
430 static SkImageFilter* make_serialized_image_filter() { 729 static SkImageFilter* make_serialized_image_filter() {
431 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); 730 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false));
432 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); 731 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
433 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); 732 const unsigned char* ptr = static_cast<const unsigned char*>(data->data());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 816 }
518 817
519 private: 818 private:
520 typedef SkView INHERITED; 819 typedef SkView INHERITED;
521 }; 820 };
522 821
523 ////////////////////////////////////////////////////////////////////////////// 822 //////////////////////////////////////////////////////////////////////////////
524 823
525 static SkView* MyFactory() { return new ImageFilterFuzzView; } 824 static SkView* MyFactory() { return new ImageFilterFuzzView; }
526 static SkViewRegister reg(MyFactory); 825 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/effects/SkPaintImageFilter.h ('k') | src/core/SkPathEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698