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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 1821103004: Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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 | « samplecode/SampleColorFilter.cpp ('k') | src/core/SkBlitter.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" 8 #include "Sk1DPathEffect.h"
9 #include "Sk2DPathEffect.h" 9 #include "Sk2DPathEffect.h"
10 #include "SkAlphaThresholdFilter.h" 10 #include "SkAlphaThresholdFilter.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 static SkBitmap bitmap[2]; 291 static SkBitmap bitmap[2];
292 static bool initialized = false; 292 static bool initialized = false;
293 if (!initialized) { 293 if (!initialized) {
294 make_g_bitmap(bitmap[0]); 294 make_g_bitmap(bitmap[0]);
295 make_checkerboard_bitmap(bitmap[1]); 295 make_checkerboard_bitmap(bitmap[1]);
296 initialized = true; 296 initialized = true;
297 } 297 }
298 return bitmap[R(2)]; 298 return bitmap[R(2)];
299 } 299 }
300 300
301 static sk_sp<SkData> make_3Dlut(int* cubeDimension, bool invR, bool invG, bool i nvB) { 301 static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
302 int size = 4 << R(5); 302 int size = 4 << R(5);
303 auto data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size); 303 SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size );
304 SkColor* pixels = (SkColor*)(data->writable_data()); 304 SkColor* pixels = (SkColor*)(data->writable_data());
305 SkAutoTMalloc<uint8_t> lutMemory(size); 305 SkAutoTMalloc<uint8_t> lutMemory(size);
306 SkAutoTMalloc<uint8_t> invLutMemory(size); 306 SkAutoTMalloc<uint8_t> invLutMemory(size);
307 uint8_t* lut = lutMemory.get(); 307 uint8_t* lut = lutMemory.get();
308 uint8_t* invLut = invLutMemory.get(); 308 uint8_t* invLut = invLutMemory.get();
309 const int maxIndex = size - 1; 309 const int maxIndex = size - 1;
310 for (int i = 0; i < size; i++) { 310 for (int i = 0; i < size; i++) {
311 lut[i] = (i * 255) / maxIndex; 311 lut[i] = (i * 255) / maxIndex;
312 invLut[i] = ((maxIndex - i) * 255) / maxIndex; 312 invLut[i] = ((maxIndex - i) * 255) / maxIndex;
313 } 313 }
(...skipping 29 matching lines...) Expand all
343 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); 343 paint.setTextSize(SkIntToScalar(kBitmapSize/3));
344 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint); 344 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint);
345 } 345 }
346 346
347 static void rand_color_table(uint8_t* table) { 347 static void rand_color_table(uint8_t* table) {
348 for (int i = 0; i < 256; ++i) { 348 for (int i = 0; i < 256; ++i) {
349 table[i] = R(256); 349 table[i] = R(256);
350 } 350 }
351 } 351 }
352 352
353 static sk_sp<SkColorFilter> make_color_filter() { 353 static SkColorFilter* make_color_filter() {
354 SkColorFilter* colorFilter;
354 switch (R(6)) { 355 switch (R(6)) {
355 case 0: { 356 case 0: {
356 SkScalar array[20]; 357 SkScalar array[20];
357 for (int i = 0; i < 20; ++i) { 358 for (int i = 0; i < 20; ++i) {
358 array[i] = make_scalar(); 359 array[i] = make_scalar();
359 } 360 }
360 return SkColorFilter::MakeMatrixFilterRowMajor255(array); 361 colorFilter = SkColorMatrixFilter::Create(array);
362 break;
361 } 363 }
362 case 1: 364 case 1:
363 return SkLumaColorFilter::Make(); 365 colorFilter = SkLumaColorFilter::Create();
366 break;
364 case 2: { 367 case 2: {
365 uint8_t tableA[256]; 368 uint8_t tableA[256];
366 uint8_t tableR[256]; 369 uint8_t tableR[256];
367 uint8_t tableG[256]; 370 uint8_t tableG[256];
368 uint8_t tableB[256]; 371 uint8_t tableB[256];
369 rand_color_table(tableA); 372 rand_color_table(tableA);
370 rand_color_table(tableR); 373 rand_color_table(tableR);
371 rand_color_table(tableG); 374 rand_color_table(tableG);
372 rand_color_table(tableB); 375 rand_color_table(tableB);
373 return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB); 376 colorFilter = SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
377 break;
374 } 378 }
375 case 3: 379 case 3:
376 return SkColorFilter::MakeModeFilter(make_color(), make_xfermode()); 380 colorFilter = SkColorFilter::CreateModeFilter(make_color(), make_xfe rmode());
381 break;
377 case 4: 382 case 4:
378 return SkColorMatrixFilter::MakeLightingFilter(make_color(), make_co lor()); 383 colorFilter = SkColorMatrixFilter::CreateLightingFilter(make_color() , make_color());
384 break;
379 case 5: 385 case 5:
380 default: 386 default:
387 colorFilter = nullptr;
381 break; 388 break;
382 } 389 }
383 return nullptr; 390 return colorFilter;
384 } 391 }
385 392
386 static SkPath make_path() { 393 static SkPath make_path() {
387 SkPath path; 394 SkPath path;
388 int numOps = R(30); 395 int numOps = R(30);
389 for (int i = 0; i < numOps; ++i) { 396 for (int i = 0; i < numOps; ++i) {
390 switch (R(6)) { 397 switch (R(6)) {
391 case 0: 398 case 0:
392 path.moveTo(make_scalar(), make_scalar()); 399 path.moveTo(make_scalar(), make_scalar());
393 break; 400 break;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 531 }
525 532
526 SkLayerRasterizer::Builder rasterizerBuilder; 533 SkLayerRasterizer::Builder rasterizerBuilder;
527 SkPaint paintForRasterizer; 534 SkPaint paintForRasterizer;
528 if (R(2) == 1) { 535 if (R(2) == 1) {
529 paintForRasterizer = make_paint(); 536 paintForRasterizer = make_paint();
530 } 537 }
531 rasterizerBuilder.addLayer(paintForRasterizer); 538 rasterizerBuilder.addLayer(paintForRasterizer);
532 paint.setRasterizer(rasterizerBuilder.detach()); 539 paint.setRasterizer(rasterizerBuilder.detach());
533 paint.setImageFilter(make_image_filter()); 540 paint.setImageFilter(make_image_filter());
534 sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool() )); 541 SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool ()));
535 paint.setTextAlign(make_paint_align()); 542 paint.setTextAlign(make_paint_align());
536 paint.setTextSize(make_scalar()); 543 paint.setTextSize(make_scalar());
537 paint.setTextScaleX(make_scalar()); 544 paint.setTextScaleX(make_scalar());
538 paint.setTextSkewX(make_scalar()); 545 paint.setTextSkewX(make_scalar());
539 paint.setTextEncoding(make_paint_text_encoding()); 546 paint.setTextEncoding(make_paint_text_encoding());
540 return paint; 547 return paint;
541 } 548 }
542 549
543 static SkImageFilter* make_image_filter(bool canBeNull) { 550 static SkImageFilter* make_image_filter(bool canBeNull) {
544 SkImageFilter* filter = 0; 551 SkImageFilter* filter = 0;
545 552
546 // Add a 1 in 3 chance to get a nullptr input 553 // Add a 1 in 3 chance to get a nullptr input
547 if (canBeNull && (R(3) == 1)) { return filter; } 554 if (canBeNull && (R(3) == 1)) { return filter; }
548 555
549 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, 556 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
550 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, 557 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
551 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, 558 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
552 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; 559 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS };
553 560
554 switch (R(NUM_FILTERS)) { 561 switch (R(NUM_FILTERS)) {
555 case ALPHA_THRESHOLD: 562 case ALPHA_THRESHOLD:
556 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar()); 563 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar());
557 break; 564 break;
558 case MERGE: 565 case MERGE:
559 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); 566 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode());
560 break; 567 break;
561 case COLOR: 568 case COLOR:
562 { 569 {
563 sk_sp<SkColorFilter> cf(make_color_filter()); 570 SkAutoTUnref<SkColorFilter> cf(make_color_filter());
564 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt er()) : 0; 571 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
565 } 572 }
566 break; 573 break;
567 case LUT3D: 574 case LUT3D:
568 { 575 {
569 int cubeDimension; 576 int cubeDimension;
570 sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1))); 577 SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1 ), (R(2) == 1)));
571 sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension)); 578 SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDime nsion));
572 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt er()) : 0; 579 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
573 } 580 }
574 break; 581 break;
575 case BLUR: 582 case BLUR:
576 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter()); 583 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
577 break; 584 break;
578 case MAGNIFIER: 585 case MAGNIFIER:
579 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true)); 586 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
580 break; 587 break;
581 case DOWN_SAMPLE: 588 case DOWN_SAMPLE:
582 filter = SkDownSampleImageFilter::Create(make_scalar()); 589 filter = SkDownSampleImageFilter::Create(make_scalar());
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 812 }
806 813
807 private: 814 private:
808 typedef SkView INHERITED; 815 typedef SkView INHERITED;
809 }; 816 };
810 817
811 ////////////////////////////////////////////////////////////////////////////// 818 //////////////////////////////////////////////////////////////////////////////
812 819
813 static SkView* MyFactory() { return new ImageFilterFuzzView; } 820 static SkView* MyFactory() { return new ImageFilterFuzzView; }
814 static SkViewRegister reg(MyFactory); 821 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleColorFilter.cpp ('k') | src/core/SkBlitter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698