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