| 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); | 776 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); |
| 777 | 777 |
| 778 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); | 778 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
| 779 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); | 779 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); |
| 780 bounds = filter2->filterBounds(bounds, SkMatrix::I()); | 780 bounds = filter2->filterBounds(bounds, SkMatrix::I()); |
| 781 | 781 |
| 782 REPORTER_ASSERT(reporter, bounds == expectedBounds); | 782 REPORTER_ASSERT(reporter, bounds == expectedBounds); |
| 783 } | 783 } |
| 784 | 784 |
| 785 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { | 785 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { |
| 786 SkAutoTUnref<SkImageFilter> filter1(makeBlur()); | 786 sk_sp<SkImageFilter> filter1(makeBlur()); |
| 787 SkAutoTUnref<SkImageFilter> filter2(makeBlur()); | 787 sk_sp<SkImageFilter> filter2(makeBlur()); |
| 788 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(filt
er1.get(), filter2.get())); | 788 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(fil
ter1), |
| 789 std::move(fil
ter2))); |
| 789 | 790 |
| 790 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); | 791 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 791 SkRect expectedBounds = SkRect::MakeXYWH( | 792 SkRect expectedBounds = SkRect::MakeXYWH( |
| 792 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); | 793 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); |
| 793 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); | 794 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); |
| 794 | 795 |
| 795 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); | 796 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
| 796 } | 797 } |
| 797 | 798 |
| 798 DEF_TEST(ImageFilterUnionBounds, reporter) { | 799 DEF_TEST(ImageFilterUnionBounds, reporter) { |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 SkCanvas canvas(temp); | 1331 SkCanvas canvas(temp); |
| 1331 test_xfermode_cropped_input(&canvas, reporter); | 1332 test_xfermode_cropped_input(&canvas, reporter); |
| 1332 } | 1333 } |
| 1333 | 1334 |
| 1334 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, | 1335 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, |
| 1335 skiatest::Reporter* reporter, | 1336 skiatest::Reporter* reporter, |
| 1336 GrContext* context) { | 1337 GrContext* context) { |
| 1337 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100)
); | 1338 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100)
); |
| 1338 | 1339 |
| 1339 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1340 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
| 1340 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); | 1341 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, nullptr,
&cropRect)); |
| 1341 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1,
SK_Scalar1, | 1342 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Sca
lar1, |
| 1342 nullptr, &c
ropRect)); | 1343 nullptr, &cropRect
)); |
| 1343 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, | 1344 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu
rFilter), |
| 1344 offs
etFilter.get())); | 1345 std::move(off
setFilter))); |
| 1345 SkIPoint offset; | 1346 SkIPoint offset; |
| 1346 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); | 1347 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
| 1347 | 1348 |
| 1348 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct
x, &offset)); | 1349 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct
x, &offset)); |
| 1349 REPORTER_ASSERT(reporter, resultImg); | 1350 REPORTER_ASSERT(reporter, resultImg); |
| 1350 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1351 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
| 1351 } | 1352 } |
| 1352 | 1353 |
| 1353 DEF_TEST(ComposedImageFilterOffset, reporter) { | 1354 DEF_TEST(ComposedImageFilterOffset, reporter) { |
| 1354 run_raster_test(reporter, 100, test_composed_imagefilter_offset); | 1355 run_raster_test(reporter, 100, test_composed_imagefilter_offset); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1366 // The bounds passed to the inner filter must be filtered by the outer | 1367 // The bounds passed to the inner filter must be filtered by the outer |
| 1367 // filter, so that the inner filter produces the pixels that the outer | 1368 // filter, so that the inner filter produces the pixels that the outer |
| 1368 // filter requires as input. This matters if the outer filter moves pixels. | 1369 // filter requires as input. This matters if the outer filter moves pixels. |
| 1369 // Here, accounting for the outer offset is necessary so that the green | 1370 // Here, accounting for the outer offset is necessary so that the green |
| 1370 // pixels of the picture are not clipped. | 1371 // pixels of the picture are not clipped. |
| 1371 | 1372 |
| 1372 SkPictureRecorder recorder; | 1373 SkPictureRecorder recorder; |
| 1373 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100)
); | 1374 SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100)
); |
| 1374 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); | 1375 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); |
| 1375 recordingCanvas->clear(SK_ColorGREEN); | 1376 recordingCanvas->clear(SK_ColorGREEN); |
| 1376 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 1377 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
| 1377 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture)); | 1378 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture)); |
| 1378 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); | 1379 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); |
| 1379 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullp
tr, &cropRect)); | 1380 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullp
tr, &cropRect)); |
| 1380 sk_sp<SkImageFilter> composedFilter( | 1381 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(off
setFilter), |
| 1381 SkComposeImageFilter::Create(offsetFilter.get(), pictureFilter.get())); | 1382 std::move(pic
tureFilter))); |
| 1382 | 1383 |
| 1383 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, proxy,
100)); | 1384 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, proxy,
100)); |
| 1384 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); | 1385 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr
); |
| 1385 SkIPoint offset; | 1386 SkIPoint offset; |
| 1386 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(),
ctx, &offset)); | 1387 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(),
ctx, &offset)); |
| 1387 REPORTER_ASSERT(reporter, offset.isZero()); | 1388 REPORTER_ASSERT(reporter, offset.isZero()); |
| 1388 REPORTER_ASSERT(reporter, result); | 1389 REPORTER_ASSERT(reporter, result); |
| 1389 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100)
); | 1390 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100)
); |
| 1390 | 1391 |
| 1391 SkBitmap resultBM; | 1392 SkBitmap resultBM; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 | 1587 |
| 1587 test_xfermode_cropped_input(&canvas, reporter); | 1588 test_xfermode_cropped_input(&canvas, reporter); |
| 1588 } | 1589 } |
| 1589 | 1590 |
| 1590 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1591 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
| 1591 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, | 1592 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
| 1592 SkImageInfo::MakeN32Premul(100, 100
))); | 1593 SkImageInfo::MakeN32Premul(100, 100
))); |
| 1593 test_large_blur_input(reporter, surface->getCanvas()); | 1594 test_large_blur_input(reporter, surface->getCanvas()); |
| 1594 } | 1595 } |
| 1595 #endif | 1596 #endif |
| OLD | NEW |