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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 2114313002: Handle negative scale in SkDropShadowImageFilter::onFilterNodeBounds. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: I can has unit test. Created 4 years, 5 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
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 "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Make(2, 2, nullptr)); 849 sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Make(2, 2, nullptr));
850 sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1))); 850 sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1)));
851 851
852 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); 852 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100);
853 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); 853 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234);
854 bounds = filter2->filterBounds(bounds, SkMatrix::I()); 854 bounds = filter2->filterBounds(bounds, SkMatrix::I());
855 855
856 REPORTER_ASSERT(reporter, bounds == expectedBounds); 856 REPORTER_ASSERT(reporter, bounds == expectedBounds);
857 } 857 }
858 858
859 DEF_TEST(ImageFilterScaledBlurRadius, reporter) {
860 // Each blur should spread 3*sigma, so 3 for the blur and 30 for the shadow
861 // (before the CTM). Bounds should be computed correctly in the presence of
862 // a (possibly negative) scale.
863 sk_sp<SkImageFilter> blur(make_blur(nullptr));
864 sk_sp<SkImageFilter> dropShadow(make_drop_shadow(nullptr));
865 {
866 // Uniform scale by 2.
867 SkMatrix scaleMatrix;
868 scaleMatrix.setScale(2, 2);
869 SkIRect bounds = SkIRect::MakeLTRB(0, 0, 200, 200);
870
871 SkIRect expectedBlurBounds = SkIRect::MakeLTRB(-6, -6, 206, 206);
872 SkIRect blurBounds = blur->filterBounds(
873 bounds, scaleMatrix, SkImageFilter::kForward_MapDirection);
874 REPORTER_ASSERT(reporter, blurBounds == expectedBlurBounds);
875 SkIRect reverseBlurBounds = blur->filterBounds(
876 bounds, scaleMatrix, SkImageFilter::kReverse_MapDirection);
877 REPORTER_ASSERT(reporter, reverseBlurBounds == expectedBlurBounds);
878
879 SkIRect expectedShadowBounds = SkIRect::MakeLTRB(0, 0, 460, 460);
880 SkIRect shadowBounds = dropShadow->filterBounds(
881 bounds, scaleMatrix, SkImageFilter::kForward_MapDirection);
882 REPORTER_ASSERT(reporter, shadowBounds == expectedShadowBounds);
883 SkIRect expectedReverseShadowBounds =
884 SkIRect::MakeLTRB(-260, -260, 200, 200);
885 SkIRect reverseShadowBounds = dropShadow->filterBounds(
886 bounds, scaleMatrix, SkImageFilter::kReverse_MapDirection);
887 REPORTER_ASSERT(reporter,
888 reverseShadowBounds == expectedReverseShadowBounds);
889 }
890 {
891 // Vertical flip.
892 SkMatrix scaleMatrix;
893 scaleMatrix.setScale(1, -1);
894 SkIRect bounds = SkIRect::MakeLTRB(0, -100, 100, 0);
895
896 SkIRect expectedBlurBounds = SkIRect::MakeLTRB(-3, -103, 103, 3);
897 SkIRect blurBounds = blur->filterBounds(
898 bounds, scaleMatrix, SkImageFilter::kForward_MapDirection);
899 REPORTER_ASSERT(reporter, blurBounds == expectedBlurBounds);
900 SkIRect reverseBlurBounds = blur->filterBounds(
901 bounds, scaleMatrix, SkImageFilter::kReverse_MapDirection);
902 REPORTER_ASSERT(reporter, reverseBlurBounds == expectedBlurBounds);
903
904 SkIRect expectedShadowBounds = SkIRect::MakeLTRB(0, -230, 230, 0);
905 SkIRect shadowBounds = dropShadow->filterBounds(
906 bounds, scaleMatrix, SkImageFilter::kForward_MapDirection);
907 REPORTER_ASSERT(reporter, shadowBounds == expectedShadowBounds);
908 SkIRect expectedReverseShadowBounds =
909 SkIRect::MakeLTRB(-130, -100, 100, 130);
910 SkIRect reverseShadowBounds = dropShadow->filterBounds(
911 bounds, scaleMatrix, SkImageFilter::kReverse_MapDirection);
912 REPORTER_ASSERT(reporter,
913 reverseShadowBounds == expectedReverseShadowBounds);
914 }
915 }
916
859 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { 917 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) {
860 sk_sp<SkImageFilter> filter1(make_blur(nullptr)); 918 sk_sp<SkImageFilter> filter1(make_blur(nullptr));
861 sk_sp<SkImageFilter> filter2(make_blur(nullptr)); 919 sk_sp<SkImageFilter> filter2(make_blur(nullptr));
862 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(fil ter1), 920 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(fil ter1),
863 std::move(fil ter2))); 921 std::move(fil ter2)));
864 922
865 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); 923 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
866 SkRect expectedBounds = SkRect::MakeXYWH( 924 SkRect expectedBounds = SkRect::MakeXYWH(
867 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar( 112)); 925 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar( 112));
868 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); 926 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc);
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 { SkColorFilterImageFilter::Make(cf, blif), false }, 1854 { SkColorFilterImageFilter::Make(cf, blif), false },
1797 { SkMergeImageFilter::Make(cfif, blif), false }, 1855 { SkMergeImageFilter::Make(cfif, blif), false },
1798 { SkComposeImageFilter::Make(blif, cfif), false }, 1856 { SkComposeImageFilter::Make(blif, cfif), false },
1799 }; 1857 };
1800 1858
1801 for (const auto& rec : recs) { 1859 for (const auto& rec : recs) {
1802 const bool canHandle = rec.fFilter->canHandleComplexCTM(); 1860 const bool canHandle = rec.fFilter->canHandleComplexCTM();
1803 REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle); 1861 REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle);
1804 } 1862 }
1805 } 1863 }
OLDNEW
« src/effects/SkDropShadowImageFilter.cpp ('K') | « src/effects/SkDropShadowImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698