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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1858813002: Update SkColorFilterImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 8 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 | « src/effects/SkColorFilterImageFilter.cpp ('k') | tests/PictureTest.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 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 SkMatrix matrix; 157 SkMatrix matrix;
158 158
159 matrix.setTranslate(SK_Scalar1, SK_Scalar1); 159 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
160 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); 160 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
161 161
162 { 162 {
163 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, 163 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
164 SkXfermode::kS rcIn_Mode)); 164 SkXfermode::kS rcIn_Mode));
165 165
166 this->addFilter("color filter", 166 this->addFilter("color filter",
167 SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect )); 167 SkColorFilterImageFilter::Make(cf, input, cropRect).release());
168 } 168 }
169 169
170 { 170 {
171 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_c ircle(64, 64))); 171 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_c ircle(64, 64)));
172 sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gr adientImage))); 172 sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gr adientImage)));
173 173
174 this->addFilter("displacement map", SkDisplacementMapEffect::Create( 174 this->addFilter("displacement map", SkDisplacementMapEffect::Create(
175 SkDisplacementMapEffect::kR_ChannelSelectorType, 175 SkDisplacementMapEffect::kR_ChannelSelectorType,
176 SkDisplacementMapEffect::kB_ChannelSelectorType, 176 SkDisplacementMapEffect::kB_ChannelSelectorType,
177 20.0f, gradientSource.get(), input.get(), cropRect)); 177 20.0f, gradientSource.get(), input.get(), cropRect));
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 SkIntToScalar(i), 326 SkIntToScalar(i),
327 SkIntToScalar(i), 327 SkIntToScalar(i),
328 SkIntToScalar(i)), darkPaint); 328 SkIntToScalar(i)), darkPaint);
329 canvas->restore(); 329 canvas->restore();
330 } 330 }
331 } 331 }
332 332
333 return surface->makeImageSnapshot(); 333 return surface->makeImageSnapshot();
334 } 334 }
335 335
336 static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) { 336 static sk_sp<SkImageFilter> make_scale(float amount, sk_sp<SkImageFilter> input) {
337 SkScalar s = amount; 337 SkScalar s = amount;
338 SkScalar matrix[20] = { s, 0, 0, 0, 0, 338 SkScalar matrix[20] = { s, 0, 0, 0, 0,
339 0, s, 0, 0, 0, 339 0, s, 0, 0, 0,
340 0, 0, s, 0, 0, 340 0, 0, s, 0, 0,
341 0, 0, 0, s, 0 }; 341 0, 0, 0, s, 0 };
342 auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); 342 sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matri x));
343 return SkColorFilterImageFilter::Create(filter.get(), input); 343 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
344 } 344 }
345 345
346 static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter:: CropRect* cropRect) { 346 static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input,
347 const SkImageFilter::CropRect* cropRe ct) {
347 SkScalar matrix[20]; 348 SkScalar matrix[20];
348 memset(matrix, 0, 20 * sizeof(SkScalar)); 349 memset(matrix, 0, 20 * sizeof(SkScalar));
349 matrix[0] = matrix[5] = matrix[10] = 0.2126f; 350 matrix[0] = matrix[5] = matrix[10] = 0.2126f;
350 matrix[1] = matrix[6] = matrix[11] = 0.7152f; 351 matrix[1] = matrix[6] = matrix[11] = 0.7152f;
351 matrix[2] = matrix[7] = matrix[12] = 0.0722f; 352 matrix[2] = matrix[7] = matrix[12] = 0.0722f;
352 matrix[18] = 1.0f; 353 matrix[18] = 1.0f;
353 auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); 354 sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matri x));
354 return SkColorFilterImageFilter::Create(filter.get(), input, cropRect); 355 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), c ropRect);
355 } 356 }
356 357
357 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR ect* cropRect) { 358 static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input,
358 auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_M ode)); 359 const SkImageFilter::CropRect* cropRect) {
359 return SkColorFilterImageFilter::Create(filter.get(), input, cropRect); 360 sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
361 SkXfermode::kSrcIn _Mode));
362 return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), c ropRect);
360 } 363 }
361 364
362 static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, 365 static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
363 SkImageFilter::Proxy * proxy, 366 SkImageFilter::Proxy * proxy,
364 int widthHeight) { 367 int widthHeight) {
365 if (context) { 368 if (context) {
366 GrSurfaceDesc desc; 369 GrSurfaceDesc desc;
367 desc.fConfig = kSkia8888_GrPixelConfig; 370 desc.fConfig = kSkia8888_GrPixelConfig;
368 desc.fFlags = kRenderTarget_GrSurfaceFlag; 371 desc.fFlags = kRenderTarget_GrSurfaceFlag;
369 desc.fWidth = widthHeight; 372 desc.fWidth = widthHeight;
(...skipping 18 matching lines...) Expand all
388 391
389 canvas->clear(0x0); 392 canvas->clear(0x0);
390 393
391 return surf->makeImageSnapshot(); 394 return surf->makeImageSnapshot();
392 } 395 }
393 396
394 397
395 DEF_TEST(ImageFilter, reporter) { 398 DEF_TEST(ImageFilter, reporter) {
396 { 399 {
397 // Check that two non-clipping color-matrice-filters concatenate into a single filter. 400 // Check that two non-clipping color-matrice-filters concatenate into a single filter.
398 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); 401 sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, nullptr));
399 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); 402 sk_sp<SkImageFilter> quarterBrightness(make_scale(0.5f, std::move(halfBr ightness)));
400 REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0)); 403 REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0));
401 SkColorFilter* cf; 404 SkColorFilter* cf;
402 REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); 405 REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf));
403 REPORTER_ASSERT(reporter, cf->asColorMatrix(nullptr)); 406 REPORTER_ASSERT(reporter, cf->asColorMatrix(nullptr));
404 cf->unref(); 407 cf->unref();
405 } 408 }
406 409
407 { 410 {
408 // Check that a clipping color-matrice-filter followed by a color-matric e-filters 411 // Check that a clipping color-matrice-filter followed by a color-matric e-filters
409 // concatenates into a single filter, but not a matrixfilter (due to cla mping). 412 // concatenates into a single filter, but not a matrixfilter (due to cla mping).
410 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); 413 sk_sp<SkImageFilter> doubleBrightness(make_scale(2.0f, nullptr));
411 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright ness)); 414 sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, std::move(doubleBri ghtness)));
412 REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0)); 415 REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0));
413 SkColorFilter* cf; 416 SkColorFilter* cf;
414 REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf)); 417 REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf));
415 REPORTER_ASSERT(reporter, !cf->asColorMatrix(nullptr)); 418 REPORTER_ASSERT(reporter, !cf->asColorMatrix(nullptr));
416 cf->unref(); 419 cf->unref();
417 } 420 }
418 421
419 { 422 {
420 // Check that a color filter image filter without a crop rect can be 423 // Check that a color filter image filter without a crop rect can be
421 // expressed as a color filter. 424 // expressed as a color filter.
422 SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); 425 sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
423 REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr)); 426 REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
424 } 427 }
425 428
426 { 429 {
427 // Check that a colorfilterimage filter without a crop rect but with an input 430 // Check that a colorfilterimage filter without a crop rect but with an input
428 // that is another colorfilterimage can be expressed as a colorfilter (c omposed). 431 // that is another colorfilterimage can be expressed as a colorfilter (c omposed).
429 SkAutoTUnref<SkImageFilter> mode(make_blue(nullptr, nullptr)); 432 sk_sp<SkImageFilter> mode(make_blue(nullptr, nullptr));
430 SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, nullptr)); 433 sk_sp<SkImageFilter> gray(make_grayscale(std::move(mode), nullptr));
431 REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr)); 434 REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
432 } 435 }
433 436
434 { 437 {
435 // Test that if we exceed the limit of what ComposeColorFilter can combi ne, we still 438 // Test that if we exceed the limit of what ComposeColorFilter can combi ne, we still
436 // can build the DAG and won't assert if we call asColorFilter. 439 // can build the DAG and won't assert if we call asColorFilter.
437 SkAutoTUnref<SkImageFilter> filter(make_blue(nullptr, nullptr)); 440 sk_sp<SkImageFilter> filter(make_blue(nullptr, nullptr));
438 const int kWayTooManyForComposeColorFilter = 100; 441 const int kWayTooManyForComposeColorFilter = 100;
439 for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) { 442 for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) {
440 filter.reset(make_blue(filter, nullptr)); 443 filter = make_blue(filter, nullptr);
441 // the first few of these will succeed, but after we hit the interna l limit, 444 // the first few of these will succeed, but after we hit the interna l limit,
442 // it will then return false. 445 // it will then return false.
443 (void)filter->asColorFilter(nullptr); 446 (void)filter->asColorFilter(nullptr);
444 } 447 }
445 } 448 }
446 449
447 { 450 {
448 // Check that a color filter image filter with a crop rect cannot 451 // Check that a color filter image filter with a crop rect cannot
449 // be expressed as a color filter. 452 // be expressed as a color filter.
450 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); 453 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
451 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRe ct)); 454 sk_sp<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
452 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr)) ; 455 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr)) ;
453 } 456 }
454 457
455 { 458 {
456 // Check that two non-commutative matrices are concatenated in 459 // Check that two non-commutative matrices are concatenated in
457 // the correct order. 460 // the correct order.
458 SkScalar blueToRedMatrix[20] = { 0 }; 461 SkScalar blueToRedMatrix[20] = { 0 };
459 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; 462 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
460 SkScalar redToGreenMatrix[20] = { 0 }; 463 SkScalar redToGreenMatrix[20] = { 0 };
461 redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1; 464 redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
462 auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatri x)); 465 sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor25 5(blueToRedMatrix));
463 SkAutoTUnref<SkImageFilter> filter1(SkColorFilterImageFilter::Create(blu eToRed.get())); 466 sk_sp<SkImageFilter> filter1(SkColorFilterImageFilter::Make(std::move(bl ueToRed),
464 auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMat rix)); 467 nullptr));
465 SkAutoTUnref<SkImageFilter> filter2(SkColorFilterImageFilter::Create(red ToGreen.get(), filter1.get())); 468 sk_sp<SkColorFilter> redToGreen(SkColorFilter::MakeMatrixFilterRowMajor2 55(redToGreenMatrix));
469 sk_sp<SkImageFilter> filter2(SkColorFilterImageFilter::Make(std::move(re dToGreen),
470 std::move(fi lter1)));
466 471
467 SkBitmap result; 472 SkBitmap result;
468 result.allocN32Pixels(kBitmapSize, kBitmapSize); 473 result.allocN32Pixels(kBitmapSize, kBitmapSize);
469 474
470 SkPaint paint; 475 SkPaint paint;
471 paint.setColor(SK_ColorBLUE); 476 paint.setColor(SK_ColorBLUE);
472 paint.setImageFilter(filter2.get()); 477 paint.setImageFilter(std::move(filter2));
473 SkCanvas canvas(result); 478 SkCanvas canvas(result);
474 canvas.clear(0x0); 479 canvas.clear(0x0);
475 SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize)); 480 SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize));
476 canvas.drawRect(rect, paint); 481 canvas.drawRect(rect, paint);
477 uint32_t pixel = *result.getAddr32(0, 0); 482 uint32_t pixel = *result.getAddr32(0, 0);
478 // The result here should be green, since we have effectively shifted bl ue to green. 483 // The result here should be green, since we have effectively shifted bl ue to green.
479 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 484 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
480 } 485 }
481 486
482 { 487 {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 // Tests that, even when an upstream filter has returned null (due to failure or clipping), a 712 // Tests that, even when an upstream filter has returned null (due to failure or clipping), a
708 // downstream filter that affects transparent black still does so even with a nu llptr input. 713 // downstream filter that affects transparent black still does so even with a nu llptr input.
709 static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy, 714 static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy,
710 skiatest::Reporter* reporter, 715 skiatest::Reporter* reporter,
711 GrContext* context) { 716 GrContext* context) {
712 sk_sp<FailImageFilter> failFilter(new FailImageFilter()); 717 sk_sp<FailImageFilter> failFilter(new FailImageFilter());
713 sk_sp<SkSpecialImage> source(create_empty_special_image(context, proxy, 5)); 718 sk_sp<SkSpecialImage> source(create_empty_special_image(context, proxy, 5));
714 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nul lptr); 719 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nul lptr);
715 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXf ermode::kSrc_Mode)); 720 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXf ermode::kSrc_Mode));
716 SkASSERT(green->affectsTransparentBlack()); 721 SkASSERT(green->affectsTransparentBlack());
717 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get( ), 722 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(gr een),
718 failFilter .get())); 723 std::move(fa ilFilter)));
719 SkIPoint offset; 724 SkIPoint offset;
720 sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &of fset)); 725 sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &of fset));
721 REPORTER_ASSERT(reporter, nullptr != result.get()); 726 REPORTER_ASSERT(reporter, nullptr != result.get());
722 if (result.get()) { 727 if (result.get()) {
723 SkBitmap resultBM; 728 SkBitmap resultBM;
724 TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM); 729 TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM);
725 SkAutoLockPixels lock(resultBM); 730 SkAutoLockPixels lock(resultBM);
726 REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN); 731 REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN);
727 } 732 }
728 } 733 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 } 793 }
789 } 794 }
790 } 795 }
791 796
792 static void draw_saveLayer_picture(int width, int height, int tileSize, 797 static void draw_saveLayer_picture(int width, int height, int tileSize,
793 SkBBHFactory* factory, SkBitmap* result) { 798 SkBBHFactory* factory, SkBitmap* result) {
794 799
795 SkMatrix matrix; 800 SkMatrix matrix;
796 matrix.setTranslate(SkIntToScalar(50), 0); 801 matrix.setTranslate(SkIntToScalar(50), 0);
797 802
798 auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode)) ; 803 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXferm ode::kSrc_Mode));
799 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get())) ; 804 sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), null ptr));
800 SkAutoTUnref<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(ma trix, kNone_SkFilterQuality, cfif.get())); 805 sk_sp<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix,
806 kNone_SkF ilterQuality,
807 cfif.get( )));
801 808
802 SkPaint paint; 809 SkPaint paint;
803 paint.setImageFilter(imageFilter.get()); 810 paint.setImageFilter(std::move(imageFilter));
804 SkPictureRecorder recorder; 811 SkPictureRecorder recorder;
805 SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50)); 812 SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
806 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width), 813 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
807 SkIntToScalar(height), 814 SkIntToScalar(height),
808 factory, 0); 815 factory, 0);
809 recordingCanvas->translate(-55, 0); 816 recordingCanvas->translate(-55, 0);
810 recordingCanvas->saveLayer(&bounds, &paint); 817 recordingCanvas->saveLayer(&bounds, &paint);
811 recordingCanvas->restore(); 818 recordingCanvas->restore();
812 sk_sp<SkPicture> picture1(recorder.finishRecordingAsPicture()); 819 sk_sp<SkPicture> picture1(recorder.finishRecordingAsPicture());
813 820
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 // Even when there's an empty saveLayer()/restore(), ensure that an image 1220 // Even when there's an empty saveLayer()/restore(), ensure that an image
1214 // filter or color filter which affects transparent black still draws. 1221 // filter or color filter which affects transparent black still draws.
1215 1222
1216 SkBitmap bitmap; 1223 SkBitmap bitmap;
1217 bitmap.allocN32Pixels(10, 10); 1224 bitmap.allocN32Pixels(10, 10);
1218 SkCanvas canvas(bitmap); 1225 SkCanvas canvas(bitmap);
1219 1226
1220 SkRTreeFactory factory; 1227 SkRTreeFactory factory;
1221 SkPictureRecorder recorder; 1228 SkPictureRecorder recorder;
1222 1229
1223 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mod e)); 1230 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
1224 SkAutoTUnref<SkImageFilter> imageFilter( 1231 SkXfermode::kSrc_Mo de));
1225 SkColorFilterImageFilter::Create(green.get())); 1232 sk_sp<SkImageFilter> imageFilter(SkColorFilterImageFilter::Make(green, nullp tr));
1226 SkPaint imageFilterPaint; 1233 SkPaint imageFilterPaint;
1227 imageFilterPaint.setImageFilter(imageFilter.get()); 1234 imageFilterPaint.setImageFilter(std::move(imageFilter));
1228 SkPaint colorFilterPaint; 1235 SkPaint colorFilterPaint;
1229 colorFilterPaint.setColorFilter(green); 1236 colorFilterPaint.setColorFilter(green);
1230 1237
1231 SkRect bounds = SkRect::MakeWH(10, 10); 1238 SkRect bounds = SkRect::MakeWH(10, 10);
1232 1239
1233 SkCanvas* recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); 1240 SkCanvas* recordingCanvas = recorder.beginRecording(10, 10, &factory, 0);
1234 recordingCanvas->saveLayer(&bounds, &imageFilterPaint); 1241 recordingCanvas->saveLayer(&bounds, &imageFilterPaint);
1235 recordingCanvas->restore(); 1242 recordingCanvas->restore();
1236 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); 1243 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
1237 1244
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 REPORTER_ASSERT(reporter, nullptr == conv.get()); 1342 REPORTER_ASSERT(reporter, nullptr == conv.get());
1336 } 1343 }
1337 1344
1338 static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re porter) { 1345 static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re porter) {
1339 canvas->clear(0); 1346 canvas->clear(0);
1340 1347
1341 SkBitmap bitmap; 1348 SkBitmap bitmap;
1342 bitmap.allocN32Pixels(1, 1); 1349 bitmap.allocN32Pixels(1, 1);
1343 bitmap.eraseARGB(255, 255, 255, 255); 1350 bitmap.eraseARGB(255, 255, 255, 255);
1344 1351
1345 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_M ode)); 1352 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
1346 SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(gre en.get())); 1353 SkXfermode::kSrcIn_ Mode));
1354 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(green, nullp tr));
1347 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); 1355 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
1348 SkAutoTUnref<SkImageFilter> croppedOut( 1356 sk_sp<SkImageFilter> croppedOut(SkColorFilterImageFilter::Make(green, nullpt r, &cropRect));
1349 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect));
1350 1357
1351 // Check that an xfermode image filter whose input has been cropped out stil l draws the other 1358 // Check that an xfermode image filter whose input has been cropped out stil l draws the other
1352 // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning. 1359 // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
1353 auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode); 1360 auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
1354 auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr)); 1361 auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode,
1355 auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr)); 1362 greenFilter.get(), croppedOut. get(), nullptr));
1356 auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedO ut, nullptr)); 1363 auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode,
1364 croppedOut.get(), greenFilter. get(), nullptr));
1365 auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode,
1366 croppedOut.get(),
1367 croppedOut.get(), nullptr) );
1357 1368
1358 SkPaint paint; 1369 SkPaint paint;
1359 paint.setImageFilter(xfermodeNoFg); 1370 paint.setImageFilter(xfermodeNoFg);
1360 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite 1371 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
1361 1372
1362 uint32_t pixel; 1373 uint32_t pixel;
1363 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType); 1374 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType);
1364 canvas->readPixels(info, &pixel, 4, 0, 0); 1375 canvas->readPixels(info, &pixel, 4, 0, 0);
1365 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1376 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1366 1377
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 } 1516 }
1506 #endif 1517 #endif
1507 1518
1508 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, 1519 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy,
1509 skiatest::Reporter* reporter, 1520 skiatest::Reporter* reporter,
1510 GrContext* context) { 1521 GrContext* context) {
1511 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) ); 1522 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) );
1512 1523
1513 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), 1524 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
1514 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); 1525 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge);
1515 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); 1526 sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
1516 SkIPoint offset; 1527 SkIPoint offset;
1517 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1528 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1518 1529
1519 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs et)); 1530 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs et));
1520 REPORTER_ASSERT(reporter, resultImg); 1531 REPORTER_ASSERT(reporter, resultImg);
1521 1532
1522 REPORTER_ASSERT(reporter, offset.fX == 0); 1533 REPORTER_ASSERT(reporter, offset.fX == 0);
1523 REPORTER_ASSERT(reporter, offset.fY == 0); 1534 REPORTER_ASSERT(reporter, offset.fY == 0);
1524 REPORTER_ASSERT(reporter, resultImg->width() == 20); 1535 REPORTER_ASSERT(reporter, resultImg->width() == 20);
1525 REPORTER_ASSERT(reporter, resultImg->height() == 30); 1536 REPORTER_ASSERT(reporter, resultImg->height() == 30);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 std::move(gray))); 1568 std::move(gray)));
1558 REPORTER_ASSERT(reporter, grayBlur->canComputeFastBounds()); 1569 REPORTER_ASSERT(reporter, grayBlur->canComputeFastBounds());
1559 } 1570 }
1560 1571
1561 { 1572 {
1562 SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0, 1573 SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0,
1563 0, 0, 0, 0, 1, 1574 0, 0, 0, 0, 1,
1564 0, 0, 0, 0, 0, 1575 0, 0, 0, 0, 0,
1565 0, 0, 0, 0, 1 }; 1576 0, 0, 0, 0, 1 };
1566 sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255( greenMatrix)); 1577 sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255( greenMatrix));
1567 sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get( ))); 1578 sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(greenCF, nullp tr));
1568 1579
1569 REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack()); 1580 REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
1570 REPORTER_ASSERT(reporter, !green->canComputeFastBounds()); 1581 REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
1571 1582
1572 sk_sp<SkImageFilter> greenBlur(SkBlurImageFilter::Make(SK_Scalar1, SK_Sc alar1, 1583 sk_sp<SkImageFilter> greenBlur(SkBlurImageFilter::Make(SK_Scalar1, SK_Sc alar1,
1573 std::move(green)) ); 1584 std::move(green)) );
1574 REPORTER_ASSERT(reporter, !greenBlur->canComputeFastBounds()); 1585 REPORTER_ASSERT(reporter, !greenBlur->canComputeFastBounds());
1575 } 1586 }
1576 1587
1577 uint8_t allOne[256], identity[256]; 1588 uint8_t allOne[256], identity[256];
1578 for (int i = 0; i < 256; ++i) { 1589 for (int i = 0; i < 256; ++i) {
1579 identity[i] = i; 1590 identity[i] = i;
1580 allOne[i] = 255; 1591 allOne[i] = 255;
1581 } 1592 }
1582 1593
1583 auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, a llOne)); 1594 sk_sp<SkColorFilter> identityCF(SkTableColorFilter::MakeARGB(identity, ident ity,
1584 SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create( identityCF.get())); 1595 identity, allOn e));
1596 sk_sp<SkImageFilter> identityFilter(SkColorFilterImageFilter::Make(identityC F, nullptr));
1585 REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack()); 1597 REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
1586 REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds()); 1598 REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds());
1587 1599
1588 auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity)); 1600 sk_sp<SkColorFilter> forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, iden tity,
1589 SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(for ceOpaqueCF.get())); 1601 identity, id entity));
1602 sk_sp<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Make(forceOpaqueC F, nullptr));
1590 REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack()); 1603 REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
1591 REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); 1604 REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
1592 } 1605 }
1593 1606
1594 // Verify that SkImageSource survives serialization 1607 // Verify that SkImageSource survives serialization
1595 DEF_TEST(ImageFilterImageSourceSerialization, reporter) { 1608 DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
1596 auto surface(SkSurface::MakeRasterN32Premul(10, 10)); 1609 auto surface(SkSurface::MakeRasterN32Premul(10, 10));
1597 surface->getCanvas()->clear(SK_ColorGREEN); 1610 surface->getCanvas()->clear(SK_ColorGREEN);
1598 sk_sp<SkImage> image(surface->makeImageSnapshot()); 1611 sk_sp<SkImage> image(surface->makeImageSnapshot());
1599 sk_sp<SkImageFilter> filter(SkImageSource::Make(std::move(image))); 1612 sk_sp<SkImageFilter> filter(SkImageSource::Make(std::move(image)));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 1706
1694 test_xfermode_cropped_input(&canvas, reporter); 1707 test_xfermode_cropped_input(&canvas, reporter);
1695 } 1708 }
1696 1709
1697 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1710 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1698 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, 1711 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
1699 SkImageInfo::MakeN32Premul(100, 100 ))); 1712 SkImageInfo::MakeN32Premul(100, 100 )));
1700 test_large_blur_input(reporter, surface->getCanvas()); 1713 test_large_blur_input(reporter, surface->getCanvas());
1701 } 1714 }
1702 #endif 1715 #endif
OLDNEW
« no previous file with comments | « src/effects/SkColorFilterImageFilter.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698