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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 182983003: Factory methods for heap-allocated SkImageFilter objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 9 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/SkXfermodeImageFilter.h ('k') | src/effects/SkDisplacementMapEffect.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 "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 enum { BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, XFERMODE, OFFSET, COMPOSE, 219 enum { BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, XFERMODE, OFFSET, COMPOSE,
220 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, 220 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
221 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; 221 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS };
222 222
223 switch (R(NUM_FILTERS)) { 223 switch (R(NUM_FILTERS)) {
224 case BICUBIC: 224 case BICUBIC:
225 // Scale is set to 1 here so that it can fit in the DAG without resizing the output 225 // Scale is set to 1 here so that it can fit in the DAG without resizing the output
226 filter = SkBicubicImageFilter::CreateMitchell(SkSize::Make(1, 1), make_i mage_filter()); 226 filter = SkBicubicImageFilter::CreateMitchell(SkSize::Make(1, 1), make_i mage_filter());
227 break; 227 break;
228 case MERGE: 228 case MERGE:
229 filter = new SkMergeImageFilter(make_image_filter(), make_image_filter() , make_xfermode()); 229 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode());
230 break; 230 break;
231 case COLOR: 231 case COLOR:
232 { 232 {
233 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ? 233 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ?
234 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) : 234 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) :
235 SkColorFilter::CreateLightingFilter(make_color(), make_color()) ); 235 SkColorFilter::CreateLightingFilter(make_color(), make_color()) );
236 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 236 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
237 } 237 }
238 break; 238 break;
239 case BLUR: 239 case BLUR:
240 filter = new SkBlurImageFilter(make_scalar(true), make_scalar(true), mak e_image_filter()); 240 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
241 break; 241 break;
242 case MAGNIFIER: 242 case MAGNIFIER:
243 filter = new SkMagnifierImageFilter(make_rect(), make_scalar(true)); 243 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
244 break; 244 break;
245 case XFERMODE: 245 case XFERMODE:
246 { 246 {
247 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(make_xfermode())); 247 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(make_xfermode()));
248 filter = new SkXfermodeImageFilter(mode, make_image_filter(), make_image _filter()); 248 filter = SkXfermodeImageFilter::Create(mode, make_image_filter(), make_i mage_filter());
249 } 249 }
250 break; 250 break;
251 case OFFSET: 251 case OFFSET:
252 filter = new SkOffsetImageFilter(make_scalar(), make_scalar(), make_imag e_filter()); 252 filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_ image_filter());
253 break; 253 break;
254 case COMPOSE: 254 case COMPOSE:
255 filter = new SkComposeImageFilter(make_image_filter(), make_image_filter ()); 255 filter = SkComposeImageFilter::Create(make_image_filter(), make_image_fi lter());
256 break; 256 break;
257 case DISTANT_LIGHT: 257 case DISTANT_LIGHT:
258 filter = (R(2) == 1) ? 258 filter = (R(2) == 1) ?
259 SkLightingImageFilter::CreateDistantLitDiffuse(make_point(), 259 SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
260 make_color(), make_scalar(), make_scalar(), make_image_filter() ) : 260 make_color(), make_scalar(), make_scalar(), make_image_filter() ) :
261 SkLightingImageFilter::CreateDistantLitSpecular(make_point(), 261 SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
262 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10) ), 262 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10) ),
263 make_image_filter()); 263 make_image_filter());
264 break; 264 break;
265 case POINT_LIGHT: 265 case POINT_LIGHT:
(...skipping 19 matching lines...) Expand all
285 SkPerlinNoiseShader::CreateFractalNoise( 285 SkPerlinNoiseShader::CreateFractalNoise(
286 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : 286 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
287 SkPerlinNoiseShader::CreateTubulence( 287 SkPerlinNoiseShader::CreateTubulence(
288 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); 288 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()));
289 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), 289 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
290 SkIntToScalar(kBitmapSize)) ); 290 SkIntToScalar(kBitmapSize)) );
291 filter = SkRectShaderImageFilter::Create(shader, &cropR); 291 filter = SkRectShaderImageFilter::Create(shader, &cropR);
292 } 292 }
293 break; 293 break;
294 case DROP_SHADOW: 294 case DROP_SHADOW:
295 filter = new SkDropShadowImageFilter(make_scalar(), make_scalar(), 295 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(),
296 make_scalar(true), make_color(), make_image_filter()); 296 make_scalar(true), make_color(), make_image_filter());
297 break; 297 break;
298 case MORPHOLOGY: 298 case MORPHOLOGY:
299 if (R(2) == 1) { 299 if (R(2) == 1) {
300 filter = new SkDilateImageFilter(R(static_cast<float>(kBitmapSize)), 300 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz e)),
301 R(static_cast<float>(kBitmapSize)), make_image_filter()); 301 R(static_cast<float>(kBitmapSize)), make_image_filter());
302 } else { 302 } else {
303 filter = new SkErodeImageFilter(R(static_cast<float>(kBitmapSize)), 303 filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize )),
304 R(static_cast<float>(kBitmapSize)), make_image_filter()); 304 R(static_cast<float>(kBitmapSize)), make_image_filter());
305 } 305 }
306 break; 306 break;
307 case BITMAP: 307 case BITMAP:
308 if (R(2) == 1) { 308 if (R(2) == 1) {
309 filter = new SkBitmapSource(make_bitmap(), make_rect(), make_rect()) ; 309 filter = SkBitmapSource::Create(make_bitmap(), make_rect(), make_rec t());
310 } else { 310 } else {
311 filter = new SkBitmapSource(make_bitmap()); 311 filter = SkBitmapSource::Create(make_bitmap());
312 } 312 }
313 break; 313 break;
314 case DISPLACE: 314 case DISPLACE:
315 filter = new SkDisplacementMapEffect(make_channel_selector_type(), 315 filter = SkDisplacementMapEffect::Create(make_channel_selector_type(),
316 make_channel_selector_type(), make_scalar(), 316 make_channel_selector_type(), m ake_scalar(),
317 make_image_filter(false), make_image_filter()); 317 make_image_filter(false), make_ image_filter());
318 break; 318 break;
319 case TILE: 319 case TILE:
320 filter = new SkTileImageFilter(make_rect(), make_rect(), make_image_filt er(false)); 320 filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_ filter(false));
321 break; 321 break;
322 case PICTURE: 322 case PICTURE:
323 { 323 {
324 SkPicture* pict = NULL; 324 SkPicture* pict = NULL;
325 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION 325 #ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION
326 pict = new SkPicture; 326 pict = new SkPicture;
327 SkAutoUnref aur(pict); 327 SkAutoUnref aur(pict);
328 drawSomething(pict->beginRecording(kBitmapSize, kBitmapSize)); 328 drawSomething(pict->beginRecording(kBitmapSize, kBitmapSize));
329 pict->endRecording(); 329 pict->endRecording();
330 #endif 330 #endif
331 filter = new SkPictureImageFilter(pict, make_rect()); 331 filter = SkPictureImageFilter::Create(pict, make_rect());
332 } 332 }
333 break; 333 break;
334 default: 334 default:
335 break; 335 break;
336 } 336 }
337 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); 337 return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
338 } 338 }
339 339
340 static SkImageFilter* make_serialized_image_filter() { 340 static SkImageFilter* make_serialized_image_filter() {
341 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); 341 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 427 }
428 428
429 private: 429 private:
430 typedef SkView INHERITED; 430 typedef SkView INHERITED;
431 }; 431 };
432 432
433 ////////////////////////////////////////////////////////////////////////////// 433 //////////////////////////////////////////////////////////////////////////////
434 434
435 static SkView* MyFactory() { return new ImageFilterFuzzView; } 435 static SkView* MyFactory() { return new ImageFilterFuzzView; }
436 static SkViewRegister reg(MyFactory); 436 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/effects/SkXfermodeImageFilter.h ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698