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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 112 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
113 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 113 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
114 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 114 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
115 }; | 115 }; |
116 const SkISize kernelSize = SkISize::Make(3, 3); | 116 const SkISize kernelSize = SkISize::Make(3, 3); |
117 const SkScalar gain = SK_Scalar1, bias = 0; | 117 const SkScalar gain = SK_Scalar1, bias = 0; |
118 const SkScalar five = SkIntToScalar(5); | 118 const SkScalar five = SkIntToScalar(5); |
119 | 119 |
120 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circl
e(64, 64))); | 120 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circl
e(64, 64))); |
121 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradien
tImage.get())); | 121 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradien
tImage.get())); |
122 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, i
nput)); | 122 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input)); |
123 SkMatrix matrix; | 123 SkMatrix matrix; |
124 | 124 |
125 matrix.setTranslate(SK_Scalar1, SK_Scalar1); | 125 matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
126 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); | 126 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); |
127 | 127 |
128 SkRTreeFactory factory; | 128 SkRTreeFactory factory; |
129 SkPictureRecorder recorder; | 129 SkPictureRecorder recorder; |
130 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0)
; | 130 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0)
; |
131 | 131 |
132 SkPaint greenPaint; | 132 SkPaint greenPaint; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), | 170 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), |
171 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, i
nput, cropRect)); | 171 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, i
nput, cropRect)); |
172 this->addFilter("merge", SkMergeImageFilter::Make(sk_ref_sp<SkImageFilte
r>(input), | 172 this->addFilter("merge", SkMergeImageFilter::Make(sk_ref_sp<SkImageFilte
r>(input), |
173 sk_ref_sp<SkImageFilte
r>(input), | 173 sk_ref_sp<SkImageFilte
r>(input), |
174 SkXfermode::kSrcOver_M
ode, | 174 SkXfermode::kSrcOver_M
ode, |
175 cropRect).release()); | 175 cropRect).release()); |
176 this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Make( | 176 this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Make( |
177 std::move(paintFilterLeft), std::move(paintFilterRight), | 177 std::move(paintFilterLeft), std::move(paintFilterRight), |
178 SkXfermode::kSrcOver_Mode, cropRect).release()); | 178 SkXfermode::kSrcOver_Mode, cropRect).release()); |
179 this->addFilter("offset", | 179 this->addFilter("offset", |
180 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, inpu
t, cropRect)); | 180 SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1, |
| 181 sk_ref_sp<SkImageFilter>(input
), |
| 182 cropRect).release()); |
181 this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropR
ect)); | 183 this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropR
ect)); |
182 this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRec
t)); | 184 this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRec
t)); |
183 this->addFilter("tile", SkTileImageFilter::Create( | 185 this->addFilter("tile", SkTileImageFilter::Create( |
184 SkRect::MakeXYWH(0, 0, 50, 50), | 186 SkRect::MakeXYWH(0, 0, 50, 50), |
185 cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100), | 187 cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100), |
186 input)); | 188 input)); |
187 if (!cropRect) { | 189 if (!cropRect) { |
188 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( | 190 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( |
189 matrix, kLow_SkFilterQuality, input)); | 191 matrix, kLow_SkFilterQuality, input)); |
190 } | 192 } |
191 this->addFilter("blur and offset", SkOffsetImageFilter::Create( | 193 this->addFilter("blur and offset", |
192 five, five, blur.get(), cropRect)); | 194 SkOffsetImageFilter::Make(five, five, blur, |
| 195 cropRect).release()); |
193 this->addFilter("picture and blur", SkBlurImageFilter::Create( | 196 this->addFilter("picture and blur", SkBlurImageFilter::Create( |
194 five, five, pictureFilter.get(), cropRect)); | 197 five, five, pictureFilter.get(), cropRect)); |
195 this->addFilter("paint and blur", SkBlurImageFilter::Create( | 198 this->addFilter("paint and blur", SkBlurImageFilter::Create( |
196 five, five, paintFilter.get(), cropRect)); | 199 five, five, paintFilter.get(), cropRect)); |
197 this->addFilter("xfermode", SkXfermodeImageFilter::Make( | 200 this->addFilter("xfermode", SkXfermodeImageFilter::Make( |
198 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel
ease()); | 201 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel
ease()); |
199 } | 202 } |
200 int count() const { return fFilters.count(); } | 203 int count() const { return fFilters.count(); } |
201 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g
et(); } | 204 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g
et(); } |
202 const char* getName(int index) const { return fFilters[index].fName; } | 205 const char* getName(int index) const { return fFilters[index].fName; } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { | 591 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestNegativeBlurSigma_Gpu, reporter, context) { |
589 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); | 592 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); |
590 } | 593 } |
591 #endif | 594 #endif |
592 | 595 |
593 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, | 596 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, |
594 skiatest::Reporter* reporter, | 597 skiatest::Reporter* reporter, |
595 GrContext* context) { | 598 GrContext* context) { |
596 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w
orks correctly. | 599 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w
orks correctly. |
597 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10)
)); | 600 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10)
)); |
598 SkAutoTUnref<SkImageFilter> input(SkOffsetImageFilter::Create(0, 0, nullptr,
&cropRect)); | 601 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec
t)); |
599 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input, &c
ropRect)); | 602 sk_sp<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input.get(), &cr
opRect)); |
600 | 603 |
601 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10
)); | 604 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10
)); |
602 surf->getCanvas()->clear(SK_ColorGREEN); | 605 surf->getCanvas()->clear(SK_ColorGREEN); |
603 sk_sp<SkSpecialImage> image(surf->makeImageSnapshot()); | 606 sk_sp<SkSpecialImage> image(surf->makeImageSnapshot()); |
604 | 607 |
605 SkIPoint offset; | 608 SkIPoint offset; |
606 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); | 609 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); |
607 | 610 |
608 sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset))
; | 611 sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset))
; |
609 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0); | 612 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 795 |
793 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); | 796 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
794 SkRect expectedBounds = SkRect::MakeXYWH( | 797 SkRect expectedBounds = SkRect::MakeXYWH( |
795 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); | 798 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); |
796 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); | 799 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); |
797 | 800 |
798 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); | 801 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
799 } | 802 } |
800 | 803 |
801 DEF_TEST(ImageFilterUnionBounds, reporter) { | 804 DEF_TEST(ImageFilterUnionBounds, reporter) { |
802 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0)); | 805 sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(50, 0, nullptr)); |
803 // Regardless of which order they appear in, the image filter bounds should | 806 // Regardless of which order they appear in, the image filter bounds should |
804 // be combined correctly. | 807 // be combined correctly. |
805 { | 808 { |
806 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offs
et.get())); | 809 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offs
et.get())); |
807 SkRect bounds = SkRect::MakeWH(100, 100); | 810 SkRect bounds = SkRect::MakeWH(100, 100); |
808 // Intentionally aliasing here, as that's what the real callers do. | 811 // Intentionally aliasing here, as that's what the real callers do. |
809 bounds = composite->computeFastBounds(bounds); | 812 bounds = composite->computeFastBounds(bounds); |
810 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); | 813 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); |
811 } | 814 } |
812 { | 815 { |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 SkCanvas canvas(temp); | 1336 SkCanvas canvas(temp); |
1334 test_xfermode_cropped_input(&canvas, reporter); | 1337 test_xfermode_cropped_input(&canvas, reporter); |
1335 } | 1338 } |
1336 | 1339 |
1337 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, | 1340 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, |
1338 skiatest::Reporter* reporter, | 1341 skiatest::Reporter* reporter, |
1339 GrContext* context) { | 1342 GrContext* context) { |
1340 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100)
); | 1343 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100)
); |
1341 | 1344 |
1342 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1345 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
1343 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, nullptr,
&cropRect)); | 1346 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, &
cropRect)); |
1344 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Sca
lar1, | 1347 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Sca
lar1, |
1345 nullptr, &cropRect
)); | 1348 nullptr, &cropRect
)); |
1346 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu
rFilter), | 1349 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu
rFilter), |
1347 std::move(off
setFilter))); | 1350 std::move(off
setFilter))); |
1348 SkIPoint offset; | 1351 SkIPoint offset; |
1349 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); | 1352 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
1350 | 1353 |
1351 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct
x, &offset)); | 1354 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct
x, &offset)); |
1352 REPORTER_ASSERT(reporter, resultImg); | 1355 REPORTER_ASSERT(reporter, resultImg); |
1353 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1356 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
(...skipping 18 matching lines...) Expand all Loading... |
1372 // Here, accounting for the outer offset is necessary so that the green | 1375 // Here, accounting for the outer offset is necessary so that the green |
1373 // pixels of the picture are not clipped. | 1376 // pixels of the picture are not clipped. |
1374 | 1377 |
1375 SkPictureRecorder recorder; | 1378 SkPictureRecorder recorder; |
1376 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100)
); | 1379 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100)
); |
1377 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); | 1380 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); |
1378 recordingCanvas->clear(SK_ColorGREEN); | 1381 recordingCanvas->clear(SK_ColorGREEN); |
1379 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); | 1382 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
1380 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture)); | 1383 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture)); |
1381 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); | 1384 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); |
1382 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullp
tr, &cropRect)); | 1385 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(-100, 0, nullptr
, &cropRect)); |
1383 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(off
setFilter), | 1386 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(off
setFilter), |
1384 std::move(pic
tureFilter))); | 1387 std::move(pic
tureFilter))); |
1385 | 1388 |
1386 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, proxy,
100)); | 1389 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, proxy,
100)); |
1387 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); | 1390 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
1388 SkIPoint offset; | 1391 SkIPoint offset; |
1389 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(),
ctx, &offset)); | 1392 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(),
ctx, &offset)); |
1390 REPORTER_ASSERT(reporter, offset.isZero()); | 1393 REPORTER_ASSERT(reporter, offset.isZero()); |
1391 REPORTER_ASSERT(reporter, result); | 1394 REPORTER_ASSERT(reporter, result); |
1392 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100)
); | 1395 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100)
); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 | 1592 |
1590 test_xfermode_cropped_input(&canvas, reporter); | 1593 test_xfermode_cropped_input(&canvas, reporter); |
1591 } | 1594 } |
1592 | 1595 |
1593 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1596 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
1594 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, | 1597 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
1595 SkImageInfo::MakeN32Premul(100, 100
))); | 1598 SkImageInfo::MakeN32Premul(100, 100
))); |
1596 test_large_blur_input(reporter, surface->getCanvas()); | 1599 test_large_blur_input(reporter, surface->getCanvas()); |
1597 } | 1600 } |
1598 #endif | 1601 #endif |
OLD | NEW |