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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 1825073002: 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: remove flag 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 SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) { 301 static sk_sp<SkData> make_3Dlut(int* cubeDimension, bool invR, bool invG, bool i nvB) {
302 int size = 4 << R(5); 302 int size = 4 << R(5);
303 SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size ); 303 auto data = SkData::MakeUninitialized(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 SkColorFilter* make_color_filter() { 353 static sk_sp<SkColorFilter> make_color_filter() {
354 SkColorFilter* colorFilter;
355 switch (R(6)) { 354 switch (R(6)) {
356 case 0: { 355 case 0: {
357 SkScalar array[20]; 356 SkScalar array[20];
358 for (int i = 0; i < 20; ++i) { 357 for (int i = 0; i < 20; ++i) {
359 array[i] = make_scalar(); 358 array[i] = make_scalar();
360 } 359 }
361 colorFilter = SkColorMatrixFilter::Create(array); 360 return SkColorFilter::MakeMatrixFilterRowMajor255(array);
362 break;
363 } 361 }
364 case 1: 362 case 1:
365 colorFilter = SkLumaColorFilter::Create(); 363 return SkLumaColorFilter::Make();
366 break;
367 case 2: { 364 case 2: {
368 uint8_t tableA[256]; 365 uint8_t tableA[256];
369 uint8_t tableR[256]; 366 uint8_t tableR[256];
370 uint8_t tableG[256]; 367 uint8_t tableG[256];
371 uint8_t tableB[256]; 368 uint8_t tableB[256];
372 rand_color_table(tableA); 369 rand_color_table(tableA);
373 rand_color_table(tableR); 370 rand_color_table(tableR);
374 rand_color_table(tableG); 371 rand_color_table(tableG);
375 rand_color_table(tableB); 372 rand_color_table(tableB);
376 colorFilter = SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB); 373 return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
377 break;
378 } 374 }
379 case 3: 375 case 3:
380 colorFilter = SkColorFilter::CreateModeFilter(make_color(), make_xfe rmode()); 376 return SkColorFilter::MakeModeFilter(make_color(), make_xfermode());
381 break;
382 case 4: 377 case 4:
383 colorFilter = SkColorMatrixFilter::CreateLightingFilter(make_color() , make_color()); 378 return SkColorMatrixFilter::MakeLightingFilter(make_color(), make_co lor());
384 break;
385 case 5: 379 case 5:
386 default: 380 default:
387 colorFilter = nullptr;
388 break; 381 break;
389 } 382 }
390 return colorFilter; 383 return nullptr;
391 } 384 }
392 385
393 static SkPath make_path() { 386 static SkPath make_path() {
394 SkPath path; 387 SkPath path;
395 int numOps = R(30); 388 int numOps = R(30);
396 for (int i = 0; i < numOps; ++i) { 389 for (int i = 0; i < numOps; ++i) {
397 switch (R(6)) { 390 switch (R(6)) {
398 case 0: 391 case 0:
399 path.moveTo(make_scalar(), make_scalar()); 392 path.moveTo(make_scalar(), make_scalar());
400 break; 393 break;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 524 }
532 525
533 SkLayerRasterizer::Builder rasterizerBuilder; 526 SkLayerRasterizer::Builder rasterizerBuilder;
534 SkPaint paintForRasterizer; 527 SkPaint paintForRasterizer;
535 if (R(2) == 1) { 528 if (R(2) == 1) {
536 paintForRasterizer = make_paint(); 529 paintForRasterizer = make_paint();
537 } 530 }
538 rasterizerBuilder.addLayer(paintForRasterizer); 531 rasterizerBuilder.addLayer(paintForRasterizer);
539 paint.setRasterizer(rasterizerBuilder.detach()); 532 paint.setRasterizer(rasterizerBuilder.detach());
540 paint.setImageFilter(make_image_filter()); 533 paint.setImageFilter(make_image_filter());
541 SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool ())); 534 sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool() ));
542 paint.setTextAlign(make_paint_align()); 535 paint.setTextAlign(make_paint_align());
543 paint.setTextSize(make_scalar()); 536 paint.setTextSize(make_scalar());
544 paint.setTextScaleX(make_scalar()); 537 paint.setTextScaleX(make_scalar());
545 paint.setTextSkewX(make_scalar()); 538 paint.setTextSkewX(make_scalar());
546 paint.setTextEncoding(make_paint_text_encoding()); 539 paint.setTextEncoding(make_paint_text_encoding());
547 return paint; 540 return paint;
548 } 541 }
549 542
550 static SkImageFilter* make_image_filter(bool canBeNull) { 543 static SkImageFilter* make_image_filter(bool canBeNull) {
551 SkImageFilter* filter = 0; 544 SkImageFilter* filter = 0;
552 545
553 // Add a 1 in 3 chance to get a nullptr input 546 // Add a 1 in 3 chance to get a nullptr input
554 if (canBeNull && (R(3) == 1)) { return filter; } 547 if (canBeNull && (R(3) == 1)) { return filter; }
555 548
556 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, 549 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
557 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, 550 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
558 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, 551 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
559 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; 552 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS };
560 553
561 switch (R(NUM_FILTERS)) { 554 switch (R(NUM_FILTERS)) {
562 case ALPHA_THRESHOLD: 555 case ALPHA_THRESHOLD:
563 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar()); 556 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar());
564 break; 557 break;
565 case MERGE: 558 case MERGE:
566 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); 559 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode());
567 break; 560 break;
568 case COLOR: 561 case COLOR:
569 { 562 {
570 SkAutoTUnref<SkColorFilter> cf(make_color_filter()); 563 sk_sp<SkColorFilter> cf(make_color_filter());
571 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 564 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt er()) : 0;
572 } 565 }
573 break; 566 break;
574 case LUT3D: 567 case LUT3D:
575 { 568 {
576 int cubeDimension; 569 int cubeDimension;
577 SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1 ), (R(2) == 1))); 570 sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
578 SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDime nsion)); 571 sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension));
579 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 572 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt er()) : 0;
580 } 573 }
581 break; 574 break;
582 case BLUR: 575 case BLUR:
583 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter()); 576 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
584 break; 577 break;
585 case MAGNIFIER: 578 case MAGNIFIER:
586 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true)); 579 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
587 break; 580 break;
588 case DOWN_SAMPLE: 581 case DOWN_SAMPLE:
589 filter = SkDownSampleImageFilter::Create(make_scalar()); 582 filter = SkDownSampleImageFilter::Create(make_scalar());
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 } 805 }
813 806
814 private: 807 private:
815 typedef SkView INHERITED; 808 typedef SkView INHERITED;
816 }; 809 };
817 810
818 ////////////////////////////////////////////////////////////////////////////// 811 //////////////////////////////////////////////////////////////////////////////
819 812
820 static SkView* MyFactory() { return new ImageFilterFuzzView; } 813 static SkView* MyFactory() { return new ImageFilterFuzzView; }
821 static SkViewRegister reg(MyFactory); 814 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