OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if (!cropRect) { | 185 if (!cropRect) { |
186 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( | 186 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( |
187 matrix, kLow_SkFilterQuality, input)); | 187 matrix, kLow_SkFilterQuality, input)); |
188 } | 188 } |
189 this->addFilter("blur and offset", SkOffsetImageFilter::Create( | 189 this->addFilter("blur and offset", SkOffsetImageFilter::Create( |
190 five, five, blur.get(), cropRect)); | 190 five, five, blur.get(), cropRect)); |
191 this->addFilter("picture and blur", SkBlurImageFilter::Create( | 191 this->addFilter("picture and blur", SkBlurImageFilter::Create( |
192 five, five, pictureFilter.get(), cropRect)); | 192 five, five, pictureFilter.get(), cropRect)); |
193 this->addFilter("paint and blur", SkBlurImageFilter::Create( | 193 this->addFilter("paint and blur", SkBlurImageFilter::Create( |
194 five, five, paintFilter.get(), cropRect)); | 194 five, five, paintFilter.get(), cropRect)); |
195 this->addFilter("xfermode", SkXfermodeImageFilter::Create( | 195 this->addFilter("xfermode", SkXfermodeImageFilter::Make( |
196 SkXfermode::Create(SkXfermode::kSrc_Mode), input, input, cropRect)); | 196 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel
ease()); |
197 } | 197 } |
198 int count() const { return fFilters.count(); } | 198 int count() const { return fFilters.count(); } |
199 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g
et(); } | 199 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g
et(); } |
200 const char* getName(int index) const { return fFilters[index].fName; } | 200 const char* getName(int index) const { return fFilters[index].fName; } |
201 private: | 201 private: |
202 struct Filter { | 202 struct Filter { |
203 Filter() : fName(nullptr), fFilter(nullptr) {} | 203 Filter() : fName(nullptr), fFilter(nullptr) {} |
204 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f
ilter) {} | 204 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f
ilter) {} |
205 const char* fName; | 205 const char* fName; |
206 sk_sp<SkImageFilter> fFilter; | 206 sk_sp<SkImageFilter> fFilter; |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); | 793 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); |
794 | 794 |
795 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); | 795 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
796 } | 796 } |
797 | 797 |
798 DEF_TEST(ImageFilterUnionBounds, reporter) { | 798 DEF_TEST(ImageFilterUnionBounds, reporter) { |
799 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0)); | 799 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0)); |
800 // Regardless of which order they appear in, the image filter bounds should | 800 // Regardless of which order they appear in, the image filter bounds should |
801 // be combined correctly. | 801 // be combined correctly. |
802 { | 802 { |
803 SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create( | 803 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offs
et.get())); |
804 nullptr, offset.get(), nullptr)); | |
805 SkRect bounds = SkRect::MakeWH(100, 100); | 804 SkRect bounds = SkRect::MakeWH(100, 100); |
806 // Intentionally aliasing here, as that's what the real callers do. | 805 // Intentionally aliasing here, as that's what the real callers do. |
807 bounds = composite->computeFastBounds(bounds); | 806 bounds = composite->computeFastBounds(bounds); |
808 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); | 807 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); |
809 } | 808 } |
810 { | 809 { |
811 SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create( | 810 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, null
ptr, |
812 nullptr, nullptr, offset.get())); | 811 offset.get(),
nullptr)); |
813 SkRect bounds = SkRect::MakeWH(100, 100); | 812 SkRect bounds = SkRect::MakeWH(100, 100); |
814 // Intentionally aliasing here, as that's what the real callers do. | 813 // Intentionally aliasing here, as that's what the real callers do. |
815 bounds = composite->computeFastBounds(bounds); | 814 bounds = composite->computeFastBounds(bounds); |
816 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); | 815 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); |
817 } | 816 } |
818 } | 817 } |
819 | 818 |
820 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, | 819 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, |
821 skiatest::Reporter* reporter, | 820 skiatest::Reporter* reporter, |
822 GrContext* context) { | 821 GrContext* context) { |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 bitmap.eraseARGB(255, 255, 255, 255); | 1243 bitmap.eraseARGB(255, 255, 255, 255); |
1245 | 1244 |
1246 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_M
ode)); | 1245 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_M
ode)); |
1247 SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(gre
en.get())); | 1246 SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(gre
en.get())); |
1248 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); | 1247 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); |
1249 SkAutoTUnref<SkImageFilter> croppedOut( | 1248 SkAutoTUnref<SkImageFilter> croppedOut( |
1250 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect)); | 1249 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect)); |
1251 | 1250 |
1252 // Check that an xfermode image filter whose input has been cropped out stil
l draws the other | 1251 // Check that an xfermode image filter whose input has been cropped out stil
l draws the other |
1253 // input. Also check that drawing with both inputs cropped out doesn't cause
a GPU warning. | 1252 // input. Also check that drawing with both inputs cropped out doesn't cause
a GPU warning. |
1254 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcOver_Mode); | 1253 auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode); |
1255 SkAutoTUnref<SkImageFilter> xfermodeNoFg( | 1254 auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut,
nullptr)); |
1256 SkXfermodeImageFilter::Create(mode, greenFilter, croppedOut)); | 1255 auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter,
nullptr)); |
1257 SkAutoTUnref<SkImageFilter> xfermodeNoBg( | 1256 auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedO
ut, nullptr)); |
1258 SkXfermodeImageFilter::Create(mode, croppedOut, greenFilter)); | |
1259 SkAutoTUnref<SkImageFilter> xfermodeNoFgNoBg( | |
1260 SkXfermodeImageFilter::Create(mode, croppedOut, croppedOut)); | |
1261 | 1257 |
1262 SkPaint paint; | 1258 SkPaint paint; |
1263 paint.setImageFilter(xfermodeNoFg); | 1259 paint.setImageFilter(xfermodeNoFg); |
1264 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite | 1260 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite |
1265 | 1261 |
1266 uint32_t pixel; | 1262 uint32_t pixel; |
1267 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul
_SkAlphaType); | 1263 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul
_SkAlphaType); |
1268 canvas->readPixels(info, &pixel, 4, 0, 0); | 1264 canvas->readPixels(info, &pixel, 4, 0, 0); |
1269 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); | 1265 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
1270 | 1266 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 | 1588 |
1593 test_xfermode_cropped_input(&canvas, reporter); | 1589 test_xfermode_cropped_input(&canvas, reporter); |
1594 } | 1590 } |
1595 | 1591 |
1596 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1592 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
1597 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, | 1593 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
1598 SkImageInfo::MakeN32Premul(100, 100
))); | 1594 SkImageInfo::MakeN32Premul(100, 100
))); |
1599 test_large_blur_input(reporter, surface->getCanvas()); | 1595 test_large_blur_input(reporter, surface->getCanvas()); |
1600 } | 1596 } |
1601 #endif | 1597 #endif |
OLD | NEW |