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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1852743002: Update SkBlurImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT & address code review comments 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/utils/SkLua.cpp ('k') | tests/RecordOptsTest.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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 SkBitmap bitmap; 99 SkBitmap bitmap;
100 bitmap.allocN32Pixels(width, height); 100 bitmap.allocN32Pixels(width, height);
101 SkCanvas canvas(bitmap); 101 SkCanvas canvas(bitmap);
102 draw_gradient_circle(&canvas, width, height); 102 draw_gradient_circle(&canvas, width, height);
103 return bitmap; 103 return bitmap;
104 } 104 }
105 105
106 class FilterList { 106 class FilterList {
107 public: 107 public:
108 FilterList(SkImageFilter* input = nullptr, const SkImageFilter::CropRect* cr opRect = nullptr) { 108 FilterList(SkImageFilter* input = nullptr, const SkImageFilter::CropRect* cr opRect = nullptr) {
109 auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mo de));
110 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 109 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
111 SkScalar kernel[9] = { 110 SkScalar kernel[9] = {
112 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 111 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
113 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 112 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
114 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 113 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
115 }; 114 };
116 const SkISize kernelSize = SkISize::Make(3, 3); 115 const SkISize kernelSize = SkISize::Make(3, 3);
117 const SkScalar gain = SK_Scalar1, bias = 0; 116 const SkScalar gain = SK_Scalar1, bias = 0;
118 const SkScalar five = SkIntToScalar(5); 117 const SkScalar five = SkIntToScalar(5);
119 118
120 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circl e(64, 64)));
121 sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gradie ntImage)));
122 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input));
123 SkMatrix matrix; 119 SkMatrix matrix;
124 120
125 matrix.setTranslate(SK_Scalar1, SK_Scalar1); 121 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
126 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); 122 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
127 123
128 SkRTreeFactory factory; 124 {
129 SkPictureRecorder recorder; 125 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
130 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0) ; 126 SkXfermode::kS rcIn_Mode));
131 127
132 SkPaint greenPaint; 128 this->addFilter("color filter",
133 greenPaint.setColor(SK_ColorGREEN); 129 SkColorFilterImageFilter::Create(cf.get(), input, cropRect));
134 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20) ), greenPaint); 130 }
135 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
136 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture));
137 sk_sp<SkShader> shader(SkPerlinNoiseShader::MakeTurbulence(SK_Scalar1, S K_Scalar1, 1, 0));
138 131
139 SkPaint paint; 132 {
140 paint.setShader(shader); 133 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_c ircle(64, 64)));
141 sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint)); 134 sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gr adientImage)));
142 135
143 sk_sp<SkShader> greenColorShader(SkShader::MakeColorShader(SK_ColorGREEN )); 136 this->addFilter("displacement map", SkDisplacementMapEffect::Create(
144 SkPaint greenColorShaderPaint; 137 SkDisplacementMapEffect::kR_ChannelSelectorType,
145 greenColorShaderPaint.setShader(greenColorShader); 138 SkDisplacementMapEffect::kB_ChannelSelectorType,
146 SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64)) ; 139 20.0f, gradientSource.get(), input, cropRect));
147 sk_sp<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Make(greenColor ShaderPaint, 140 }
148 &leftSideC ropRect));
149 SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64 ));
150 sk_sp<SkImageFilter> paintFilterRight(SkPaintImageFilter::Make(greenColo rShaderPaint,
151 &rightSid eCropRect));
152 141
153 this->addFilter("color filter", 142 this->addFilter("blur", SkBlurImageFilter::Make(SK_Scalar1,
154 SkColorFilterImageFilter::Create(cf.get(), input, cropRect)); 143 SK_Scalar1,
155 this->addFilter("displacement map", SkDisplacementMapEffect::Create( 144 sk_ref_sp<SkImageFilter> (input),
156 SkDisplacementMapEffect::kR_ChannelSelectorType, 145 cropRect).release());
157 SkDisplacementMapEffect::kB_ChannelSelectorType,
158 20.0f, gradientSource.get(), input, cropRect));
159 this->addFilter("blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1 , input, cropRect));
160 this->addFilter("drop shadow", SkDropShadowImageFilter::Create( 146 this->addFilter("drop shadow", SkDropShadowImageFilter::Create(
161 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, 147 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN,
162 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, input, cropRect)); 148 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, input, cropRect));
163 this->addFilter("diffuse lighting", SkLightingImageFilter::CreatePointLi tDiffuse( 149 this->addFilter("diffuse lighting", SkLightingImageFilter::CreatePointLi tDiffuse(
164 location, SK_ColorGREEN, 0, 0, input, cropRect)); 150 location, SK_ColorGREEN, 0, 0, input, cropRect));
165 this->addFilter("specular lighting", 151 this->addFilter("specular lighting",
166 SkLightingImageFilter::CreatePointLitSpecular(location, SK_Col orGREEN, 0, 0, 0, 152 SkLightingImageFilter::CreatePointLitSpecular(location, SK_Col orGREEN, 0, 0, 0,
167 input, cropRect) ); 153 input, cropRect) );
168 this->addFilter("matrix convolution", 154 this->addFilter("matrix convolution",
169 SkMatrixConvolutionImageFilter::Create( 155 SkMatrixConvolutionImageFilter::Create(
170 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), 156 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1),
171 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, i nput, cropRect)); 157 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, i nput, cropRect));
172 this->addFilter("merge", SkMergeImageFilter::Make(sk_ref_sp<SkImageFilte r>(input), 158 this->addFilter("merge", SkMergeImageFilter::Make(sk_ref_sp<SkImageFilte r>(input),
173 sk_ref_sp<SkImageFilte r>(input), 159 sk_ref_sp<SkImageFilte r>(input),
174 SkXfermode::kSrcOver_M ode, 160 SkXfermode::kSrcOver_M ode,
175 cropRect).release()); 161 cropRect).release());
176 this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Make( 162 {
163 SkPaint greenColorShaderPaint;
164 greenColorShaderPaint.setShader(SkShader::MakeColorShader(SK_ColorGR EEN));
165
166 SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64));
167 sk_sp<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Make(greenC olorShaderPaint,
168 &leftS ideCropRect));
169 SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32 , 64));
170 sk_sp<SkImageFilter> paintFilterRight(SkPaintImageFilter::Make(green ColorShaderPaint,
171 &righ tSideCropRect));
172
173
174 this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Ma ke(
177 std::move(paintFilterLeft), std::move(paintFilterRight), 175 std::move(paintFilterLeft), std::move(paintFilterRight),
178 SkXfermode::kSrcOver_Mode, cropRect).release()); 176 SkXfermode::kSrcOver_Mode, cropRect).release());
177 }
178
179 this->addFilter("offset", 179 this->addFilter("offset",
180 SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1, 180 SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1,
181 sk_ref_sp<SkImageFilter>(input ), 181 sk_ref_sp<SkImageFilter>(input ),
182 cropRect).release()); 182 cropRect).release());
183 this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropR ect)); 183 this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropR ect));
184 this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRec t)); 184 this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRec t));
185 this->addFilter("tile", SkTileImageFilter::Create( 185 this->addFilter("tile", SkTileImageFilter::Create(
186 SkRect::MakeXYWH(0, 0, 50, 50), 186 SkRect::MakeXYWH(0, 0, 50, 50),
187 cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100), 187 cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100),
188 input)); 188 input));
189 if (!cropRect) { 189 if (!cropRect) {
190 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( 190 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
191 matrix, kLow_SkFilterQuality, input)); 191 matrix, kLow_SkFilterQuality, input));
192 } 192 }
193 this->addFilter("blur and offset", 193
194 SkOffsetImageFilter::Make(five, five, blur, 194 {
195 cropRect).release()); 195 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five,
196 this->addFilter("picture and blur", SkBlurImageFilter::Create( 196 sk_ref_sp<SkImageF ilter>(input)));
197 five, five, pictureFilter.get(), cropRect)); 197
198 this->addFilter("paint and blur", SkBlurImageFilter::Create( 198 this->addFilter("blur and offset", SkOffsetImageFilter::Make(five, f ive,
199 five, five, paintFilter.get(), cropRect)); 199 std::mo ve(blur),
200 cropRec t).release());
201 }
202 {
203 SkRTreeFactory factory;
204 SkPictureRecorder recorder;
205 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory , 0);
206
207 SkPaint greenPaint;
208 greenPaint.setColor(SK_ColorGREEN);
209 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), greenPaint);
210 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
211 sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(std::m ove(picture)));
212
213 this->addFilter("picture and blur", SkBlurImageFilter::Make(five, fi ve,
214 std::mov e(pictureFilter),
215 cropRect ).release());
216 }
217 {
218 SkPaint paint;
219 paint.setShader(SkPerlinNoiseShader::MakeTurbulence(SK_Scalar1, SK_S calar1, 1, 0));
220 sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint));
221
222 this->addFilter("paint and blur", SkBlurImageFilter::Make(five, five ,
223 std::move( paintFilter),
224 cropRect). release());
225 }
200 this->addFilter("xfermode", SkXfermodeImageFilter::Make( 226 this->addFilter("xfermode", SkXfermodeImageFilter::Make(
201 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel ease()); 227 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel ease());
202 } 228 }
203 int count() const { return fFilters.count(); } 229 int count() const { return fFilters.count(); }
204 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g et(); } 230 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g et(); }
205 const char* getName(int index) const { return fFilters[index].fName; } 231 const char* getName(int index) const { return fFilters[index].fName; }
206 private: 232 private:
207 struct Filter { 233 struct Filter {
208 Filter() : fName(nullptr), fFilter(nullptr) {} 234 Filter() : fName(nullptr), fFilter(nullptr) {}
209 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f ilter) {} 235 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f ilter) {}
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 496 }
471 497
472 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, 498 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy,
473 skiatest::Reporter* reporter, 499 skiatest::Reporter* reporter,
474 GrContext* context) { 500 GrContext* context) {
475 // Check that SkBlurImageFilter will accept a negative sigma, either in 501 // Check that SkBlurImageFilter will accept a negative sigma, either in
476 // the given arguments or after CTM application. 502 // the given arguments or after CTM application.
477 const int width = 32, height = 32; 503 const int width = 32, height = 32;
478 const SkScalar five = SkIntToScalar(5); 504 const SkScalar five = SkIntToScalar(5);
479 505
480 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f ive)); 506 sk_sp<SkImageFilter> positiveFilter(SkBlurImageFilter::Make(five, five, null ptr));
481 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five, five)); 507 sk_sp<SkImageFilter> negativeFilter(SkBlurImageFilter::Make(-five, five, nul lptr));
482 508
483 SkBitmap gradient = make_gradient_circle(width, height); 509 SkBitmap gradient = make_gradient_circle(width, height);
484 sk_sp<SkSpecialImage> imgSrc(SkSpecialImage::MakeFromRaster(proxy, 510 sk_sp<SkSpecialImage> imgSrc(SkSpecialImage::MakeFromRaster(proxy,
485 SkIRect::MakeWH( width, height), 511 SkIRect::MakeWH( width, height),
486 gradient)); 512 gradient));
487 513
488 SkIPoint offset; 514 SkIPoint offset;
489 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); 515 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
490 516
491 sk_sp<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get (), ctx, &offset)); 517 sk_sp<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get (), ctx, &offset));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 run_gpu_test(reporter, context, 100, test_negative_blur_sigma); 618 run_gpu_test(reporter, context, 100, test_negative_blur_sigma);
593 } 619 }
594 #endif 620 #endif
595 621
596 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy, 622 static void test_zero_blur_sigma(SkImageFilter::Proxy* proxy,
597 skiatest::Reporter* reporter, 623 skiatest::Reporter* reporter,
598 GrContext* context) { 624 GrContext* context) {
599 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w orks correctly. 625 // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset w orks correctly.
600 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10) )); 626 SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10) ));
601 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec t)); 627 sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRec t));
602 sk_sp<SkImageFilter> filter(SkBlurImageFilter::Create(0, 0, input.get(), &cr opRect)); 628 sk_sp<SkImageFilter> filter(SkBlurImageFilter::Make(0, 0, std::move(input), &cropRect));
603 629
604 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10 )); 630 sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, proxy, 10 ));
605 surf->getCanvas()->clear(SK_ColorGREEN); 631 surf->getCanvas()->clear(SK_ColorGREEN);
606 sk_sp<SkSpecialImage> image(surf->makeImageSnapshot()); 632 sk_sp<SkSpecialImage> image(surf->makeImageSnapshot());
607 633
608 SkIPoint offset; 634 SkIPoint offset;
609 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); 635 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr);
610 636
611 sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset)) ; 637 sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset)) ;
612 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0); 638 REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 761
736 for (int y = 0; y < height; y++) { 762 for (int y = 0; y < height; y++) {
737 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res ult1.rowBytes()); 763 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res ult1.rowBytes());
738 REPORTER_ASSERT(reporter, !diffs); 764 REPORTER_ASSERT(reporter, !diffs);
739 if (diffs) { 765 if (diffs) {
740 break; 766 break;
741 } 767 }
742 } 768 }
743 } 769 }
744 770
745 static SkImageFilter* makeBlur(SkImageFilter* input = nullptr) { 771 static sk_sp<SkImageFilter> make_blur(sk_sp<SkImageFilter> input) {
746 return SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, input); 772 return SkBlurImageFilter::Make(SK_Scalar1, SK_Scalar1, std::move(input));
747 } 773 }
748 774
749 static SkImageFilter* makeDropShadow(SkImageFilter* input = nullptr) { 775 static sk_sp<SkImageFilter> make_drop_shadow(sk_sp<SkImageFilter> input) {
750 return SkDropShadowImageFilter::Create( 776 return sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
751 SkIntToScalar(100), SkIntToScalar(100), 777 SkIntToScalar(100), SkIntToScalar(100),
752 SkIntToScalar(10), SkIntToScalar(10), 778 SkIntToScalar(10), SkIntToScalar(10),
753 SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMo de, 779 SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMo de,
754 input, nullptr); 780 input.get(), nullptr));
755 } 781 }
756 782
757 DEF_TEST(ImageFilterBlurThenShadowBounds, reporter) { 783 DEF_TEST(ImageFilterBlurThenShadowBounds, reporter) {
758 SkAutoTUnref<SkImageFilter> filter1(makeBlur()); 784 sk_sp<SkImageFilter> filter1(make_blur(nullptr));
759 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); 785 sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1)));
760 786
761 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); 787 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100);
762 SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236); 788 SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236);
763 bounds = filter2->filterBounds(bounds, SkMatrix::I()); 789 bounds = filter2->filterBounds(bounds, SkMatrix::I());
764 790
765 REPORTER_ASSERT(reporter, bounds == expectedBounds); 791 REPORTER_ASSERT(reporter, bounds == expectedBounds);
766 } 792 }
767 793
768 DEF_TEST(ImageFilterShadowThenBlurBounds, reporter) { 794 DEF_TEST(ImageFilterShadowThenBlurBounds, reporter) {
769 SkAutoTUnref<SkImageFilter> filter1(makeDropShadow()); 795 sk_sp<SkImageFilter> filter1(make_drop_shadow(nullptr));
770 SkAutoTUnref<SkImageFilter> filter2(makeBlur(filter1.get())); 796 sk_sp<SkImageFilter> filter2(make_blur(std::move(filter1)));
771 797
772 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); 798 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100);
773 SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236); 799 SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236);
774 bounds = filter2->filterBounds(bounds, SkMatrix::I()); 800 bounds = filter2->filterBounds(bounds, SkMatrix::I());
775 801
776 REPORTER_ASSERT(reporter, bounds == expectedBounds); 802 REPORTER_ASSERT(reporter, bounds == expectedBounds);
777 } 803 }
778 804
779 DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) { 805 DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) {
780 SkAutoTUnref<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2)); 806 sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2));
781 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); 807 sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1)));
782 808
783 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); 809 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100);
784 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); 810 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234);
785 bounds = filter2->filterBounds(bounds, SkMatrix::I()); 811 bounds = filter2->filterBounds(bounds, SkMatrix::I());
786 812
787 REPORTER_ASSERT(reporter, bounds == expectedBounds); 813 REPORTER_ASSERT(reporter, bounds == expectedBounds);
788 } 814 }
789 815
790 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { 816 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) {
791 sk_sp<SkImageFilter> filter1(makeBlur()); 817 sk_sp<SkImageFilter> filter1(make_blur(nullptr));
792 sk_sp<SkImageFilter> filter2(makeBlur()); 818 sk_sp<SkImageFilter> filter2(make_blur(nullptr));
793 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(fil ter1), 819 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(fil ter1),
794 std::move(fil ter2))); 820 std::move(fil ter2)));
795 821
796 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); 822 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
797 SkRect expectedBounds = SkRect::MakeXYWH( 823 SkRect expectedBounds = SkRect::MakeXYWH(
798 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar( 112)); 824 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar( 112));
799 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); 825 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc);
800 826
801 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); 827 REPORTER_ASSERT(reporter, boundsDst == expectedBounds);
802 } 828 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 run_raster_test(reporter, 100, test_imagefilter_merge_result_size); 873 run_raster_test(reporter, 100, test_imagefilter_merge_result_size);
848 } 874 }
849 875
850 #if SK_SUPPORT_GPU 876 #if SK_SUPPORT_GPU
851 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterMergeResultSize_Gpu, reporter, context ) { 877 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterMergeResultSize_Gpu, reporter, context ) {
852 run_gpu_test(reporter, context, 100, test_imagefilter_merge_result_size); 878 run_gpu_test(reporter, context, 100, test_imagefilter_merge_result_size);
853 } 879 }
854 #endif 880 #endif
855 881
856 static void draw_blurred_rect(SkCanvas* canvas) { 882 static void draw_blurred_rect(SkCanvas* canvas) {
857 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8 ), 0));
858 SkPaint filterPaint; 883 SkPaint filterPaint;
859 filterPaint.setColor(SK_ColorWHITE); 884 filterPaint.setColor(SK_ColorWHITE);
860 filterPaint.setImageFilter(filter); 885 filterPaint.setImageFilter(SkBlurImageFilter::Make(SkIntToScalar(8), 0, null ptr));
861 canvas->saveLayer(nullptr, &filterPaint); 886 canvas->saveLayer(nullptr, &filterPaint);
862 SkPaint whitePaint; 887 SkPaint whitePaint;
863 whitePaint.setColor(SK_ColorWHITE); 888 whitePaint.setColor(SK_ColorWHITE);
864 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); 889 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint);
865 canvas->restore(); 890 canvas->restore();
866 } 891 }
867 892
868 static void draw_picture_clipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) { 893 static void draw_picture_clipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) {
869 canvas->save(); 894 canvas->save();
870 canvas->clipRect(clipRect); 895 canvas->clipRect(clipRect);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 pixel = *bitmap.getAddr32(0, 0); 1190 pixel = *bitmap.getAddr32(0, 0);
1166 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1191 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1167 } 1192 }
1168 1193
1169 static void test_huge_blur(SkCanvas* canvas, skiatest::Reporter* reporter) { 1194 static void test_huge_blur(SkCanvas* canvas, skiatest::Reporter* reporter) {
1170 SkBitmap bitmap; 1195 SkBitmap bitmap;
1171 bitmap.allocN32Pixels(100, 100); 1196 bitmap.allocN32Pixels(100, 100);
1172 bitmap.eraseARGB(0, 0, 0, 0); 1197 bitmap.eraseARGB(0, 0, 0, 0);
1173 1198
1174 // Check that a blur with an insane radius does not crash or assert. 1199 // Check that a blur with an insane radius does not crash or assert.
1175 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(SkIntToScalar(1<< 30), SkIntToScalar(1<<30)));
1176
1177 SkPaint paint; 1200 SkPaint paint;
1178 paint.setImageFilter(blur); 1201 paint.setImageFilter(SkBlurImageFilter::Make(SkIntToScalar(1<<30),
1202 SkIntToScalar(1<<30),
1203 nullptr));
1179 canvas->drawBitmap(bitmap, 0, 0, &paint); 1204 canvas->drawBitmap(bitmap, 0, 0, &paint);
1180 } 1205 }
1181 1206
1182 DEF_TEST(HugeBlurImageFilter, reporter) { 1207 DEF_TEST(HugeBlurImageFilter, reporter) {
1183 SkBitmap temp; 1208 SkBitmap temp;
1184 temp.allocN32Pixels(100, 100); 1209 temp.allocN32Pixels(100, 100);
1185 SkCanvas canvas(temp); 1210 SkCanvas canvas(temp);
1186 test_huge_blur(&canvas, reporter); 1211 test_huge_blur(&canvas, reporter);
1187 } 1212 }
1188 1213
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 test_xfermode_cropped_input(&canvas, reporter); 1362 test_xfermode_cropped_input(&canvas, reporter);
1338 } 1363 }
1339 1364
1340 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, 1365 static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy,
1341 skiatest::Reporter* reporter, 1366 skiatest::Reporter* reporter,
1342 GrContext* context) { 1367 GrContext* context) {
1343 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) ); 1368 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) );
1344 1369
1345 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); 1370 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
1346 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, & cropRect)); 1371 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, & cropRect));
1347 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Sca lar1, 1372 sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Make(SK_Scalar1, SK_Scala r1,
1348 nullptr, &cropRect )); 1373 nullptr, &cropRect)) ;
1349 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu rFilter), 1374 sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blu rFilter),
1350 std::move(off setFilter))); 1375 std::move(off setFilter)));
1351 SkIPoint offset; 1376 SkIPoint offset;
1352 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); 1377 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr );
1353 1378
1354 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct x, &offset)); 1379 sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ct x, &offset));
1355 REPORTER_ASSERT(reporter, resultImg); 1380 REPORTER_ASSERT(reporter, resultImg);
1356 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); 1381 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
1357 } 1382 }
1358 1383
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 } 1465 }
1441 #endif 1466 #endif
1442 1467
1443 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { 1468 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
1444 1469
1445 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 1470 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
1446 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi ffuse( 1471 SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi ffuse(
1447 location, SK_ColorGREEN, 0, 0)); 1472 location, SK_ColorGREEN, 0, 0));
1448 REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); 1473 REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds());
1449 1474
1450 SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
1451 REPORTER_ASSERT(reporter, gray->canComputeFastBounds());
1452 { 1475 {
1453 SkColorFilter* grayCF; 1476 sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
1454 REPORTER_ASSERT(reporter, gray->asAColorFilter(&grayCF)); 1477 REPORTER_ASSERT(reporter, gray->canComputeFastBounds());
1455 REPORTER_ASSERT(reporter, !grayCF->affectsTransparentBlack()); 1478 {
1456 grayCF->unref(); 1479 SkColorFilter* grayCF;
1480 REPORTER_ASSERT(reporter, gray->asAColorFilter(&grayCF));
1481 REPORTER_ASSERT(reporter, !grayCF->affectsTransparentBlack());
1482 grayCF->unref();
1483 }
1484 REPORTER_ASSERT(reporter, gray->canComputeFastBounds());
1485
1486 sk_sp<SkImageFilter> grayBlur(SkBlurImageFilter::Make(SK_Scalar1, SK_Sca lar1,
1487 std::move(gray)));
1488 REPORTER_ASSERT(reporter, grayBlur->canComputeFastBounds());
1457 } 1489 }
1458 REPORTER_ASSERT(reporter, gray->canComputeFastBounds());
1459 1490
1460 SkAutoTUnref<SkImageFilter> grayBlur(SkBlurImageFilter::Create(SK_Scalar1, S K_Scalar1, gray.get())); 1491 {
1461 REPORTER_ASSERT(reporter, grayBlur->canComputeFastBounds()); 1492 SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0,
1493 0, 0, 0, 0, 1,
1494 0, 0, 0, 0, 0,
1495 0, 0, 0, 0, 1 };
1496 sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255( greenMatrix));
1497 sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get( )));
1462 1498
1463 SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0, 1499 REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
1464 0, 0, 0, 0, 1, 1500 REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
1465 0, 0, 0, 0, 0,
1466 0, 0, 0, 0, 1 };
1467 auto greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix));
1468 SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.g et()));
1469 1501
1470 REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack()); 1502 sk_sp<SkImageFilter> greenBlur(SkBlurImageFilter::Make(SK_Scalar1, SK_Sc alar1,
1471 REPORTER_ASSERT(reporter, !green->canComputeFastBounds()); 1503 std::move(green)) );
1472 1504 REPORTER_ASSERT(reporter, !greenBlur->canComputeFastBounds());
1473 SkAutoTUnref<SkImageFilter> greenBlur(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, green.get())); 1505 }
1474 REPORTER_ASSERT(reporter, !greenBlur->canComputeFastBounds());
1475 1506
1476 uint8_t allOne[256], identity[256]; 1507 uint8_t allOne[256], identity[256];
1477 for (int i = 0; i < 256; ++i) { 1508 for (int i = 0; i < 256; ++i) {
1478 identity[i] = i; 1509 identity[i] = i;
1479 allOne[i] = 255; 1510 allOne[i] = 255;
1480 } 1511 }
1481 1512
1482 auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, a llOne)); 1513 auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, a llOne));
1483 SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create( identityCF.get())); 1514 SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create( identityCF.get()));
1484 REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack()); 1515 REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 ERRORF(reporter, "Failed to create large image."); 1569 ERRORF(reporter, "Failed to create large image.");
1539 return; 1570 return;
1540 } 1571 }
1541 1572
1542 sk_sp<SkImageFilter> largeSource(SkImageSource::Make(std::move(largeImage))) ; 1573 sk_sp<SkImageFilter> largeSource(SkImageSource::Make(std::move(largeImage))) ;
1543 if (!largeSource) { 1574 if (!largeSource) {
1544 ERRORF(reporter, "Failed to create large SkImageSource."); 1575 ERRORF(reporter, "Failed to create large SkImageSource.");
1545 return; 1576 return;
1546 } 1577 }
1547 1578
1548 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, largeSource. get())); 1579 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(10.f, 10.f, std::move(larg eSource)));
1549 if (!blur) { 1580 if (!blur) {
1550 ERRORF(reporter, "Failed to create SkBlurImageFilter."); 1581 ERRORF(reporter, "Failed to create SkBlurImageFilter.");
1551 return; 1582 return;
1552 } 1583 }
1553 1584
1554 SkPaint paint; 1585 SkPaint paint;
1555 paint.setImageFilter(std::move(blur)); 1586 paint.setImageFilter(std::move(blur));
1556 1587
1557 // This should not crash (http://crbug.com/570479). 1588 // This should not crash (http://crbug.com/570479).
1558 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); 1589 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 1623
1593 test_xfermode_cropped_input(&canvas, reporter); 1624 test_xfermode_cropped_input(&canvas, reporter);
1594 } 1625 }
1595 1626
1596 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1627 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1597 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, 1628 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
1598 SkImageInfo::MakeN32Premul(100, 100 ))); 1629 SkImageInfo::MakeN32Premul(100, 100 )));
1599 test_large_blur_input(reporter, surface->getCanvas()); 1630 test_large_blur_input(reporter, surface->getCanvas());
1600 } 1631 }
1601 #endif 1632 #endif
OLDNEW
« no previous file with comments | « src/utils/SkLua.cpp ('k') | tests/RecordOptsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698